Skip to main content
https://travis-ci.org/snipsco/snips-nlu.svg?branch=develop https://ci.appveyor.com/api/projects/status/github/snipsco/snips-nlu?branch=develop&svg=true https://img.shields.io/pypi/v/snips-nlu.svg?branch=develop https://img.shields.io/pypi/pyversions/snips-nlu.svg?branch=develop https://codecov.io/gh/snipsco/snips-nlu/branch/develop/graph/badge.svg https://img.shields.io/twitter/url/http/shields.io.svg?style=social

Snips NLU (Natural Language Understanding) is a Python library that allows to parse sentences written in natural language and extracts structured information.

Summary

What is Snips NLU about ?

Behind every chatbot and voice assistant lies a common piece of technology: Natural Language Understanding (NLU). Anytime a user interacts with an AI using natural language, their words need to be translated into a machine-readable description of what they meant.

The NLU engine first detects what the intention of the user is (a.k.a. intent), then extracts the parameters (called slots) of the query. The developer can then use this to determine the appropriate action or response.

Let’s take an example to illustrate this, and consider the following sentence:

"What will be the weather in paris at 9pm?"

Properly trained, the Snips NLU engine will be able to extract structured data such as:

{
   "intent": {
      "intentName": "searchWeatherForecast",
      "probability": 0.95
   },
   "slots": [
      {
         "value": "paris",
         "entity": "locality",
         "slotName": "forecast_locality"
      },
      {
         "value": {
            "kind": "InstantTime",
            "value": "2018-02-08 20:00:00 +00:00"
         },
         "entity": "snips/datetime",
         "slotName": "forecast_start_datetime"
      }
   ]
}

In this case, the identified intent is searchWeatherForecast and two slots were extracted, a locality and a datetime. As you can see, Snips NLU does an extra step on top of extracting entities: it resolves them. The extracted datetime value has indeed been converted into a handy ISO format.

Check out our blog post to get more details about why we built Snips NLU and how it works under the hood. We also published a paper on arxiv, presenting the machine learning architecture of the Snips Voice Platform.

Getting Started

System requirements

  • Python 2.7 or Python >= 3.4, < 3.7

  • RAM: Snips NLU will typically use between 100MB and 200MB of RAM, depending on the language and the size of the dataset.

Installation

pip install snips-nlu

We currently have pre-built binaries (wheels) for snips-nlu and its dependencies for MacOS (10.11 and later), Linux x86_64 and Windows.

For any other architecture/os snips-nlu can be installed from the source distribution. To do so, Rust and setuptools_rust must be installed before running the pip install snips-nlu command.

Language resources

Snips NLU relies on external language resources that must be downloaded before the library can be used. You can fetch resources for a specific language by running the following command:

python -m snips_nlu download en

Or simply:

snips-nlu download en

Once the resources have been fetched, they can be loaded in Python using:

from snips_nlu import load_resources

load_resources("en")

The list of supported languages is available at this address.

API Usage

Command Line Interface

The easiest way to test the abilities of this library is through the command line interface.

First, start by training the NLU with one of the sample datasets:

snips-nlu train path/to/dataset.json path/to/output_trained_engine

Where path/to/dataset.json is the path to the dataset which will be used during training, and path/to/output_trained_engine is the location where the trained engine should be persisted once the training is done.

After that, you can start parsing sentences interactively by running:

snips-nlu parse path/to/trained_engine

Where path/to/trained_engine corresponds to the location where you have stored the trained engine during the previous step.

Sample code

Here is a sample code that you can run on your machine after having installed snips-nlu, fetched the english resources and downloaded one of the sample datasets:

from __future__ import unicode_literals, print_function

import io
import json

from snips_nlu import SnipsNLUEngine, load_resources
from snips_nlu.default_configs import CONFIG_EN

with io.open("sample_dataset.json") as f:
    sample_dataset = json.load(f)

load_resources("en")
nlu_engine = SnipsNLUEngine(config=CONFIG_EN)
nlu_engine.fit(sample_dataset)

text = "What will be the weather in San Francisco next week?"
parsing = nlu_engine.parse(text)
print(json.dumps(parsing, indent=2))

What it does is training an NLU engine on a sample weather dataset and parsing a weather query.

Sample datasets

Here is a list of some datasets that can be used to train a Snips NLU engine:

  • Lights dataset: “Turn on the lights in the kitchen”, “Set the light to red in the bedroom”

  • Beverage dataset: “Prepare two cups of cappucino”, “Make me a cup of tea”

  • Flights dataset: “Book me a flight to go to boston this weekend”, “book me some tickets from istanbul to moscow in three days”

Benchmarks

In January 2018, we reproduced an academic benchmark which was published during the summer 2017. In this article, authors assessed the performance of API.ai (now Dialogflow, Google), Luis.ai (Microsoft), IBM Watson, and Rasa NLU. For fairness, we used an updated version of Rasa NLU and compared it to the latest version of Snips NLU (both in dark blue).

.img/benchmarks.png

In the figure above, F1 scores of both intent classification and slot filling were computed for several NLU providers, and averaged accross the three datasets used in the academic benchmark mentionned before. All the underlying results can be found here.

Documentation

To find out how to use Snips NLU please refer to the package documentation, it will provide you with a step-by-step guide on how to setup and use this library.

FAQ

Please join Snips Discord channel to ask your questions and get feedback from the community.

How do I contribute ?

Please see the Contribution Guidelines.

Licence

This library is provided by Snips as Open Source software. See LICENSE for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snips_nlu-0.17.3.tar.gz (71.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snips_nlu-0.17.3-py2.py3-none-any.whl (102.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file snips_nlu-0.17.3.tar.gz.

File metadata

  • Download URL: snips_nlu-0.17.3.tar.gz
  • Upload date:
  • Size: 71.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for snips_nlu-0.17.3.tar.gz
Algorithm Hash digest
SHA256 da03fe585146bc0b4ae753cfd7be26032d5e0b9d38790c4d7483370aaeee449b
MD5 861b1ccdc46beb823b396c8ab36428b7
BLAKE2b-256 c8f4a363305977856dad43003270a70995d4f48644c5b046f4c461f44fc74c21

See more details on using hashes here.

File details

Details for the file snips_nlu-0.17.3-py2.py3-none-any.whl.

File metadata

  • Download URL: snips_nlu-0.17.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 102.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for snips_nlu-0.17.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dcdd1653b73ac5c4d300682aa1f7505d8c56a06289176db88b2c5fdcc0a70a8f
MD5 8f5ca36dcc4d7a965c01d023dbba8299
BLAKE2b-256 bc5cb3f9da0a38e0b8366b1a79edfcff07d8c770971ddcbfe5b80b7b5d410dd5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page