Acdong
Learn by doing
Acdong
전체 방문자
오늘
어제
  • 분류 전체보기
    • Economy
      • Saving Money
    • Self-improvement
    • Thoughts
    • Machine learning
      • Deep Learning
      • Chatbot
      • NLP
    • MLops
      • AWS
      • Container
      • Serving
    • Computer Vision
    • Data Science
      • ADsP
      • R
    • Project
    • Python
      • Data Structure & Algorithm
    • C,C++
    • API
      • ElasticSearch
    • Error Note
    • Network
    • RDBMS
      • SQL

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • [GitHub]

인기 글

태그

  • 존댓말 반말 분류
  • Python
  • 기계학습
  • 데이터 전처리
  • SentenceTransformer
  • 포인터
  • 머신러닝
  • 회귀계수
  • c포인터
  • R
  • sbert
  • R시각화
  • R그래프
  • plot()
  • nlp
  • 다중공선성
  • 어텐션
  • Numpy
  • 이미지 전처리
  • pandas

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Acdong

Learn by doing

Machine learning/NLP

[NLP]. 한국어 메신저(구어체)대화 맞춤법(typos) 오타 교정기(Corrector) 모델 : Korean Typos(Spelling) Corrector Using Deep Learning

2023. 6. 25. 18:34
728x90

한국어 맞춤법 교정기

  • ETRI-et5 모델을 기반으로 fine-tuning한 한국어 구어체 전용 맞춤법 교정기 입니다.
  • 바로 사용하실 분들은 밑에 예제 코드 참고해서 모델('j5ng/et5-typos-corrector') 다운받아 사용하실 수 있습니다.

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)
  • 맞춤법 교정 데이터

예시

original corrected
이런게 눔 ㄱ ㅣ찮아서 ㅠㅠ 이런 게 넘 귀찮아서 ㅠㅠ
어쩌다 가게되써 어쩌다 가게 됐어?
이따 얘기하쟈 이따 얘기하자
ㅋㅋㅋㅋㅋㅋ언넝 맞이해 ㅋㅋㅋㅋㅋㅋ 얼른 맞이해
그냥 일을안가르쳐주고 그냥 일을 안 가르쳐 주고

Data Preprocessing

  • 특수문자 제거 (쉼표) .(마침표) 제거
  • null 값("") 제거
  • 너무 짧은 문장 제거(길이 2 이하)
  • 문장 내 &name&, name1 등 이름 태그가 포함된 단어 제거(단어만 제거하고 문장은 살림)
  • total : 318,882 쌍

How to use

import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer

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

device = "cuda:0" if torch.cuda.is_available() else "cpu"
# device = "mps:0" if torch.cuda.is_available() else "cpu" # for mac m1

model = model.to(device) 

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

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

input_ids = input_encoding.input_ids.to(device)
attention_mask = input_encoding.attention_mask.to(device)

# 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) # 아니 진짜 뭐 하냐고.

With Transformer Pipeline

import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer, pipeline

model = T5ForConditionalGeneration.from_pretrained('j5ng/et5-typos-corrector')
tokenizer = T5Tokenizer.from_pretrained('j5ng/et5-typos-corrector')

typos_corrector = pipeline(
    "text2text-generation",
    model=model,
    tokenizer=tokenizer,
    device=0 if torch.cuda.is_available() else -1,
    framework="pt",
)

input_text = "완죤 어이업ㅅ네진쨬ㅋㅋㅋ"
output_text = typos_corrector("맞춤법을 고쳐주세요: " + input_text,
            max_length=128,
            num_beams=5,
            early_stopping=True)[0]['generated_text']

print(output_text) # 완전 어이없네 진짜 ᄏᄏᄏᄏ.

Thanks to

맞춤법 교정기의 학습은 인공지능산업융합사업단(AICA)의 GPU 리소스를 지원받아 학습되었습니다.

 

Github : https://github.com/jongmin-oh/korean-typos-corrector
 

GitHub - jongmin-oh/korean-typos-corrector: 한국어 메신저(구어체)대화 맞춤법(typos) 오타 교정기(Corrector)

한국어 메신저(구어체)대화 맞춤법(typos) 오타 교정기(Corrector) 입니다. . Contribute to jongmin-oh/korean-typos-corrector development by creating an account on GitHub.

github.com

 

반응형
저작자표시 비영리 (새창열림)

'Machine learning > NLP' 카테고리의 다른 글

[NLP]. 한국어(Korean)에서 반말(informal)을 존댓말(formal)로 바꿔주는 변환기(convertor) - korean Formal Convertor Using Deep Learning  (0) 2023.06.25
[NLP]. 크로스 인코더(Cross Encoder) Onnx Runtime 양자화 하기  (0) 2023.05.16
[NLP]. Ray와 Sklearn Pipeline을 사용하여 Pandas 데이터 전처리하기  (0) 2023.04.05
[NLP]. HuggingFace Tokenizer에 token 추가(add)하기  (0) 2023.02.27
[NLP]. MultipleNegativesRankingLoss 적용기(Sentence Transfomer)  (0) 2023.02.21
    'Machine learning/NLP' 카테고리의 다른 글
    • [NLP]. 한국어(Korean)에서 반말(informal)을 존댓말(formal)로 바꿔주는 변환기(convertor) - korean Formal Convertor Using Deep Learning
    • [NLP]. 크로스 인코더(Cross Encoder) Onnx Runtime 양자화 하기
    • [NLP]. Ray와 Sklearn Pipeline을 사용하여 Pandas 데이터 전처리하기
    • [NLP]. HuggingFace Tokenizer에 token 추가(add)하기
    Acdong
    Acdong
    E-mail : alswhddh@naver.com / 자연어처리와 MLops 를 연구하고 있는 스타트업 개발자입니다.

    티스토리툴바