LUIS技术咨询:单Utterance中多复合实体归属识别问题
Hey there! As someone who's wrestled with LUIS's entity recognition quirks before, I feel your pain when multiple items in a single utterance don't get mapped to their correct composite entities. Let's walk through how to get your order scenario working right with that test phrase: "purchase for me 2 red hot chilli pepper albuns and an amazing spiderman figure please"
Step 1: Verify Your Composite Entity Structure
First, make sure you've set up a parent composite entity (let's call it OrderItem) that wraps all the child entities relevant to a single order line. Your structure should look something like this:
- Parent Entity:
OrderItem(Composite type)- Child Entities:
Quantity(can use the prebuiltNumberentity or a custom one)ProductName(custom entity for the item's specific name)ProductType(custom entity for categories like "albums", "figure")
- Child Entities:
If you haven't layered your entities this way, LUIS won't know how to group attributes to individual items.
Step 2: Correctly Label Utterances with Entity Boundaries
This is the most critical part—LUIS learns from how you label examples. For your test utterance, you need to explicitly label two separate OrderItem instances, each with their own child entities:
- Highlight "2 red hot chilli pepper albuns" and assign it to
OrderItem:- Inside this, label "2" as
Quantity - Label "red hot chilli pepper" as
ProductName - Label "albuns" as
ProductType
- Inside this, label "2" as
- Highlight "an amazing spiderman figure" and assign it to a second
OrderItem:- Label "an" as
Quantity(you can map this to the value1in your post-processing code) - Label "amazing spiderman" as
ProductName - Label "figure" as
ProductType
- Label "an" as
Add 5-10 more similar utterances with multiple items, each labeled consistently. Examples like:
- "buy 3 harry potter books and 2 star wars action figures"
- "order 1 large pizza and 2 bottles of soda"
Step 3: Use Patterns to Reinforce Repeatable Structures
LUIS patterns help it recognize recurring sentence structures. Create a pattern like this to teach it to expect multiple OrderItem instances:
purchase for me {OrderItem} and {OrderItem} please
You can add variations too, like:
buy {OrderItem} and {OrderItem} order {OrderItem}, {OrderItem}, and {OrderItem}
Step 4: Check for Entity Conflicts
If you're using prebuilt entities (like Number), make sure they're properly associated with your composite entity. Sometimes prebuilt entities can override custom labels—double-check that in your entity settings, the child entities are set to be part of the OrderItem composite, not standalone.
Step 5: Test and Iterate
After labeling examples and adding patterns, train your LUIS app, then test your utterance again. Look at the returned JSON's entities array—you should see two distinct OrderItem instances, each containing their respective Quantity, ProductName, and ProductType values. If something's off, go back to your labeled utterances and make sure boundaries are correct (no overlapping labels, no missing child entity assignments).
内容的提问来源于stack exchange,提问作者Bruno Alves

