Improve grading to be more strict and give 0 if the question is not addressed.

This commit is contained in:
Cristiano Ferreira
2024-01-23 23:23:17 +00:00
parent 64a4759fbc
commit bc2cedb821

76
app.py
View File

@@ -207,14 +207,15 @@ def grade_writing_task_1():
question = data.get('question')
answer = data.get('answer')
if has_words(answer):
message = (
"Grade this Writing Task 1 answer according to ielts grading system and provide an example of a perfect "
"answer (min 150 words) and an elaborated comment where you deep dive into what is wrong and right"
" about the answer. Provide your answer on the following json format: {'perfect_answer': 'example "
"perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, "
"'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, "
"'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' "
"and the answer was '" + answer + "'")
message = ("Evaluate the given Writing Task 1 response based on the IELTS grading system, ensuring a "
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
"exemplary answer with a minimum of 150 words, along with a detailed commentary highlighting "
"both strengths and weaknesses in the response. Present your evaluation in JSON format with "
"the following structure: {'perfect_answer': 'example perfect answer', 'comment': "
"'comment about answer quality', 'overall': 0.0, 'task_response': {'Task Achievement': 0.0, "
"'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range and Accuracy': "
"0.0}}\n Question: '" + question + "' \n Answer: '" + answer + "'")
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
@@ -261,14 +262,15 @@ def grade_writing_task_2():
question = data.get('question')
answer = data.get('answer')
if has_words(answer):
message = (
"Grade this Writing Task 2 answer according to ielts grading system and provide an example of a perfect "
"answer (min 250 words) and an elaborated comment where you deep dive into what is wrong and right "
"about the answer. Provide your answer on the following json format: {'perfect_answer': 'example "
"perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, "
"'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, "
"'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' "
"and the answer was '" + answer + "'")
message = ("Evaluate the given Writing Task 2 response based on the IELTS grading system, ensuring a "
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
"exemplary answer with a minimum of 250 words, along with a detailed commentary highlighting "
"both strengths and weaknesses in the response. Present your evaluation in JSON format with "
"the following structure: {'perfect_answer': 'example perfect answer', 'comment': "
"'comment about answer quality', 'overall': 0.0, 'task_response': {'Task Achievement': 0.0, "
"'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range and Accuracy': "
"0.0}}\n Question: '" + question + "' \n Answer: '" + answer + "'")
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
@@ -308,6 +310,7 @@ def get_writing_task_2_general_question():
except Exception as e:
return str(e)
# THE SAVING OF WRITING IS DONE WITHOUT THE API ON THE FRONTEND
# @app.route('/writing', methods=['POST'])
# @jwt_required()
@@ -342,13 +345,14 @@ def grade_speaking_task_1():
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
answer = speech_to_text(sound_file_name)
if has_10_words(answer):
message = (
"Grade this Speaking Part 1 answer according to ielts grading system and provide an elaborated "
"comment where you deep dive into what is wrong and right about the answer."
"Please assign a grade of 0 if the answer provided does not address the question."
"Provide your answer on the following json format: {'comment': 'comment about answer quality', 'overall': 0.0, "
"'task_response': {'Fluency and Coherence': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range and Accuracy': 0.0, "
"'Pronunciation': 0.0}}\n The question was '" + question + "' and the answer was '" + answer + "'")
message = ("Evaluate the given Speaking Part 1 response based on the IELTS grading system, ensuring a "
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
"assign a score of 0 if the response fails to address the question. Additionally, provide "
"detailed commentary highlighting both strengths and weaknesses in the response. Present your "
"evaluation in JSON format with "
"the following structure: {'comment': 'comment about answer quality', 'overall': 0.0, "
"'task_response': {'Fluency and Coherence': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range "
"and Accuracy': 0.0, 'Pronunciation': 0.0}}\n Question: '" + question + "' \n Answer: '" + answer + "'")
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
@@ -411,13 +415,15 @@ def grade_speaking_task_2():
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
answer = speech_to_text(sound_file_name)
if has_10_words(answer):
message = (
"Grade this Speaking Part 2 answer according to ielts grading system and provide an elaborated "
"comment where you deep dive into what is wrong and right about the answer."
"Please assign a grade of 0 if the answer provided does not address the question."
"Provide your answer on the following json format: {'comment': 'comment about answer quality', 'overall': 0.0, "
"'task_response': {'Fluency and Coherence': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range and Accuracy': 0.0, "
"'Pronunciation': 0.0}}\n The question was '" + question + "' and the answer was '" + answer + "'")
message = ("Evaluate the given Speaking Part 2 response based on the IELTS grading system, ensuring a "
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
"assign a score of 0 if the response fails to address the question. Additionally, provide "
"detailed commentary highlighting both strengths and weaknesses in the response. Present your "
"evaluation in JSON format with "
"the following structure: {'comment': 'comment about answer quality', 'overall': 0.0, "
"'task_response': {'Fluency and Coherence': 0.0, 'Lexical Resource': 0.0, 'Grammatical Range "
"and Accuracy': 0.0, "
"'Pronunciation': 0.0}}\n Question: '" + question + "' \n Answer: '" + answer + "'")
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
@@ -525,9 +531,10 @@ def grade_speaking_task_3():
None,
GEN_QUESTION_TEMPERATURE))
message = (
"Grade this Speaking Part 3 answer according to ielts grading system and provide "
"an elaborated comment where you deep dive into what is wrong and right about the answers."
"Please assign a grade of 0 if the answer provided does not address the question."
"Evaluate the given Speaking Part 2 response based on the IELTS grading system, ensuring a "
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
"assign a score of 0 if the response fails to address the question. Additionally, provide detailed "
"commentary highlighting both strengths and weaknesses in the response."
"\n\n The questions and answers are: \n\n'")
formatted_text = ""
@@ -587,6 +594,7 @@ def save_speaking():
except Exception as e:
return str(e)
@app.route("/speaking/generate_speaking_video", methods=['POST'])
@jwt_required()
def generate_speaking_video():
@@ -616,6 +624,7 @@ def generate_speaking_video():
except Exception as e:
return str(e)
@app.route("/speaking/generate_interactive_video", methods=['POST'])
@jwt_required()
def generate_interactive_video():
@@ -649,6 +658,7 @@ def generate_interactive_video():
except Exception as e:
return str(e)
@app.route('/reading_passage_1', methods=['GET'])
@jwt_required()
def get_reading_passage_1_question():