증강 종류
단어 단위 증강
- 단어 일부 삭제(random deletion)
- 단어 일부 교환(random swap)
- 단어 일부 주입(random input)
- 단어 일부 교체(random replace)
- 동의어 교체(random replace, synonem)
문장 단위 증강
- 역번역 (back-translastion)
- 문장 교환
- 문장 오류 주입(add noising)
언어모델 기반 증강
- Bert 모델 기반
- 생성형 모델 기반
텍스트 증강은 일반적으로 토큰화 한 뒤에 하게 된다.
증강 라이브러리 실습
단어 레벨 변환
텍스트 전처리, 증강 전용 전통 라이브러리로써, 최근 LLM 기반 증강 기법들에 비해서 사용되는 비중이 줄어들었으나, 저비용, 저중량 기법으로써 자원이 충분하지 않은 환경에서 여전히 활용도는 높다.
NLPAug:
- !pip install nlpaug
- import nlpaug.augmenter.word as naw
- import nltk
- nltk.download('averaged_perceptron_tagger_eng')
# 워드넷 기반 동의어 교체
- aug = naw.SynonymAug(aug_src='wordnet')
- sentence = "Natural language processing is interesting."
- augmented_text = aug.augment(sentence)
- augmented_text
# 단어 임의 삭제
- # aug = naw.RandomWordAug(action="delete")
- aug = naw.RandomWordAug(action="swap")
- sentence = "Natural language processing is interesting."
- augmented_text = aug.augment(sentence)
- augmented_text
3TextAttack:
- !pip install textattack
- from textattack.augmentation import WordNetAugmenter
augmenter = WordNetAugmenter()
augmented_texts = augmenter.augment("Natural language processing is interesting.")
augmented_texts
역번역
- 문장을 증강하기 위해, 어떤 언어를 다른 언어로 바꾸었다가 다시 원래 언어로 바꾼다.
- ex) 한국어 > 프랑스어 > 한국어 등
BERT 모델 사용 증강

import nlpaug.augmenter.word as naw
aug = naw.ContextualWordEmbsAug(
model_path='bert-base-uncased',
action="substitute"
)
augmented_text = aug.augment("Natural language processing is interesting.")
augmented_text
Tags:
AI개발_교육