How can i implement a sentiment analysis in RASA 2.x

@Rasa I have followed this tutorial but ended up with couple of errors, and understood that it is in older version of RASA. Is there any way to do it in RASA 2.x

Hi Susaj,

I’m not aware of any changes to custom components in Rasa 2.0, and don’t see anything in the migration guide:

What errors are you experiencing?

@kearnsw When i am trying with pre trained model

Traceback (most recent call last):
  File "/home/fingent/venvs/bbc_demo/bin/rasa", line 8, in <module>
    sys.exit(main())
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/__main__.py", line 116, in main
    cmdline_arguments.func(cmdline_arguments)
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/cli/train.py", line 81, in train
    return rasa.train(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/train.py", line 43, in train
    return rasa.utils.common.run_in_loop(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/utils/common.py", line 308, in run_in_loop
    result = loop.run_until_complete(f)
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/train.py", line 102, in train_async
    return await _train_async_internal(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/train.py", line 198, in _train_async_internal
    await _do_training(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/train.py", line 240, in _do_training
    model_path = await _train_nlu_with_validated_data(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/train.py", line 541, in _train_nlu_with_validated_data
    await rasa.nlu.train(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/nlu/train.py", line 117, in train
    persisted_path = trainer.persist(
  File "/home/fingent/venvs/bbc_demo/lib/python3.8/site-packages/rasa/nlu/model.py", line 244, in persist
    update = component.persist(file_name, dir_name)
TypeError: persist() takes 2 positional arguments but 3 were given

and when trying to generate a model then the following occurs

File "/home/fingent/works/RASA/bbc_demo/sentiment.py", line 36, in train
    tokens = [list(map(lambda x: x.text, t.get('tokens'))) for t in training_data]
  File "/home/fingent/works/RASA/bbc_demo/sentiment.py", line 36, in <listcomp>
    tokens = [list(map(lambda x: x.text, t.get('tokens'))) for t in training_data]
TypeError: 'NoneType' object is not iterable

i have kept label.txt as well

This should not be necessary, but I saw it as a solution on the following GitHub isssue:

Can you try overriding the persist method with a signature that only takes the two positional arguments?


@staticmethod
def persist(file_name, dir_name)

In the second, it appears t.get(‘tokens’) are None, resulting in the error. What does your config.yml file look like?

It may be useful for debugging purposes as well if you could print the output of [msg.as_dict() for msg in training_data.training_examples]?

Depending on if this is only impacting a subset of your training data, you may try catching the error, by expanding the list comprehension and checking for the case that tokens is None.

1 Like