Rasa: Composite entities support

Created on 28 Apr 2017  路  20Comments  路  Source: RasaHQ/rasa

It would be very helpful if composite entities would be supported, these are entities that have a hierarchical structure. For example: "I need a red dress with blue dots" or "The shirt should be not yellow" or "I need a red shirt and blue sneakers".

In wit.ai they have those entities and they're very helpful: https://wit.ai/blog/2015/05/05/composite-entity

type

Most helpful comment

this feature would be super useful, was trying to import api.ai agent with composite entities and realized that this is not yet supported ((
more on the use case behind it you can find here
https://docs.api.ai/docs/concept-entities#section-developer-composite-entities

All 20 comments

@natreen from my understanding this is a duplicate of #267 . Do you think so too?

I'm not so sure if we mean the same. For me #267 sounds more like word-compounds (two entities for one word) and I rather mean nested entities.

this feature would be super useful, was trying to import api.ai agent with composite entities and realized that this is not yet supported ((
more on the use case behind it you can find here
https://docs.api.ai/docs/concept-entities#section-developer-composite-entities

actually now, when i faced that composite entities is not available in rasa, i am kind of stuck how to handle following situation.
imagine i need to compare sales of 2 configuration of cars
so my question would be:
"please give me sales of red sport convertible cars compared to sport hatchback cars in june 2017"

with composite entity i would identify 2 cars entites with following attributes (works in api.ai)
car1{ color:red, trim:sport, chassis:convertible}
car2{trim:sport, chassis:hatchback}

in rasa i need to make it 3 different entities and i will get a response
color:[red]
trim:[sport,sport]
chassis[convertible, hatchback]
from this i can figure out user is talking about 2 cars ( length of array > 1), but to which car shall assign red, to the first or to the second is not clear.

may be you can suggest how to handle this.

We don't have a general purpose feature for this yet, but you can write something for your particular case using spaCy's parse tree. Here's how the parse looks for this sentence.

So you can identify relationships using each token's ancestors attribute, or example. See here

I may be wrong but I think that would require either a new component for entity classification using a structured classifier like a structured SVM or adding some changes to the existing CRF component as CRF is by nature a strructured classfiffier.

amn41, thanks for suggestion
for now looks complex for me to write it, i do no know python.
what i am thinking of is to create entity car with all possible combinations of attributes (likely i have 3 only) like
red
red sport
sport red
red sport hatchback
red hatchback sport
hatchback red sport
etc...

@amn41 This is really useful info.
How can Rasa provide this data? Does it expose the spacy information?
Or does it mean a new spacy instance is needed, outside of the scope of Rasa?

you could either write a new component, which accesses the spacy language object (spacy_nlp), see an example here: https://github.com/RasaHQ/rasa_nlu/blob/master/rasa_nlu/featurizers/spacy_featurizer.py#L23

otherwise yes you could load a separate spacy instance somewhere in your application.

Great.
That's my next question - maybe Rasa can expose the 'featurizer' as a REST API?

What is the status on this one? Is there any current form of building nested entities? I need to build something like this ->
_"List of Walmart purchases:
Boots, 28 March
Tent, 30 March"_
as
walmart_purchase{
item:boots
date:03-28-2018 }
walmart_purchase(
item:tent
date:03-30-2018
}

My team got this working, but it's messy. We'd like to talk to someone (@amn41 ?) about how to make the integration cleaner.

@samhavens is this something you'd be willing to share with the community?

Our PR handling this within Rasa NLU wasn't getting merged, so we figured out how to do this as a custom component. We've open sourced it in Innatis. Let us know if you have trouble getting it working, as so far we are our only consumers, so docs are probably lacking.

@samhavens sorry about that, we're looking into the PR in detail this week :)

No worries! Whoever looks at it should also look at https://github.com/Revmaker/innatis, it probably makes sense to keep it as a custom component and close the PR

if we find it's essential though we'd still like to add it to the code base :)

Cool! Just keep us posted. It should make migration from DF->Rasa easier

Hey, we have released our own component that handles composite entities at https://github.com/BeWe11/rasa_composite_entities. Maybe this can be of use to some people here.

@BeWe11 thanks for sharing as well :)
I think we can close this issue now, as the feature exists in multiple libraries

Was this page helpful?
0 / 5 - 0 ratings