I want to extract entities and entity scores using the ner_crf component

Hello, I am trying to extract the entities and entity scores (using the ner_crf component) from sentences while a conversation is going on. I have described the things I have done to solve the issue, the error and code for more reference.

While I am providing key1 = tracker.latest_message.entities and, l_confidence_1 = tracker.latest_message.entities(confidence) in the actions.py file, it gives an empty list for any question I provide.

In addition, if I provide the lines as given below it shows errors “cannot accept strings”

key1 = tracker.latest_message.entities[“name”] l_confidence_1 = tracker.latest_message.entities[“confidence”]

I am providing the code for actions.py below for better understanding. It would be helpful if anybody could please help me identify the issue to solve the problem. Thanks in advance.

from future import absolute_import from future import division from future import print_function from future import unicode_literals

import argparse import logging import warnings

from rasa_core import utils from rasa_core.actions import Action from rasa_core.agent import Agent from rasa_core.trackers import DialogueStateTracker

with warnings.catch_warnings(): warnings.filterwarnings(“ignore”, category= DeprecationWarning)

lclass ActionTest(Action): def name(self): return ‘action_test’

def run(self, dispatcher, tracker, domain):
   key1 = tracker.latest_message.entities
    l_confidence_1 = tracker.latest_message.entities(confidence)
    if tracker:
        print(tracker.current_state()) # or do other things
   return []

are you sure that entities are being extracted? if you run your bot with rasa_core.run --debug you should be able to see detailed output

Thank you for the response but unfortunately I am not getting the entity and its confidence for the .json data I have (I only get the answer for intent and intent confidence) and surprisingly only for 1 example, I get the entity details which is “find me a chinese restaurant” and the result is:

{‘sender_id’: ‘default’, ‘slots’: {‘expert_name’: None, ‘world_region’: None}, ‘latest_message’: {‘intent’: {‘name’: ‘deny’, ‘confidence’: 0.7647595405578613}, ‘entities’: [{‘entity’: ‘NORP’, ‘value’: ‘chinese’, ‘start’: 10, ‘confidence’: None, ‘end’: 17, ‘extractor’: ‘ner_spacy’}], ‘intent_ranking’: [{‘name’: ‘deny’, ‘confidence’: 0.7647595405578613}, {‘name’: ‘identity’, ‘confidence’: 0.6648507118225098}, {‘name’: ‘world_region_specified’, ‘confidence’: 0.43626418709754944}, {‘name’: ‘goodbye’, ‘confidence’: 0.37390995025634766}, {‘name’: ‘affirm’, ‘confidence’: 0.3427983820438385}, {‘name’: ‘state_of_mind’, ‘confidence’: 0.3231664001941681}, {‘name’: ‘gdpr_principles’, ‘confidence’: 0.3081985116004944}, {‘name’: ‘gdpr_affected_areas_specification’, ‘confidence’: 0.2131408452987671}, {‘name’: ‘gdpr_target_public’, ‘confidence’: 0.20181195437908173}, {‘name’: ‘gdpr_consent_when’, ‘confidence’: 0.20151212811470032}], ‘text’: ‘find me a chinese restaurant please’}, ‘latest_event_time’: 1535108341.9519327,‘paused’: False, ‘events’: None}

I have highlighted the portion for convenience.

Please let me know what can be done to solved the problem. I have tried the sudo python3 train_nlu.py version, sudo python3 -m rasa_core.train and finally the sudo python3 -m rasa_core.run in the terminal (as per the rasa documentation) but it does not give me the entity score and the entities (although the answers are fine ).

Thanks in advance.

Ah, you are using spaCy’s NER, which does not report the confidence value. See the note at the bottom of this page: http://rasa.com/docs/nlu/entities/

Sorry for the late response from my side, thank you for the information but now I am trying to use ner_crf for the extraction actually. Thanks in advance.


 key1 = tracker.latest_message.entities
AttributeError: 'dict' object has no attribute 'entities'

Any help ?