Add comment for each criteria in speaking grading.

This commit is contained in:
Cristiano Ferreira
2024-05-28 19:38:27 +01:00
parent a4caecdb4f
commit 64cc207fe8

98
app.py
View File

@@ -435,15 +435,35 @@ def grade_speaking_task_1():
answer = speech_to_text(sound_file_name) answer = speech_to_text(sound_file_name)
logging.info("POST - speaking_task_1 - " + str(request_id) + " - Transcripted answer: " + answer) logging.info("POST - speaking_task_1 - " + str(request_id) + " - Transcripted answer: " + answer)
json_format = {
"comment": "extensive comment about answer quality",
"overall": 0.0,
"task_response": {
"Fluency and Coherence": {
"grade": 0.0,
"comment": "extensive comment about fluency and coherence"
},
"Lexical Resource": {
"grade": 0.0,
"comment": "extensive comment about lexical resource"
},
"Grammatical Range and Accuracy": {
"grade": 0.0,
"comment": "extensive comment about grammatical range and accuracy"
},
"Pronunciation": {
"grade": 0.0,
"comment": "extensive comment about pronunciation on the transcribed answer"
}
}
}
if has_x_words(answer, 20): if has_x_words(answer, 20):
messages = [ messages = [
{ {
"role": "system", "role": "system",
"content": ( "content": (
'You are a helpful assistant designed to output JSON on this format: ' 'You are a helpful assistant designed to output JSON on this format: ' + str(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}}')
}, },
{ {
"role": "user", "role": "user",
@@ -453,6 +473,10 @@ def grade_speaking_task_1():
'assign a score of 0 if the response fails to address the question. Additionally, provide ' '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.' 'detailed commentary highlighting both strengths and weaknesses in the response.'
'\n Question: "' + question + '" \n Answer: "' + answer + '"') '\n Question: "' + question + '" \n Answer: "' + answer + '"')
},
{
"role": "user",
"content": 'Address the student as "you"'
} }
] ]
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
@@ -579,15 +603,35 @@ def grade_speaking_task_2():
answer = speech_to_text(sound_file_name) answer = speech_to_text(sound_file_name)
logging.info("POST - speaking_task_2 - " + str(request_id) + " - Transcripted answer: " + answer) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Transcripted answer: " + answer)
json_format = {
"comment": "extensive comment about answer quality",
"overall": 0.0,
"task_response": {
"Fluency and Coherence": {
"grade": 0.0,
"comment": "extensive comment about fluency and coherence"
},
"Lexical Resource": {
"grade": 0.0,
"comment": "extensive comment about lexical resource"
},
"Grammatical Range and Accuracy": {
"grade": 0.0,
"comment": "extensive comment about grammatical range and accuracy"
},
"Pronunciation": {
"grade": 0.0,
"comment": "extensive comment about pronunciation on the transcribed answer"
}
}
}
if has_x_words(answer, 20): if has_x_words(answer, 20):
messages = [ messages = [
{ {
"role": "system", "role": "system",
"content": ( "content": (
'You are a helpful assistant designed to output JSON on this format: ' 'You are a helpful assistant designed to output JSON on this format: ' + str(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}}')
}, },
{ {
"role": "user", "role": "user",
@@ -597,12 +641,16 @@ def grade_speaking_task_2():
'assign a score of 0 if the response fails to address the question. Additionally, provide ' '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.' 'detailed commentary highlighting both strengths and weaknesses in the response.'
'\n Question: "' + question + '" \n Answer: "' + answer + '"') '\n Question: "' + question + '" \n Answer: "' + answer + '"')
},
{
"role": "user",
"content": 'Address the student as "you"'
} }
] ]
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
logging.info("POST - speaking_task_2 - " + str(request_id) + " - Requesting grading of the answer.") logging.info("POST - speaking_task_2 - " + str(request_id) + " - Requesting grading of the answer.")
response = make_openai_call(GPT_3_5_TURBO, messages, token_count,["comment"], response = make_openai_call(GPT_3_5_TURBO, messages, token_count, ["comment"],
GRADING_TEMPERATURE) GRADING_TEMPERATURE)
logging.info("POST - speaking_task_2 - " + str(request_id) + " - Answer graded: " + str(response)) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Answer graded: " + str(response))
@@ -800,15 +848,34 @@ def grade_speaking_task_3():
token_count, token_count,
["answer"], ["answer"],
GEN_QUESTION_TEMPERATURE)) GEN_QUESTION_TEMPERATURE))
json_format = {
"comment": "extensive comment about answer quality",
"overall": 0.0,
"task_response": {
"Fluency and Coherence": {
"grade": 0.0,
"comment": "extensive comment about fluency and coherence"
},
"Lexical Resource": {
"grade": 0.0,
"comment": "extensive comment about lexical resource"
},
"Grammatical Range and Accuracy": {
"grade": 0.0,
"comment": "extensive comment about grammatical range and accuracy"
},
"Pronunciation": {
"grade": 0.0,
"comment": "extensive comment about pronunciation on the transcribed answer"
}
}
}
messages = [ messages = [
{ {
"role": "system", "role": "system",
"content": ( "content": (
'You are a helpful assistant designed to output JSON on this format: ' 'You are a helpful assistant designed to output JSON on this format: ' + str(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}}')
} }
] ]
message = ( message = (
@@ -833,6 +900,11 @@ def grade_speaking_task_3():
"content": message "content": message
}) })
messages.append({
"role": "user",
"content": 'Address the student as "you"'
})
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
logging.info("POST - speaking_task_3 - " + str(request_id) + " - Requesting grading of the answers.") logging.info("POST - speaking_task_3 - " + str(request_id) + " - Requesting grading of the answers.")