Beispiel #1
0
    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)
Beispiel #2
0
 def test_initialize_label_tensorizer(self):
     tensorizer = LabelTensorizer(column="label")
     init = tensorizer.initialize()
     init.send(None)  # kick
     for row in self.data.train:
         init.send(row)
     init.close()
     self.assertEqual(7, len(tensorizer.labels))
Beispiel #3
0
    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)
Beispiel #4
0
    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())