Instructions to use Xcz2568/robustness_t5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Xcz2568/robustness_t5 with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("summarization", model="Xcz2568/robustness_t5")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("Xcz2568/robustness_t5") model = AutoModelForSeq2SeqLM.from_pretrained("Xcz2568/robustness_t5") - Notebooks
- Google Colab
- Kaggle
import random
def add_spelling_errors(text):
noisy_text = list(text)
modified_text = []
for i in range(len(noisy_text)):
if random.random() < 0.1:
if noisy_text[i] in ['은', '는', '이', '가','을','를']:
noisy_text[i] = random.choice(['은', '는', '이', '가','를','을']) # 语法
continue
elif noisy_text[i] in ['와','과']:
noisy_text[i] = random.choice(['와','과']) # 语法
continue
elif random.random() < 0.1:
# 随机插入字符
noisy_text.insert(i, random.choice(['하', '로', '니', '고', '었', '나']))
# 这里不需要增加i,因为insert操作会将插入位置之后的字符向后移动
#i += 1 # 移动到下一个位置,因为插入了一个字符
# 删除空格或交换字符
if noisy_text[i] == ' ' and random.random() < 0.1:
continue # 跳过空格
elif random.random() < 0.1: # 控制交换字符的概率
if i < len(noisy_text) - 1:
noisy_text[i], noisy_text[i + 1] = noisy_text[i + 1], noisy_text[i]
modified_text.append(noisy_text[i])
return ''.join(modified_text)
- Downloads last month
- 11