def test_should_not_get_sequence_probability_when_not_fitted(self): # Given slot_filler = CRFSlotFiller() # When / Then with self.assertRaises(NotTrained): slot_filler.get_sequence_probability(tokens=[], labels=[])
def test_should_compute_sequence_probability_when_no_slots(self): # Given dataset = { "language": "en", "intents": { "intent1": { "utterances": [{ "data": [{ "text": "This is an utterance without " "slots" }] }] } }, "entities": {} } shared = self.get_shared_data(dataset) slot_filler = CRFSlotFiller(**shared).fit(dataset, "intent1") tokens = tokenize("hello world foo bar", "en") # When res1 = slot_filler.get_sequence_probability(tokens, ["O", "O", "O", "O"]) res2 = slot_filler.get_sequence_probability( tokens, ["O", "O", "B-location", "O"]) # Then self.assertEqual(1.0, res1) self.assertEqual(0.0, res2)