Dyma cydran syml a chyflym sydd yn priflythrennu geiriau o fewn destunau Cymraeg.
I'w ddefnyddio rhaid gosod
Sacremoses
A'i defnyddio fel hyn...
1from sacremoses import MosesTruecaser
2from huggingface_hub import hf_hub_download
3
4tc_model_path = hf_hub_download(repo_id="techiaith/sacremoses-truecaser-cy", filename="tc.model")
5mtr = MosesTruecaser(tc_model_path)
6
7capitalized_str = mtr.truecase("mae pwllheli yn dref ym mhen llŷn", return_str=True)
8print (capitalized_str)
9
10Mae Pwllheli yn dref ym Mhen Llŷn
11