# yoctol-nlu-py
[](https://travis-ci.org/Yoctol/yoctol-nlu-py)
[](https://badge.fury.io/py/yoctol-nlu)
Yoctol Natural Language Understanding SDK for python.
## Install
Use Python3
```
pip install yoctol-nlu
```
## Usage
### Intent Classifier Service
#### Fetch Model & One Line Prediction
```python
from ynlu import NLUClient
client = NLUClient(token='YOUR_TOKEN_HERE')
# Get all possible clf ids
ids = client.get_all_available_clf_ids()
print(ids)
# Get model by id
model = client.get_model_by_id(ids[0])
# Predict
intent_prediction, entity_prediction = model.predict('飲料喝到飽')
# Also could get the clf by clf's name
# Get all possible clf names
names = client.get_all_available_clf_names()
print(names)
# Get model by name
model = client.get_model_by_name(names[0])
# Predict
intent_prediction, entity_prediction = model.predict('飲料喝到飽')
```
#### Evaluations for Intent
```python
from ynlu import NLUClient
from ynlu.sdk.evaluation import {
# Accuracy
intent_accuracy_score_with_threshold,
# Precision
intent_precision_score_with_threshold,
# Recall
intent_recall_score_with_threshold,
}
client = NLUClient(token='YOUR_TOKEN_HERE')
model = client.get_model_by_id('TARGET_MODEL_ID_HERE')
test_data = [
'This is a line ',
'for testing the NLUClient ',
'and evaluating the prediction ',
'from the trained model. ',
]
intent_predictions, entities_predictions = model.batch_predict(test_data)
# Pure Accuracy
print(intent_accuracy_score_with_threshold(
intent_predictions=intent_predictions,
y_trues=test_data,
threshold=0.,
)
)
# Accuracy with threshold 0.5
print(intent_accuracy_score_with_threshold(
intent_predictions=intent_predictions,
y_trues=test_data,
threshold=0.5,
)
)
```
Check out the tutorials for more examples.
## Documentation
We rely on Sphinx for user and API documentation.
You can run just make to do rebuild the API stubs and then build the HTML documentation.
```
cd docs
make # equivalent to `make apidoc && make html`
```
To only build the html pages:
```
cd docs
make html
```
To just re-generate the API reference.
```
cd docs
make apidoc # calls sphinx-apidoc
```
Run `make help` for a full list of build options.
[](https://travis-ci.org/Yoctol/yoctol-nlu-py)
[](https://badge.fury.io/py/yoctol-nlu)
Yoctol Natural Language Understanding SDK for python.
## Install
Use Python3
```
pip install yoctol-nlu
```
## Usage
### Intent Classifier Service
#### Fetch Model & One Line Prediction
```python
from ynlu import NLUClient
client = NLUClient(token='YOUR_TOKEN_HERE')
# Get all possible clf ids
ids = client.get_all_available_clf_ids()
print(ids)
# Get model by id
model = client.get_model_by_id(ids[0])
# Predict
intent_prediction, entity_prediction = model.predict('飲料喝到飽')
# Also could get the clf by clf's name
# Get all possible clf names
names = client.get_all_available_clf_names()
print(names)
# Get model by name
model = client.get_model_by_name(names[0])
# Predict
intent_prediction, entity_prediction = model.predict('飲料喝到飽')
```
#### Evaluations for Intent
```python
from ynlu import NLUClient
from ynlu.sdk.evaluation import {
# Accuracy
intent_accuracy_score_with_threshold,
# Precision
intent_precision_score_with_threshold,
# Recall
intent_recall_score_with_threshold,
}
client = NLUClient(token='YOUR_TOKEN_HERE')
model = client.get_model_by_id('TARGET_MODEL_ID_HERE')
test_data = [
'This is a line ',
'for testing the NLUClient ',
'and evaluating the prediction ',
'from the trained model. ',
]
intent_predictions, entities_predictions = model.batch_predict(test_data)
# Pure Accuracy
print(intent_accuracy_score_with_threshold(
intent_predictions=intent_predictions,
y_trues=test_data,
threshold=0.,
)
)
# Accuracy with threshold 0.5
print(intent_accuracy_score_with_threshold(
intent_predictions=intent_predictions,
y_trues=test_data,
threshold=0.5,
)
)
```
Check out the tutorials for more examples.
## Documentation
We rely on Sphinx for user and API documentation.
You can run just make to do rebuild the API stubs and then build the HTML documentation.
```
cd docs
make # equivalent to `make apidoc && make html`
```
To only build the html pages:
```
cd docs
make html
```
To just re-generate the API reference.
```
cd docs
make apidoc # calls sphinx-apidoc
```
Run `make help` for a full list of build options.
Metadata
Release files for yoctol-nlu 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yoctol_nlu-0.7.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / yoctol_nlu-0.7.1-py3-none-any.whl
| Download URL | yoctol_nlu-0.7.1-py3-none-any.whl |
|---|---|
| Size | 38.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc3fd4e0b8d7afbfa715e2a126a507b5a79827eb0325f40556e6775165f05649
|
|
BLAKE2b-256 checksum How to use checksums |
15b5fbbdd2255569165cae5334cee9919e1aec6fb17a4529e99b9c95fb10bd88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for yoctol-nlu 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.