Instructions to use kesha-humonen/runic-reader-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use kesha-humonen/runic-reader-2 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download code/retrieval_baseline.py from kesha-humonen/runic-reader-2: direct link, hf CLI and curl.
- Browser
- Download file 902 Bytes
-
https://huggingface.co/kesha-humonen/runic-reader-2/resolve/main/code/retrieval_baseline.py
- Command line
-
hf download hf://kesha-humonen/runic-reader-2/code/retrieval_baseline.py
-
curl -L -o retrieval_baseline.py https://huggingface.co/kesha-humonen/runic-reader-2/resolve/main/code/retrieval_baseline.py
902 Bytes
| """Retrieval baseline: output the translation of the most similar training transliteration | |
| (Indel similarity on space-free strings, same target language).""" | |
| import json | |
| import sys | |
| from rapidfuzz import fuzz, process | |
| train = [json.loads(l) for l in open(sys.argv[1])] | |
| test = [json.loads(l) for l in open(sys.argv[2])] | |
| out = open(sys.argv[3], "w") | |
| by_lang = {} | |
| for r in train: | |
| by_lang.setdefault(r["lang"], []).append(r) | |
| keys = {lang: [r["src"].replace(" ", "") for r in rows] for lang, rows in by_lang.items()} | |
| for r in test: | |
| q = (r.get(sys.argv[4]) if len(sys.argv) > 4 else r["src"]) or "" | |
| match = process.extractOne(q.replace(" ", ""), keys[r["lang"]], scorer=fuzz.ratio) | |
| rec = dict(r) | |
| rec["pred"] = by_lang[r["lang"]][match[2]]["tgt"] if match else "" | |
| rec["retrieval_score"] = match[1] if match else 0 | |
| out.write(json.dumps(rec, ensure_ascii=False) + "\n") | |
| out.close() | |