Command Line Interface¶
The easiest way to test the abilities of the Snips NLU library is through the
command line interface (CLI). The CLI is installed with the python package and
is typically used by running
snips-nlu <command> [args] or alternatively
python -m snips_nlu <command> [args].
Creating a dataset¶
snips-nlu generate-dataset en intent_1.txt intent_2.txt entity_1.txt
This will print a Json string to the standard output. If you want to store the dataset directly in a Json file, you just have to pipe the previous command like below:
snips-nlu generate-dataset en intent_1.txt intent_2.txt entity_1.txt > dataset.json
Each intent file corresponds to a single intent, and the name of the file must
intent_. The same is true for entity files, which must start
An intent file is a text file in which each row corresponds to an utterance. Slots, along with their corresponding slot type (entity), can be defined using the following syntax:
Find me a flight from [departure:city](Paris) to [destination:city](London) Find me a flight from [departure:city](Moscow) [departureDate:snips/datetime](tomorrow around 9pm)
In this example, there are three different slots –
departureDate – and two different entities –
snips/datetime (which is a builtin entity).
Check this section to have more details about the
difference between slots and entities.
An entity file is a comma separated text file in which each row corresponds to an entity value, optionally followed with its synonyms. The syntax used is the following:
Here, the entity (room) has two values which are
"backyard", are defined for
If a value or a synonym contains a comma, the value must be put between
If the value contains double quotes, it must be doubled
to be escaped like this:
"A value with a "","" in it" which corresponds
to the actual value
A value with a "," in it.
By default entities are generated as automatically extensible, i.e. the recognition will accept additional values than the ones listed in the entity file. This behavior can be changed by adding at the beginning of the entity file the following:
Once you have built a proper dataset, you can use the CLI to train an NLU engine:
snips-nlu train path/to/dataset.json path/to/persisted_engine
The first parameter corresponds to the path of the dataset file. The second
parameter is the directory where the engine should be saved after training.
The CLI takes care of creating this directory.
You can enable logs by adding a
Finally, you can use the parsing command line to test interactively the parsing abilities of a trained NLU engine:
snips-nlu parse path/to/persisted_engine
This will run a prompt allowing you to parse queries interactively. You can also pass a single query using an optional parameter:
snips-nlu parse path/to/persisted_engine -q "my query"
Two simple commands allow to print the version of the library and the version of the NLU model:
snips-nlu version snips-nlu model-version