Update multiple choice questions generation.
This commit is contained in:
@@ -53,6 +53,7 @@ def replace_first_occurrences_with_placeholders(text: str, words_to_replace: lis
|
|||||||
text = pattern.sub(placeholder, text, 1)
|
text = pattern.sub(placeholder, text, 1)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def replace_first_occurrences_with_placeholders_notes(notes: list, words_to_replace: list, start_id):
|
def replace_first_occurrences_with_placeholders_notes(notes: list, words_to_replace: list, start_id):
|
||||||
replaced_notes = []
|
replaced_notes = []
|
||||||
for i, note in enumerate(notes, start=0):
|
for i, note in enumerate(notes, start=0):
|
||||||
@@ -63,6 +64,7 @@ def replace_first_occurrences_with_placeholders_notes(notes: list, words_to_repl
|
|||||||
replaced_notes.append(note)
|
replaced_notes.append(note)
|
||||||
return replaced_notes
|
return replaced_notes
|
||||||
|
|
||||||
|
|
||||||
def add_random_words_and_shuffle(word_array, num_random_words):
|
def add_random_words_and_shuffle(word_array, num_random_words):
|
||||||
r = RandomWord()
|
r = RandomWord()
|
||||||
random_words_selected = r.random_words(num_random_words)
|
random_words_selected = r.random_words(num_random_words)
|
||||||
@@ -107,6 +109,7 @@ def build_write_blanks_text(questions: [], start_id):
|
|||||||
result = result + q["question"] + placeholder + "\\n"
|
result = result + q["question"] + placeholder + "\\n"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def build_write_blanks_text_form(form: [], start_id):
|
def build_write_blanks_text_form(form: [], start_id):
|
||||||
result = ""
|
result = ""
|
||||||
replaced_words = []
|
replaced_words = []
|
||||||
@@ -147,6 +150,7 @@ def build_write_blanks_solutions(questions: [], start_id):
|
|||||||
)
|
)
|
||||||
return solutions
|
return solutions
|
||||||
|
|
||||||
|
|
||||||
def build_write_blanks_solutions_listening(words: [], start_id):
|
def build_write_blanks_solutions_listening(words: [], start_id):
|
||||||
solutions = []
|
solutions = []
|
||||||
for i, word in enumerate(words, start=start_id):
|
for i, word in enumerate(words, start=start_id):
|
||||||
@@ -212,6 +216,7 @@ def generate_listening_1_conversation(topic: str):
|
|||||||
segment['voice'] = voice
|
segment['voice'] = voice
|
||||||
return response, processed
|
return response, processed
|
||||||
|
|
||||||
|
|
||||||
def generate_listening_2_monologue(topic: str):
|
def generate_listening_2_monologue(topic: str):
|
||||||
gen_listening_2_monologue_social = "Generate a comprehensive monologue set in the social context of: '" + topic + "'"
|
gen_listening_2_monologue_social = "Generate a comprehensive monologue set in the social context of: '" + topic + "'"
|
||||||
token_count = count_tokens(gen_listening_2_monologue_social)["n_tokens"]
|
token_count = count_tokens(gen_listening_2_monologue_social)["n_tokens"]
|
||||||
@@ -224,6 +229,7 @@ def generate_listening_2_monologue(topic: str):
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def generate_listening_3_conversation(topic: str):
|
def generate_listening_3_conversation(topic: str):
|
||||||
gen_listening_3_conversation_4_people = "Compose an authentic and elaborate conversation between up to four individuals " \
|
gen_listening_3_conversation_4_people = "Compose an authentic and elaborate conversation between up to four individuals " \
|
||||||
"in the everyday social context of '" + topic + \
|
"in the everyday social context of '" + topic + \
|
||||||
@@ -264,6 +270,7 @@ def generate_listening_3_conversation(topic: str):
|
|||||||
segment['voice'] = voice
|
segment['voice'] = voice
|
||||||
return response, processed
|
return response, processed
|
||||||
|
|
||||||
|
|
||||||
def generate_listening_4_monologue(topic: str):
|
def generate_listening_4_monologue(topic: str):
|
||||||
gen_listening_4_monologue_academic = "Generate a comprehensive monologue an academic subject of: '" + topic + "'"
|
gen_listening_4_monologue_academic = "Generate a comprehensive monologue an academic subject of: '" + topic + "'"
|
||||||
token_count = count_tokens(gen_listening_4_monologue_academic)["n_tokens"]
|
token_count = count_tokens(gen_listening_4_monologue_academic)["n_tokens"]
|
||||||
@@ -276,6 +283,7 @@ def generate_listening_4_monologue(topic: str):
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def generate_reading_exercises(passage: str, req_exercises: list, number_of_exercises_q, start_id):
|
def generate_reading_exercises(passage: str, req_exercises: list, number_of_exercises_q, start_id):
|
||||||
exercises = []
|
exercises = []
|
||||||
for req_exercise in req_exercises:
|
for req_exercise in req_exercises:
|
||||||
@@ -302,6 +310,7 @@ def generate_reading_exercises(passage: str, req_exercises: list, number_of_exer
|
|||||||
|
|
||||||
return exercises
|
return exercises
|
||||||
|
|
||||||
|
|
||||||
def generate_listening_conversation_exercises(conversation: str, req_exercises: list, number_of_exercises_q, start_id):
|
def generate_listening_conversation_exercises(conversation: str, req_exercises: list, number_of_exercises_q, start_id):
|
||||||
exercises = []
|
exercises = []
|
||||||
for req_exercise in req_exercises:
|
for req_exercise in req_exercises:
|
||||||
@@ -312,15 +321,18 @@ def generate_listening_conversation_exercises(conversation: str, req_exercises:
|
|||||||
exercises.append(question)
|
exercises.append(question)
|
||||||
print("Added multiple choice: " + str(question))
|
print("Added multiple choice: " + str(question))
|
||||||
elif req_exercise == "writeBlanksQuestions":
|
elif req_exercise == "writeBlanksQuestions":
|
||||||
question = gen_write_blanks_questions_exercise_listening_conversation(conversation, number_of_exercises, start_id)
|
question = gen_write_blanks_questions_exercise_listening_conversation(conversation, number_of_exercises,
|
||||||
|
start_id)
|
||||||
exercises.append(question)
|
exercises.append(question)
|
||||||
print("Added write blanks questions: " + str(question))
|
print("Added write blanks questions: " + str(question))
|
||||||
elif req_exercise == "writeBlanksFill":
|
elif req_exercise == "writeBlanksFill":
|
||||||
question = gen_write_blanks_notes_exercise_listening_conversation(conversation, number_of_exercises, start_id)
|
question = gen_write_blanks_notes_exercise_listening_conversation(conversation, number_of_exercises,
|
||||||
|
start_id)
|
||||||
exercises.append(question)
|
exercises.append(question)
|
||||||
print("Added write blanks notes: " + str(question))
|
print("Added write blanks notes: " + str(question))
|
||||||
elif req_exercise == "writeBlanksForm":
|
elif req_exercise == "writeBlanksForm":
|
||||||
question = gen_write_blanks_form_exercise_listening_conversation(conversation, number_of_exercises, start_id)
|
question = gen_write_blanks_form_exercise_listening_conversation(conversation, number_of_exercises,
|
||||||
|
start_id)
|
||||||
exercises.append(question)
|
exercises.append(question)
|
||||||
print("Added write blanks form: " + str(question))
|
print("Added write blanks form: " + str(question))
|
||||||
|
|
||||||
@@ -328,6 +340,7 @@ def generate_listening_conversation_exercises(conversation: str, req_exercises:
|
|||||||
|
|
||||||
return exercises
|
return exercises
|
||||||
|
|
||||||
|
|
||||||
def generate_listening_monologue_exercises(monologue: str, req_exercises: list, number_of_exercises_q, start_id):
|
def generate_listening_monologue_exercises(monologue: str, req_exercises: list, number_of_exercises_q, start_id):
|
||||||
exercises = []
|
exercises = []
|
||||||
for req_exercise in req_exercises:
|
for req_exercise in req_exercises:
|
||||||
@@ -354,6 +367,7 @@ def generate_listening_monologue_exercises(monologue: str, req_exercises: list,
|
|||||||
|
|
||||||
return exercises
|
return exercises
|
||||||
|
|
||||||
|
|
||||||
def gen_multiple_choice_exercise(text: str, quantity: int, start_id):
|
def gen_multiple_choice_exercise(text: str, quantity: int, start_id):
|
||||||
gen_multiple_choice_for_text = "Generate " + str(quantity) + " multiple choice questions for this text: " \
|
gen_multiple_choice_for_text = "Generate " + str(quantity) + " multiple choice questions for this text: " \
|
||||||
"'" + text + "'\n" \
|
"'" + text + "'\n" \
|
||||||
@@ -375,7 +389,13 @@ def gen_multiple_choice_exercise(text: str, quantity: int, start_id):
|
|||||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||||
["questions"],
|
["questions"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
return fix_exercise_ids(question, start_id)
|
return {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Select the appropriate option.",
|
||||||
|
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||||
|
"type": "multipleChoice",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_summary_fill_blanks_exercise(text: str, quantity: int, start_id):
|
def gen_summary_fill_blanks_exercise(text: str, quantity: int, start_id):
|
||||||
gen_summary_for_text = "Summarize this text: " + text
|
gen_summary_for_text = "Summarize this text: " + text
|
||||||
@@ -408,6 +428,7 @@ def gen_summary_fill_blanks_exercise(text: str, quantity: int, start_id):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_true_false_not_given_exercise(text: str, quantity: int, start_id):
|
def gen_true_false_not_given_exercise(text: str, quantity: int, start_id):
|
||||||
gen_true_false_not_given = "Generate " + str(
|
gen_true_false_not_given = "Generate " + str(
|
||||||
quantity) + " statements in JSON format (True, False, or Not Given) " \
|
quantity) + " statements in JSON format (True, False, or Not Given) " \
|
||||||
@@ -436,6 +457,7 @@ def gen_true_false_not_given_exercise(text: str, quantity: int, start_id):
|
|||||||
"type": "trueFalse"
|
"type": "trueFalse"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_exercise(text: str, quantity: int, start_id):
|
def gen_write_blanks_exercise(text: str, quantity: int, start_id):
|
||||||
gen_short_answer_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
gen_short_answer_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
||||||
"(max 3 words per answer), about this text: '" + text + "'. " \
|
"(max 3 words per answer), about this text: '" + text + "'. " \
|
||||||
@@ -456,8 +478,10 @@ def gen_write_blanks_exercise(text: str, quantity: int, start_id):
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int, start_id):
|
def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int, start_id):
|
||||||
gen_multiple_choice_for_text = "Generate " + str(quantity) + " multiple choice questions of 4 options for this conversation: " \
|
gen_multiple_choice_for_text = "Generate " + str(
|
||||||
|
quantity) + " multiple choice questions of 4 options for this conversation: " \
|
||||||
"'" + text + "'"
|
"'" + text + "'"
|
||||||
token_count = count_tokens(gen_multiple_choice_for_text)["n_tokens"]
|
token_count = count_tokens(gen_multiple_choice_for_text)["n_tokens"]
|
||||||
mc_questions = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_multiple_choice_for_text, token_count,
|
mc_questions = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_multiple_choice_for_text, token_count,
|
||||||
@@ -472,7 +496,13 @@ def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int
|
|||||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||||
["questions"],
|
["questions"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
return fix_exercise_ids(question, start_id)
|
return {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Select the appropriate option.",
|
||||||
|
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||||
|
"type": "multipleChoice",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, start_id):
|
def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, start_id):
|
||||||
gen_multiple_choice_for_text = "Generate " + str(quantity) + " multiple choice questions for this monologue: " \
|
gen_multiple_choice_for_text = "Generate " + str(quantity) + " multiple choice questions for this monologue: " \
|
||||||
@@ -490,7 +520,13 @@ def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, s
|
|||||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||||
["questions"],
|
["questions"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
return fix_exercise_ids(question, start_id)
|
return {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Select the appropriate option.",
|
||||||
|
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||||
|
"type": "multipleChoice",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_questions_exercise_listening_conversation(text: str, quantity: int, start_id):
|
def gen_write_blanks_questions_exercise_listening_conversation(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
gen_write_blanks_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
||||||
@@ -513,6 +549,7 @@ def gen_write_blanks_questions_exercise_listening_conversation(text: str, quanti
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_questions_exercise_listening_monologue(text: str, quantity: int, start_id):
|
def gen_write_blanks_questions_exercise_listening_monologue(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
gen_write_blanks_questions = "Generate " + str(quantity) + " short answer questions, and the possible answers " \
|
||||||
"(max 3 words per answer), about a monologue and" \
|
"(max 3 words per answer), about a monologue and" \
|
||||||
@@ -534,6 +571,7 @@ def gen_write_blanks_questions_exercise_listening_monologue(text: str, quantity:
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_notes_exercise_listening_conversation(text: str, quantity: int, start_id):
|
def gen_write_blanks_notes_exercise_listening_conversation(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_notes = "Generate " + str(quantity) + " notes taken from the conversation and and respond in this " \
|
gen_write_blanks_notes = "Generate " + str(quantity) + " notes taken from the conversation and and respond in this " \
|
||||||
"JSON format: { \"notes\": [\"note_1\", \"note_2\"] }. The monologue is this: '" + text + "'"
|
"JSON format: { \"notes\": [\"note_1\", \"note_2\"] }. The monologue is this: '" + text + "'"
|
||||||
@@ -558,6 +596,7 @@ def gen_write_blanks_notes_exercise_listening_conversation(text: str, quantity:
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_notes_exercise_listening_monologue(text: str, quantity: int, start_id):
|
def gen_write_blanks_notes_exercise_listening_monologue(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_notes = "Generate " + str(quantity) + " notes taken from the monologue and and respond in this " \
|
gen_write_blanks_notes = "Generate " + str(quantity) + " notes taken from the monologue and and respond in this " \
|
||||||
"JSON format: { \"notes\": [\"note_1\", \"note_2\"] }. The monologue is this: '" + text + "'"
|
"JSON format: { \"notes\": [\"note_1\", \"note_2\"] }. The monologue is this: '" + text + "'"
|
||||||
@@ -582,6 +621,7 @@ def gen_write_blanks_notes_exercise_listening_monologue(text: str, quantity: int
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_form_exercise_listening_conversation(text: str, quantity: int, start_id):
|
def gen_write_blanks_form_exercise_listening_conversation(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_form = "Generate a form with " + str(quantity) + " key-value pairs about the conversation. " \
|
gen_write_blanks_form = "Generate a form with " + str(quantity) + " key-value pairs about the conversation. " \
|
||||||
"The conversation is this: '" + text + "'"
|
"The conversation is this: '" + text + "'"
|
||||||
@@ -604,6 +644,7 @@ def gen_write_blanks_form_exercise_listening_conversation(text: str, quantity: i
|
|||||||
"type": "writeBlanks"
|
"type": "writeBlanks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen_write_blanks_form_exercise_listening_monologue(text: str, quantity: int, start_id):
|
def gen_write_blanks_form_exercise_listening_monologue(text: str, quantity: int, start_id):
|
||||||
gen_write_blanks_form = "Generate a form with " + str(quantity) + " key-value pairs about the monologue. " \
|
gen_write_blanks_form = "Generate a form with " + str(quantity) + " key-value pairs about the monologue. " \
|
||||||
"The monologue is this: '" + text + "'"
|
"The monologue is this: '" + text + "'"
|
||||||
|
|||||||
Reference in New Issue
Block a user