Entity Recognition Issues

I have a couple issues that I’m trying to figure out how to address.

  1. How can you identify the slot that an entity came from when there are 2 entities of the same type in a single utterance?

Problematic utterances:

  • give me directions from {fromAddress:address} to {toAddress:address}
  • give me directions to {toAddress:address} from {fromAddress:address}

Generally when crafting utterances, each entity is given a name and a type. However it seems with rasa, entities are only defined by their type. So, when you have a single utterance with two of the same entity types, you left wondering which entity is which.

  1. How can you support entity types for one intent that overlap with entity types for other intents?

Problematic utterances:

  • updateDrink: I would like a {drink:liquidFood} to drink
  • updateAnyFood: I gave my children {food:anyFood} for dinner

In this case liquidFood might contain milk, soda, water, etc… while anyFood would contain cheeseburger, fries, etc… as well as all the items found in liquidFood.

When rasa resolves the entities for “I would like a milk shake to drink” it finds an entity called “food” with a value of “milk shake” when the intent was looking for a drink…

thanks for posting your question, @benawhite!

The from ... to pattern is an example of entity roles , e.g. the same entity can have multiple roles depending on context. For now, you can just create separate entity types for this (fromAddress and toAddress ) and the crf will figure out it should pay attention to the words “from” and “to”. However this can risk overfitting specific addresses, so I recommend having a look at lookup tables as a way of making that model more robust.

Alternatively, for cases like the “from” “to” pattern you can also use spaCy to get a dependency parse of the sentence, and then look for the parents of the entities that were recognized.

for example, you could do something like this:

import spacy

# extremely dumb entity extractor
colors = ["red", "blue"]
items = ["jacket", "jeans"]

def entity_type(word):
    _type = None
    if word.text in colors:
        _type = "color"
    elif word.text in items:
        _type = "item"
    return _type


# load spacy's English model
nlp = spacy.load('en')
# Create the document
doc = nlp("let's see that jacket in red and some blue jeans")

# Iterate over parents in parse tree until an item entity is found
def find_parent_item(word):
    # Iterate over the word's ancestors
    for parent in word.ancestors:
        # Check for an "item" entity
        if entity_type(parent) == "item":
            return parent.text
    return None

# For all color entities, find their parent item
def assign_colors(doc):
    # Iterate over the document
    for word in doc:
        # Check for "color" entities
        if entity_type(word) == "color":
            # Find the parent
            item =  find_parent_item(word)
            print("item: {0} has color : {1}".format(item, word))

# Assign the colors
assign_colors(doc)