MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / metrics

Method metrics

AgentBench.old/src/tasks/knowledgegraph/task.py:107–175  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

105
106 @property
107 def metrics(self):
108 # {'predict': []} [{'answer_type': 'Entity', 'answer_argument': 'm.05ch8k4', 'entity_name': 'Guard'}]
109 def main_metric(outputs, targets):
110 F1_sum = 0
111 count = 0
112 for i in range(len(outputs)):
113 if outputs[i] is None:
114 continue
115 count += 1
116 predicted_answer = set(outputs[i]['predict'])
117 gold_answer = targets[i]
118 TP = len(gold_answer.intersection(predicted_answer))
119 FP = len(predicted_answer) - TP
120 FN = len(gold_answer) - TP
121 if TP == 0:
122 continue
123 precision = TP / (TP + FP)
124 recall = TP / (TP + FN)
125 F1 = 2 * precision * recall / (precision + recall)
126 F1_sum += F1
127 if count == 0:
128 return 0
129 else:
130 return F1_sum / count
131
132 def EM(outputs, targets):
133 em_sum = 0
134 count = 0
135 for i in range(len(outputs)):
136 if outputs[i] is None:
137 continue
138 count += 1
139 predicted_answer = set(outputs[i]['predict'])
140 gold_answer = targets[i]
141 if len(gold_answer.intersection(predicted_answer)) == len(gold_answer) and len(gold_answer.intersection(predicted_answer)) == len(predicted_answer):
142 em_sum += 1
143
144 if count == 0:
145 return 0
146 else:
147 return em_sum / count
148
149
150 def executability(outputs):
151 count = 0
152 executability_sum = 0
153 for i in range(len(outputs)):
154 if outputs[i] is None:
155 continue
156 count += 1
157 if outputs[i]['predict'] is not None and len(outputs[i]['predict']) > 0:
158 executability_sum += 1
159 if count == 0:
160 return 0
161 else:
162 return executability_sum / count
163
164

Callers

nothing calls this directly

Calls 1

EMFunction · 0.85

Tested by

no test coverage detected