Skip to content

Commit e2bf3db

Browse files
⚡️ Benchmark with stanza
1 parent 19c9169 commit e2bf3db

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

benchmarks/stanza_benchmark.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import stanza
2+
# stanza.download('en')
3+
nlp = stanza.Pipeline('en')
4+
5+
from .english_golden_rules import GOLDEN_EN_RULES
6+
7+
def stanza_english_benchmark(golden_rules):
8+
global percent_score
9+
total_rules = len(golden_rules)
10+
score = 0
11+
for rule in golden_rules:
12+
text, expected = rule
13+
doc = nlp(text)
14+
segments = [e.text for e in doc.sentences]
15+
if segments == expected:
16+
score += 1
17+
percent_score = (score / total_rules) * 100.0
18+
19+
if __name__ == "__main__":
20+
import timeit
21+
time_taken = timeit.timeit("stanza_english_benchmark(GOLDEN_EN_RULES)",
22+
setup="from __main__ import stanza_english_benchmark, GOLDEN_EN_RULES",
23+
number=10)
24+
print(f'{stanza.__name__} - v{stanza.__version__}')
25+
print(f'GRS score: {percent_score:0.2f}%')
26+
print(f'Speed: {time_taken*1000:>10.2f} ms')
27+
stanza - v1.0.1
28+
GRS score: 72.92%
29+
Speed: 109839.63 ms

0 commit comments

Comments
 (0)