Cannot get entity extraction to work with Rasa NLU

Hi, I have successfully got my code to detect the correct intent but no entities appear even though I provided some entities in my training data.

data.json: { “common_examples”: [ { “text”:“Hello”, “intent”:“greeting”, “entities”:[] }, { “text”:“Hi”, “intent”:“greeting”, “entities”:[] }, { “text”:“I want a recipe for my lunch”, “intent”:“get_recipe”, “entities”:[ { “start”:22, “end”: 28, “value”: “lunch”, “entity”: “mealtime” } ] }, { “text”:“Can you give me a recipe for dinner tonight?”, “intent”:“get_recipe”, “entities”:[ { “start”:29, “end”:35, “value”: “dinner”, “entity”: “mealtime” } ] }, { “text”:“I don’t know what to have for lunch”, “intent”:“get_recipe”, “entities”:[ { “start”:31, “end”: 35, “value”: “lunch”, “entity”: “mealtime” } ] }, },

}

This is just a snippet. I have created 11 example sentences in total for the get_recipe intent. I just need it to pick out the entity of ‘mealtime’ as either lunch or dinner depending on how the sentence is phrased.

My config.yml is as follows:

language: “en”

pipeline:

  • name: “nlp_spacy”
  • name: “tokenizer_spacy”
  • name: “intent_entity_featurizer_regex”
  • name: “intent_featurizer_spacy”
  • name: “ner_crf”
  • name: “ner_synonyms”
  • name: “intent_featurizer_count_vectors”
  • name: “intent_classifier_tensorflow_embedding”

and this if the code I run to train the bot: from rasa_nlu.training_data import load_data from rasa_nlu.model import Trainer from rasa_nlu import config from rasa_nlu.model import Interpreter

def train_bot(data_json,config_file,model_dir): training_data = load_data(data_json) trainer = Trainer(config.load(config_file)) trainer.train(training_data) model_directory=trainer.persist(model_dir,fixed_model_name=‘vegabot’)

And the code I run to predict the intent: def predict_intent(text): interpreter = Interpreter.load(‘models/nlu/default/vegabot’) print(interpreter.parse(text))

Which produces the result: {‘intent’: {‘name’: ‘get_recipe’, ‘confidence’: 0.9701309204101562}, ‘entities’: [], ‘intent_ranking’: [{‘name’: ‘get_recipe’, ‘confidence’: 0.9701309204101562}, {‘name’: ‘greeting’, ‘confidence’: 0.03588612377643585}], ‘text’: ‘can you find me a recipe for dinner’}

As you can see the intent is correct but entities is blank [] and I can’t figure out why. Any help would be greatly appreciated.

I ran an evaluation and got: - intent examples: 12 (2 distinct intents) - Found intents: ‘greeting’, ‘get_recipe’ - entity examples: 10 (1 distinct entities) - found entities: ‘mealtime’ which all looks fine.

I’m using rasa nlu version 0.14.

I seem to have solved this by adding more similar examples. Maybe I wasn’t training it on enough data. The entity confidence is around 0.5 now so should be able to increase with more examples to train it on :slight_smile:

1 Like

Hey @francescaz. Yes, adding more examples usually helps, especially at the early stages of the development.

Hi Juste,

Like how we get intent rankings which contains rankings of other intents that our model predicts, is there any way where we can get other entities rankings as well ?

hey I am using rasa_nlu for which my code is:

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

train_data = load_data(‘test.json’)

trainer = Trainer(config.load(“config_spacy.yaml”))

trainer.train(train_data)

model_directory = trainer.persist(’/home/ec2-user/projects/’)

and for the prediction it’s

import spacy

from rasa_nlu.model import Metadata, Interpreter

interpreter = Interpreter.load(’/home/ec2-user/projects/default/model_20191015-10052 print(interpreter.parse(u"I want an African Spot to eat"))

but it’s only printing out the intent rankings and not the entity values could you please help me.