2017-09-04 74 views
0

我試圖複製樣品餐廳搜索預測。我在Windows 64/python 3.6 Anaconda 4.4上運行它。我的config.json看起來像這樣。無法使用rasa_nlu在python

{ 
     "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服務器模式下運行它時,相同的配置工作正常。請幫助我解決問題。

+0

是'D:/ rasa-nlu-working/models/model_20170904-132507'目錄或文件嗎?它應該是目錄 –

+0

它的一個目錄。我有六個文件,分別是crf_model.pkl,entity_synonyms.json,intent_classifier.pkl,metadata.json,regex_featurizer.json和training_data.json。我在訓練樣本數據後生成了這個子文件夾。 – Subramanian

+0

你可以發佈你用來訓練的命令嗎?你也可以發佈metadata.json的內容嗎? –

回答

1

我問在評論一些澄清,但想到我會開始寫反正答案。

自己張貼的錯誤實際上與你的配置文件有問題。它看起來像metadata.json沒有正確加載和/或解析。 metadata.json有點像模型訓練時配置文件的快照。

這裏的操作順序:

  1. 每當你調用Interpreter.load那得到執行加載的metadata.json文件中的第一件事情之一。 See here.
  2. 下完了在Metadata.load我們嘗試加載和解析該文件。 See here
  3. 早在解釋我們試圖從被返回的元數據管道。 See here.

這就是你的錯誤發生的地方。出於某種原因,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文件訓練的不同之處。

隨着您提供更多信息,還有更多。

+0

我使用的是0.9 .2版本​​。由於安全限制,克隆github版本時遇到問題。一旦我過來,會回覆給你 – Subramanian

+0

我將添加我的metadata.json作爲答覆。由於其巨大,不能作爲評論粘貼。就JSON而言,我看起來很好。 – Subramanian

+0

@Subramanian你有沒有找到解決這個問題的辦法,即使面臨同樣的問題 –

0

我從python使用rasa時遇到了同樣的問題,並且偶然發現了這個線程,同時使用@Caleb Keller在上面提到了同樣的錯誤,將rasa版本從0.9.0更改爲0.10.0a5解決了這個問題。謝謝您的幫助。