Skip to main content

Snips NLU Metrics

https://travis-ci.org/snipsco/snips-nlu-metrics.svg?branch=master https://img.shields.io/pypi/v/snips-nlu-metrics.svg?branch=master https://img.shields.io/pypi/pyversions/snips-nlu-metrics.svg?branch=master

This tools is a python library for computing cross-validation and train/test metrics on an NLU parsing pipeline such as the Snips NLU one.

Its purpose is to help evaluating and iterating on the tested intent parsing pipeline.

Install

$ pip install snips_nlu_metrics

NLU Metrics API

Snips NLU metrics API consists in the following functions:

The metrics output (json) provides detailed information about:

Data

Some sample datasets, that can be used to compute metrics, are available here. Alternatively, you can create your own dataset either by using snips-nlu’s dataset generation tool or by going on the Snips console.

Examples

The Snips NLU metrics library can be used with any NLU pipeline which satisfies the Engine API:

class Engine:
    def fit(self, dataset):
        # Perform training ...
        return self

    def parse(self, text):
        # extract intent and slots ...
        return {
            "input": text,
            "intent": {
                "intentName": intent_name,
                "probability": probability
            },
            "slots": slots
        }

Snips NLU Engine

This library can be used to benchmark NLU solutions such as Snips NLU. To install the snips-nlu python library, and fetch the language resources for english, run the following commands:

$ pip install snips-nlu
$ snips-nlu download en

Then, you can compute metrics for the snips-nlu pipeline using the metrics API as follows:

from snips_nlu import SnipsNLUEngine
from snips_nlu_metrics import compute_train_test_metrics, compute_cross_val_metrics

tt_metrics = compute_train_test_metrics(train_dataset="samples/train_dataset.json",
                                        test_dataset="samples/test_dataset.json",
                                        engine_class=SnipsNLUEngine)

cv_metrics = compute_cross_val_metrics(dataset="samples/cross_val_dataset.json",
                                       engine_class=SnipsNLUEngine,
                                       nb_folds=5)

Custom NLU Engine

You can also compute metrics on a custom NLU engine, here is a simple example:

import random

from snips_nlu_metrics import compute_train_test_metrics

class MyNLUEngine:
    def fit(self, dataset):
        self.intent_list = list(dataset["intents"])
        return self

    def parse(self, text):
        return {
            "input": text,
            "intent": {
                "intentName": random.choice(self.intent_list),
                "probability": 0.5
            },
            "slots": []
        }

compute_train_test_metrics(train_dataset="samples/train_dataset.json",
                           test_dataset="samples/test_dataset.json",
                           engine_class=MyNLUEngine)

Contributing

Please see the Contribution Guidelines.

Metadata

Release files for snips-nlu-metrics 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snips-nlu-metrics 0.15.0
File Size Uploaded
snips_nlu_metrics-0.15.0.tar.gz 32.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snips-nlu-metrics 0.15.0
File Interpreter ABI Platform
snips_nlu_metrics-0.15.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.6 kB

Release files / snips_nlu_metrics-0.15.0.tar.gz

Download URL snips_nlu_metrics-0.15.0.tar.gz
Size 32.6 kB
Tags Source
SHA-256 checksum
How to use checksums
39acf98d74047666390b51c0dab90a47ab930de94766210cabd1f0b599cab687
BLAKE2b-256 checksum
How to use checksums
a537ae7d2f61b54e2a9c78ee91be071839eb60cccf817e9b3dc45a0fa52af728
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

Release files / snips_nlu_metrics-0.15.0-py3-none-any.whl

Download URL snips_nlu_metrics-0.15.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc5985c7acf552b38e8ea33864792d845299011d3039146efda6b0711860df74
BLAKE2b-256 checksum
How to use checksums
b114496ba4076b73880753222954ba688fb80a023718ba9051edb165ce045958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.15.0 This release

2 release files

0.14.6

2 release files

0.14.5

2 release files

0.14.4

2 release files

0.14.3

2 release files

0.14.2

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page