Commit
•
d5fb2a9
1
Parent(s):
e954413
Update README.md
Browse files
README.md
CHANGED
@@ -36,18 +36,35 @@ The key differences between NuNerZero Long in comparison to GLiNER are:
|
|
36 |
```python
|
37 |
from gliner import GLiNER
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
model = GLiNER.from_pretrained("numind/NuNerZero")
|
40 |
|
41 |
# NuZero requires labels to be lower-cased!
|
42 |
-
labels = ["
|
43 |
-
labels [l.lower() for l in labels]
|
44 |
|
45 |
-
text = ""
|
46 |
-
|
47 |
-
"""
|
48 |
|
49 |
entities = model.predict_entities(text, labels)
|
50 |
|
|
|
|
|
51 |
for entity in entities:
|
52 |
print(entity["text"], "=>", entity["label"])
|
53 |
```
|
|
|
36 |
```python
|
37 |
from gliner import GLiNER
|
38 |
|
39 |
+
def merge_entities(entities):
|
40 |
+
if not entities:
|
41 |
+
return []
|
42 |
+
merged = []
|
43 |
+
current = entities[0]
|
44 |
+
for next_entity in entities[1:]:
|
45 |
+
if next_entity['label'] == current['label'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
|
46 |
+
current['text'] = text[current['start']: next_entity['end']].strip()
|
47 |
+
current['end'] = next_entity['end']
|
48 |
+
else:
|
49 |
+
merged.append(current)
|
50 |
+
current = next_entity
|
51 |
+
# Append the last entity
|
52 |
+
merged.append(current)
|
53 |
+
return merged
|
54 |
+
|
55 |
+
|
56 |
model = GLiNER.from_pretrained("numind/NuNerZero")
|
57 |
|
58 |
# NuZero requires labels to be lower-cased!
|
59 |
+
labels = ["organization", "initiative", "project"]
|
60 |
+
labels = [l.lower() for l in labels]
|
61 |
|
62 |
+
text = "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."
|
|
|
|
|
63 |
|
64 |
entities = model.predict_entities(text, labels)
|
65 |
|
66 |
+
entities = merge_entities(entities)
|
67 |
+
|
68 |
for entity in entities:
|
69 |
print(entity["text"], "=>", entity["label"])
|
70 |
```
|