无法预测在python中使用rasa_nlu

时间:2017-09-04 11:56:21

标签: python anaconda rasa-nlu

我正在尝试复制样本餐馆搜索。我在Windows 64 / python 3.6 Anaconda 4.4上运行它。我的config.json看起来像这样。

    {
      "name": null,
      "pipeline": ["nlp_spacy", "tokenizer_spacy", "intent_entity_featurizer_regex", "intent_featurizer_spacy", "ner_crf", "ner_synonyms",  "intent_classifier_sklearn"],
      "language": "en",
      "num_threads": 4,
      "path": "D:/rasa-nlu-working/models",
      "response_log": "logs",
      "config": "config.json",
      "log_level": "INFO",
      "port": 5000,
      "data": null,
      "emulate": null,
      "log_file": null,
      "mitie_file": "data/total_word_feature_extractor.dat",
      "spacy_model_name": null,
      "server_model_dirs": null,
      "token": null,
      "max_number_of_ngrams": 7,
      "duckling_dimensions": ["time", "number", "money","ordinal","duration"],
      "entity_crf_BILOU_flag": true,
      "entity_crf_features": [
        ["low", "title", "upper", "pos", "pos2"],
        ["bias", "low", "word3", "word2", "upper", "title", "digit", "pos", "pos2", "pattern"],
        ["low", "title", "upper", "pos", "pos2"]]
    }

我正在尝试使用jupyter笔记本进行训练和预测。火车步骤顺利进行。正如预期的模型一样。但是当我尝试使用以下代码进行预测时。

from rasa_nlu.model import Metadata, Interpreter

# where `model_directory points to the folder the model is persisted in
interpreter = Interpreter.load('D:/rasa-nlu-working/models/model_20170904-132507', RasaNLUConfig("D:/rasa-nlu-working/config.json"))

我收到以下错误。

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-9f85d157325d> in <module>()
      4 
      5 # where `model_directory points to the folder the model is persisted in
----> 6 interpreter = Interpreter.load('D:/rasa-nlu-working/models/model_20170904-132507', RasaNLUConfig("D:/rasa-nlu-working/config.json"))

D:\Anaconda3\lib\site-packages\rasa_nlu\model.py in load(model_metadata, config, component_builder, skip_valdation)
    206         # Before instantiating the component classes, lets check if all required packages are available
    207         if not skip_valdation:
--> 208             components.validate_requirements(model_metadata.pipeline)
    209 
    210         for component_name in model_metadata.pipeline:

AttributeError: 'str' object has no attribute 'pipeline'

但是当我在HTTP服务器模式下运行时,相同的配置工作正常。请帮助我解决问题。

2 个答案:

答案 0 :(得分:2)

我在评论中要求澄清一些,但我想我会开始写答案。

您发布的错误实际上不是配置文件的问题。看起来像metadata.json没有被正确加载和/或解析。 metadata.json有点像模型训练时配置文件的快照。

这是操作的顺序:

  1. 无论何时调用Interpreter.load,首先要做的事情之一就是加载metadata.json文件。 See here.
  2. 接下来在Metadata.load中我们尝试加载并解析该文件。 See here
  3. 回到Interpreter中,我们尝试从返回的元数据中获取管道。 See here.
  4. 发生错误的地方。由于某种原因,metadata.json文件加载时没有错误,但是没有正确解析。

    一些可能的错误:

    • metadata.json是格式不正确的JSON。不知道会发生什么,但你能不能提供metadata.json,以便我们查看。
    • Windows编码问题无法正确处理。

    另外,您特别提到了http API。 http API可以加载此模型并使用它来解析吗?在您启动服务器之后,您应该可以调用以下内容进行测试。

    curl -XPOST localhost:5000/parse -d '{"q":"hello there", "model": "model_20170904-132507"}'
    

    如果HTTP服务器可以加载/解析它,那么我们知道它可能是你的python代码中的特定内容。

    相反,如果可行,那么您应该尝试使用http API训练数据,并通过http api与您的python实现查看metadata.json文件培训的不同之处。

    随着您提供更多信息,还有更多信息。

答案 1 :(得分:0)

我在使用python的rasa时遇到了同样的问题,并且在谷歌搜索相同的错误时偶然发现了这个问题,但正如上面提到的@Caleb Keller,将rasa版本从0.9.0更改为0.10.0a5解决了这个问题。谢谢你的帮助。