Garvitj commited on
Commit
7450487
·
verified ·
1 Parent(s): 54f6e5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -12,7 +12,7 @@ import torch.nn.functional as F
12
  # Load pre-trained models
13
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
14
  bert_model = BertModel.from_pretrained('bert-base-uncased')
15
- sentence_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
16
 
17
  # Load the pre-trained T5 model and tokenizer for grammar error detection
18
  grammar_model = T5ForConditionalGeneration.from_pretrained('t5-base')
@@ -118,7 +118,7 @@ def penalize_for_grammar(student_answer):
118
  grammar_errors = detect_grammar_errors(student_answer)
119
 
120
  # Apply a penalty based on the number of grammar errors (max 50% penalty)
121
- penalty = max(0.5, 1 - 0.05 * grammar_errors)
122
  return penalty
123
 
124
  def compare_answers(student_answer, teacher_answer):
@@ -126,7 +126,7 @@ def compare_answers(student_answer, teacher_answer):
126
  sentence_similarity = calculate_sentence_similarity(student_answer, teacher_answer)
127
 
128
  # Use a higher weight for BERT similarity
129
- semantic_similarity = (0.75 * bert_similarity + 0.25 * sentence_similarity)
130
 
131
  # Apply grammar penalty
132
  grammar_penalty = penalize_for_grammar(student_answer)
 
12
  # Load pre-trained models
13
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
14
  bert_model = BertModel.from_pretrained('bert-base-uncased')
15
+ sentence_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
16
 
17
  # Load the pre-trained T5 model and tokenizer for grammar error detection
18
  grammar_model = T5ForConditionalGeneration.from_pretrained('t5-base')
 
118
  grammar_errors = detect_grammar_errors(student_answer)
119
 
120
  # Apply a penalty based on the number of grammar errors (max 50% penalty)
121
+ penalty = max(0.3, 1 - 0.1 * grammar_errors)
122
  return penalty
123
 
124
  def compare_answers(student_answer, teacher_answer):
 
126
  sentence_similarity = calculate_sentence_similarity(student_answer, teacher_answer)
127
 
128
  # Use a higher weight for BERT similarity
129
+ semantic_similarity = (0.50 * bert_similarity + 0.50 * sentence_similarity)
130
 
131
  # Apply grammar penalty
132
  grammar_penalty = penalize_for_grammar(student_answer)