Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Fix: Allow slot tags to be discontinuous
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Apr 16, 2020
1 parent 9c15204 commit 59b18fe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public Map<String, String> getSlots(
String value = encoded.decodeRange(slotRange.getKey(),
slotRange.getValue(), true);
String slotName = tagLabels[slotRange.getKey()].substring(2);
slots.put(slotName, value);
String curValue = slots.get(slotName);
if (curValue != null) {
curValue += " " + value;
slots.put(slotName, curValue);
} else {
slots.put(slotName, value);
}
}
return slots;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ public void classify() throws Exception {
assertEquals(slots, result.getSlots());
assertEquals(utterance, result.getUtterance());
assertTrue(result.getContext().isEmpty());

// simulate two different spans being tagged as the same slot
// in this example, "bad" doesn't get tagged as part of the noun phrase
// (which is incorrect, but we're just testing the slot extraction
// logic here)
utterance = "this bad code is for test 1";
intentResult = buildIntentResult(2, env.metadata.getIntents().length);
tagResult = new float[utterance.split(" ").length
* env.metadata.getTags().length];
setTag(tagResult, env.metadata.getTags().length, 0, 1);
setTag(tagResult, env.metadata.getTags().length, 2, 1);
setTag(tagResult, env.metadata.getTags().length, 6, 3);
env.testModel.setOutputs(intentResult, tagResult);
result = env.classify(utterance).get();

slots = new HashMap<>();
slots.put("noun_phrase",
new Slot("noun_phrase", "this code", "this code"));
slots.put("test_num", new Slot("test_num", "1", 1));

assertNull(result.getError());
assertEquals("describe_test", result.getIntent());
assertEquals(10.0, result.getConfidence());
for (String slotName : slots.keySet()) {
assertEquals(slots.get(slotName), result.getSlots().get(slotName));
}
assertEquals(slots, result.getSlots());
assertEquals(utterance, result.getUtterance());
assertTrue(result.getContext().isEmpty());
}

private float[] buildIntentResult(int index, int numIntents) {
Expand Down

0 comments on commit 59b18fe

Please sign in to comment.