• Stars
    star
    3,889
  • Rank 11,267 (Top 0.3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Snips Python library to extract meaning from text

Snips NLU

https://travis-ci.org/snipsco/snips-nlu.svg?branch=master https://ci.appveyor.com/api/projects/status/github/snipsco/snips-nlu?branch=master&svg=true https://img.shields.io/pypi/v/snips-nlu.svg?branch=master https://img.shields.io/pypi/pyversions/snips-nlu.svg?branch=master https://img.shields.io/twitter/url/http/shields.io.svg?style=social

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

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.5
  • 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

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
>>> from snips_nlu.default_configs import CONFIG_EN
>>> with io.open("sample_datasets/lights_dataset.json") as f:
...     sample_dataset = json.load(f)
>>> nlu_engine = SnipsNLUEngine(config=CONFIG_EN)
>>> nlu_engine = nlu_engine.fit(sample_dataset)
>>> text = "Please turn the light on in the kitchen"
>>> parsing = nlu_engine.parse(text)
>>> parsing["intent"]["intentName"]
'turnLightOn'

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 across 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.

Citing Snips NLU

Please cite the following paper when using Snips NLU:

@article{coucke2018snips,
  title   = {Snips Voice Platform: an embedded Spoken Language Understanding system for private-by-design voice interfaces},
  author  = {Coucke, Alice and Saade, Alaa and Ball, Adrien and Bluche, Th{\'e}odore and Caulier, Alexandre and Leroy, David and Doumouro, Cl{\'e}ment and Gisselbrecht, Thibault and Caltagirone, Francesco and Lavril, Thibaut and others},
  journal = {arXiv preprint arXiv:1805.10190},
  pages   = {12--16},
  year    = {2018}
}

FAQ & Community

Please join the forum to ask your questions and get feedback from the community.

Related content

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.

Geonames Licence

The snips/city, snips/country and snips/region builtin entities rely on software from Geonames, which is made available under a Creative Commons Attribution 4.0 license international. For the license and warranties for Geonames please refer to: https://creativecommons.org/licenses/by/4.0/legalcode.

More Repositories

1

Postal

A Swift framework for working with emails
Swift
653
star
2

snips-nlu-rs

Snips NLU rust implementation
Rust
340
star
3

ntm-lasagne

Neural Turing Machines library in Theano with Lasagne
Python
300
star
4

awesome-snips

A curated list of awesome Snips projects
276
star
5

tensorflow-build

A set of scripts to (cross-)build the Tensorflow C lib for various architectures / OS
Shell
178
star
6

rust-threshold-secret-sharing

A pure-Rust implementation of various threshold secret sharing schemes
Rust
156
star
7

react-inview-monitor

Declarative in-view scroll monitor for React JS
JavaScript
114
star
8

rust-paillier

A pure-Rust implementation of the Paillier encryption scheme
Rust
80
star
9

snips-nlu-ontology

Ontology of Snips NLU
Rust
57
star
10

react-scrolling-color-background

background with color transitioning as you scroll, declarative and easy to setup
JavaScript
57
star
11

sda

Secure distributed aggregation of high-dimensional vectors
Rust
55
star
12

snips-skill-respeaker

Official Snips Animation Feedback For Makers Kits/Dev Kits, supporting all kinds of APA102 based LED hardwares.
C
41
star
13

snips-record-personal-hotword

Python
40
star
14

hermes-protocol

Definition of the Hermes protocol used by the Snips platform
Rust
36
star
15

snips-nlu-language-resources

Language resources for the Snips Natural Language Understanding (NLU)
Python
34
star
16

snips-platform-android-demo

A demo of the Snips Platform for Android
Java
22
star
17

paillier-libraries-benchmarks

Companion repository for blog post on benchmarking implementations of Paillier encryption
Go
19
star
18

SuperCombinators

[Deprecated] A Swift parser combinator framework
Swift
19
star
19

nlp-workshops

Introduction and tutorial about Natural Language Processing
Jupyter Notebook
16
star
20

snipsmanager

The Snips Assistant Manager
Python
16
star
21

snips-nlu-parsers

Rust crate for entity parsing
Rust
16
star
22

gazetteer-entity-parser

Rust library for parsing and resolving entity values based on a gazetteer
Rust
16
star
23

snips-issues

Feel free to share your bugs with us.
14
star
24

snips-app-sonos

Sonos app for Snips
Python
13
star
25

snips-nlu-metrics

Python package to compute metrics on an NLU intent parsing pipeline
Python
13
star
26

snips-nlu-utils

Rust library for NLU utils with wrappers in other languages
Rust
12
star
27

snips-app-template-py

Action code template written in Python.
Python
11
star
28

snips-platform-swift

The Swift framework for the Snips Platform
Swift
11
star
29

snips-actions-templates

Template files for snips actions
Python
11
star
30

snips-nlu-resources

10
star
31

play-mongo-bson

Scala client for MongoDB using macros for case class serialization/deserialization
Scala
10
star
32

snips-platform-docker

Shell
10
star
33

snips-skill-owm

OpenWeatherMap skill for Snips
Python
9
star
34

snips-javascript-toolkit

Everything you need in order to write Snips actions in javascript / typescript.
TypeScript
9
star
35

snips-skill-hue

Philips Hue skill for Snips
Python
8
star
36

create-snips-action

Generator for writing Snips action code in Javascript/Typescript.
JavaScript
7
star
37

crfsuite-rs

Rust bindings for CRFSuite
C
7
star
38

snips-jeedom-plugin

Jeedom plugin allows connecting Snips voice assistant with Jeedom platform.
PHP
6
star
39

snips-demo-dev-kit

Official action code for Snips Voice Interaction Development Kit. (Temperature & Relay)
Python
6
star
40

snips-javascript-actions-runner

A lightweight javascript actions runner. 🏃‍♂️
JavaScript
5
star
41

ripb

A rust crate providing an implementation of a lock-free type-safe in-process bus.
Rust
4
star
42

snips-action-alarm

Snips action code for the Alarm app
TypeScript
4
star
43

snipsmanagercore

Core Python utilities for the Snips Manager
Python
4
star
44

snips-skill-fakeweather

Fake weather forecasts for Snips
Python
3
star
45

snips-app-relay-switch

Control the switch connected on Raspberry Pi by using your voice.
Python
3
star
46

snips-skill-weather

skill for the Snips assistant, En & Fr
JavaScript
2
star
47

snips-skill-weather-tts

Skill to show how to parse a weather intent and respond with a TTS.
Python
2
star
48

snips-skill-neopixel

NeoPixel Ring 24 skill for Snips
Python
2
star
49

snips-app-sht31

Get temperature and humidity from SHT31 (I2C protocol) by using your voice.
Python
2
star
50

snips-actions-runner-hook

Temporary solution to link snips-skill-server and snips-actions-runner
JavaScript
1
star
51

braccio_arm_demo

Code to control the braccio robotic arm for maker fare
Python
1
star
52

snips-action-reminder

Snips action code for the Reminder app
TypeScript
1
star
53

snips-action-timer

Snips action code for the Timer app
TypeScript
1
star
54

snips-action-unit-converter

Snips action code for the Unit Converter app
TypeScript
1
star
55

snips-action-nutrition

Snips action code for the Nutrition app
TypeScript
1
star
56

homebrew-snips

Snips formulae for the Homebrew package manager
Ruby
1
star
57

snipsair_whitepaper

Snips whitepapers, summaries, traductions etc.. Get in touch if you would like to help translate!
1
star
58

snips-skill-hue-pro

Handler for [Smart Light - Hue] bundle.
Python
1
star
59

SDP-swift

Swift reference implementation for Simple Datagram Protocol.
Swift
1
star
60

create-snips-action-typescript

Generator for writing Snips action code in Typescript.
TypeScript
1
star
61

Snips_Lights

Arduino library for light animations for the smart speaker project.
C++
1
star
62

snips-skill-times-tables-quiz

This skill enable your snips voice assistant to give you a quiz on times tables under the form of a dialog session.
Python
1
star