GithubHelp home page GithubHelp logo

isabella232 / snips-nlu-metrics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snipsco/snips-nlu-metrics

0.0 0.0 0.0 261 KB

Python package to compute metrics on an NLU intent parsing pipeline

License: Apache License 2.0

Python 100.00%

snips-nlu-metrics's Introduction

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)

Links

Contributing

Please see the Contribution Guidelines.

Copyright

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

snips-nlu-metrics's People

Contributors

adrienball avatar alaa-saade avatar choufractal avatar clemdoum avatar garvys avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.