Spaces:
Build error
Build error
Download fomula.py from ShynBui/Create_Vietnamese_spelling_errors: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/ShynBui/Create_Vietnamese_spelling_errors/resolve/main/fomula.py
- Command line
-
hf download hf://spaces/ShynBui/Create_Vietnamese_spelling_errors/fomula.py
-
curl -L -o fomula.py https://huggingface.co/spaces/ShynBui/Create_Vietnamese_spelling_errors/resolve/main/fomula.py
1.72 kB
| import pandas as pd | |
| import numpy as np | |
| import random | |
| import math | |
| ''' | |
| AP = a.ER^(bx) * sigmoidP(x) | |
| ER: Tỉ lệ lỗi trong 1 phép tạo lỗi: 0.5% - 10% | |
| AP (augmentation_probability) : Tỉ lệ sửa (0.1 <= AP <= 0.5) | |
| a: weight (0.5442) | |
| b: bias (-16.94145) | |
| SER: Tỷ lệ lỗi đã thêm (mong muốn: < 15% - tối đa <= 30%) | |
| ''' | |
| ER_min = 0.01 | |
| ER_max = 0.1 | |
| def find_a_b_for_AP(min_AP = 0.5, max_AP = 1): | |
| ''' | |
| :param min_AP: | |
| :param max_AP: | |
| :return: a, b | |
| {a * e^(b * ER_min) = max_AP | |
| {a * e^(b * ER_max) = min_AP | |
| (ER_max - ER_min) * b = ln(min_AP / max_AP) | |
| ''' | |
| exponential = ER_max - ER_min | |
| b = np.log(min_AP / max_AP) / exponential | |
| ''' | |
| a * e^(b * ER_min) = max_AP | |
| ''' | |
| a = max_AP / math.pow(np.e, b * ER_min) | |
| return a, b | |
| def AP_fomula(a = 0.5442, b = -16.94145, error_rate=0.1): | |
| a, b = find_a_b_for_AP() | |
| # print(a, b) | |
| augmentation_probability = a * math.pow(np.e, b * error_rate) | |
| return augmentation_probability | |
| ''' | |
| Hàm sigmoid: | |
| Sigmoid(x) = 1 / (1 + e^(-k * x)) | |
| Giới hạn tỉ lệ lỗi tối đa của một câu là <= 35% | |
| x: là SER_max - SER_mong muốn | |
| => Sigmoid - lim(x) -> 0.35 ~ 1 | |
| Sigmoid(x) = 1 / (1 + e^(-k * x)) ~ 1 | |
| => 1 / (1 + e^(-0.35k)) = 999/1000 | |
| Đk kich hoạt hàm sigmoid => Khi SER đạt đến một độ min nhật định vd: 10% | |
| ''' | |
| def get_k_sigmoid(x=0.2, lim1 = 0.999): | |
| ''' | |
| :param x: ##SER: Tỷ lệ lỗi đã thêm (mong muốn: < 15% - tối đa <= 30%) | |
| :param lim1: Giá trị ~1 | |
| :return: k | |
| ''' | |
| sum1 = 1 - lim1 | |
| sum1 = sum1 / lim1 | |
| k = -np.log(sum1) / x | |
| return k | |
| print(1 - (1 / (1 + pow(math.e, 0.0 * get_k_sigmoid(x=0.1))))) |