Skip to content

Instantly share code, notes, and snippets.

@nikhilcheke
Last active October 8, 2020 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhilcheke/589e242063f914ccf4dfa0da096ea28d to your computer and use it in GitHub Desktop.
Save nikhilcheke/589e242063f914ccf4dfa0da096ea28d to your computer and use it in GitHub Desktop.
Custom component for spell checking in Rasa NLU
from rasa.nlu.components import Component
from rasa.nlu import utils
from rasa.nlu.model import Metadata
from spellchecker import SpellChecker
spell = SpellChecker()
class CorrectSpelling(Component):
name = "Spell_checker"
provides = ["message"]
requires = ["message"]
language_list = ["en"]
def __init__(self, component_config=None):
super(CorrectSpelling, self).__init__(component_config)
def train(self, training_data, cfg, **kwargs):
"""Not needed, because the the model is pretrained"""
pass
def process(self, message, **kwargs):
"""Retrieve the text message, do spelling correction word by word,
then append all the words and form the sentence,
pass it to next component of pipeline"""
textdata = message.text
textdata = textdata.split()
new_message = ' '.join(spell.correction(w) for w in textdata)
message.text = new_message
def persist(self,file_name, model_dir):
"""Pass because a pre-trained model is already persisted"""
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment