Spaces:
Running
Running
oliviercaron
commited on
Commit
•
5adda08
1
Parent(s):
c1d73b2
Update gliner_file.py
Browse files- gliner_file.py +10 -10
gliner_file.py
CHANGED
@@ -3,23 +3,23 @@ from typing import List
|
|
3 |
|
4 |
def run_ner(model, texts: List[str], labels_list: List[str], threshold=0.4):
|
5 |
"""
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
- model:
|
10 |
-
- texts:
|
11 |
-
- labels_list:
|
12 |
-
- threshold:
|
13 |
|
14 |
-
|
15 |
-
- ner_results:
|
16 |
"""
|
17 |
ner_results = []
|
18 |
for text in texts:
|
19 |
try:
|
20 |
-
#
|
21 |
entities = model.predict_entities(text, labels_list, threshold=threshold)
|
22 |
ner_results.append(entities)
|
23 |
except Exception as e:
|
24 |
ner_results.append([])
|
25 |
-
return ner_results
|
|
|
3 |
|
4 |
def run_ner(model, texts: List[str], labels_list: List[str], threshold=0.4):
|
5 |
"""
|
6 |
+
Executes named entity recognition (NER) on a list of texts.
|
7 |
|
8 |
+
Parameters:
|
9 |
+
- model: loaded GLiNER model.
|
10 |
+
- texts: list of texts to analyze.
|
11 |
+
- labels_list: list of NER labels to detect.
|
12 |
+
- threshold: confidence threshold for predictions.
|
13 |
|
14 |
+
Returns:
|
15 |
+
- ner_results: list of dictionaries containing detected entities for each text.
|
16 |
"""
|
17 |
ner_results = []
|
18 |
for text in texts:
|
19 |
try:
|
20 |
+
# Predict entities for the text
|
21 |
entities = model.predict_entities(text, labels_list, threshold=threshold)
|
22 |
ner_results.append(entities)
|
23 |
except Exception as e:
|
24 |
ner_results.append([])
|
25 |
+
return ner_results
|