Skip to content

Commit 386a6c6

Browse files
authored
Merge pull request #95 from snipsco/release/0.13.0
Release 0.13.0
2 parents ae0a5a4 + 5330cc4 commit 386a6c6

File tree

14 files changed

+252
-521
lines changed

14 files changed

+252
-521
lines changed

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [Unreleased]
4+
## [0.13.0] - 2018-07-25
5+
### Fixed
6+
- Crash while computing metrics when either actual or predicted intent is unknown
7+
8+
### Removed
9+
- APIs depending implicitely on Snips NLU:
10+
- `compute_cross_val_nlu_metrics`
11+
- `compute_train_test_nlu_metrics`
12+
13+
### Changed
14+
- Use flexible version specifiers for dependencies
15+
516

617
## [0.12.0] - 2018-03-29
718
### Added
@@ -10,5 +21,6 @@ All notable changes to this project will be documented in this file.
1021
- New option to exclude slot metrics in the output
1122
- Samples
1223

13-
[Unreleased]: https://github.com/snipsco/snips-nlu-metrics/compare/0.12.0...HEAD
24+
25+
[0.13.0]: https://github.com/snipsco/snips-nlu-metrics/compare/0.12.0...0.13.0
1426
[0.12.0]: https://github.com/snipsco/snips-nlu-metrics/compare/0.11.1...0.12.0

README.rst

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Install
2222

2323
.. code-block:: console
2424
25-
pip install snips_nlu_metrics
25+
$ pip install snips_nlu_metrics
2626
2727
2828
NLU Metrics API
@@ -40,24 +40,64 @@ The metrics output (json) provides detailed information about:
4040
* parsing errors
4141
* `confusion matrix`_
4242

43+
Data
44+
----
45+
46+
Some sample datasets, that can be used to compute metrics, are available
47+
`here <samples/>`_. Alternatively, you can create your own dataset either by
48+
using ``snips-nlu``'s `dataset generation tool`_ or by going on the
49+
`Snips console`_.
50+
4351
Examples
4452
--------
4553

46-
The Snips NLU metrics library can be used either with `Snips NLU`_ or with a
47-
custom intent parsing pipeline.
54+
The Snips NLU metrics library can be used with any NLU pipeline which satisfies
55+
the ``Engine`` API:
56+
57+
.. code-block:: python
58+
59+
from builtins import object
60+
61+
class Engine(object):
62+
def fit(self, dataset):
63+
# Perform training ...
64+
return self
65+
66+
def parse(self, text):
67+
# extract intent and slots ...
68+
return {
69+
"input": text,
70+
"intent": {
71+
"intentName": intent_name,
72+
"probability": probability
73+
},
74+
"slots": slots
75+
}
76+
4877
4978
----------------
5079
Snips NLU Engine
5180
----------------
5281

53-
Here is how you can use the metrics API to compute metrics for the Snips NLU
54-
pipeline:
82+
This library can be used to benchmark NLU solutions such as `Snips NLU`_. To
83+
install the ``snips-nlu`` python library, and fetch the language resources for
84+
english, run the following commands:
85+
86+
.. code-block:: bash
87+
88+
$ pip install snips-nlu
89+
$ snips-nlu download en
90+
91+
92+
Then, you can compute metrics for the ``snips-nlu`` pipeline using the metrics
93+
API as follows:
5594

5695
.. code-block:: python
5796
58-
from snips_nlu import SnipsNLUEngine
97+
from snips_nlu import load_resources, SnipsNLUEngine
5998
from snips_nlu_metrics import compute_train_test_metrics, compute_cross_val_metrics
6099
100+
load_resources("en")
61101
62102
tt_metrics = compute_train_test_metrics(train_dataset="samples/train_dataset.json",
63103
test_dataset="samples/test_dataset.json",
@@ -67,16 +107,6 @@ pipeline:
67107
engine_class=SnipsNLUEngine,
68108
nb_folds=5)
69109
70-
Some `sample code and datasets <samples/>`_ are also available, you can have an
71-
overview of the metrics output by running:
72-
73-
.. code-block:: bash
74-
75-
git clone https://github.com/snipsco/snips-nlu-metrics.git
76-
cd snips-nlu-metrics
77-
pip install -e ".[samples]"
78-
python samples/sample.py train-test
79-
80110
-----------------
81111
Custom NLU Engine
82112
-----------------
@@ -128,4 +158,6 @@ This library is provided by `Snips <https://www.snips.ai>`_ as Open Source softw
128158
.. _train/test: https://en.wikipedia.org/wiki/Training,_test,_and_validation_sets
129159
.. _Snips NLU: https://github.com/snipsco/snips-nlu
130160
.. _precision, recall and f1 scores: https://en.wikipedia.org/wiki/Precision_and_recall
131-
.. _confusion matrix: https://en.wikipedia.org/wiki/Confusion_matrix
161+
.. _confusion matrix: https://en.wikipedia.org/wiki/Confusion_matrix
162+
.. _dataset generation tool: http://snips-nlu.readthedocs.io/en/latest/tutorial.html#snips-dataset-format
163+
.. _Snips console: https://console.snips.ai

