https://github.com/ivankunyankin/intent_suggestions
https://pypi.org/project/intent-suggestions/
https://github.com/ivankunyankin/intent_suggestions
intent-detection n-gram-language-models suggestions
Last synced: 3 months ago
JSON representation
https://pypi.org/project/intent-suggestions/
- Host: GitHub
- URL: https://github.com/ivankunyankin/intent_suggestions
- Owner: ivankunyankin
- License: mit
- Created: 2022-08-10T13:19:29.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-06T17:41:18.000Z (almost 4 years ago)
- Last Synced: 2025-12-16T03:19:40.039Z (7 months ago)
- Topics: intent-detection, n-gram-language-models, suggestions
- Language: Python
- Homepage: https://bit.ly/3e2iYpD
- Size: 84 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Intent suggestions
Python package for early user intent detection using n-gram language models

The idea behind intent suggestions is similar to autofill when we use words that were typed to make predictions. But instead of predicting the next word, we try to detect the user's intent.
The proposed approach uses `n` recursively initialised models. Each next model uses a smaller `n`. I.e. a model initialised with `n=3` will include three models (with `n=3`, `n=2` and `n=1`)
This recursive approach allows to also take into account frequency counts from smaller n-grams in case there is no match for the parent model.
### Installation
```
pip install intent_suggestions
```
### Quickstart
`Fit` takes a list of items (training phrases) and a list of labels (intents) as input.
```
from intent_suggestions import IntentSuggester
model = IntentSuggester()
items = ["one two three four", "five six seven eight"]
labels = ["intent_1", "intent_2"]
model.fit(items, labels)
print(model.predict("zero two three four"))
```
Output:
```
{'intent_1': 0.9902, 'intent_2': 0.0098}
```
During training the model splits phrases by words. Thus, it works better when given input phrases with *complete last words*. For example, instead of making a prediction when a user typed "five six se", wait until they type "five six seven" and put a space. Now make the prediction.
### Notation
According to the common notation, an n-gram language model uses `n-1` words to predict the next word.
Given that we are trying to predict a user's intent rather the next word, we'll use a slightly different notation. `n` in our case will represent the number of words used to predict intent probabilities. So a 3-gram (or trigram) model will use three words to make predictions.
### References
The approach was inspired by [this](https://habr.com/ru/post/346578/) work