【问题标题】:doc.vector not working after loading from stored model in spacy从 spacy 中的存储模型加载后,doc.vector 不起作用
【发布时间】:2017-09-09 17:47:16
【问题描述】:

我已经训练了以下模型 https://github.com/explosion/spaCy/blob/master/examples/training/train_new_entity_type.py

我将它保存到某个目录,然后再次加载和使用它。但是当我尝试访问 doc.vector 时加载它后,它会抛出以下错误。

 Traceback (most recent call last):
  File "C:/Users/ankita.a.rath/Desktop/my_codes/Rasa_nlu/rasa_nlu-master/train_spacy_ner.py", line 248, in <module>
    main("en", "new_model")
  File "C:/Users/ankita.a.rath/Desktop/my_codes/Rasa_nlu/rasa_nlu-master/train_spacy_ner.py", line 238, in main
    print (doc2.vector)
  File "spacy/tokens/doc.pyx", line 275, in spacy.tokens.doc.Doc.vector.__get__ (spacy/tokens/doc.cpp:7291)
    self._vector = sum(t.vector for t in self) / len(self)
  File "spacy/tokens/doc.pyx", line 275, in genexpr (spacy/tokens/doc.cpp:7114)
    self._vector = sum(t.vector for t in self) / len(self)
  File "spacy/tokens/token.pyx", line 240, in spacy.tokens.token.Token.vector.__get__ (spacy/tokens/token.cpp:7249)
    raise ValueError(
ValueError: Word vectors set to length 0. This may be because you don't have a model installed or loaded, or because your model doesn't include word vectors. For more info, see the documentation: 
https://spacy.io/docs/usage

关于我的环境的信息。

Python 版本:2.7.13

平台:Windows-10

spaCy 版本:1.9.0

已安装型号:zh

请提出一些解决方案。

【问题讨论】:

    标签: python windows spacy rasa-nlu


    【解决方案1】:

    抱歉,如果您出于特定原因使用 Spacy NER,我可能不会最有帮助地回答您的问题。然而,在 Rasa 中使用的 Spacy NER 旨在与 built in Entities 一起使用。请参阅ner_spacy here 上的 Rasa 文档。特别是这条评论:

    截至目前,该组件只能使用 spacy 内置的实体提取模型,无法重新训练。

    在 Rasa 中训练实体是使用 ner_mitiener_crf 管道组件完成的。

    Rasa 有完整的Getting started 指南。

    例如,要开始使用 ner_crf,您最适合使用 spacy_sklearn pre-built 管道。

    git clone https://github.com/RasaHQ/rasa_nlu.git
    cd rasa_nlu
    pip install -r requirements.txt
    python setup.py install
    pip install -U spacy
    python -m spacy download en
    conda install scikit-learn
    pip install -U sklearn-crfsuite
    

    所有这些都完成后,您就可以启动 Rasa 服务器了:

    python -m rasa_nlu.server -c sample_configs/config_spacy.json
    

    并使用HTTP API 来训练和解析数据。

    curl -XPOST localhost:5000/train?name=my_project -d @data/examples/rasa/demo-rasa.json
    curl -XPOST localhost:5000/parse -d '{"q":"hello there", "project": "my_project"}
    

    如果您在 Github 上需要任何进一步的帮助 create an issuejoin us on Gitter。我会提到,Windows 会使事情变得复杂,您最好在 Docker 或 unix VM 上尝试 Rasa。

    【讨论】:

    • ner_crf 没有给出正确的结果,所以我正在训练 spacy。
    【解决方案2】:

    我认为当我们保存模型时,向量没有被保存。 我找不到任何直接的解决方案,所以我正在做的是,我将向量单独存储,然后在加载模型后加载它。

    它解决了我的问题。关闭这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-01
      相关资源
      最近更新 更多