-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue #782 #783
fix issue #782 #783
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3.5 | ||
|
||
|
||
import unittest | ||
|
||
from neuralmonkey.evaluators.chrf import ChrFEvaluator | ||
|
||
|
||
CORPUS_DECODED = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neni lepší to naimportovat z testu na BLEU? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jasne, to asi jo. Nebo respektive to mit uplne bokem; porovnavani s hypo vet s refe vetama delas u vice metrik |
||
"colorful thoughts furiously sleep", | ||
"little piglet slept all night", | ||
"working working working working working be be be be be be be", | ||
"ich bin walrus", | ||
"walrus for präsident" | ||
] | ||
|
||
CORPUS_REFERENCE = [ | ||
"the colorless ideas slept furiously", | ||
"pooh slept all night", | ||
"working class hero is something to be", | ||
"I am the working class walrus", | ||
"walrus for president" | ||
] | ||
|
||
TOKENS = ["a", "b", "a"] | ||
NGRAMS = [ | ||
{"a": 2, "b" : 1}, | ||
{"ab": 1, "ba" : 1}, | ||
{"aba" : 1}, | ||
{}] | ||
|
||
|
||
DECODED = [d.split() for d in CORPUS_DECODED] | ||
REFERENCE = [r.split() for r in CORPUS_REFERENCE] | ||
|
||
FUNC = ChrFEvaluator() | ||
FUNC_P = FUNC.chr_p | ||
FUNC_R = FUNC.chr_r | ||
FUNC_NGRAMS = FUNC._get_ngrams | ||
|
||
class TestChrF(unittest.TestCase): | ||
|
||
def test_empty_decoded(self): | ||
# Recall == 0.0 | ||
self.assertEqual(FUNC([[] for _ in DECODED], REFERENCE), 0.0) | ||
|
||
def test_empty_reference(self): | ||
# Precision == 0.0 | ||
self.assertEqual(FUNC([[] for _ in REFERENCE], DECODED), 0.0) | ||
|
||
def test_identical(self): | ||
self.assertEqual(FUNC(REFERENCE, REFERENCE), 1.0) | ||
|
||
def test_empty_sentence(self): | ||
ref_empty = REFERENCE + [[]] | ||
out_empty = DECODED + [["something"]] | ||
score = FUNC(out_empty, ref_empty) | ||
self.assertAlmostEqual(score, 0.38, delta=10) | ||
|
||
def test_chrf(self): | ||
score = FUNC(DECODED, REFERENCE) | ||
self.assertAlmostEqual(score, 0.46, delta=10) | ||
|
||
def test_get_ngrams(self): | ||
tokens = ["a", "b", "a"] | ||
ngrams_out = FUNC_NGRAMS(tokens, 4) | ||
self.assertEqual(len(ngrams_out), 4) | ||
for i, _ in enumerate(NGRAMS): | ||
self.assertDictEqual(ngrams_out[i], NGRAMS[i]) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Komentář vyfičet.