当前位置:网站首页>Texttext data enhancement method data argument

Texttext data enhancement method data argument

2022-07-06 10:26:00 How about a song without trace

 Knowledge point :text  Data to enhance  data argumentation
random insertion  Insert randomly 
random deletion  Random delete 
random swap  Random exchange 
 Reference paper : EDA : Easy Data Augmentation Techniques for Boosting Performance on Text Classification Tasks

Back Translation
 give an example :  English  -->  chinese  -->  English 

#  Need to install  : pip install google_trans_new
​
from google_trans_new import google_translator
​
translator = google_translator()
sentence = ['stay hungry, stay foolish. -- spoken / said by Steve Jobs']
#  Britain  -->  in 
translation_cn = translator.translate(sentence, lang_tgt='zh-cn')
translation_cn
#  in  -->  Britain 
translation_en = translator.translate(translation_cn, lang_tgt='en')
translation_en
 Choose a language translation randomly 
import random
import google_trans_new
​
languages = list(google_trans_new.LANGUAGES.keys())
len(languages) #  Translatable languages  108  Kind of 
object_lang = random.choice(languages)
​
object_lang
#  Forward translation 
​
translations = translator.translate(sentence, lang_tgt=object_lang)
​
translations
#  Reverse translation 

back_trans = translator.translate(translations, lang_tgt='en')

back_trans
#  Reverse translation 
​
back_trans = translator.translate(translations, lang_tgt='en')
​
back_trans

原网站

版权声明
本文为[How about a song without trace]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060910586858.html