def test_create_label_tensors(self): tensorizer = LabelTensorizer(column="label") init = tensorizer.initialize() init.send(None) # kick for row in self.data.train: init.send(row) init.close() rows = [ { "label": types.Label("weather/find") }, { "label": types.Label("alarm/set_alarm") }, { "label": types.Label("non/existent") }, ] tensors = (tensorizer.numberize(row) for row in rows) tensor = next(tensors) self.assertEqual(6, tensor) tensor = next(tensors) self.assertEqual(1, tensor) with self.assertRaises(Exception): tensor = next(tensors)
def test_create_label_tensors_fails_with_unknown_label(self): tensorizer = LabelTensorizer(column="label") init = tensorizer.initialize() init.send(None) # kick for row in self.data.train: init.send(row) init.close() batch = [ {"label": types.Label("non/existent")}, {"label": types.Label("alarm/set_alarm")}, ] with self.assertRaises(Exception): tensorizer.create_training_tensors(batch)
def test_create_label_tensors(self): tensorizer = LabelTensorizer(column="label") init = tensorizer.initialize() init.send(None) # kick for row in self.data.train: init.send(row) init.close() batch = [ {"label": types.Label("weather/find")}, {"label": types.Label("alarm/set_alarm")}, ] tensor = tensorizer.create_training_tensors(batch) self.assertEqual((2,), tensor.size()) self.assertEqual([6, 1], tensor.tolist())
def load_label(s): return types.Label(s)