def test_should_be_serializable_into_bytearray(self): # Given dataset_stream = io.StringIO(""" --- type: intent name: MakeTea utterances: - make me [number_of_cups:snips/number](one) cup of tea - i want [number_of_cups] cups of tea please - can you prepare [number_of_cups] cups of tea ?""") dataset = Dataset.from_yaml_files("en", [dataset_stream]).json shared = self.get_shared_data(dataset) slot_filler = CRFSlotFiller(**shared).fit(dataset, "MakeTea") # When slot_filler_bytes = slot_filler.to_byte_array() loaded_slot_filler = CRFSlotFiller.from_byte_array( slot_filler_bytes, **shared) slots = loaded_slot_filler.get_slots("make me two cups of tea") # Then expected_slots = [ unresolved_slot(match_range={ START: 8, END: 11 }, value='two', entity='snips/number', slot_name='number_of_cups') ] self.assertListEqual(expected_slots, slots)
def test_should_be_serializable_into_bytearray(self): # Given dataset = BEVERAGE_DATASET slot_filler = CRFSlotFiller().fit(dataset, "MakeTea") builtin_intent_parser = slot_filler.builtin_entity_parser custom_entity_parser = slot_filler.custom_entity_parser # When slot_filler_bytes = slot_filler.to_byte_array() loaded_slot_filler = CRFSlotFiller.from_byte_array( slot_filler_bytes, builtin_entity_parser=builtin_intent_parser, custom_entity_parser=custom_entity_parser) slots = loaded_slot_filler.get_slots("make me two cups of tea") # Then expected_slots = [ unresolved_slot(match_range={ START: 8, END: 11 }, value='two', entity='snips/number', slot_name='number_of_cups') ] self.assertListEqual(expected_slots, slots)