-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add: bleu with tokenizer * add: hf evaluation test
- Loading branch information
1 parent
87ab215
commit beccf8e
Showing
7 changed files
with
129 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import List | ||
import time | ||
|
||
import evaluate | ||
import bleuscore | ||
|
||
|
||
def hf_bleu(references: List[List[str]], predictions: List[str]): | ||
# Compute BLEU score | ||
bleu = evaluate.load("bleu") | ||
results = bleu.compute(predictions=predictions, references=references) | ||
print(results) | ||
return results | ||
|
||
|
||
def rust_bleu(references: List[List[str]], predictions: List[str]): | ||
rust_result = bleuscore.compute_bleu(reference_corpus=references, | ||
translation_corpus=predictions, | ||
max_order=4, | ||
smooth=False) | ||
print(rust_result) | ||
return rust_result | ||
|
||
|
||
def compare(): | ||
references = [ | ||
["Oh, hello bleu score from rust!", | ||
"Oh, hello bleu score from python!"], | ||
] | ||
predictions = ["hello bleu score from"] | ||
t0 = time.time() | ||
n_times = 10 | ||
for _ in range(n_times): | ||
hf_bleu(references, predictions) | ||
t1 = time.time() | ||
for _ in range(n_times): | ||
rust_bleu(references, predictions) | ||
t2 = time.time() | ||
|
||
hf_py_bleu_spend_seconds = t1 - t0 | ||
rust_bleu_spend_seconds = t2 - t1 | ||
print(f"hf py: {hf_py_bleu_spend_seconds}s\n" | ||
f"rust: {rust_bleu_spend_seconds}s\n" | ||
f"fast: {hf_py_bleu_spend_seconds / rust_bleu_spend_seconds:.2f}") | ||
|
||
|
||
if __name__ == "__main__": | ||
compare() |
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