gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:17:58 28 4
gpt4 key购买 nike

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

textcat.add_label("pos")
产生了警告:
在'(Doc) -> Doc | 中找不到引用'add_label' (Doc) -> Doc'
我知道这是因为“ nlp.create_pipe() ”生成了一个 Doc 而不是字符串,但是(主要是因为我不知道在这种情况下该怎么做!)我还是运行了脚本,但是然后我从这一行得到了一个错误:
textcat = nlp.create_pipe("textcat", config={"architecture": "simple_cnn"})
错误消息:
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'}
我正在使用:
  • Pycharm 诉:2019.3.4
  • python v: 3.8.6
  • spaCy v:3.0.5
  • 最佳答案

    男人!完整的 spaCy 升级是否真的消除了该教程或什么......
    有几件事你可能可以解决。我还没有完全修复那个损坏的教程。它在待办事项列表中。但是,我确实解决了您遇到的确切问题。

    textcat = nlp.create_pipe("textcat", config={"architecture": "simple_cnn"})
    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")
    让我知道这是否有意义并有帮助。在接下来的几周内,我将尝试完全从 spaCy 修改教程。

    关于python - textcat -> 不允许架构额外字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66790649/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com