Getting Started¶
The original goal of taipo
was to augment NLU data such that we can train
Rasa models to be robust against misspellings. This guide will show you how
to train models that are robust against spelling errors.
Installation¶
You can install this experiment via pip.
python -m pip install "taipo @ git+https://github.com/RasaHQ/taipo.git"
This will install the taipo
command line interface in your virtualenv.
You can confirm the installation went fine by running:
python -m taipo
Generating Spelling Errors¶
Let's say that you've gotten a Rasa project. Your folder structure would look something like:
๐ rasa-project-dir
โฃโโ ๐ actions
โฃโโ ๐ data
โ โฃโโ ๐ nlu.yml
โ โฃโโ ๐ rules.yml
โ โโโ ๐ stories.yml
โฃโโ ๐ models
โฃโโ ๐ tests
โฃโโ ๐ config.yml
โฃโโ ๐ credentials.yml
โฃโโ ๐ domain.yml
โโโ ๐ endpoints.yml
The idea is that we will generate a variant of nlu.yml
that contains spelling errors.
This way, we might be able to train our models to be robust against it.
A straightforward way to do this is via;
python -m taipo keyboard augment data/nlu.yml data/typo-nlu.yml
This will generate a new file that contains typos.
๐ rasa-project-dir
โฃโโ ๐ actions
โฃโโ ๐ data
โ โฃโโ ๐ nlu.yml
โ โฃโโ ๐ typo-nlu.yml
โ โฃโโ ๐ rules.yml
โ โโโ ๐ stories.yml
โฃโโ ๐ models
โฃโโ ๐ tests
โฃโโ ๐ config.yml
โฃโโ ๐ credentials.yml
โฃโโ ๐ domain.yml
โโโ ๐ endpoints.yml
When you inspect the typo-nlu.yml
file you'll notice that we copied each
example from the original nlu.yml
file but added some typos. These typos
are based on the keyboard layout. The base setting assumes the US layout but
you can configure some non-English layouts as well. Check the API docs for
more info.
When you now train your nlu model, it will also train on these misspelled items.
python -m rasa train
You will notice that training takes a fair bit longer because we're training on twice as much data now.
Finetuning¶
If you're worried about the long training time, you may prefer to use the fine-tuning feature instead. If you're unfamiliar with the technique, you may appreciate this algorithm whiteboard video.
To train the system with finetuning you can first train your NLU model on the original data.
rasa train nlu --nlu nlu/nlu.yml --fixed-model-name orig
Once this model is trained, you can finetune it on the misspelled data.
rasa train nlu --nlu nlu/nlu.yml \
--finetune models/orig.tar.gz \
--epoch-fraction 0.1 \
--fixed-model-name finetuned
Benchmarking¶
Training against misspelled data is nice, but we'd also like to quantify the effect
that typos have on our system. This guide assumes that you have a tests/nlu-valid.yml
file which can be used as a validation dataset. Let's make a misspelled variant of this
dataset first.
python -m taipo keyboard augment tests/nlu-valid.yml tests/typo-nlu-valid.yml
We can now run our two models models/orig.tar.gz
and models/finetuned.tar.gz
against
both of these datasets.
rasa test nlu -u tests/nlu-valid.yml --model models/orig.tar.gz --out gridresults/orig-model
rasa test nlu -u tests/nlu-valid.yml --model models/finetuned.tar.gz --out gridresults/finetuned-model
rasa test nlu -u tests/typo-nlu-valid.yml --model models/orig.tar.gz --out gridresults/typo-orig-model
rasa test nlu -u tests/typo-nlu-valid.yml --model models/finetuned.tar.gz --out gridresults/typo-finetuned-model
This results in 4 folders that contain your benchmarked results. You could use rasalit to visualise these but you can also use a utility function from the command line. Let's say that you've got a folder structure like so:
๐ gridresults
โฃโโ ๐ orig-model
โ โฃโโ ...
โ โโโ ๐ intent_report.json
โฃโโ ๐ finetuned-model
โ โฃโโ ...
โ โโโ ๐ intent_report.json
โฃโโ ๐ typo-orig-model
โ โฃโโ ...
โ โโโ ๐ intent_report.json
โโโ ๐ typo-finetuned-model
โฃโโ ...
โโโ ๐ intent_report.json
Then you can get a convenient summary via:
python -m taipo util summary gridresults
You may get a table that looks like this:
โโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโณโโโโโโโโโโ
โ folder โ accuracy โ precision โ recall โ f1 โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ finetuned-model โ 0.9022 โ 0.90701 โ 0.9022 โ 0.90265 โ
โ orig-model โ 0.90018 โ 0.90972 โ 0.90018 โ 0.90192 โ
โ typo-finetuned-model โ 0.89965 โ 0.90302 โ 0.89965 โ 0.89984 โ
โ typo-orig-model โ 0.79419 โ 0.82945 โ 0.79419 โ 0.80266 โ
โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโ
Feedback¶
This project is part of ongoing research. In general NLP algorithms have proven to be brittle against typos and we wanted to make it easy for our community to investigate this. Feedback on the tool, as well as any interesting typo-related findings, is much appreciated.
Feel free to mention any bugs on Github and any
other feedback on the rasa forum. You can poke
@koaning
on the Rasa forum if you have any typo-related insights. Especially insights from
non-English languages would be much appreciated!