Spaces:
Runtime error
Runtime error
Ikala-allen
commited on
Commit
•
db06d31
1
Parent(s):
5d9145f
Update README.md
Browse files
README.md
CHANGED
@@ -44,16 +44,16 @@ evaluation_scores = module.compute(predictions=predictions, references=reference
|
|
44 |
```
|
45 |
|
46 |
### Inputs
|
47 |
-
- **predictions** (`list` of `list` of `dictionary`):
|
48 |
-
- **references** (`list` of `list` of `dictionary`):
|
49 |
-
- **mode** (`str`):
|
50 |
-
- **
|
51 |
-
- **relation_types** (`list`):
|
52 |
|
53 |
### Output Values
|
54 |
|
55 |
-
**output** (`dictionary` of `dictionary`s)
|
56 |
-
- **ALL** (`dictionary`): score of
|
57 |
- **tp** : true positive count
|
58 |
- **fp** : false positive count
|
59 |
- **fn** : false negative count
|
@@ -79,7 +79,7 @@ Output Example:
|
|
79 |
Remind : Macro_f1、Macro_p、Macro_r、p、r、f1 are always a number between 0 and 1. And tp、fp、fn depend on how many data inputs.
|
80 |
|
81 |
### Examples
|
82 |
-
Example1 : only one prediction and reference, mode=strict,
|
83 |
```python
|
84 |
metric_path = "Ikala-allen/relation_extraction"
|
85 |
module = evaluate.load(metric_path)
|
@@ -96,12 +96,12 @@ predictions = [
|
|
96 |
{"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
|
97 |
]
|
98 |
]
|
99 |
-
evaluation_scores = module.compute(predictions=predictions, references=references, mode="strict",
|
100 |
print(evaluation_scores)
|
101 |
>>> {'tp': 1, 'fp': 1, 'fn': 2, 'p': 50.0, 'r': 33.333333333333336, 'f1': 40.0, 'Macro_f1': 25.0, 'Macro_p': 25.0, 'Macro_r': 25.0}
|
102 |
```
|
103 |
|
104 |
-
Example2 : only one prediction and reference, mode=boundaries,
|
105 |
```python
|
106 |
metric_path = "Ikala-allen/relation_extraction"
|
107 |
module = evaluate.load(metric_path)
|
@@ -118,12 +118,12 @@ predictions = [
|
|
118 |
{"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
|
119 |
]
|
120 |
]
|
121 |
-
evaluation_scores = module.compute(predictions=predictions, references=references, mode="strict",
|
122 |
print(evaluation_scores)
|
123 |
>>> {'tp': 1, 'fp': 1, 'fn': 2, 'p': 50.0, 'r': 33.333333333333336, 'f1': 40.0, 'Macro_f1': 25.0, 'Macro_p': 25.0, 'Macro_r': 25.0}
|
124 |
```
|
125 |
|
126 |
-
Example3 : two or more prediction and reference, mode=boundaries,
|
127 |
```python
|
128 |
metric_path = "Ikala-allen/relation_extraction"
|
129 |
module = evaluate.load(metric_path)
|
@@ -147,12 +147,12 @@ predictions = [
|
|
147 |
{'head': 'SNTAIWAN', 'tail': '大馬士革玫瑰有機光燦系列', 'head_type': 'brand', 'tail_type': 'product', 'type': 'sell'}
|
148 |
]
|
149 |
]
|
150 |
-
evaluation_scores = module.compute(predictions=predictions, references=references, mode="boundaries",
|
151 |
print(evaluation_scores)
|
152 |
>>> {'sell': {'tp': 3, 'fp': 1, 'fn': 0, 'p': 75.0, 'r': 100.0, 'f1': 85.71428571428571}, 'belongs_to': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0}, 'ALL': {'tp': 3, 'fp': 1, 'fn': 1, 'p': 75.0, 'r': 75.0, 'f1': 75.0, 'Macro_f1': 42.857142857142854, 'Macro_p': 37.5, 'Macro_r': 50.0}}
|
153 |
```
|
154 |
|
155 |
-
Example 4 : two or more prediction and reference, mode=boundaries,
|
156 |
```python
|
157 |
metric_path = "Ikala-allen/relation_extraction"
|
158 |
module = evaluate.load(metric_path)
|
@@ -176,7 +176,7 @@ predictions = [
|
|
176 |
{'head': 'SNTAIWAN', 'tail': '大馬士革玫瑰有機光燦系列', 'head_type': 'brand', 'tail_type': 'product', 'type': 'sell'}
|
177 |
]
|
178 |
]
|
179 |
-
evaluation_scores = module.compute(predictions=predictions, references=references, mode="boundaries",
|
180 |
print(evaluation_scores)
|
181 |
>>> {'belongs_to': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0}, 'ALL': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0, 'Macro_f1': 0.0, 'Macro_p': 0.0, 'Macro_r': 0.0}}
|
182 |
```
|
|
|
44 |
```
|
45 |
|
46 |
### Inputs
|
47 |
+
- **predictions** (`list` of `list` of `dictionary`): A list of predicted relations from the model.
|
48 |
+
- **references** (`list` of `list` of `dictionary`): A list of ground-truth or reference relations to compare the predictions against.
|
49 |
+
- **mode** (`str`): Evaluation mode - 'strict' or 'boundaries'. 'strict' mode takes into account both entities type and their relationships, while 'boundaries' mode only considers the entity spans of the relationships.
|
50 |
+
- **detailed_scores** (`bool`): If True it returns scores for each relation type specifically, if False it returns the overall scores.
|
51 |
+
- **relation_types** (`list`): A list of relation types to consider while evaluating. If not provided, relation types will be constructed from the ground truth or reference data.
|
52 |
|
53 |
### Output Values
|
54 |
|
55 |
+
**output** (`dictionary` of `dictionary`s) A dictionary mapping each entity type to its respective scoring metrics such as Precision, Recall, F1 Score.
|
56 |
+
- **ALL** (`dictionary`): score of total relation type
|
57 |
- **tp** : true positive count
|
58 |
- **fp** : false positive count
|
59 |
- **fn** : false negative count
|
|
|
79 |
Remind : Macro_f1、Macro_p、Macro_r、p、r、f1 are always a number between 0 and 1. And tp、fp、fn depend on how many data inputs.
|
80 |
|
81 |
### Examples
|
82 |
+
Example1 : only one prediction and reference, mode=strict, detailed_scores=False, only output total relation score
|
83 |
```python
|
84 |
metric_path = "Ikala-allen/relation_extraction"
|
85 |
module = evaluate.load(metric_path)
|
|
|
96 |
{"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
|
97 |
]
|
98 |
]
|
99 |
+
evaluation_scores = module.compute(predictions=predictions, references=references, mode="strict", detailed_scores=False, relation_types=[])
|
100 |
print(evaluation_scores)
|
101 |
>>> {'tp': 1, 'fp': 1, 'fn': 2, 'p': 50.0, 'r': 33.333333333333336, 'f1': 40.0, 'Macro_f1': 25.0, 'Macro_p': 25.0, 'Macro_r': 25.0}
|
102 |
```
|
103 |
|
104 |
+
Example2 : only one prediction and reference, mode=boundaries, detailed_scores=False, only output total relation score
|
105 |
```python
|
106 |
metric_path = "Ikala-allen/relation_extraction"
|
107 |
module = evaluate.load(metric_path)
|
|
|
118 |
{"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
|
119 |
]
|
120 |
]
|
121 |
+
evaluation_scores = module.compute(predictions=predictions, references=references, mode="strict", detailed_scores=False, relation_types=[])
|
122 |
print(evaluation_scores)
|
123 |
>>> {'tp': 1, 'fp': 1, 'fn': 2, 'p': 50.0, 'r': 33.333333333333336, 'f1': 40.0, 'Macro_f1': 25.0, 'Macro_p': 25.0, 'Macro_r': 25.0}
|
124 |
```
|
125 |
|
126 |
+
Example3 : two or more prediction and reference, mode=boundaries, detailed_scores=True, output all relation type score
|
127 |
```python
|
128 |
metric_path = "Ikala-allen/relation_extraction"
|
129 |
module = evaluate.load(metric_path)
|
|
|
147 |
{'head': 'SNTAIWAN', 'tail': '大馬士革玫瑰有機光燦系列', 'head_type': 'brand', 'tail_type': 'product', 'type': 'sell'}
|
148 |
]
|
149 |
]
|
150 |
+
evaluation_scores = module.compute(predictions=predictions, references=references, mode="boundaries", detailed_scores=True, relation_types=[])
|
151 |
print(evaluation_scores)
|
152 |
>>> {'sell': {'tp': 3, 'fp': 1, 'fn': 0, 'p': 75.0, 'r': 100.0, 'f1': 85.71428571428571}, 'belongs_to': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0}, 'ALL': {'tp': 3, 'fp': 1, 'fn': 1, 'p': 75.0, 'r': 75.0, 'f1': 75.0, 'Macro_f1': 42.857142857142854, 'Macro_p': 37.5, 'Macro_r': 50.0}}
|
153 |
```
|
154 |
|
155 |
+
Example 4 : two or more prediction and reference, mode=boundaries, detailed_scores=True, output all relation type score, relation_types = ["belongs_to"], only consider belongs_to type score
|
156 |
```python
|
157 |
metric_path = "Ikala-allen/relation_extraction"
|
158 |
module = evaluate.load(metric_path)
|
|
|
176 |
{'head': 'SNTAIWAN', 'tail': '大馬士革玫瑰有機光燦系列', 'head_type': 'brand', 'tail_type': 'product', 'type': 'sell'}
|
177 |
]
|
178 |
]
|
179 |
+
evaluation_scores = module.compute(predictions=predictions, references=references, mode="boundaries", detailed_scores=True, relation_types=["belongs_to"])
|
180 |
print(evaluation_scores)
|
181 |
>>> {'belongs_to': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0}, 'ALL': {'tp': 0, 'fp': 0, 'fn': 1, 'p': 0, 'r': 0, 'f1': 0, 'Macro_f1': 0.0, 'Macro_p': 0.0, 'Macro_r': 0.0}}
|
182 |
```
|