Exemple #1
0
    def test_fit_and_predict_with_new_labels_set_via_method(self):
        # Initialize model
        invalid_entities = {"PAD": 0, "BACKGROUND": 1, "test3": 2}
        cnn_model = CharacterLevelCnnModel(invalid_entities)
        cnn_model._construct_model()
        invalid_entities2 = {"PAD": 0, "BACKGROUND": 1}
        cnn_model.set_label_mapping(invalid_entities2)
        cnn_model._reconstruct_model()
        cnn_model.set_label_mapping(self.label_mapping)

        # data for model
        data_gen = [[
            np.array([['test']]),  # x_data
            np.zeros((1, 3400, max(self.label_mapping.values()) + 1))
        ]
                    # y_data
                    ]
        cv_gen = data_gen

        cnn_model._construct_model()

        # set different labels
        cnn_model.set_label_mapping(self.label_mapping)
        history, f1, f1_report = cnn_model.fit(data_gen, cv_gen)

        # test predict on just the text
        cnn_model.predict(data_gen[0][0])
Exemple #2
0
    def test_fit_and_predict_with_reset_weights(self, *mocks):
        # model
        cnn_model = CharacterLevelCnnModel(self.label_mapping)

        # data for model
        data_gen = [[
            np.array([['test']]),  # x_data
            np.zeros((1, 3400, max(self.label_mapping.values()) + 1))
        ]  # y_data
                    ]
        cv_gen = data_gen

        # Basic Fit with Validation Data
        history, f1, f1_report = cnn_model.fit(data_gen,
                                               cv_gen,
                                               reset_weights=True)
        data_gen = [np.array([['test']])]
        cnn_model.predict(data_gen)
Exemple #3
0
    def test_fit_and_predict_with_new_labels(self):
        # Initialize model
        cnn_model = CharacterLevelCnnModel(self.label_mapping)

        # data for model
        data_gen = [[
            np.array([['test']]),  # x_data
            np.zeros((1, 3400, max(self.label_mapping.values()) + 1))
        ]
                    # y_data
                    ]
        cv_gen = data_gen

        cnn_model._construct_model()

        # fit with new labels
        history, f1, f1_report = cnn_model.fit(
            data_gen, cv_gen, label_mapping=self.label_mapping)

        # predict after fitting on just the text
        cnn_model.predict(data_gen[0][0])
Exemple #4
0
    def test_fit_and_predict_with_reset_weights(self, *mocks):
        # model
        cnn_model = CharacterLevelCnnModel(self.label_mapping)

        # data for model
        data_gen = [[
            np.array([["test"]]),  # x_data
            np.zeros((1, 3400, max(self.label_mapping.values()) + 1)),
        ]  # y_data
                    ]
        cv_gen = data_gen

        # Basic Fit with Validation Data
        with self.assertLogs("DataProfiler.labelers.character_level_cnn_model",
                             level="INFO") as logs:
            history, f1, f1_report = cnn_model.fit(data_gen,
                                                   cv_gen,
                                                   reset_weights=True)

        # Ensure info was logged during fit
        self.assertTrue(len(logs.output))

        data_gen = [np.array([["test"]])]
        cnn_model.predict(data_gen)