samples/__init__.py

Whitespace-only changes.

samples/sample.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

setup.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@
1919

2020
install_requires = [
2121
"future",
22-
"numpy==1.14.0",
23-
"scipy==1.0.0",
24-
"scikit-learn==0.19.1",
22+
"numpy>=1.7,<2.0",
23+
"scipy>=1.0,<2.0",
24+
"scikit-learn>=0.19,<0.20",
2525
]
2626

2727
extras_require = {
2828
"test": [
29-
"mock==2.0.0",
30-
],
31-
"samples": [
32-
"snips-nlu==0.12.1"
29+
"mock>=2.0,<3.0",
3330
]
3431
}
3532

snips_nlu_metrics/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
from snips_nlu_metrics.engine import Engine
44
from snips_nlu_metrics.metrics import (compute_train_test_metrics,
5-
compute_train_test_nlu_metrics,
6-
compute_cross_val_metrics,
7-
compute_cross_val_nlu_metrics)
5+
compute_cross_val_metrics)

snips_nlu_metrics/__version__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.12.0
1+
0.13.0

snips_nlu_metrics/engine.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
from __future__ import unicode_literals
22

3-
import io
4-
import json
5-
import os
6-
import zipfile
73
from abc import ABCMeta, abstractmethod
84
from builtins import object
9-
from builtins import str
10-
from copy import deepcopy
115

126
from future.utils import with_metaclass
137

14-
from snips_nlu_metrics.utils.temp_utils import tempdir_ctx
15-
16-
TRAINED_ENGINE_FILENAME = "trained_assistant.json"
17-
188

199
class Engine(with_metaclass(ABCMeta, object)):
2010
"""Abstract class which represents an engine that can be used in the
@@ -28,50 +18,3 @@ def fit(self, dataset):
2818
@abstractmethod
2919
def parse(self, text):
3020
pass
31-
32-
33-
def build_nlu_engine_class(training_class, inference_class,
34-
training_config=None):
35-
_training_config = deepcopy(training_config)
36-
37-
class NLUEngine(Engine):
38-
def __init__(self):
39-
self.inference_engine = None
40-
self.training_config = _training_config
41-
42-
def fit(self, dataset):
43-
if self.training_config is not None:
44-
training_engine = training_class(config=self.training_config)
45-
else:
46-
training_engine = training_class()
47-
training_engine.fit(dataset)
48-
trained_engine_dict = training_engine.to_dict()
49-
self.inference_engine = get_inference_nlu_engine(
50-
trained_engine_dict, inference_class)
51-
52-
def parse(self, text):
53-
return self.inference_engine.parse(text)
54-
55-
return NLUEngine
56-
57-
58-
def get_trained_nlu_engine(train_dataset, training_engine_class):
59-
language = train_dataset["language"]
60-
engine = training_engine_class(language)
61-
engine.fit(train_dataset)
62-
return engine
63-
64-
65-
def get_inference_nlu_engine(trained_engine_dict, inference_engine_class):
66-
with tempdir_ctx() as engine_dir:
67-
trained_engine_path = os.path.join(engine_dir, TRAINED_ENGINE_FILENAME)
68-
archive_path = os.path.join(engine_dir, 'assistant.zip')
69-
70-
with io.open(trained_engine_path, mode='w', encoding='utf8') as f:
71-
f.write(str(json.dumps(trained_engine_dict)))
72-
with zipfile.ZipFile(archive_path, 'w') as zf:
73-
zf.write(trained_engine_path, arcname=TRAINED_ENGINE_FILENAME)
74-
with io.open(archive_path, mode='rb') as f:
75-
data_zip = bytearray(f.read())
76-
77-
return inference_engine_class(data_zip=data_zip)

0 commit comments

Comments
 (0)