Add misspelled pairs to writing grading.
This commit is contained in:
2
app.py
2
app.py
@@ -204,6 +204,7 @@ def grade_writing_task_1():
|
|||||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
|
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
|
||||||
["comment"],
|
["comment"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
|
response['misspelled_pairs'] = get_misspelled_pairs(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
@@ -256,6 +257,7 @@ def grade_writing_task_2():
|
|||||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
|
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
|
||||||
["comment"],
|
["comment"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
|
response['misspelled_pairs'] = get_misspelled_pairs(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import string
|
||||||
import whisper
|
import whisper
|
||||||
import os
|
import os
|
||||||
import nltk
|
import nltk
|
||||||
import boto3
|
import boto3
|
||||||
import random
|
import random
|
||||||
|
from spellchecker import SpellChecker
|
||||||
|
|
||||||
nltk.download('words')
|
nltk.download('words')
|
||||||
from nltk.corpus import words
|
from nltk.corpus import words
|
||||||
from helper.constants import *
|
from helper.constants import *
|
||||||
@@ -101,3 +104,27 @@ def divide_text(text, max_length=3000):
|
|||||||
current_position = next_position
|
current_position = next_position
|
||||||
|
|
||||||
return divisions
|
return divisions
|
||||||
|
|
||||||
|
|
||||||
|
def get_misspelled_pairs(text):
|
||||||
|
spell = SpellChecker()
|
||||||
|
|
||||||
|
# Remove punctuation from the text
|
||||||
|
translator = str.maketrans("", "", string.punctuation)
|
||||||
|
text_without_punctuation = text.translate(translator)
|
||||||
|
|
||||||
|
# Split the text into words
|
||||||
|
words = text_without_punctuation.split()
|
||||||
|
|
||||||
|
# Find misspelled words
|
||||||
|
misspelled = spell.unknown(words)
|
||||||
|
|
||||||
|
# Create a list to store misspelled word pairs
|
||||||
|
misspelled_pairs = []
|
||||||
|
|
||||||
|
# Generate misspelled word pairs with their corrections
|
||||||
|
for word in misspelled:
|
||||||
|
correction = spell.correction(word)
|
||||||
|
misspelled_pairs.append({"misspelled": word, "correction": correction})
|
||||||
|
|
||||||
|
return misspelled_pairs
|
||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Reference in New Issue
Block a user