farnazzeidi
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -32,15 +32,36 @@ In our paper, we outline the steps taken to train this model and demonstrate its
|
|
32 |
```python
|
33 |
from transformers import pipeline
|
34 |
|
35 |
-
# Load the pipeline
|
36 |
-
model = pipeline("ner", model="pei-germany/MEDNER-de-fp-gbert", aggregation_strategy=
|
37 |
|
38 |
# Input text
|
39 |
-
text="Der Patient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
# Get predictions
|
42 |
-
predictions = model(text)
|
43 |
-
print(predictions)
|
44 |
```
|
45 |
|
46 |
|
|
|
32 |
```python
|
33 |
from transformers import pipeline
|
34 |
|
35 |
+
# Load the NER pipeline
|
36 |
+
model = pipeline("ner", model="pei-germany/MEDNER-de-fp-gbert", aggregation_strategy="none")
|
37 |
|
38 |
# Input text
|
39 |
+
text = "Der Patient wurde mit AstraZeneca geimpft und nahm anschließend Ibuprofen, um das Fieber zu senken."
|
40 |
+
|
41 |
+
# Get raw predictions and merge subwords
|
42 |
+
merged_predictions = []
|
43 |
+
current = None
|
44 |
+
|
45 |
+
for pred in model(text):
|
46 |
+
if pred['word'].startswith("##"):
|
47 |
+
if current:
|
48 |
+
current['word'] += pred['word'][2:]
|
49 |
+
current['end'] = pred['end']
|
50 |
+
current['score'] = (current['score'] + pred['score']) / 2
|
51 |
+
else:
|
52 |
+
if current:
|
53 |
+
merged_predictions.append(current)
|
54 |
+
current = pred.copy()
|
55 |
+
|
56 |
+
if current:
|
57 |
+
merged_predictions.append(current)
|
58 |
+
|
59 |
+
# Filter by confidence threshold and print
|
60 |
+
threshold = 0.5
|
61 |
+
filtered_predictions = [p for p in merged_predictions if p['score'] >= threshold]
|
62 |
+
for p in filtered_predictions:
|
63 |
+
print(f"Entity: {p['entity']}, Word: {p['word']}, Score: {p['score']:.2f}, Start: {p['start']}, End: {p['end']}")
|
64 |
|
|
|
|
|
|
|
65 |
```
|
66 |
|
67 |
|