div文字自动扩充

自然语言处理 (Natural Language Processing)

Data Augmentation is the process that enables us to increase the size of the training data without actually collecting the data. But why do we need more data? The answer is simple — the more data we have, the better the performance of the model.

Data Augmentation是使我们能够在不实际收集数据的情况下增加训练数据的大小的过程。 但是为什么我们需要更多数据? 答案很简单-我们拥有的数据越多,模型的性能就越好。

Image data augmentation steps such as flipping, cropping, rotation, blurring, zooming, etc. helped tremendously in the computer vision. Also, it is relatively easy to create augmented images but the same is not the case with Natural Language Processing (NLP) due to the complexities inherent in the language. (For example, we can not replace every word by its synonym and even if we replace, the meaning of the sentence might change completely). Based on my findings/research, I haven’t seen as much research around text data augmentation as image augmentation.

图像数据增强步骤(例如翻转,裁切,旋转,模糊,缩放等)极大地帮助了计算机视觉。 同样,创建增强图像相对容易,但是Natural Language Processing (NLP)并非如此,因为该语言固有的复杂性。 (例如,我们不能用同义词代替每个单词,即使我们替换,句子的含义也可能会完全改变)。 根据我的发现/研究,关于文本数据增强的研究还不多于图像增强。

However, in this article, we will go thru 2 libraries TextAttack & Googletrans I have come across recently when I was trying augmentation for text data. So, let’s get started.

但是,在本文中,我们将通过2个库TextAttackGoogletrans我最近在尝试扩展文本数据时遇到的。 因此,让我们开始吧。

We will apply the augmentation techniques we are going to learn on these quotes of Simon Sinek.

我们将在Simon Sinek的这些报价中应用将要学习的增强技术。

“Leadership requires two things: a vision of the world that does not yet exist and the ability to communicate it.”

“领导力需要两件事:对尚不存在的世界的愿景以及与之沟通的能力。”

“The role of a leader is not to come up with all the great ideas. The role of a leader is to create an environment in which great ideas can happen”

“领导者的角色不是提出所有伟大的想法。 领导者的作用是创造一个可以产生好主意的环境”

- Simon Sinek

-西蒙·辛尼克

文字攻击 (TextAttack)

TextAttack is a Python framework for adversarial attacks, adversarial training, and data augmentation in NLP. In this article, we will focus only on data augmentation.

TextAttack是一个Python框架,用于NLP中的对抗攻击,对抗训练和数据增强。 在本文中,我们将仅关注数据扩充。

安装 (Installation)

!pip install textattack

用法 (Usage)

The textattack.Augmenter class provides four methods for data augmentation.

textattack.Augmenter类提供了四种数据扩充方法。

  1. WordNetAugmenter: Augments text by replacing with synonyms from the WordNet thesaurus.

    WordNetAugmenter :通过替换WordNet同义词库中的同义词来增强文本。

  2. EmbeddingAugmenter: Augments text by transforming words with their embeddings, with a constraint to ensure their cosine similarity is at least 0.8.

    EmbeddingAugmenter :通过转换带有嵌入词的单词来增强文本,并具有约束以确保其余弦相似度至少为0.8。

  3. CharSwapAugmenter: Augments text by substituting, deleting, inserting, and swapping adjacent characters.

    CharSwapAugmenter :通过替换,删除,插入和交换相邻字符来增强文本。

  4. EasyDataAugmenter: This augments the text with a combination of Wordnet synonym replacement, word deletion, word order swaps & synonym insertions. All these 4 functionalities happen randomly. So we will get different results each time we run the code. This returns 4 augmented results, unlike the other three methods.

    EasyDataAugmenter :这结合了Wordnet同义词替换,单词删除,单词顺序交换和同义词插入的组合来增加文本。 所有这四个功能都是随机发生的。 因此,每次运行代码时,我们都会得到不同的结果。 与其他三种方法不同,这将返回4个增强结果。

Let’s look at the data augmentation results using these four methods. Note that pct_words_to_swap=0.1, transformations_per_example=4 are passed to each of these methods by default. We can modify these default values as needed.

让我们看看使用这四种方法的数据扩充结果。 请注意,默认情况下将pct_words_to_swap=0.1transformations_per_example=4传递给每个方法。 我们可以根据需要修改这些默认值。

We can apply these methods to real-world data to increase the size of the data. The sample code is given below. Here the originaltrain dataframe is copied to the train_aug dataframe and then augmentation is applied on train_aug. And finally, train_aug is appended to the original train dataset.

我们可以将这些方法应用于实际数据,以增加数据的大小。 示例代码如下。 在这里,原始train数据帧被复制到train_aug数据帧,然后对train_aug进行train_aug 。 最后, train_aug被附加到原始train数据集。

