@botonic/plugin-nlu
v0.19.0
Published
## What Does This Plugin Do?
Downloads
93
Readme
Botonic Plugin NLU
What Does This Plugin Do?
Botonic Plugin NLU allows you to predict intents from the user inputs for your bot.
To set up a new example using Botonic Plugin NLU, you can create a bot by running the following command:
$ botonic new {BOT_NAME} nlu
Alternatively, if you already have a project, you can follow the steps below to setup it up.
Setup
Install the plugin
- From your project, enter the command
npm install @botonic/plugin-nlu
. This command installs everything necessary to start working with your intents and entities. Note: Windows users should first use the commandnpm install --global --production windows-build-tools --vs2015
followed bynpm install @botonic/plugin-nlu
- Under the
src
files of your project, create a folder callednlu
.
Require the Plugin
You must require the plugin in src/plugins.js
to be able to predict the intent of user inputs. You must set its id
to nlu for the plugin to work.
In case that you have trained your model with default preprocessing engines, you only need to specify the languages that you want to support.
src/plugins.js
E.g.:
export const plugins = [
{
id: 'nlu',
resolve: require('@botonic/plugin-nlu'),
options: {
en: {},
es: {},
},
},
]
Otherwise, you must load also the preprocessing engines for every language used to train your models.
E.g.:
import { ENTokenizer, ESTokenizer } from './nlu/preprocessing-tools/tokenizer'
export const plugins = [
{
id: 'nlu',
resolve: require('@botonic/plugin-nlu'),
options: {
en: {
tokenizer: ENTokenizer,
},
es: {
tokenizer: ESTokenizer,
},
},
},
]
Use
Define Intents
- Under the
nlu
folder, create a folder calledutterances
, which will contain your multilingual intents. - For every language you want to support, create a folder under
/src/nlu/utterances
with its language code (it must be ISO 639-1). Ex: Training for English (en
), will result in the following path:/src/nlu/utterances/en/
. - Add a text file for each intent you want to create by naming them
IntentName.txt
. - Fill them with possible ways to express each intent. Every sentence must be on a different line of the file. See Natural Language Understanding section for more information.
Train the Bot
Now it's time to order Botonic NLU to train each intent with the provided sentences:
botonic train
Alternatively you can also run
npm run train
.
After this, the bot will be able to run predictions on new inputs.
Every time you make changes in your utterances, you will need to run again the command above so that the changes take effect.
Define Routes with Intents
Once you've defined your intents, you can use them in the routes in the same way you use text
, payloads
, and the like.
Below, we see how we might use them:
routes.js
import Start from './actions/start'
import ShowRestaurants from './actions/show-restaurants'
import NotFound from './actions/not-found'
import ShowDirections from './actions/show-directions'
export const routes = [
{ input: i => i.confidence < 0.7, action: NotFound },
{ intent: 'Greetings', action: Start },
{ intent: 'BookRestaurant', action: ShowRestaurants },
]
Go Live
- Run
botonic serve
to see how the bot runs in the development environment. - For further details of the variables stored during the execution, open the
Botonic Dev Console
by clicking on the tab in the top-left corner. - Deploy your bot with
botonic deploy
. You got a bot with a customized intent and entity recognition system!
Multilingual Support
The pre-trained word embeddings below are supported, which means that you can train your bot in these specific languages. For more information about other supported languages, feel free to contact us on Slack.
You can also generate your own word embeddings following these instructions.
| Language | Language Code | Type* | Dimensions | Source | | :--------: | :-----------: | :----------: | :--------: | :----------------------------------------------------------------------------------------------------------------: | | English | en | glove | 50 | glove-50d-en | | English | en | 10k-fasttext | 300 | 10k-fasttext-300d-en | | Spanish | es | 10k-fasttext | 300 | 10k-fasttext-300d-es | | Catalan | ca | 10k-fasttext | 300 | 10k-fasttext-300d-ca | | French | fr | 10k-fasttext | 300 | 10k-fasttext-300d-fr | | Portuguese | pt | 10k-fasttext | 300 | 10k-fasttext-300d-pt | | German | de | 10k-fasttext | 300 | 10k-fasttext-300d-de | | Italian | it | 10k-fasttext | 300 | 10k-fasttext-300d-it | | Hindi | hi | 10k-fasttext | 300 | 10k-fasttext-300d-hi | | Indonesian | id | 10k-fasttext | 300 | 10k-fasttext-300d-id | | Russian | ru | 10k-fasttext | 300 | 10k-fasttext-300d-ru | | Turkish | tr | 10k-fasttext | 300 | 10k-fasttext-300d-tr |
*10k-fasttext word embeddings contain the 10k most commons words of the language.
Note: All the word embeddings are stored by default in ~/.botonic/word-embeddings/
. If you encounter any issues when automatically downloading word embeddings, you can download them manually and store them in the mentioned directory.