代码

github 几个简单的NLP数据增强示例:

  • random delete word
  • random delete char
  • random delete symbol
  • random swag word
  • random back translate by google (需要能访问谷歌)
  • random synonym substitution
  • random back translate by youdao(免费,有道支持)

示例

使用单独的增强

from aug_func import func_list
import random

if __name__ == '__main__':
    sentences = "爱打篮球的男生喜欢什么样的女生"
    func = random.choice(func_list)
    print(func(sentences, prob=1.0))

使用全部的增强

from aug_func import func_list
import random

if __name__ == '__main__':
    sentences = "爱打篮球的男生喜欢什么样的女生"
    for func in func_list:
        sentences = func(sentences, prob=random.random())
    print(sentences)