Views
No views yet

!pip install gliner==0.1.121from gliner import GLiNER
2
3def merge_entities(entities):
4 if not entities:
5 return []
6 merged = []
7 current = entities[0]
8 for next_entity in entities[1:]:
9 if next_entity['label'] == current['label'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
10 current['text'] = text[current['start']: next_entity['end']].strip()
11 current['end'] = next_entity['end']
12 else:
13 merged.append(current)
14 current = next_entity
15 # Append the last entity
16 merged.append(current)
17 return merged
18
19
20model = GLiNER.from_pretrained("numind/NuNerZero")
21
22# NuZero requires labels to be lower-cased!
23labels = ["organization", "initiative", "project"]
24labels = [l.lower() for l in labels]
25
26text = "At the annual technology summit, the keynote address was delivered by a senior member of the Association for Computing Machinery Special Interest Group on Algorithms and Computation Theory, which recently launched an expansive initiative titled 'Quantum Computing and Algorithmic Innovations: Shaping the Future of Technology'. This initiative explores the implications of quantum mechanics on next-generation computing and algorithm design and is part of a broader effort that includes the 'Global Computational Science Advancement Project'. The latter focuses on enhancing computational methodologies across scientific disciplines, aiming to set new benchmarks in computational efficiency and accuracy."
27
28entities = model.predict_entities(text, labels)
29
30entities = merge_entities(entities)
31
32for entity in entities:
33 print(entity["text"], "=>", entity["label"])Association for Computing Machinery Special Interest Group on Algorithms and Computation Theory => organization
Quantum Computing and Algorithmic Innovations: Shaping the Future of Technology => initiative
Global Computational Science Advancement Project => project1@misc{bogdanov2024nuner,
2 title={NuNER: Entity Recognition Encoder Pre-training via LLM-Annotated Data},
3 author={Sergei Bogdanov and Alexandre Constantin and Timothée Bernard and Benoit Crabbé and Etienne Bernard},
4 year={2024},
5 eprint={2402.15343},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@misc{zaratiana2023gliner,
2 title={GLiNER: Generalist Model for Named Entity Recognition using Bidirectional Transformer},
3 author={Urchade Zaratiana and Nadi Tomeh and Pierre Holat and Thierry Charnois},
4 year={2023},
5 eprint={2311.08526},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}