train_aug = train.copy()from textattack.augmentation import EmbeddingAugmenteraug = EmbeddingAugmenter()train_aug['text'] = train_aug['text'].apply(lambda x: str(aug.augment(x)))train = train.append(train_copy, ignore_index=True)

谷歌翻译 (Googletrans)

Googletrans is built on top Google Translate API. This uses Google Translate Ajax API for language detection and translation.

Googletrans基于顶级的Google Translate API构建。 这使用Google Translate Ajax API进行语言检测和翻译。

安装 (Installation)

!pip install googletrans

用法 (Usage)

The key parameters to translate() method are:

translate()方法的关键参数是:

src: source language. Optional parameter as googletrans will detect it.

src :源语言。 可选参数googletrans会检测到它。

dest: destination language. Mandatory parameter.

dest :目标语言。 必填参数。

text: the text to be translated from source language to the destination language. Mandatory parameter.

text :要从源语言转换为目标语言的文本。 必填参数。

As we can see, the given text is first translated from English to Italian and then translated to back to English. During this back translation, as we can see, there is a slight change in the sentence between the original text and the back-translated text but the overall meaning of the sentence is still retained.

如我们所见,给定的文本首先从EnglishItalian ,然后再翻译回English 。 如我们所见,在反向翻译过程中,原始文本和反向翻译文本之间的句子略有变化,但句子的整体含义仍然保留。

We can apply this technique to real-world data. The sample code is given below. Here the original train dataframe is copied to tran_aug dataframe and then back-translation is applied on train_aug dataframe. And finally, train_aug is appended to the original train dataframe. Note that we are translating original text from English to Italian and then from Italian to English.

我们可以将此技术应用于实际数据。 示例代码如下。 在这里,原始train数据帧被复制到tran_aug数据帧,然后在train_aug数据帧上应用back-translation 。 最后, train_aug被附加到原始train数据帧中。 请注意,我们正在将原始文本从英语翻译为意大利语,然后从意大利语翻译为英语。

train_aug = train.copy()from googletrans import Translatortranslator = Translator()train_aug['text'] = train_aug['text'].apply(lambda x: translator.translate(translator.translate(x, dest='it').text, dest='en').text)train = train.append(train_aug, ignore_index=True)

结论 (Conclusion)

Now you know how to make use of TextAttack and Googletrans libraries for your data science projects for text data augmentation.

现在,您知道如何在您的数据科学项目中使用TextAttackGoogletrans库来进行文本数据扩充。

翻译自: https://towardsdatascience.com/text-data-augmentation-f4143571ecd2

div文字自动扩充

http://www.taodudu.cc/news/show-863701.html

