snipsco / snips-nlu

Snips Python library to extract meaning from text
https://snips-nlu.readthedocs.io
Apache License 2.0
3.89k stars 513 forks source link

How to use the training output? #842

Closed barak-11 closed 5 years ago

barak-11 commented 5 years ago

Beginner question, I use Chatito to generate jsons, I get from there two jsons, one is for training and the other is for testing. After I run the following command: snips-nlu train path/to/chatito/training.json path/to/persisted_engine I get a new folder called 'persisted_engine', I navigate to the new folder and there there are few folders:

builtin_entity_parser
lookup_intent_parser
probabilistic_intent_parser custom_entity_parser
nlu_engine.json
resources

My question is, how do I use the trained model above in my code? I tried the following:

with io.open("path/to/persisted_engine") as f: ... sample_dataset = json.load(f)

I also tried referencing the nlu_engine.json file but same results

with io.open("path/to/persisted_engine/nlu_engine.json") as f: ... sample_dataset = json.load(f)

but got the following error: snips_nlu.exceptions.DatasetFormatError: Expected dataset to have key: 'intents' Of course if I use the training file downloaded from Chatito instead, it works fine.

Please assist

adrienball commented 5 years ago

@barak-11 I encouraged you to have a look a the tutorial part of documentation as everything is explained here.

Once you have trained and persisted an NLU engine, as you did, you can load it as follow:

from snips_nlu import SnipsNLUEngine

loaded_engine = SnipsNLUEngine.from_path("path/to/persisted_engine")

print(loaded_engine.parse("hello world")