Esempio n. 1
0
 def test_greedy_tagger_accuracy(self):
     self.tagger = GreedyBigramTagger(0.001)
     self.tagger.train(load_pos_data("test_data/train_pos.txt"))
     tagged_sents = load_pos_data("test_data/100_dev.txt")
     predicted, actual = self.tagger.test(tagged_sents)
     accuracy = accuracy_score(actual, predicted)
     print(f"GreedyBigram Accuracy: {accuracy * 100:.2f}")
     self.assertLessEqual(0.953, accuracy)
Esempio n. 2
0
class TestGreedyBigramTagger(unittest.TestCase):
    def setUp(self):
        self.tagger = GreedyBigramTagger(0.0)
        self.tagger.train(SENTENCES_AB_XYZ)

    @points(2)
    def test_ab_xyz_tag1(self):
        sent = ["x", "x"]
        self.assertEqual(["A", "A"], self.tagger.tag_sentence(sent))

    @points(2)
    def test_ab_xyz_tag2(self):
        sent = ["y", "y"]
        self.assertEqual(["B", "B"], self.tagger.tag_sentence(sent))

    @points(2)
    def test_ab_xyz_tag4(self):
        sent = ["x", "y"]
        self.assertEqual(["A", "A"], self.tagger.tag_sentence(sent))

    @points(2)
    def test_ab_xyz_tag3(self):
        sent = ["x", "z"]
        self.assertEqual(["A", "A"], self.tagger.tag_sentence(sent))

    @points(3)
    def test_greedy_tagger_accuracy(self):
        self.tagger = GreedyBigramTagger(0.001)
        self.tagger.train(load_pos_data("test_data/train_pos.txt"))
        tagged_sents = load_pos_data("test_data/100_dev.txt")
        predicted, actual = self.tagger.test(tagged_sents)
        accuracy = accuracy_score(actual, predicted)
        print(f"GreedyBigram Accuracy: {accuracy * 100:.2f}")
        self.assertLessEqual(0.953, accuracy)
Esempio n. 3
0
class TestDeterminism(unittest.TestCase):
    def setUp(self) -> None:
        self.greedy_tagger = GreedyBigramTagger(0.0)
        self.viterbi_tagger = ViterbiBigramTagger(0.0)
        self.greedy_tagger.train(SENTENCES_NN_VB_XZY)
        self.viterbi_tagger.train(SENTENCES_NN_VB_XZY)

    @points(2)
    def test_greedy_determinism(self):
        sent = ["ghost", "pumpkin", "cider"]
        self.assertEqual(["#", "#", "#"], self.greedy_tagger.tag_sentence(sent))

    @points(2)
    def test_viterbi_determinism(self):
        sent = ["ghost", "pumpkin", "cider"]
        self.assertEqual(["#", "#", "#"], self.viterbi_tagger.tag_sentence(sent))
Esempio n. 4
0
class TestBigramSequenceProbability(unittest.TestCase):
    def setUp(self):
        # We test through the greedy tagger but could also do it through Viterbi
        self.tagger = GreedyBigramTagger(0.0)
        self.tagger.train(SENTENCES_AB_XYZ)

    @points(2)
    def test_prob1(self):
        self.assertAlmostEqual(
            -3.2188758248682006,
            self.tagger.sequence_probability(["x", "y"], ["A", "A"]),
        )

    @points(1)
    def test_prob2(self):
        self.assertEqual(
            float("-inf"), self.tagger.sequence_probability(["x", "y"], ["A", "B"])
        )

    @points(1)
    def test_prob3(self):
        self.assertEqual(
            float("-inf"), self.tagger.sequence_probability(["x", "y"], ["B", "A"])
        )

    @points(2)
    def test_prob4(self):
        self.assertAlmostEqual(
            -2.8134107167600364,
            self.tagger.sequence_probability(["x", "y"], ["B", "B"]),
        )
Esempio n. 5
0
 def setUp(self) -> None:
     self.greedy_tagger = GreedyBigramTagger(0.0)
     self.viterbi_tagger = ViterbiBigramTagger(0.0)
     self.greedy_tagger.train(SENTENCES_NN_VB_XZY)
     self.viterbi_tagger.train(SENTENCES_NN_VB_XZY)
Esempio n. 6
0
 def setUp(self):
     self.tagger = GreedyBigramTagger(0.0)
     self.tagger.train(SENTENCES_AB_XYZ)
Esempio n. 7
0
 def setUp(self):
     # We test through the greedy tagger but could also do it through Viterbi
     self.tagger = GreedyBigramTagger(0.0)
     self.tagger.train(SENTENCES_AB_XYZ)