-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_augmenter.py
More file actions
35 lines (22 loc) · 843 Bytes
/
Copy pathtext_augmenter.py
File metadata and controls
35 lines (22 loc) · 843 Bytes
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
# -*- coding: utf-8 -*-
"""text_augmenter.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1vZUhqAPFi-WvDod17nt7x62sN2yfe7jP
"""
import os
import pandas as pd
import nlpaug.augmenter.char as nac
TEST_DATA_FILE = './input/jigsaw-toxic-comment-classification-challenge/test.csv'
test = pd.read_csv(TEST_DATA_FILE)
def augment_text_ocr(comment):
aug = nac.OcrAug(aug_char_p=0.3,
aug_word_p=0.4,
aug_word_min=len(comment))
try:
augmented_texts = aug.augment(comment,n=1)
except:
augmented_texts = None
return augmented_texts
test['augmented_comment'] = test['comment_text'].apply(augment_text_ocr)
test.to_csv('./input/jigsaw-toxic-comment-classification-challenge/test_with_augmentation.csv', index=False)