File size: 1,803 Bytes
f4a42ba
 
 
 
0dab382
 
37b474a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language:
- ko
pipeline_tag: text-generation
---

## 한국어 맞춤법 교정기(Korean Typos Corrector)
 - ETRI-et5 모델을 기반으로한 한국어 구어체 맞춤법 교정기 입니다.

## Base on PLM model(ET5)
 - ETRI(https://aiopen.etri.re.kr/et5Model)

## Base on Dataset
 - 모두의 말뭉치(https://corpus.korean.go.kr/request/reausetMain.do?lang=ko) 맞춤법 교정 데이터

 ## Data Preprocessing
  - 1. 특수문자 제거 (쉼표) .(마침표) 제거
  - 2. null 값("") 제거
  - 3. 너무 짧은 문장 제거(길이 2 이하) 
  - 4. 문장 내 &name&, name1 등 이름 태그가 포함된 단어 제거

## How to use
```python
from transformers import T5ForConditionalGeneration, T5Tokenizer

# T5 모델 로드
model = T5ForConditionalGeneration.from_pretrained("j5ng/et5-typos-corrector")
tokenizer = T5Tokenizer.from_pretrained("j5ng/et5-typos-corrector")

model = model.to('mps:0') # for mac m1
# model = model.to('cuda:0') # for nvidia cuda

# 예시 입력 문장
input_text = "아늬 진짜 무ㅓ하냐고"

# 입력 문장 인코딩
input_encoding = tokenizer("맞춤법을 고쳐주세요: " + input_text, return_tensors="pt")

input_ids = input_encoding.input_ids.to('mps:0')
attention_mask = input_encoding.attention_mask.to('mps:0')

# input_ids = input_encoding.input_ids.to('cuda:0') # for nvidia cuda
# attention_mask = input_encoding.attention_mask.to('cuda:0') # for nvidia cuda

# T5 모델 출력 생성
output_encoding = model.generate(
    input_ids=input_ids,
    attention_mask=attention_mask,
    max_length=128,
    num_beams=5,
    early_stopping=True,
)

# 출력 문장 디코딩
output_text = tokenizer.decode(output_encoding[0], skip_special_tokens=True)

# 결과 출력
print(output_text)
```

```bash
아니 진짜 뭐 하냐고.
```