Views
No views yet
1from gliner import GLiNER
2
3# Initialize GLiNER with the base model
4model = GLiNER.from_pretrained("ljvmiranda921/tl_gliner_small")
5
6# Sample text for entity prediction
7# Reference: Leni Robredo’s speech at the 2022 UP College of Law recognition rites
8text = """"
9Nagsimula ako sa Public Attorney’s Office, kung saan araw-araw, mula Lunes hanggang Biyernes, nasa loob ako ng iba’t ibang court room at tambak ang kaso.
10Bawat Sabado, nasa BJMP ako para ihanda ang aking mga kliyente. Nahasa ako sa crim law at litigation. Pero kinalaunan, lumipat ako sa isang NGO,
11‘yung Sentro ng Alternatibong Lingap Panligal. Sa SALIGAN talaga ako nahubog bilang abugado: imbes na tinatanggap na lang ang mga batas na kailangang
12sundin, nagtatanong din kung ito ba ay tunay na instrumento para makapagbigay ng katarungan sa ordinaryong Pilipino. Imbes na maghintay ng mga kliyente
13sa de-aircon na opisina, dinadayo namin ang mga malalayong komunidad. Kadalasan, naka-tsinelas, naka-t-shirt at maong, hinahanap namin ang mga komunidad,
14tinatawid ang mga bundok, palayan, at mga ilog para tumungo sa mga lugar kung saan hirap ang mga batayang sektor na makakuha ng access to justice.
15Naaalala ko pa noong naging lead lawyer ako para sa isang proyekto: sa loob ng mahigit dalawang taon, bumibiyahe ako buwan-buwan papunta sa malayong
16isla ng Masbate, nagpa-paralegal training sa mga batayang sektor doon, ipinapaliwanag, itinituturo, at sinasanay sila sa mga batas na nagbibigay-proteksyon
17sa mga karapatan nila.
18"""
19
20# Labels for entity prediction
21# Most GLiNER models should work best when entity types are in lower case or title case
22labels = ["person", "organization", "location"]
23
24# Perform entity prediction
25entities = model.predict_entities(text, labels, threshold=0.5)
26
27# Display predicted entities and their labels
28for entity in entities:
29 print(entity["text"], "=>", entity["label"])
30
31# Sample output:
32# Public Attorney’s Office => organization
33# BJMP => organization
34# Sentro ng Alternatibong Lingap Panligal => organization
35# Masbate => location
36@misc{zaratiana2023gliner,
title={GLiNER: Generalist Model for Named Entity Recognition using Bidirectional Transformer},
author={Urchade Zaratiana and Nadi Tomeh and Pierre Holat and Thierry Charnois},
year={2023},
eprint={2311.08526},
archivePrefix={arXiv},
primaryClass={cs.CL}
}@inproceedings{miranda-2023-calamancy,
title = "calaman{C}y: A {T}agalog Natural Language Processing Toolkit",
author = "Miranda, Lester James",
booktitle = "Proceedings of the 3rd Workshop for Natural Language Processing Open Source Software (NLP-OSS 2023)",
month = dec,
year = "2023",
address = "Singapore, Singapore",
publisher = "Empirical Methods in Natural Language Processing",
url = "https://aclanthology.org/2023.nlposs-1.1",
pages = "1--7",
} @inproceedings{miranda-2023-developing,
title = "Developing a Named Entity Recognition Dataset for {T}agalog",
author = "Miranda, Lester James",
booktitle = "Proceedings of the First Workshop in South East Asian Language Processing",
month = nov,
year = "2023",
address = "Nusa Dua, Bali, Indonesia",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.sealp-1.2",
doi = "10.18653/v1/2023.sealp-1.2",
pages = "13--20",
}