Improve speaking grading

This commit is contained in:
Cristiano Ferreira
2024-03-24 01:33:21 +00:00
parent 6aba83f3bb
commit 7049fd86d4

30
app.py
View File

@@ -97,7 +97,8 @@ def get_listening_section_2_question():
app.logger.info("Generated monologue: " + str(monologue))
start_id = 11
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id, difficulty)
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id,
difficulty)
return {
"exercises": exercises,
"text": monologue,
@@ -158,7 +159,8 @@ def get_listening_section_4_question():
app.logger.info("Generated monologue: " + str(monologue))
start_id = 31
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id, difficulty)
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id,
difficulty)
return {
"exercises": exercises,
"text": monologue,
@@ -257,7 +259,7 @@ def get_writing_task_1_general_question():
try:
gen_wt1_question = "Craft a prompt for an IELTS Writing Task 1 General Training exercise that instructs the " \
"student to compose a letter. The prompt should present a specific scenario or situation, " \
"based on the topic of '" + topic + "', "\
"based on the topic of '" + topic + "', " \
"requiring the student to provide information, advice, or instructions within the letter. " \
"Make sure that the generated prompt is of " + difficulty + " difficulty and does not contain forbidden subjects in muslim countries."
token_count = count_tokens(gen_wt1_question)["n_tokens"]
@@ -378,7 +380,7 @@ def grade_speaking_task_1():
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
GEN_QUESTION_TEMPERATURE)
GRADING_TEMPERATURE)
perfect_answer_message = ("Provide a perfect answer according to ielts grading system to the following "
"Speaking Part 1 question: '" + question + "'")
token_count = count_tokens(perfect_answer_message)["n_tokens"]
@@ -389,6 +391,11 @@ def grade_speaking_task_1():
GEN_QUESTION_TEMPERATURE)
response['transcript'] = answer
response['fixed_text'] = get_speaking_corrections(answer)
if response["overall"] == "0.0" or response["overall"] == 0.0:
response["overall"] = round((response["task_response"]["Fluency and Coherence"] +
response["task_response"]["Lexical Resource"] + response["task_response"][
"Grammatical Range and Accuracy"] + response["task_response"][
"Pronunciation"]) / 4, 1)
return response
else:
return {
@@ -453,7 +460,7 @@ def grade_speaking_task_2():
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
GEN_QUESTION_TEMPERATURE)
GRADING_TEMPERATURE)
perfect_answer_message = ("Provide a perfect answer according to ielts grading system to the following "
"Speaking Part 2 question: '" + question + "'")
token_count = count_tokens(perfect_answer_message)["n_tokens"]
@@ -464,6 +471,12 @@ def grade_speaking_task_2():
GEN_QUESTION_TEMPERATURE)
response['transcript'] = answer
response['fixed_text'] = get_speaking_corrections(answer)
if response["overall"] == "0.0" or response["overall"] == 0.0:
response["overall"] = round((response["task_response"]["Fluency and Coherence"] +
response["task_response"]["Lexical Resource"] + response["task_response"][
"Grammatical Range and Accuracy"] + response["task_response"][
"Pronunciation"]) / 4, 1)
return response
else:
return {
@@ -586,13 +599,18 @@ def grade_speaking_task_3():
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
GEN_QUESTION_TEMPERATURE)
GRADING_TEMPERATURE)
for i, answer in enumerate(perfect_answers, start=1):
response['perfect_answer_' + str(i)] = answer
for i, answer in enumerate(text_answers, start=1):
response['transcript_' + str(i)] = answer
response['fixed_text_' + str(i)] = get_speaking_corrections(answer)
if response["overall"] == "0.0" or response["overall"] == 0.0:
response["overall"] = round((response["task_response"]["Fluency and Coherence"] + response["task_response"][
"Lexical Resource"] + response["task_response"]["Grammatical Range and Accuracy"] +
response["task_response"]["Pronunciation"]) / 4, 1)
return response
except Exception as e:
return str(e), 400