Download runtime/bench.py from iapp/OpenThai2.0-NLP-Core-Lite: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/iapp/OpenThai2.0-NLP-Core-Lite/resolve/main/runtime/bench.py
- Command line
-
hf download hf://iapp/OpenThai2.0-NLP-Core-Lite/runtime/bench.py
-
curl -L -o bench.py https://huggingface.co/iapp/OpenThai2.0-NLP-Core-Lite/resolve/main/runtime/bench.py
1.37 kB
| """Speed of the main model through the installed wheel: characters per second (whitespace not counted), one thread. | |
| python bench.py LINES.txt [--batch 64] | |
| One line per call (the mode every tool supports) unless --batch N, through the batch functions. Best of 2 passes.""" | |
| import sys | |
| import time | |
| from openthai_nlp_core_lite import NLPCore | |
| lines = [x.rstrip("\n") for x in open(sys.argv[1], encoding="utf-8") if x.strip()] | |
| batch = int(sys.argv[sys.argv.index("--batch") + 1]) if "--batch" in sys.argv else 1 | |
| chars = sum(len("".join(x.split())) for x in lines) | |
| nlp = NLPCore(threads=1) | |
| jobs = { | |
| "words (tokenize_batch)": lambda xs: nlp.tokenize_batch(xs, keep_whitespace=False), | |
| "sentences (sent_tokenize_batch)": nlp.sent_tokenize_batch, | |
| "POS (pos_tag_batch)": nlp.pos_tag_batch, | |
| "named entities (ner_batch)": nlp.ner_batch, | |
| "dependency trees (dependency_parse_batch)": nlp.dependency_parse_batch, | |
| "every task (analyze_batch)": nlp.analyze_batch, | |
| } | |
| for name, f in jobs.items(): | |
| f(lines[:4]) # load the heads first | |
| best = 1e9 | |
| for _ in range(2): | |
| t0 = time.perf_counter() | |
| for i in range(0, len(lines), batch): | |
| f(lines[i:i + batch]) | |
| best = min(best, time.perf_counter() - t0) | |
| print(f"{name:42s} {chars / best / 1000:7.1f}K chars/s ({len(lines)} lines, {chars} chars, {batch} per call)") | |