forked from huggingface/neuralcoref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove support for Python 2 (huggingface#233)
* remove support for python <= 3.6 * removing python2-compat future imports and utf8 declarations * version bump to 4.1.0 * formatting with black for uniformity * remove u strings, add f strings * more u strings to remove * remove 2.7 from Travis CI
- Loading branch information
Showing
17 changed files
with
1,999 additions
and
970 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,44 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, absolute_import | ||
|
||
import os | ||
import shutil | ||
import tarfile | ||
import tempfile | ||
import logging | ||
|
||
# Filter Cython warnings that would force everybody to re-compile from source (like https://github.com/numpy/numpy/pull/432). | ||
import warnings | ||
|
||
warnings.filterwarnings("ignore", message="spacy.strings.StringStore size changed") | ||
|
||
from neuralcoref.neuralcoref import NeuralCoref | ||
from neuralcoref.file_utils import NEURALCOREF_MODEL_URL, NEURALCOREF_MODEL_PATH, NEURALCOREF_CACHE, cached_path | ||
from neuralcoref.file_utils import ( | ||
NEURALCOREF_MODEL_URL, | ||
NEURALCOREF_MODEL_PATH, | ||
NEURALCOREF_CACHE, | ||
cached_path, | ||
) | ||
|
||
__all__ = ['NeuralCoref', 'add_to_pipe'] | ||
__version__ = "4.0.0" | ||
__all__ = ["NeuralCoref", "add_to_pipe"] | ||
__version__ = "4.1.0" | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
if os.path.exists(NEURALCOREF_MODEL_PATH) and os.path.exists(os.path.join(NEURALCOREF_MODEL_PATH, "cfg")): | ||
logger.info("Loading model from {}".format(NEURALCOREF_MODEL_PATH)) | ||
if os.path.exists(NEURALCOREF_MODEL_PATH) and os.path.exists( | ||
os.path.join(NEURALCOREF_MODEL_PATH, "cfg") | ||
): | ||
logger.info(f"Loading model from {NEURALCOREF_MODEL_PATH}") | ||
local_model = cached_path(NEURALCOREF_MODEL_PATH) | ||
else: | ||
if not os.path.exists(NEURALCOREF_MODEL_PATH): | ||
os.makedirs(NEURALCOREF_MODEL_PATH) | ||
logger.info("Getting model from {} or cache".format(NEURALCOREF_MODEL_URL)) | ||
logger.info(f"Getting model from {NEURALCOREF_MODEL_URL} or cache") | ||
downloaded_model = cached_path(NEURALCOREF_MODEL_URL) | ||
|
||
logger.info("extracting archive file {} to dir {}".format(downloaded_model, NEURALCOREF_MODEL_PATH)) | ||
with tarfile.open(downloaded_model, 'r:gz') as archive: | ||
logger.info( | ||
f"extracting archive file {downloaded_model} to dir {NEURALCOREF_MODEL_PATH}" | ||
) | ||
with tarfile.open(downloaded_model, "r:gz") as archive: | ||
archive.extractall(NEURALCOREF_CACHE) | ||
|
||
|
||
def add_to_pipe(nlp, **kwargs): | ||
coref = NeuralCoref(nlp.vocab, **kwargs) | ||
nlp.add_pipe(coref, name='neuralcoref') | ||
nlp.add_pipe(coref, name="neuralcoref") | ||
return nlp |
Oops, something went wrong.