explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
30.12k stars 4.4k forks source link

Can't find factory for 'relation_extractor' for language English (en) #12957

Closed Gowdasuma closed 1 year ago

Gowdasuma commented 1 year ago

Hi Team, am not able to load the model, showing factory for 'relation_extractor' for language English (en) issue. i'm using Jupyter notebook.

import spacy nlp = spacy.load("rel_component/training/model-best") nlp

ValueError Traceback (most recent call last) Cell In[2], line 2 1 import spacy ----> 2 nlp = spacy.load("rel_component/training/model-best") 3 nlp

File ~\AppData\Local\anaconda3\lib\site-packages\spacy__init__.py:51, in load(name, vocab, disable, enable, exclude, config) 27 def load( 28 name: Union[str, Path], 29 *, (...) 34 config: Union[Dict[str, Any], Config] = util.SimpleFrozenDict(), 35 ) -> Language: 36 """Load a spaCy model from an installed package or a local path. 37 38 name (str): Package name or model path. (...) 49 RETURNS (Language): The loaded nlp object. 50 """ ---> 51 return util.load_model( 52 name, 53 vocab=vocab, 54 disable=disable, 55 enable=enable, 56 exclude=exclude, 57 config=config, 58 )

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\util.py:467, in load_model(name, vocab, disable, enable, exclude, config) 465 return load_model_from_package(name, kwargs) # type: ignore[arg-type] 466 if Path(name).exists(): # path to model data directory --> 467 return load_model_from_path(Path(name), kwargs) # type: ignore[arg-type] 468 elif hasattr(name, "exists"): # Path or Path-like to model data 469 return load_model_from_path(name, **kwargs) # type: ignore[arg-type]

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\util.py:539, in load_model_from_path(model_path, meta, vocab, disable, enable, exclude, config) 537 overrides = dict_to_dot(config, for_overrides=True) 538 config = load_config(config_path, overrides=overrides) --> 539 nlp = load_model_from_config( 540 config, 541 vocab=vocab, 542 disable=disable, 543 enable=enable, 544 exclude=exclude, 545 meta=meta, 546 ) 547 return nlp.from_disk(model_path, exclude=exclude, overrides=overrides)

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\util.py:587, in load_model_from_config(config, meta, vocab, disable, enable, exclude, auto_fill, validate) 584 # This will automatically handle all codes registered via the languages 585 # registry, including custom subclasses provided via entry points 586 lang_cls = get_lang_class(nlp_config["lang"]) --> 587 nlp = lang_cls.from_config( 588 config, 589 vocab=vocab, 590 disable=disable, 591 enable=enable, 592 exclude=exclude, 593 auto_fill=auto_fill, 594 validate=validate, 595 meta=meta, 596 ) 597 return nlp

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\language.py:1847, in Language.from_config(cls, config, vocab, disable, enable, exclude, meta, auto_fill, validate) 1844 factory = pipe_cfg.pop("factory") 1845 # The pipe name (key in the config) here is the unique name 1846 # of the component, not necessarily the factory -> 1847 nlp.add_pipe( 1848 factory, 1849 name=pipe_name, 1850 config=pipe_cfg, 1851 validate=validate, 1852 raw_config=raw_config, 1853 ) 1854 else: 1855 assert "source" in pipe_cfg

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\language.py:814, in Language.add_pipe(self, factory_name, name, before, after, first, last, source, config, raw_config, validate) 810 pipe_component, factory_name = self.create_pipe_from_source( 811 factory_name, source, name=name 812 ) 813 else: --> 814 pipe_component = self.create_pipe( 815 factory_name, 816 name=name, 817 config=config, 818 raw_config=raw_config, 819 validate=validate, 820 ) 821 pipe_index = self._get_pipe_index(before, after, first, last) 822 self._pipe_meta[name] = self.get_factory_meta(factory_name)

File ~\AppData\Local\anaconda3\lib\site-packages\spacy\language.py:683, in Language.create_pipe(self, factory_name, name, config, raw_config, validate) 675 if not self.has_factory(factory_name): 676 err = Errors.E002.format( 677 name=factory_name, 678 opts=", ".join(self.factory_names), (...) 681 lang_code=self.lang, 682 ) --> 683 raise ValueError(err) 684 pipe_meta = self.get_factory_meta(factory_name) 685 # This is unideal, but the alternative would mean you always need to 686 # specify the full config settings, which is not really viable.

ValueError: [E002] Can't find factory for 'relation_extractor' for language English (en). This usually happens when spaCy calls nlp.create_pipe with a custom component name that's not registered on the current language class. If you're using a Transformer, make sure to install 'spacy-transformers'. If you're using a custom component, make sure you've added the decorator @Language.component (for function components) or @Language.factory (for class components).

Available factories: attribute_ruler, tok2vec, merge_noun_chunks, merge_entities, merge_subtokens, token_splitter, doc_cleaner, parser, beam_parser, lemmatizer, trainable_lemmatizer, entity_linker, entity_ruler, tagger, morphologizer, ner, beam_ner, senter, sentencizer, spancat, spancat_singlelabel, span_finder, future_entity_ruler, span_ruler, textcat, textcat_multilabel, en.lemmatizer

Your Environment

svlandeg commented 1 year ago

Let me move this to the discussion forum...