Download inference_example.py from Nerthus-Project/OE_Lemmatiser_Retrained: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/Nerthus-Project/OE_Lemmatiser_Retrained/resolve/main/inference_example.py
- Command line
-
hf download hf://Nerthus-Project/OE_Lemmatiser_Retrained/inference_example.py
-
curl -L -o inference_example.py https://huggingface.co/Nerthus-Project/OE_Lemmatiser_Retrained/resolve/main/inference_example.py
1.13 kB
| """Runnable demo for the Old English lemmatiser (Nerthus resource-enhanced release). | |
| Usage: | |
| pip install -r requirements.txt | |
| python inference_example.py | |
| """ | |
| from lemmatizer import OldEnglishLemmatizer | |
| def main() -> None: | |
| lem = OldEnglishLemmatizer.from_pretrained(".") | |
| words = ["cyninges", "cwæð", "godan", "þurh", "cyning", "folce", "halgan"] | |
| print("word -> (lemma, POS)") | |
| print("-" * 34) | |
| for w, pred in zip(words, lem.lemmatize_batch(words)): | |
| print(f"{w:12} -> {pred}") | |
| print("\nText:") | |
| for item in lem.lemmatize_text("se cyning cwæð to his folce"): | |
| print(f" {item['word']:10} {item['lemma']:12} {item['pos']}") | |
| # The prior assumes the gold lemma is an Old English headword. Switch it off | |
| # for embedded Latin and dense onomastic material, where the corpus leaves | |
| # the inflected form standing as its own lemma. | |
| print("\nWithout the lexicon prior (lexicon_bonus=0):") | |
| for item in lem.lemmatize_text("israeles daniele", lexicon_bonus=0): | |
| print(f" {item['word']:10} {item['lemma']:12} {item['pos']}") | |
| if __name__ == "__main__": | |
| main() | |