I am trying to train a model for chatbot and created the following files.
Model configuration file config_spacy.json
{
"pipeline": "spacy_sklearn",
"path":"./models/nlu",
"data":"./data/data.json"
}
Training file nlu_model.py
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu import config
def train_nlu(data, config, model_dir):
training_data = load_data(data)
trainer = Trainer(RasaNLUModelConfig(config))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name = 'weathernlu')
if __name__ == '__main__':
train_nlu('./data/data.json','config_spacy.json','./models/nlu')
On running the file, I am getting the following error.
Traceback (most recent call last):
File "nlu_model.py", line 13, in <module>
train_nlu('./data/data.json','config_spacy.json','./models/nlu')
File "nlu_model.py", line 8, in train_nlu
trainer = Trainer(RasaNLUModelConfig(config))
File "C:\anaconda3\lib\site-packages\rasa_nlu\config.py", line 103, in __init__
self.override(configuration_values)
File "C:\anaconda3\lib\site-packages\rasa_nlu\config.py", line 180, in override
self.__dict__.update(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
I searched a lot but I am unable to fix this error.
Thanks for raising this issue, @EPedrotti will get back to you about it soon.
I am struggling with the same issue.
@EPedrotti please take a look at this
I found a closed GitHub issue that dealt with the training problem. You can work around it by calling the statements directly instead of using the _def_train_nlu()_ method. This worked in my case and it seems that the model is trained now.
But, I come across the same problem when I want to test the model I just created.
nlu_model.py
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu.model import Metadata, Interpreter
def run_nlu():
interpreter = Interpreter.load('./models/nlu/default/weathernlu', RasaNLUModelConfig('config_spacy.json'))
print(interpreter.prase(u"I am planning my holiday to Barcelona. I wonder what is the weather out there."))
if __name__ == '__main__':
run_nlu()
After executing I receive the following message:
Traceback (most recent call last):
File "nlu_model.py", line 30, in <module>
run_nlu()
File "nlu_model.py", line 26, in run_nlu
interpreter = Interpreter.load('./models/nlu/default/weathernlu', RasaNLUModelConfig('config_spacy.json'))
File "/home/dejan/anaconda3/lib/python3.6/site-packages/rasa_nlu/config.py", line 103, in __init__
self.override(configuration_values)
File "/home/dejan/anaconda3/lib/python3.6/site-packages/rasa_nlu/config.py", line 180, in override
self.__dict__.update(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
This time it does not work with the direct call of the statements. Any ideas or progress already?
@EPedrotti please take a look at this
@i-am-dejan @dummybot123 please modify you code as follows
def train_nlu(data, config_file, model_dir):
training_data = load_data(data)
trainer = Trainer(config.load(config_file))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name = 'weathernlu')
The problem was that RasaNLUModelConfig requires a json object, not just the file path to the configuration. The easiest way to load the json config file and pass it directly to the RasaNLUModelConfig is to use the config.load function. I hope this helps.
@EPedrotti
That is exactly what is written in the Issue I found 3 day ago. So it should work for everyone therefore and not only for me. Thank you.
But how is it in the case of testing the model? The config.load function seems not to work there:
def run_nlu():
interpreter = Interpreter.load('./models/nlu/default/weathernlu', config.load('config_spacy.json'))
print(interpreter.prase(u"I am planning my holiday to Barcelona. I wonder what is the weather out there."))
if __name__ == '__main__':
run_nlu()
I get the following error:
Traceback (most recent call last):
File "nlu_model.py", line 33, in <module>
run_nlu()
File "nlu_model.py", line 28, in run_nlu
interpreter = Interpreter.load('./models/nlu/default/weathernlu', config.load('config_spacy.json'))
NameError: name 'config' is not defined
By using RasaNLUModelConfig with the full path:
def run_nlu():
interpreter = Interpreter.load('./models/nlu/default/weathernlu', RasaNLUModelConfig('/home/dejan/Schreibtisch/Chatbot-Experiment/config_spacy.json'))
print(interpreter.prase(u"I am planning my holiday to Barcelona. I wonder what is the weather out there."))
if __name__ == '__main__':
run_nlu()
I still get the same error as before:
Traceback (most recent call last):
File "nlu_model.py", line 33, in <module>
run_nlu()
File "nlu_model.py", line 26, in run_nlu
interpreter = Interpreter.load('./models/nlu/default/weathernlu', RasaNLUModelConfig('/home/dejan/Schreibtisch/Chatbot-Experiment/config_spacy.json'))
File "/home/dejan/anaconda3/lib/python3.6/site-packages/rasa_nlu/config.py", line 103, in __init__
self.override(configuration_values)
File "/home/dejan/anaconda3/lib/python3.6/site-packages/rasa_nlu/config.py", line 180, in override
self.__dict__.update(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Am I doing something completely wrong?
@i-am-dejan just add from rasa_nlu import config. I forgot to add it to the example, sorry about that.
@EPedrotti
Thank you very much for you fast response. I got a little further. After the import I was struggling with the AttributeError: 'RasaNLUModelConfig' object has no attribute 'load_component' error message. That's why I followed the instructions in Issue 1066 and adapted my code. After executing the following code:
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu.model import Metadata, Interpreter
from rasa_nlu import config
def run_nlu():
interpreter = Interpreter.load('./models/nlu/default/weathernlu')
print(interpreter.prase(u"I am planning my holiday to Barcelona. I wonder what is the weather out there."))
if __name__ == '__main__':
run_nlu()
I get the following error message:
/home/dejan/anaconda3/lib/python3.6/site-packages/rasa_nlu/extractors/entity_synonyms.py:85: UserWarning: Failed to load synonyms file from './models/nlu/default/weathernlu/entity_synonyms.json'
"".format(entity_synonyms_file))
Traceback (most recent call last):
File "nlu_model.py", line 20, in <module>
run_nlu()
File "nlu_model.py", line 16, in run_nlu
print(interpreter.prase(u"I am planning my holiday to Barcelona. I wonder what is the weather out there."))
AttributeError: 'Interpreter' object has no attribute 'prase'
Do I have to add the deleted config.load attribute to the Interpreter.load()?
Thank you and best regards
Dejan
@i-am-dejan I think you just mispelled parse.
Marking as closed now
You have eagle eyes :)
Thank you both @EPedrotti and @akelad !
It works perfectly.