Esempio n. 1
0
    def test_givenAModelTypeWithAttentionInName_whenHandleModelNameWithoutAttFlag_thenRaiseError(
            self):
        with self.assertRaises(ValueError):
            handle_model_name("fasttextAttention", attention_mechanism=False)

        with self.assertRaises(ValueError):
            handle_model_name("bpembAttention", attention_mechanism=False)
Esempio n. 2
0
    def test_givenAModelTypeWithAttentionInName_whenHandleModelNameWithAttFlag_thenReturnProperModelType(
            self):
        expected_model_type = "fasttextAttention"
        actual_model_type, _ = handle_model_name("fasttextAttention",
                                                 attention_mechanism=True)
        self.assertEqual(expected_model_type, actual_model_type)

        expected_model_type = "bpembAttention"
        actual_model_type, _ = handle_model_name("bpembAttention",
                                                 attention_mechanism=True)
        self.assertEqual(expected_model_type, actual_model_type)
Esempio n. 3
0
    def test_givenAInvalidModelType_whenHandleModelName_thenRaiseError(self):
        model_type = "invalid_model_type"
        with self.assertRaises(ValueError):
            handle_model_name(model_type, attention_mechanism=False)

        expect_error_message = (
            f"Could not handle {model_type}. Read the docs at https://deepparse.org/ for possible model types."
        )

        try:
            handle_model_name(model_type, attention_mechanism=False)
        except ValueError as actual_error_message:
            self.assertEqual(actual_error_message.args[0],
                             expect_error_message)
Esempio n. 4
0
    def test_givenModelTypes_whenHandleThem_then_ReturnProperFormattedModelType(
            self):
        # "Normal" Fasttext setup
        model_types = ["fasttext", "fastest"]
        attention_mechanism_settings = [True, False]

        for model_type in model_types:
            for attention_mechanism_setting in attention_mechanism_settings:
                expected_formatted_model_type = "FastText"
                _, actual_formatted_model_type = handle_model_name(
                    model_type,
                    attention_mechanism=attention_mechanism_setting)
                if attention_mechanism_setting:
                    expected_formatted_model_type += "Attention"
                self.assertEqual(expected_formatted_model_type,
                                 actual_formatted_model_type)

        # fasttext-light setup
        expected_formatted_model_type = "FastTextLight"
        model_types = ["fasttext-light", "lightest"]
        for model_type in model_types:
            _, actual_formatted_model_type = handle_model_name(
                model_type, attention_mechanism=False)
            self.assertEqual(expected_formatted_model_type,
                             actual_formatted_model_type)

        # BPEmb setup
        model_types = ["bpemb", "best"]
        attention_mechanism_settings = [True, False]

        for model_type in model_types:
            for attention_mechanism_setting in attention_mechanism_settings:
                expected_formatted_model_type = "BPEmb"
                _, actual_formatted_model_type = handle_model_name(
                    model_type,
                    attention_mechanism=attention_mechanism_setting)
                if attention_mechanism_setting:
                    expected_formatted_model_type += "Attention"
                self.assertEqual(expected_formatted_model_type,
                                 actual_formatted_model_type)