Ikala-allen commited on
Commit
46c9e1a
1 Parent(s): 54553f6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -9
README.md CHANGED
@@ -40,14 +40,14 @@ predictions = [
40
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
41
  ]
42
  ]
43
- evaluation_scores = module.compute(predictions=predictions, references=references)
44
  ```
45
 
46
  ### Inputs
47
- - **predictions** (`list` of `list` of `dictionary`): relation and its type of prediction
48
- - **references** (`list` of `list` of `dictionary`): references for each relation and its type
49
- - **mode** (`str`): define strict or boundaries mode
50
- - **only_all** (`bool`): define whether only output ["ALL"] relation_type score or every relation_type score, default True
51
  - **relation_types** (`list`): define relation type that need to be evaluate, if not given, it will construct relation_types from ground truth, default []
52
 
53
  ### Output Values
@@ -79,25 +79,58 @@ 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
- Example of only one prediction and reference:
83
  ```python
84
  metric_path = "Ikala-allen/relation_extraction"
85
  module = evaluate.load(metric_path)
86
  references = [
87
  [
88
- {"head": "phip igments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
 
90
  ]
91
  ]
 
 
92
  predictions = [
93
  [
94
  {"head": "phipigments", "head_type": "product", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
95
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
96
  ]
97
  ]
98
- evaluation_scores = module.compute(predictions=predictions, references=references)
 
 
 
99
  print(evaluation_scores)
100
- >>> {'sell': {'tp': 1, 'fp': 1, 'fn': 1, 'p': 50.0, 'r': 50.0, 'f1': 50.0}, 'ALL': {'tp': 1, 'fp': 1, 'fn': 1, 'p': 50.0, 'r': 50.0, 'f1': 50.0, 'Macro_f1': 50.0, 'Macro_p': 50.0, 'Macro_r': 50.0}}
101
  ```
102
 
103
  Example with two or more prediction and reference:
 
40
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
41
  ]
42
  ]
43
+ evaluation_scores = module.compute(predictions=predictions, references=references, mode = "strict")
44
  ```
45
 
46
  ### Inputs
47
+ - **predictions** (`list` of `list` of `dictionary`): a list of list of dictionary with every element's relation_type and their entity name
48
+ - **references** (`list` of `list` of `dictionary`): a list of list of dictionary with every element's relation_type and their entity name
49
+ - **mode** (`str`): define strict or boundaries mode for evaluation, strict mode consider "head_type" and "tail_type", boundaries mode doesn't consider "head_type" and "tail_type"
50
+ - **only_all** (`bool`): True for only output ["ALL"] relation_type score. False for output every relation_type score, default True
51
  - **relation_types** (`list`): define relation type that need to be evaluate, if not given, it will construct relation_types from ground truth, default []
52
 
53
  ### Output Values
 
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, consider only output ALL relation score
83
  ```python
84
  metric_path = "Ikala-allen/relation_extraction"
85
  module = evaluate.load(metric_path)
86
  references = [
87
  [
88
+ {"head": "phipigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
89
+ {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
90
+ {'head': 'A醛賦活緊緻精華', 'tail': 'Serum', 'head_type': 'product', 'tail_type': 'category', 'type': 'belongs_to'},
91
+ ]
92
+ ]
93
+
94
+ # Example references (ground truth)
95
+ predictions = [
96
+ [
97
+ {"head": "phipigments", "head_type": "product", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
98
+ {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
99
+ ]
100
+ ]
101
+
102
+ # Calculate evaluation scores using the loaded metric
103
+ evaluation_scores = module.compute(predictions=predictions, references=references, mode = "strict", only_all=True,relation_types = [])
104
+
105
+ print(evaluation_scores)
106
+ >>> {'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}
107
+ ```
108
+
109
+ Example2 : only one prediction and reference, mode = boundaries, consider only output ALL relation score
110
+ ```python
111
+ metric_path = "Ikala-allen/relation_extraction"
112
+ module = evaluate.load(metric_path)
113
+ references = [
114
+ [
115
+ {"head": "phipigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
116
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
117
+ {'head': 'A醛賦活緊緻精華', 'tail': 'Serum', 'head_type': 'product', 'tail_type': 'category', 'type': 'belongs_to'},
118
  ]
119
  ]
120
+
121
+ # Example references (ground truth)
122
  predictions = [
123
  [
124
  {"head": "phipigments", "head_type": "product", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
125
  {"head": "tinadaviespigments", "head_type": "brand", "type": "sell", "tail": "國際認證之色乳", "tail_type": "product"},
126
  ]
127
  ]
128
+
129
+ # Calculate evaluation scores using the loaded metric
130
+ evaluation_scores = module.compute(predictions=predictions, references=references, mode = "strict", only_all=True,relation_types = [])
131
+
132
  print(evaluation_scores)
133
+ >>> {'tp': 2, 'fp': 0, 'fn': 1, 'p': 100.0, 'r': 66.66666666666667, 'f1': 80.0, 'Macro_f1': 50.0, 'Macro_p': 50.0, 'Macro_r': 50.0}
134
  ```
135
 
136
  Example with two or more prediction and reference: