在进行文本数据增强的处理中,也就是将汉字翻译成多国语言后再翻译回汉字的操作中,要使用到gooletrans来进行文本的翻译,但在使用过程中出现了握手报错导致的链接超时,通过关闭防火墙、链接外网、更新版本问题依旧无法解决。
又尝试了该博主的方法使用google_trans_new库依旧404报错python3--googletrans超时报错解决以及翻译工具优化(附源码)_googletrans connecttimeout: timed out-优快云博客
最后我使用
deep-translator库来进行语句翻译-通过终端来安装库
pip install deep-translator
将多个文本整合为一个文本以换行隔开再听过换行符输出多个文本
from deep_translator import GoogleTranslator
combined_text = "\n".join([p_sample1, p_sample2, n_sample1, n_sample2])
translations = GoogleTranslator(source='auto', target='ko').translate(combined_text)
print(translations.split("\n"))