File size: 2,534 Bytes
5d1cb81 4eda87a 5d1cb81 4eda87a 5d1cb81 4eda87a 14e96ee 4eda87a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
---
language:
- zh
license: apache-2.0
tags:
- t5
- text error correction
widget:
- text: "今天天气不太好,我的心情也不是很偷快"
example_title: "案例1"
- text: "听到这个消息,心情真的蓝瘦"
example_title: "案例2"
- text: "脑子有点胡涂了,这道题冥冥学过还没有做出来"
example_title: "案例3"
inference:
parameters:
max_length: 256
num_beams: 10
no_repeat_ngram_size: 5
do_sample: True
early_stopping: True
---
## 功能介绍
T5Corrector:中文字音与字形纠错模型
这个模型是基于mengzi-t5-base进行文本纠错训练,使用500w+句子,通过替换同音词、近音词和形近字来构造纠错平行语料,共计3kw+句对,累计训练45000步。
<a href='https://github.com/Macielyoung/T5Corrector'>Github项目地址</a>
加载模型:
```python
# 加载模型
from transformers import T5Tokenizer, T5ForConditionalGeneration
pretrained = "Maciel/T5Corrector-base-v1"
tokenizer = T5Tokenizer.from_pretrained(pretrained)
model = T5ForConditionalGeneration.from_pretrained(pretrained)
```
使用模型进行预测推理方法:
```python
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
def correct(text, max_length):
model_inputs = tokenizer(text,
max_length=max_length,
truncation=True,
return_tensors="pt").to(device)
output = model.generate(**model_inputs,
num_beams=5,
no_repeat_ngram_size=4,
do_sample=True,
early_stopping=True,
max_length=max_length,
return_dict_in_generate=True,
output_scores=True)
pred_output = tokenizer.batch_decode(output.sequences, skip_special_tokens=True)[0]
return pred_output
text = "听到这个消息,心情真的蓝瘦"
correction = correct(text, max_length=32)
print(correction)
```
### 案例展示
```
示例1:
input: 听到这个消息,心情真的蓝瘦
output: 听到这个消息,心情真的难受
示例2:
input: 脑子有点胡涂了,这道题冥冥学过还没有做出来
output: 脑子有点糊涂了,这道题明明学过还没有做出来
示例3:
input: 今天天气不太好,我的心情也不是很偷快
output: 今天天气不太好,我的心情也不是很愉快
``` |