while trying to train nlu, I keep having this error: '
“AttributeError: type object ‘SpellChecker’ has no attribute ‘required_packages’ Makefile:28: recipe for target ‘train-nlu’ failed make: *** [train-nlu] Error 1”
I’m trying to add my pre-trained spell checker as a custom component to rasa pipeline, my pre-trained checker class named as “SpellChecker” in spell_checker.py file , after importing it in the file that contains my custom component,
I then built my custom component class:
from complete_spell_checker.spell_checker import SpellChecker
class spell_checker_component(Component):
"""A new component"""
name = "complete_spell_checker.spell_checker.SpellChecker"
#name = "custom_component.spell_checker_component"
provides = ["spell_checking"]
requires = ["text"]
defaults = {}
language_list = "en"
def __init__(self, component_config=None):
super(spell_checker_component, self).__init__(component_config)
def train(self, training_data, cfg, **kwargs):
pass
def process(self, message, **kwargs):
m = message.text
new_m = SpellChecker.corrector(m)
message.set("text", new_m, add_to_output=True)
print("new meassage becomes--> ",message.text)
@classmethod
def required_packages(self):
return ["jamspell"]
def persist(self, model_dir):
"""Persist this component to disk for future loading."""
pass
and my nlu_config.yml file:
language: "en"
pipeline:
- name: "complete_spell_checker.spell_checker.SpellChecker"
- name: "spacy_sklearn"
my SpellChecker class:
import jamspell
class SpellChecker(object):
#required_packages = []
def __init__(self, sentence = ''):
self.modified_sentence = sentence
#self.modified_sentence = self.corrector(sentence)
self.required_packages = []
def corrector (self,sentence: str) ->str:
'''
A function that is used to check a sentence for any spell-mistakes and try to modify it.
Args:
sentence(string): The input sentence that want to be spell-checked
Returns:
modified_sentence(string): The input sentence after modifying it
'''
corrector = jamspell.TSpellCorrector()
corrector.LoadLangModel('JamSpell/build/model_cars.bin')
modified_sentence = corrector.FixFragment(sentence)
return modified_sentence
@classmethod
def required_packages(self):
return ["jamspell"]