Garvitj commited on
Commit
dd5270c
·
verified ·
1 Parent(s): 75bf678

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -110,9 +110,19 @@ def detect_grammar_errors(text):
110
  outputs = grammar_model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
111
  grammar_analysis = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
112
 
113
- # Count the number of errors based on specific indicators (customize based on analysis)
114
- error_count = grammar_analysis.count('error') # Use your own criteria
115
- return error_count
 
 
 
 
 
 
 
 
 
 
116
 
117
  def penalize_for_grammar(student_answer):
118
  grammar_errors = detect_grammar_errors(student_answer)
 
110
  outputs = grammar_model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
111
  grammar_analysis = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
112
 
113
+ # Compare the corrected sentence with the original one
114
+ corrected_sentence = grammar_analysis
115
+
116
+ # Simple heuristic to count changes as errors (e.g., difference in word count)
117
+ # You can also use edit distance or other sophisticated techniques to count errors
118
+ original_words = text.split()
119
+ corrected_words = corrected_sentence.split()
120
+
121
+ # Calculate a rough estimate of grammar errors based on differences in word count
122
+ error_count = abs(len(original_words) - len(corrected_words))
123
+
124
+ return error_count, corrected_sentence
125
+
126
 
127
  def penalize_for_grammar(student_answer):
128
  grammar_errors = detect_grammar_errors(student_answer)