Zekun Wu
commited on
Commit
·
d9ab1da
1
Parent(s):
4d4a56e
add
Browse files- util/evaluator.py +61 -39
util/evaluator.py
CHANGED
@@ -33,8 +33,8 @@ class evaluator:
|
|
33 |
|
34 |
evaluation_prompt = f"""You are provided with a user's question and the corresponding explanation generated by
|
35 |
an AI model. Your task is to evaluate the explanation based on the following five principles. Each principle
|
36 |
-
should be scored on a scale from 0 to
|
37 |
-
and
|
38 |
|
39 |
Question:
|
40 |
{question}
|
@@ -119,48 +119,70 @@ class evaluator:
|
|
119 |
def evaluate_conversation(self, conversation, context):
|
120 |
formatted_conversation = self.format_conversation(conversation)
|
121 |
evaluation_prompt = f"""
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
Answer:
|
159 |
"""
|
160 |
|
161 |
print(evaluation_prompt)
|
162 |
|
163 |
-
response = self.model.invoke(evaluation_prompt, temperature=0, max_tokens=
|
164 |
try:
|
165 |
scores = json.loads(response)
|
166 |
except json.JSONDecodeError:
|
|
|
33 |
|
34 |
evaluation_prompt = f"""You are provided with a user's question and the corresponding explanation generated by
|
35 |
an AI model. Your task is to evaluate the explanation based on the following five principles. Each principle
|
36 |
+
should be scored on a scale from 0 to 10, where 0 indicates that the principle is not met at all,
|
37 |
+
and 10 indicates that the principle is fully satisfied. Additionally, provide a brief ten words explanation for each score to justify your rating.
|
38 |
|
39 |
Question:
|
40 |
{question}
|
|
|
119 |
def evaluate_conversation(self, conversation, context):
|
120 |
formatted_conversation = self.format_conversation(conversation)
|
121 |
evaluation_prompt = f"""
|
122 |
+
You are provided with a conversation between a user and a chatbot and the context about them. Your task is to evaluate the explanation based on the following five principles. Each principle
|
123 |
+
should be scored on a scale from 0 to 10, where 0 indicates that the principle is not met at all,
|
124 |
+
and 10 indicates that the principle is fully satisfied. Additionally, provide a brief ten words explanation for each score to justify your rating.
|
125 |
+
|
126 |
+
Conversation:
|
127 |
+
{formatted_conversation}
|
128 |
+
|
129 |
+
Context:
|
130 |
+
{context}
|
131 |
+
|
132 |
+
Evaluation Criteria:
|
133 |
+
|
134 |
+
Factually Correct:
|
135 |
+
Definition: The explanation must be accurate and relevant to the question and the subject matter.
|
136 |
+
Score: (0-10) How factually correct is the explanation? Consider the accuracy of the details provided and their relevance to the question.
|
137 |
+
|
138 |
+
Useful:
|
139 |
+
Definition: The explanation should enable the user to understand the answer better and should facilitate further reasoning or decision-making.
|
140 |
+
Score: (0-10) How useful is the explanation in helping the user understand the answer and make informed decisions?
|
141 |
+
|
142 |
+
Context Specific:
|
143 |
+
Definition: The explanation should be relevant to the specific context or scenario implied by the question.
|
144 |
+
Score: (0-10) How well does the explanation address the specific context or scenario of the question?
|
145 |
+
|
146 |
+
User Specific:
|
147 |
+
Definition: The explanation should cater to the knowledge level and interests of the user, assuming typical or specified user characteristics.
|
148 |
+
Score: (0-10) How well does the explanation cater to the needs and knowledge level of the intended user?
|
149 |
+
|
150 |
+
Provides Pluralism:
|
151 |
+
Definition: The explanation should offer or accommodate multiple viewpoints or interpretations, allowing the user to explore various perspectives.
|
152 |
+
Score: (0-10) How well does the explanation provide or support multiple perspectives?
|
153 |
+
|
154 |
+
After evaluating the provided question and explanation based on the five principles, please format your scores and justifications in a JSON dictionary. Directly provide me with the JSON without any additional text.
|
155 |
+
|
156 |
+
Example JSON format:
|
157 |
+
{{
|
158 |
+
"Factually Correct": {{
|
159 |
+
"Justification": "xxx",
|
160 |
+
"Score": 9
|
161 |
+
}},
|
162 |
+
"Useful": {{
|
163 |
+
"Justification": "xxx",
|
164 |
+
"Score": 8.5
|
165 |
+
}},
|
166 |
+
"Context Specific": {{
|
167 |
+
"Justification": "xxx",
|
168 |
+
"Score": 8
|
169 |
+
}},
|
170 |
+
"User Specific": {{
|
171 |
+
"Justification": "xxx",
|
172 |
+
"Score": 7.5
|
173 |
+
}},
|
174 |
+
"Provides Pluralism": {{
|
175 |
+
"Justification": "xxx",
|
176 |
+
"Score": 7
|
177 |
+
}}
|
178 |
+
}}
|
179 |
+
|
180 |
Answer:
|
181 |
"""
|
182 |
|
183 |
print(evaluation_prompt)
|
184 |
|
185 |
+
response = self.model.invoke(evaluation_prompt, temperature=0, max_tokens=1000).strip()
|
186 |
try:
|
187 |
scores = json.loads(response)
|
188 |
except json.JSONDecodeError:
|