-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#22] fixed the logic for computing bleu scores. black-formatted all …
…files
- Loading branch information
Showing
14 changed files
with
152 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ def main(): | |
print(len(test)) | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from torchmetrics import functional as F # noqa | ||
|
||
|
||
# reference corpus must be an iterable (instances) of iterables (candidates) of iterables (tokens) of strings | ||
answers = [["I love you more than anyone else".split()], ["I hate you so much".split()]] | ||
# translation corpus must be an iterable (instances) of iterables (tokens) of strings | ||
predictions = ["I love you so much".split(), "I hate you so much".split()] | ||
|
||
# the scores should decrease as n_gram increases because the window of exact matches increases | ||
print(F.bleu_score(answers, predictions, n_gram=1)) | ||
print(F.bleu_score(answers, predictions, n_gram=2)) | ||
print(F.bleu_score(answers, predictions, n_gram=3)) | ||
print(F.bleu_score(answers, predictions, n_gram=4)) # default | ||
print(F.bleu_score(answers, predictions, n_gram=5)) | ||
# this should be zero because no predictions have length longer than 6 | ||
# it is impossible to have 6-ngram matches (exact matches of length 6) | ||
print(F.bleu_score(answers, predictions, n_gram=6)) | ||
print("after smoothing is applied") | ||
# why apply smoothing?: https://aclanthology.org/P04-1077.pdf | ||
print(F.bleu_score(answers, predictions, n_gram=1, smooth=True)) | ||
print(F.bleu_score(answers, predictions, n_gram=2, smooth=True)) | ||
print(F.bleu_score(answers, predictions, n_gram=3, smooth=True)) | ||
print(F.bleu_score(answers, predictions, n_gram=4, smooth=True)) | ||
print(F.bleu_score(answers, predictions, n_gram=5, smooth=True)) | ||
print(F.bleu_score(answers, predictions, n_gram=6, smooth=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
""" | ||
Deploy a pre-trained transformer with fastapi. | ||
""" | ||
""" |
Oops, something went wrong.