Skip to content

Commit

Permalink
fix: update spacy patch & remove ineffective and buggy registry override
Browse files Browse the repository at this point in the history
  • Loading branch information
percevalw committed Dec 13, 2023
1 parent d14d4d0 commit a1107ba
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions edsnlp/patch_spacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(
max_length: int = 10**6,
meta: Dict[str, Any] = {},
create_tokenizer: Optional[Callable[["Language"], Callable[[str], Doc]]] = None,
create_vectors: Optional[Callable[["Vocab"], Any]] = None,
batch_size: int = 1000,
**kwargs,
) -> None:
Expand All @@ -139,12 +140,6 @@ def __init__(
DOCS: https://spacy.io/api/language#init
"""

# EDS-NLP: disable spacy default call to load every factory
# since some of them may be missing dependencies (like torch)
# util.registry._entry_point_factories.get_all()
util.registry.factories = util.registry._entry_point_factories

self._config = DEFAULT_CONFIG.merge(self.default_config)
self._meta = dict(meta)
self._path = None
Expand All @@ -158,21 +153,23 @@ def __init__(
if vocab is True:
vectors_name = meta.get("vectors", {}).get("name")
vocab = create_vocab(self.lang, self.Defaults, vectors_name=vectors_name)
if (self.lang and vocab.lang) and (self.lang != vocab.lang):
raise ValueError(Errors.E150.format(nlp=self.lang, vocab=vocab.lang))
if not create_vectors and "@vectors" in self._config["nlp"]["vectors"]:
vectors_cfg = {"vectors": self._config["nlp"]["vectors"]}
create_vectors = registry.resolve(vectors_cfg)["vectors"]
vocab.vectors = create_vectors(vocab)
else:
if (self.lang and vocab.lang) and (self.lang != vocab.lang):
raise ValueError(Errors.E150.format(nlp=self.lang, vocab=vocab.lang))
self.vocab: Vocab = vocab
if self.lang is None:
self.lang = self.vocab.lang
self._components: List[Tuple[str, Callable[[Doc], Doc]]] = []
self._disabled: Set[str] = set()
self.max_length = max_length
# Create the default tokenizer from the default config
create_tokenizer = (
create_tokenizer
or registry.resolve({"tokenizer": self._config["nlp"]["tokenizer"]})[
"tokenizer"
]
)
if not create_tokenizer:
tokenizer_cfg = {"tokenizer": self._config["nlp"]["tokenizer"]}
create_tokenizer = registry.resolve(tokenizer_cfg)["tokenizer"]
self.tokenizer = create_tokenizer(self)
self.batch_size = batch_size
self.default_error_handler = raise_error
Expand Down

0 comments on commit a1107ba

Please sign in to comment.