Textmentations
Textmentations is a Python library for augmenting Korean text. Inspired by albumentations. Textmentations uses the albumentations as a dependency.
Installation
pip install textmentations
A simple example
Textmentations provides text augmentation techniques implemented using the TextTransform, which inherits from the albumentations BasicTransform.
This allows textmentations to reuse the existing functionalities of albumentations.
import textmentations as T
from albumentations import Compose
text = "์ด์ ์๋น์ ๊ฐ๋ค. ๋ชฉ์ด ๋๋ฌด ๋ง๋๋ค. ๋จผ์ ๋ฌผ ํ์์ ๋ง์
จ๋ค. ๊ทธ๋ฆฌ๊ณ ํ์์ก์ ๋ง์๊ฒ ๋จน์๋ค."
rd = T.RandomDeletion(deletion_prob=0.3, min_words_each_sentence=1)
ri = T.RandomInsertion(insertion_prob=0.3, n_times=1)
rs = T.RandomSwap(n_times=3)
sr = T.SynonymReplacement(replacement_prob=0.3)
eda = Compose([rd, ri, rs, sr])
print(rd(text=text)["text"])
# ์๋น์ ๊ฐ๋ค. ๋ชฉ์ด ๋๋ฌด ๋ง๋๋ค. ๋จผ์ ๋ฌผ. ๊ทธ๋ฆฌ๊ณ ํ์์ก์ ๋ง์๊ฒ.
print(ri(text=text)["text"])
# ์ด์ ์ต๊ทผ ์๋น์ ๊ฐ๋ค. ๋ชฉ์ด ๋๋ฌด ๋ง๋๋ค. ๋จผ์ ๋ฌผ ํ์์ ๋ง์
จ๋ค ์๋ฃ์. ๊ทธ๋ฆฌ๊ณ ํ์์ก์ ๋ง์๊ฒ ๋จน์๋ค.
print(rs(text=text)["text"])
# ์ด์ ๊ฐ๋ค ์๋น์. ๋ชฉ์ด ๋๋ฌด ๋ง๋๋ค. ๋ฌผ ๋จผ์ ํ์์ ๋ง์
จ๋ค. ๊ทธ๋ฆฌ๊ณ ๋จน์๋ค ๋ง์๊ฒ ํ์์ก์.
print(sr(text=text)["text"])
# ๊ณผ๊ฑฐ ์๋น์ ๊ฐ๋ค. ๋ชฉ์ด ๋๋ฌด ๋ง๋๋ค. ๋จผ์ ์์ฃผ ํ์์ ๋ง์
จ๋ค. ๊ทธ๋ฆฌ๊ณ ํ์์ก์ ๋ง์๊ฒ ๋จน์๋ค.
print(eda(text=text)["text"])
# ์๋น์ ์ด์ ๊ณผ๊ฑฐ. ๋๋ฌด ๋ง๋๋ค. ์์ ํ์์ ๋ง์
จ๋ค ๋งน๋ฌผ. ๋จน์๋ค ๊ทธ๋ฆฌ๊ณ ๋ง์๊ฒ.
List of augmentations
- AEDA
- BackTranslation
- RandomDeletion
- RandomDeletionSentence
- RandomInsertion
- RandomSwap
- RandomSwapSentence
- SynonymReplacement