相关文章:

  • ml是什么_ML,ML,谁是所有人的冠军?
  • 随机森林分类器_建立您的第一个随机森林分类器
  • Python中的线性回归:Sklearn与Excel
  • 机器学习中倒三角符号_机器学习的三角误差
  • 使用Java解决您的数据科学问题
  • 树莓派 神经网络植入_使用自动编码器和TensorFlow进行神经植入
  • opencv 运动追踪_足球运动员追踪-使用OpenCV根据运动员的球衣颜色识别运动员的球队
  • 犀牛建模软件的英文语言包_使用tidytext和textmineR软件包在R中进行主题建模(
  • 使用Keras和TensorFlow构建深度自动编码器
  • 出人意料的生日会400字_出人意料的有效遗传方法进行特征选择
  • fast.ai_使用fast.ai自组织地图—步骤4:使用Fast.ai DataBunch处理非监督数据
  • 无监督学习与监督学习_有监督与无监督学习
  • 分类决策树 回归决策树_决策树分类器背后的数学
  • 检测对抗样本_对抗T恤以逃避ML人检测器
  • 机器学习中一阶段网络是啥_机器学习项目的各个阶段
  • 目标检测 dcn v2_使用Detectron2分6步进行目标检测
  • 生成高分辨率pdf_用于高分辨率图像合成的生成变分自编码器
  • 神经网络激活函数对数函数_神经网络中的激活函数
  • 算法伦理
  • python 降噪_使用降噪自动编码器重建损坏的数据(Python代码)
  • bert简介_BERT简介
  • 卷积神经网络结构_卷积神经网络
  • html两个框架同时_两个框架的故事
  • 深度学习中交叉熵_深度计算机视觉,用于检测高熵合金中的钽和铌碎片
  • 梯度提升树python_梯度增强树回归— Spark和Python
  • 5行代码可实现5倍Scikit-Learn参数调整的更快速度
  • tensorflow 多人_使用TensorFlow2.x进行实时多人2D姿势估计
  • keras构建卷积神经网络_在Keras中构建,加载和保存卷积神经网络
  • 深度学习背后的数学_深度学习背后的简单数学
  • 深度学习:在图像上找到手势_使用深度学习的人类情绪和手势检测器:第1部分

div文字自动扩充_文字资料扩充相关推荐

  1. 输入文字自动生成图片_原来Word还可以自动生成图片和图表目录!

    小李接到了一个任务,将技术文档中的示意图目录做出来,让客户能根据需求快速找到操作示意图,可是这份文档有三百多张图片,不过,这可难不倒小李. 说到Word目录,大多数人都知道,可以为文档的标题设置大纲级 ...

  2. 计算机课件文字,计算机应用基础_文字处理wordppt课件.ppt

    <计算机应用基础_文字处理wordppt课件.ppt>由会员分享,提供在线免费全文阅读可下载,此文档格式为ppt,更多相关<计算机应用基础_文字处理wordppt课件.ppt> ...

  3. python提取图片中的文字自动填表_如何 提取图片中的文字?这款Python 库 4行代码搞定!...

    OCR是什么? 有一款软件叫扫描全能王,想必一些小伙伴听过,这是一个OCR集成软件,可以将图像内容扫描成文字. 所以说,OCR作用是对文本资料的图像文件进行分析识别处理,获取文字及版面信息. OCR的 ...

  4. 输入文字自动生成图片_批量生成变化的图片文字海报

    最近"双十一"活动大家已经进入了鸡血状态,运营的小伙伴给设计出了个难题,搞的设计小伙伴们进入了癫狂模式.本着工具提升效率的原则,我又开始去研究如何批量修改图片内容了,小小的成果和大 ...

  5. div超出不换行_文字超出显示点点点之ellipsis 设置

    一般情况下一行文字在一定区域显示的话如果不限定高度,那么在内容超过的宽度的话就会换行显示,为了页面的美观,目前的通用做法就是在最后显示-,然后鼠标悬浮显示完整内容,具体设置如下: height: 40 ...

  6. python实现文字识别软件_文字识别(OCR)CRNN(基于pytorch、python3) 实现不定长中文字符识别...

    文字识别(OCR)CRNN(基于pytorch.python3) 实现不定长中文字符识别 发布时间:2018-09-26 19:40, 浏览次数:1265 , 标签: OCR CRNN pytorch ...

  7. css文字图片动画_文字图像互动动画

    css文字图片动画 Following on from last week's issue (and inspired a bit by receiving the latest Type Direc ...

  8. tabcontrol选项卡颜色把文字覆盖了_文字拆分神器,这3个PPT插件满足你的所有需求...

    文/清清 首发于一周进步 在之前的两篇文章中,已经为大家介绍了在Word和Excel中的文字拆分和字符提取,今天轮到了PPT中的文字拆分. 相信有上过一周进步寒暑假训练营的同学都知道,大梦老师的PPT ...

  9. java编写文字三国杀初学_文字版三国杀开发

    近期考期偷闲开发娱乐项目文字版三国杀,历时一个月基本完成,工程量10000+行 那么主要亮点是? checkstyle满分✌️ 简介 开发语言:java 运行模式:图形界面 / 命令行 支持武将:标准 ...

最新文章

  1. django 设置外键_django2.0前后版本定义外键和一对一关系的差别
  2. github上传流程图记录
  3. echarts图表实例
  4. CentOS安装高版本gcc
  5. 【offer去哪了】我一连面试了十个Java岗,统统石沉大海!
  6. 全景图像拼接——基本流程
  7. php 上传多个txt文件上传,一个多文件上传的例子(原创)
  8. Oracle数据库完全卸载
  9. linux /home recovering journal,Ubuntu启动之后显示Recovering journal ,clean block。。。。问题`...
  10. 51单片机学习 基础知识总结
  11. 操作系统——经典同步问题
  12. word文本框中插入文本框_在Word 2007中快速将文本翻译成另一种语言
  13. 20172301 2017-2018-2 《程序设计与数据结构》第七周学习总结
  14. 实验三 图像空间域平滑与锐化(Python实现)
  15. 根据日期、时间和当地经纬度计算太阳天顶角和方位角的原理
  16. 阿里云ECS数据迁移到阿里云OSS
  17. 集成科大讯飞语音合成
  18. VSS2005安装指南
  19. 判断ip地址是否在同一网段
  20. TMF容器使用iTouch运行就报错的问题

热门文章

  1. 关于C语言中递归的一点点小问题
  2. SSAS系列——【08】多维数据(程序展现Cube)
  3. mysql(slow-query) 快速开启慢日志查询的方法
  4. 云计算:企业商业模式创新的新战线
  5. Visual C++中的异常处理浅析(上)
  6. 轻松上手系列教程java_小白也能轻松上手的Prometheus教程
  7. 语言舒尔特方格程序_有效提升孩子注意力的方法,舒尔特方格训练法,简单有效...
  8. oracle lsnrctl status unknown,数据库监听卡住 Oracle lsnrctl status 卡在connecting ......
  9. 基于tensorflow2.0实现猫狗大战(搭建网络迁移学习)
  10. 这两天学习nRF51822的心得