首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能加载spacy en_core_web_trf

不能加载spacy en_core_web_trf
EN

Stack Overflow用户
提问于 2021-10-01 13:32:50
回答 3查看 6.4K关注 0票数 7

正如自我向导说的,我已经安装了(conda环境)

代码语言:javascript
复制
conda install -c conda-forge spacy
python -m spacy download en_core_web_trf

我已经安装了spacy-transformers。但当我这么做的时候

代码语言:javascript
复制
import spacy
spacy.load("en_core_web_trf")

它向我展示了这个错误:

代码语言:javascript
复制
ValueError: [E002] Can't find factory for 'transformer' 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, parser, beam_parser, entity_linker, ner, beam_ner, entity_ruler, lemmatizer, tagger, morphologizer, senter, sentencizer, textcat, spancat, textcat_multilabel, en.lemmatizer

有关错误的更多信息:

代码语言:javascript
复制
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11108/2648447056.py in <module>
----> 1 nlp_en = spacy.load("en_core_web_trf")

~\Anaconda3\envs\rl\lib\site-packages\spacy\__init__.py in load(name, vocab, disable, exclude, config)
     49     RETURNS (Language): The loaded nlp object.
     50     """
---> 51     return util.load_model(
     52         name, vocab=vocab, disable=disable, exclude=exclude, config=config
     53     )

~\Anaconda3\envs\rl\lib\site-packages\spacy\util.py in load_model(name, vocab, disable, exclude, config)
    345             return get_lang_class(name.replace("blank:", ""))()
    346         if is_package(name):  # installed as package
--> 347             return load_model_from_package(name, **kwargs)
    348         if Path(name).exists():  # path to model data directory
    349             return load_model_from_path(Path(name), **kwargs)

~\Anaconda3\envs\rl\lib\site-packages\spacy\util.py in load_model_from_package(name, vocab, disable, exclude, config)
    378     """
    379     cls = importlib.import_module(name)
--> 380     return cls.load(vocab=vocab, disable=disable, exclude=exclude, config=config)
    381 
    382 

~\Anaconda3\envs\rl\lib\site-packages\en_core_web_trf\__init__.py in load(**overrides)
      8 
      9 def load(**overrides):
---> 10     return load_model_from_init_py(__file__, **overrides)

~\Anaconda3\envs\rl\lib\site-packages\spacy\util.py in load_model_from_init_py(init_file, vocab, disable, exclude, config)
    538     if not model_path.exists():
    539         raise IOError(Errors.E052.format(path=data_path))
--> 540     return load_model_from_path(
    541         data_path,
    542         vocab=vocab,

~\Anaconda3\envs\rl\lib\site-packages\spacy\util.py in load_model_from_path(model_path, meta, vocab, disable, exclude, config)
    413     overrides = dict_to_dot(config)
    414     config = load_config(config_path, overrides=overrides)
--> 415     nlp = load_model_from_config(config, vocab=vocab, disable=disable, exclude=exclude)
    416     return nlp.from_disk(model_path, exclude=exclude, overrides=overrides)
    417 

~\Anaconda3\envs\rl\lib\site-packages\spacy\util.py in load_model_from_config(config, vocab, disable, exclude, auto_fill, validate)
    450     # registry, including custom subclasses provided via entry points
    451     lang_cls = get_lang_class(nlp_config["lang"])
--> 452     nlp = lang_cls.from_config(
    453         config,
    454         vocab=vocab,

~\Anaconda3\envs\rl\lib\site-packages\spacy\language.py in from_config(cls, config, vocab, disable, exclude, meta, auto_fill, validate)
   1712                     # The pipe name (key in the config) here is the unique name
   1713                     # of the component, not necessarily the factory
-> 1714                     nlp.add_pipe(
   1715                         factory,
   1716                         name=pipe_name,

~\Anaconda3\envs\rl\lib\site-packages\spacy\language.py in add_pipe(self, factory_name, name, before, after, first, last, source, config, raw_config, validate)
    774                     lang_code=self.lang,
    775                 )
--> 776             pipe_component = self.create_pipe(
    777                 factory_name,
    778                 name=name,

~\Anaconda3\envs\rl\lib\site-packages\spacy\language.py in create_pipe(self, factory_name, name, config, raw_config, validate)
    639                 lang_code=self.lang,
    640             )
--> 641             raise ValueError(err)
    642         pipe_meta = self.get_factory_meta(factory_name)
    643         # This is unideal, but the alternative would mean you always need to
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-10-01 23:49:20

你确定你安装了空间变压器吗?在安装spacy之后?

我正在使用pip: pip安装spacy变压器,并且我在加载en_core_web_trf时没有问题。

票数 7
EN

Stack Overflow用户

发布于 2022-06-05 17:23:05

对于那些尝试过这个解决方案但仍然没有成功的人来说。他们没有提到(因为这是微不足道的)但让我盯着它看了很久的事情是

代码语言:javascript
复制
!pip install spacy-transformers

你还得把

代码语言:javascript
复制
import spacy_transformers

在你的代码顶端。

票数 3
EN

Stack Overflow用户

发布于 2022-04-24 01:17:33

代码语言:javascript
复制
# !pip install spacy
# !pip install spacy-transformers
# !python3 -m spacy download en_core_web_trf

它很好,如果你在google工作,请使用下面这个

代码语言:javascript
复制
# !pip install spacy==(last version of spacy(3.2.4)) 

其余都是相同的,colab下载旧版本。希望你能得到答案!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69406767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档