KeyError in Custom Component

I’m trying to implement the Custom Component Sentiment Analyzer following the below blog:

but landed up in a Key Error: Please find the error traceback: Traceback (most recent call last): File “nlu_model.py”, line 31, in train_nlu(‘./data/nlu.md’, ‘nlu_config.yml’, ‘./models’) File “nlu_model.py”, line 19, in train_nlu run_evaluation(data_path, model_directory) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 767, in run_evaluation report_folder) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 399, in evaluate_entities tokens, extractors) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 579, in align_all_entity_predictions extractors)) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 558, in align_entity_predictions extracted = determine_token_labels(t, entities, extractor) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 526, in determine_token_labels candidates = find_intersecting_entites(token, entities) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 483, in find_intersecting_entites if is_token_within_entity(token, e): File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 438, in is_token_within_entity return determine_intersection(token, entity) == len(token.text) File “/home/nitin/anaconda3/envs/botenv/lib/python3.6/site-packages/rasa_nlu/evaluate.py”, line 452, in determine_intersection pos_entity = set(range(entity[“start”], entity[“end”])) KeyError: ‘start’

Awaiting for a solution.

Hi @nihtinajet. At which step do you get the following error?

@Juste I also have a similar error after following that blog. The custom sentiment component that I added works fine when use the created modes for prediction however when I use the 'test" method I get this error:

File "train.py", line 103, in <module>
    test_result = test(jsonPath + "test/", persistPath)
  File "/home/jamie/Documents/standalone/venv/lib/python3.7/site-packages/rasa_nlu/test.py", line 779, in run_evaluation
    report_folder)
  File "/home/jamie/Documents/standalone/venv/lib/python3.7/site-packages/rasa_nlu/test.py", line 397, in evaluate_entities
    tokens, extractors)
  File "/home/jamie/Documents/standalone/venv/lib/python3.7/site-packages/rasa_nlu/test.py", line 581, in align_all_entity_predictions
    extractors))
  File "/home/jamie/Documents/standalone/venv/lib/python3.7/site-packages/rasa_nlu/test.py", line 554, in align_entity_predictions
    entities_by_extractors[p["extractor"]].append(p)
KeyError: 'sentiment_extractor'

This error happens just after the testing is apparently 100% complete according to the debug progress bar.
Is this error occurring because my test data doesn’t have any mention of the sentiment entities that it is looking for?

Thanks, Jamie

Hi Jamie, curious to know if you managed to get output using rasa test? I’ve built a custom component and convert it to rasa output as per the tutorial. Using rasa shell i get the output i am looking for on a per message basis. However I want to look at the output by scoring a larger set, but rasa test breaks since my training&test data do not have entities that can be compared to the model output. Wanted to ask if you managed to solve your issue and can perhaps share some ideas? Thanks

Hey,

Yeah that’s pretty much the same situation I’m in. Never got the evaluations working and i haven’t had a chance yet to look at it again.

I will have a look at this later this month, need to upgrade to the new version of rasa too so maybe that’ll have fixed it.

If I do manage to get somewhere with it I’ll yet you know, cheers

I have the same issue.

I’m using MSRTExtractor and, even though it doesn’t need traning, I get this KeyError at the end of training.

hey @ogabrielluiz, can you show me the screenshot or logs?

I solved it.

In my case it was happening because MSRTExtractor is inheriting from Component. I’m creating a pull request as we speak as it should inherit from EntityExtractor.

This fixes the issue in my specific case. In summary, when Rasa would check all the extractors, it would look for MSRTExtractor and wouldn’t find it in the the pipeline’s extractors because it was registered as a Component.

1 Like

I tried inheriting from rasa.nlu.extractors.extractor import EntityExtractor

instead of Component, as suggested but no luck here. How did everybody else resolve this?

For reference, I am using rasa/rasa:2.3.4-full

any luck?