ShynBui commited on
Commit
fa274a5
·
1 Parent(s): a7b12ed

add condition for teencode def

Browse files
Files changed (1) hide show
  1. utils.py +5 -1
utils.py CHANGED
@@ -359,11 +359,15 @@ def common_misspelling_replacement(text, error_rate=0.03, C=0.01):
359
  # Tìm các từ có thể thay thế
360
  candidate_indices = [i for i, word in enumerate(words) if word in common_misspellings]
361
 
 
 
 
 
362
  # Tính toán xác suất thay thế từ dựa trên error_rate sử dụng hàm logarit
363
  augmentation_probability = C / math.log(error_rate + 1)
364
 
365
  # Thực hiện thay thế từ tại các vị trí ngẫu nhiên
366
- num_errors = int(len(candidate_indices) * error_rate)
367
  for _ in range(num_errors):
368
  if len(candidate_indices) > 0 and random.random() <= augmentation_probability:
369
  index = random.choice(candidate_indices)
 
359
  # Tìm các từ có thể thay thế
360
  candidate_indices = [i for i, word in enumerate(words) if word in common_misspellings]
361
 
362
+ #Kiểm tra xem có thể thay không
363
+ if len(candidate_indices) == 0:
364
+ return ' '.join(words)
365
+
366
  # Tính toán xác suất thay thế từ dựa trên error_rate sử dụng hàm logarit
367
  augmentation_probability = C / math.log(error_rate + 1)
368
 
369
  # Thực hiện thay thế từ tại các vị trí ngẫu nhiên
370
+ num_errors = int(len(text) * error_rate) if len(text) * error_rate > 1 else int(random.random())
371
  for _ in range(num_errors):
372
  if len(candidate_indices) > 0 and random.random() <= augmentation_probability:
373
  index = random.choice(candidate_indices)