Reputation: 348
I'm trying to load a model using Python 3.7
and Rasa 1.1.4
in the following way:
from rasa.nlu.model import Interpreter
interpreter = Interpreter.load("./models/generic")
The following error happens:
FileNotFoundError:
[Errno 2] No such file or directory: './models/generic/metadata.json'
The model has been trained with the following command:
rasa train nlu --config config.yml
--nlu data/generic.md
--out models
--fixed-model-name generic/model
Which only produces the following file, no metadata file has been generated:
models/generic/model.tar.gz
What is the best step forward? Generate the metadata file, load the model differently?
Upvotes: 1
Views: 1334
Reputation: 29608
You can untar the model.tar.gz to expose the metadata.json and the rest of the model files.
Using the sample model generated from rasa init
, if I untar it:
$ ls models
20190622-213707.tar.gz
$ cd models
$ mkdir 20190622-213707
$ tar xvf 20190622-213707.tar.gz -C 20190622-213707
$ tree 20190622-213707
I'll get:
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
...which reveals the metadata.json under the nlu folder.
You can then use the full path to the actual model directory.
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'}
I am not that familiar with rasa
, but you might be mixing command line usage with "manual" Python APIs for writing your own trainer/interpreter apps.
Check out the Trainer
class in rasa.nlu.model
. It has a persist
method that saves your model to a directory, but not as a tar.gz. The result of the Trainer
can then be used by the Interpreter
.
Upvotes: 4