使用 Python 中的 Rasa NLU 时找不到元数据



我正在尝试使用以下方式使用 Python 3.7Rasa 1.1.4 加载模型:

from rasa.nlu.model import Interpreter
interpreter = Interpreter.load("./models/generic")

发生以下错误:

FileNotFoundError:
[Errno 2] No such file or directory: './models/generic/metadata.json'

已使用以下命令训练模型:

rasa train nlu --config config.yml
               --nlu data/generic.md
               --out models
               --fixed-model-name generic/model

它只生成以下文件,没有生成元数据文件:

models/generic/model.tar.gz

最好的一步是什么?生成元数据文件,以不同的方式加载模型?

您可以解压缩模型.tar.gz以公开元数据.json和其余模型文件。

使用从rasa init生成的示例模型,如果我解压缩它:

$ ls models 
20190622-213707.tar.gz
$ cd models
$ mkdir 20190622-213707
$ tar xvf 20190622-213707.tar.gz -C 20190622-213707
$ tree 20190622-213707

我会得到:

20190622-213707
├── core
│   ├── ....
├── fingerprint.json
└── nlu
    ├── checkpoint
    ├── component_1_RegexFeaturizer.pkl
    ├── component_4_CountVectorsFeaturizer.pkl
    ├── component_5_EmbeddingIntentClassifier.ckpt.data-00000-of-00001
    ├── component_5_EmbeddingIntentClassifier.ckpt.index
    ├── component_5_EmbeddingIntentClassifier.ckpt.meta
    ├── component_5_EmbeddingIntentClassifier_encoded_all_intents.pkl
    ├── component_5_EmbeddingIntentClassifier_inv_intent_dict.pkl
    ├── metadata.json
    └── training_data.json

。这将显示 nlu 文件夹下的元数据.json
然后,可以使用实际模型目录的完整路径。

interpreter = Interpreter.load("./models/20190622-213707/nlu/")
print(interpreter.parse("hello"))
# {'intent': {'name': 'greet', 'confidence': 0.9470939636230469},  
#  'entities': [], 
#  'intent_ranking': [{'name': 'greet', 'confidence': 0.9470939636230469}, 
#                     {'name': 'deny', 'confidence': 0.17162932455539703}, 
#                     {'name': 'affirm', 'confidence': 0.05398404598236084}, 
#                     {'name': 'mood_great', 'confidence': 0.0}, 
#                     {'name': 'goodbye', 'confidence': 0.0}, 
#                     {'name': 'mood_unhappy', 'confidence': 0.0}], 
#  'text': 'hello'}

我对rasa不太熟悉,但您可能会将命令行用法与"手动"Python API 混合使用,以编写自己的培训师/解释器应用程序。

查看rasa.nlu.modelTrainer类。它有一个persist方法,可以将模型保存到目录,但不保存为 tar.gz。然后,Interpreter可以使用Trainer的结果。

最新更新