Spaces:
Sleeping
Sleeping
JiaenLiu
commited on
Commit
•
3f9cb68
1
Parent(s):
b0198e8
LLM_eval
Browse filesFormer-commit-id: e006c931f38f3298f295e04cb9b16b3509442aee
- evaluation/scores/LLM_eval.py +42 -69
evaluation/scores/LLM_eval.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
# This script is used to evaluate the performance of Pigeon AI Video Translation system by using Large Language Model.
|
2 |
|
3 |
# Written by Jiaen LIU, 2023/09/18
|
@@ -5,72 +6,44 @@
|
|
5 |
# Import the necessary packages
|
6 |
from langchain.evaluation import load_evaluator, EvaluatorType
|
7 |
from langchain.prompts import PromptTemplate
|
8 |
-
from langchain.chat_models import
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# description="Useful when you need to answer questions about current events. You should ask targeted questions.",
|
50 |
-
# ),
|
51 |
-
# ]
|
52 |
-
# agents = [
|
53 |
-
# initialize_agent(tools, llm, agent=AgentType.OPENAI_MULTI_FUNCTIONS, verbose=False),
|
54 |
-
# initialize_agent(tools, llm, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=False)
|
55 |
-
# ]
|
56 |
-
|
57 |
-
llm = ChatAnthropic(temperature=0)
|
58 |
-
|
59 |
-
fstring = """You are an expert English to Chinese translator specialized in Startcraft2.
|
60 |
-
You are grading the following question:
|
61 |
-
{query}
|
62 |
-
Here is the real answer:
|
63 |
-
{answer}
|
64 |
-
You are grading the following predicted answer:
|
65 |
-
{result}
|
66 |
-
Give two grades, one for completness and another for accuracy and rate them from a scale of 0 to 100, where 0 is the lowest (very low completeness/accuracy) and 100 is the highest (very high completness/accuracy)?
|
67 |
-
Do not base the two scores off each other give them the scores independently. Give explanations for every single one and if the answer if partially correct that is acceptable. However punish the scores for answers that are
|
68 |
-
numerically incorrect this also includes values that have the $ in front
|
69 |
-
Please give the completeness score first followed by the accuracy score.
|
70 |
-
For example: Completeness: 70. Accuracy: 40. Explanation here
|
71 |
-
Do not differ from the format ever
|
72 |
-
"""
|
73 |
-
prompt = PromptTemplate.from_template(fstring)
|
74 |
-
|
75 |
-
self.__llm_evaluator = load_evaluator("criteria", llm=llm, criteria="conciseness",prompt=prompt)
|
76 |
-
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
# This script is used to evaluate the performance of Pigeon AI Video Translation system by using Large Language Model.
|
3 |
|
4 |
# Written by Jiaen LIU, 2023/09/18
|
|
|
6 |
# Import the necessary packages
|
7 |
from langchain.evaluation import load_evaluator, EvaluatorType
|
8 |
from langchain.prompts import PromptTemplate
|
9 |
+
from langchain.chat_models import ChatOpenAI
|
10 |
+
# from src.srt_util.srt import SrtScript
|
11 |
+
|
12 |
+
# Load the evaluator
|
13 |
+
|
14 |
+
def init_evaluator():
|
15 |
+
|
16 |
+
llm = ChatOpenAI(temperature=0, model="gpt-4-0613")
|
17 |
+
|
18 |
+
fstring = """You are an expert English to Chinese translator specialized in Startcraft2.
|
19 |
+
You are grading the following question:
|
20 |
+
{input}
|
21 |
+
Here is the real answer:
|
22 |
+
{reference}
|
23 |
+
You are grading the following predicted answer:
|
24 |
+
{output}
|
25 |
+
based on the following criteria:
|
26 |
+
{criteria}
|
27 |
+
Give two grades, one for completness and another for accuracy and rate them from a scale of 0 to 100, where 0 is the lowest (very low completeness/accuracy) and 100 is the highest (very high completness/accuracy)?
|
28 |
+
Do not base the two scores off each other give them the scores independently. Give explanations for every single one and if the answer if partially correct that is acceptable. However punish the scores for answers that are
|
29 |
+
numerically incorrect this also includes values that have the $ in front
|
30 |
+
Please give the completeness score first followed by the accuracy score.
|
31 |
+
For example: Completeness: 70. Accuracy: 40. Explanation here
|
32 |
+
Do not differ from the format ever
|
33 |
+
"""
|
34 |
+
prompt = PromptTemplate.from_template(fstring)
|
35 |
+
|
36 |
+
return load_evaluator("labeled_criteria", llm=llm, prompt=prompt, criteria="correctness")
|
37 |
+
|
38 |
+
def evaluate_prediction(input, reference, prediction, evaluator):
|
39 |
+
eval_result = evaluator.evaluate_strings(
|
40 |
+
prediction=prediction,
|
41 |
+
input=input,
|
42 |
+
reference=reference,
|
43 |
+
)
|
44 |
+
return eval_result
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
evaluator = init_evaluator()
|
48 |
+
eval_result = evaluate_prediction("this is an test sentences", "这不是一个测试语句。", "这是一个测试句子。", evaluator)
|
49 |
+
print(eval_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|