def create_frame(intent_label, slot_names_str, utterance): frame = Node( label=intent_label, span=Span(0, byte_length(utterance)), children={ Node(label=slot.label, span=Span(slot.start, slot.end)) for slot in parse_slot_string(slot_names_str) }, ) return frame
def aggregate_targets(self, batch_targets, batch_context): intent_targets = batch_targets[0] self.all_targets.extend([ create_frame( text, self.doc_label_names[intent_target], raw_slot_label, byte_length(text), ) for text, intent_target, raw_slot_label, seq_len in zip( batch_context[self.text_column_name], intent_targets, batch_context[DatasetFieldName.RAW_WORD_LABEL], batch_context[DatasetFieldName.SEQ_LENS], ) ])
def test_create_node(self): TEXT_EXAMPLES = [ ("exit", "device/close_app", "", "[device/close_app exit ]"), ( "call mom", "IN:CREATE_CALL", "5:8:SL:CONTACT", "[IN:CREATE_CALL call [SL:CONTACT mom ] ]", ), ( "An Yu", "meta/provideSlotValue", "0:5:SL:CONTACT", "[meta/provideSlotValue [SL:CONTACT An Yu ] ]", ), ( "Set a reminder to pick up Sean at 3:15 pm today.", "IN:CREATE_REMINDER", "18:30:SL:TODO,34:47:SL:DATE_TIME", "[IN:CREATE_REMINDER Set a reminder to [SL:TODO pick up Sean ] " "at [SL:DATE_TIME 3:15 pm today ]. ]", ), ( "Set a reminder to pick up Sean at 3:15 pm today.", "IN:CREATE_REMINDER", "34:47:SL:DATE_TIME,18:30:SL:TODO", "[IN:CREATE_REMINDER Set a reminder to [SL:TODO pick up Sean ] " "at [SL:DATE_TIME 3:15 pm today ]. ]", ), ('["Fine"]', "cu:other", "", r'[cu:other \["Fine"\] ]'), ( # Example in byte offset. "establece el escándalo a 7", "IN:SET_VOLUME", "26:27:SL:PRECISE_AMOUNT", "[IN:SET_VOLUME establece el escándalo a [SL:PRECISE_AMOUNT 7 ] ]", ), ] for ( utterance, intent_label, slot_names_str, expected_annotation_str, ) in TEXT_EXAMPLES: frame = create_frame( utterance, intent_label, slot_names_str, byte_length(utterance) ) self.assertEqual(frame_to_str(frame), expected_annotation_str)
def aggregate_preds(self, batch_preds, batch_context): intent_preds, word_preds = batch_preds self.all_preds.extend([ create_frame( text, self.doc_label_names[intent_pred], merge_token_labels_to_slot( token_range[0:seq_len], [self.word_label_names[p] for p in word_pred[0:seq_len]], self.use_bio_labels, ), byte_length(text), ) for text, intent_pred, word_pred, seq_len, token_range in zip( batch_context[self.text_column_name], intent_preds, word_preds, batch_context[DatasetFieldName.SEQ_LENS], batch_context[DatasetFieldName.TOKEN_RANGE], ) ])