textcat -> 不允许架构额外字段

Ami*_*ira 7 python data-analysis pycharm spacy

我一直在尝试使用 PyCharm 练习从本教程中学到的知识:( https://realpython.com/sentiment-analysis-python/ )。

还有这一行:

textcat.add_label("pos")
Run Code Online (Sandbox Code Playgroud)

生成警告: 无法在“(Doc) -> Doc | ”中找到引用“add_label” (文档)-> 文档'

我知道这是因为“ nlp.create_pipe() ”生成一个文档而不是字符串,但是(本质上是因为我不知道在这种情况下该怎么做!)无论如何我都运行了脚本,但后来我得到了一个错误从这一行:

textcat = nlp.create_pipe("textcat", config={"architecture": "simple_cnn"})
Run Code Online (Sandbox Code Playgroud)

错误消息:

raise ConfigValidationError(
thinc.config.ConfigValidationError:

Config validation error

textcat -> architecture extra fields not permitted

{'nlp': <spacy.lang.en.English object at 0x0000015E74F625E0>, 'name': 'textcat', 'architecture': 'simple_cnn', 'model': {'@architectures': 'spacy.TextCatEnsemble.v2', 'linear_model': {'@architectures': 'spacy.TextCatBOW.v1', 'exclusive_classes': True, 'ngram_size': 1, 'no_output_layer': False}, 'tok2vec': {'@architectures': 'spacy.Tok2Vec.v2', 'embed': {'@architectures': 'spacy.MultiHashEmbed.v1', 'width': 64, 'rows': [2000, 2000, 1000, 1000, 1000, 1000], 'attrs': ['ORTH', 'LOWER', 'PREFIX', 'SUFFIX', 'SHAPE', 'ID'], 'include_static_vectors': False}, 'encode': {'@architectures': 'spacy.MaxoutWindowEncoder.v2', 'width': 64, 'window_size': 1, 'maxout_pieces': 3, 'depth': 2}}}, 'threshold': 0.5, '@factories': 'textcat'}
Run Code Online (Sandbox Code Playgroud)

我在用着:

  • Pycharm v:2019.3.4
  • 蟒蛇五:3.8.6
  • spaCy v:3.0.5

jla*_*s32 6

男人!完整的 spaCy 升级是否真的删除了该教程或者什么......

您可能可以解决一些问题。我还没有完全修复那个损坏的教程。它在待办事项清单上。不过,我确实解决了您遇到的确切问题。

textcat = nlp.create_pipe("textcat", config={"architecture": "simple_cnn"})
Run Code Online (Sandbox Code Playgroud)

create_pipe行为已被弃用,因此您可以直接使用add_pipe. 所以你可以做的一件事如下:

from spacy.pipeline.textcat import single_label_cnn_config

<more good code>

nlp = spacy.load("en_core_web_trf")
if "textcat" not in nlp.pipe_names:
     nlp.add_pipe('textcat', config=single_label_cnn_config, last=True)
textcat = nlp.get_pipe('textcat')
textcat.add_label("pos")
textcat.add_label("neg")
Run Code Online (Sandbox Code Playgroud)

让我知道这是否有意义并且有帮助。在接下来的几周内,我将尝试完全从 spaCy 修改该教程。

  • 您好,我尝试使用您的 add_pipe 解决方案,但出现以下错误(Spacy 3.0.6): ValueError: [E962] 收到管道“textcat”的错误配置。预期的字典,得到:&lt;class 'str'&gt;。 (3认同)

Ami*_*ira 3

感谢@polm23,整个问题是因为我使用的 spaCy 版本比本教程的作者更新。

我的:3.0.5 作者:2.3.2

目前,我刚刚降级了我的 spacy,以便能够跟进本教程。