schy
schy

Reputation: 21

Rasa nlu model is not working. AttributeError: 'str' object has no attribute 'load'

First of all i want to say that i am completly new to this topic. I was trying to build a Chatbot with Rasa. While following a tutorial on YouTube :https://www.youtube.com/watch?v=xu6D_vLP5vY&t=514s I came across a problem with the nlu_model.py file.

Because the tutorial is made a while ago, there have been some changes made. I tried the old and the new Version and both won't work for me.

from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer

def train_nlu(data, config, model_dir):
    training_data = load_data(data)
    trainer = Trainer(config.load(configs))
    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')

this is my nlu_model.py file

C:\Users\Yannic\Documents\Waetherbot>python nlu_model.py
Traceback (most recent call last):
  File "nlu_model.py", line 12, in <module>
    train_nlu('./data/data.json', 'config_spacy.json', './models/nlu')
  File "nlu_model.py", line 7, in train_nlu
    trainer = Trainer(config.load(configs))
AttributeError: 'str' object has no attribute 'load'

And this is my Shell Output. I really hope i can get some help.

Upvotes: 1

Views: 1653

Answers (1)

DobromirM
DobromirM

Reputation: 2027

config is a module imported from rasa_nlu, however you are shadowing it with the parameter config in the function. I think you meant to name your function parameter configs.

Fixed Code:

from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer

def train_nlu(data, configs, model_dir):
    training_data = load_data(data)
    trainer = Trainer(config.load(configs))
    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')

Upvotes: 2

Related Questions