Spaces:
Sleeping
Sleeping
added default predictions in predefined examples
Browse files- predefined_example.py +53 -2
predefined_example.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from dataclasses import dataclass
|
| 2 |
|
| 3 |
from span_dataclass_converters import get_ner_spans_from_annotations
|
| 4 |
|
|
@@ -7,6 +7,7 @@ from span_dataclass_converters import get_ner_spans_from_annotations
|
|
| 7 |
class PredefinedExample:
|
| 8 |
text: str
|
| 9 |
gt_labels: dict
|
|
|
|
| 10 |
# gt_spans: list
|
| 11 |
# predictions: list
|
| 12 |
|
|
@@ -19,7 +20,7 @@ class PredefinedExample:
|
|
| 19 |
|
| 20 |
@property
|
| 21 |
def predictions(self):
|
| 22 |
-
return [self.gt_spans]
|
| 23 |
|
| 24 |
@property
|
| 25 |
def tags(self):
|
|
@@ -36,6 +37,29 @@ small_example = PredefinedExample(
|
|
| 36 |
{"start": 63, "end": 72, "label": "mucolytic"},
|
| 37 |
],
|
| 38 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
big_example = PredefinedExample(
|
|
@@ -57,6 +81,33 @@ big_example = PredefinedExample(
|
|
| 57 |
{"start": 46, "end": 63, "label": "flu like symptoms"},
|
| 58 |
],
|
| 59 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
EXAMPLES = [small_example, big_example]
|
|
|
|
| 1 |
+
from dataclasses import dataclass, field
|
| 2 |
|
| 3 |
from span_dataclass_converters import get_ner_spans_from_annotations
|
| 4 |
|
|
|
|
| 7 |
class PredefinedExample:
|
| 8 |
text: str
|
| 9 |
gt_labels: dict
|
| 10 |
+
default_predictions: list = field(default_factory=list)
|
| 11 |
# gt_spans: list
|
| 12 |
# predictions: list
|
| 13 |
|
|
|
|
| 20 |
|
| 21 |
@property
|
| 22 |
def predictions(self):
|
| 23 |
+
return [self.gt_spans] + self.default_predictions
|
| 24 |
|
| 25 |
@property
|
| 26 |
def tags(self):
|
|
|
|
| 37 |
{"start": 63, "end": 72, "label": "mucolytic"},
|
| 38 |
],
|
| 39 |
},
|
| 40 |
+
default_predictions=[
|
| 41 |
+
[
|
| 42 |
+
{
|
| 43 |
+
"start": 26,
|
| 44 |
+
"end": 41,
|
| 45 |
+
"label": "Disease",
|
| 46 |
+
"span_text": "with bronchitis",
|
| 47 |
+
},
|
| 48 |
+
{"start": 61, "end": 72, "label": "Drug", "span_text": "a mucolytic"},
|
| 49 |
+
],
|
| 50 |
+
[
|
| 51 |
+
{"start": 31, "end": 41, "label": "Drug", "span_text": "bronchitis"},
|
| 52 |
+
{"start": 63, "end": 72, "label": "Drug", "span_text": "mucolytic"},
|
| 53 |
+
],
|
| 54 |
+
[
|
| 55 |
+
{
|
| 56 |
+
"start": 31,
|
| 57 |
+
"end": 72,
|
| 58 |
+
"label": "Disease",
|
| 59 |
+
"span_text": "bronchitis and was prescribed a mucolytic",
|
| 60 |
+
}
|
| 61 |
+
],
|
| 62 |
+
],
|
| 63 |
)
|
| 64 |
|
| 65 |
big_example = PredefinedExample(
|
|
|
|
| 81 |
{"start": 46, "end": 63, "label": "flu like symptoms"},
|
| 82 |
],
|
| 83 |
},
|
| 84 |
+
default_predictions=[
|
| 85 |
+
[
|
| 86 |
+
{"start": 29, "end": 41, "label": "Symptoms", "span_text": "stomach pain"},
|
| 87 |
+
{"start": 46, "end": 49, "label": "Symptoms", "span_text": "flu"},
|
| 88 |
+
{
|
| 89 |
+
"start": 120,
|
| 90 |
+
"end": 136,
|
| 91 |
+
"label": "Disease",
|
| 92 |
+
"span_text": "acute bronchitis",
|
| 93 |
+
},
|
| 94 |
+
{"start": 213, "end": 222, "label": "Drug", "span_text": "mucolytic"},
|
| 95 |
+
{"start": 234, "end": 245, "label": "Drug", "span_text": "paracetamol"},
|
| 96 |
+
],
|
| 97 |
+
[
|
| 98 |
+
{"start": 29, "end": 41, "label": "Symptoms", "span_text": "stomach pain"},
|
| 99 |
+
{"start": 46, "end": 49, "label": "Disease", "span_text": "flu"},
|
| 100 |
+
{
|
| 101 |
+
"start": 120,
|
| 102 |
+
"end": 136,
|
| 103 |
+
"label": "Disease",
|
| 104 |
+
"span_text": "acute bronchitis",
|
| 105 |
+
},
|
| 106 |
+
{"start": 213, "end": 222, "label": "Drug", "span_text": "mucolytic"},
|
| 107 |
+
{"start": 234, "end": 245, "label": "Drug", "span_text": "paracetamol"},
|
| 108 |
+
{"start": 250, "end": 260, "label": "Symptoms", "span_text": "body pains"},
|
| 109 |
+
],
|
| 110 |
+
],
|
| 111 |
)
|
| 112 |
|
| 113 |
EXAMPLES = [small_example, big_example]
|