当前位置: 首页 > news >正文

Transformer-Bert---散装知识点---mlm,nsp

        本文记录的是笔者在了解了transformer结构后嗑bert中记录的一些散装知识点,有时间就会整理收录,希望最后能把transformer一个系列都完整的更新进去。

1.自监督学习
        bert与原始的transformer不同,bert是使用大量无标签的数据进行预训练,下游则使用少量的标注数据进行微调。预训练使用的就是自监督学习。
        自监督学习直白来说就是对原始数据添加辅助任务来使得数据能够根据自身生成标签。

举几个简单的例子来解释一下常见的自监督学习:(ps:插一嘴,bert使用的是mlm,会在最后的例子中解释)

1.1图像类:

1.1.1填充:

将图片扣掉一块,让模型进行填充。
输入:扣掉一块的图片
输出:填充部分
标签:原图扣掉的部分

1.1.2拼图

选取图片中的一部分图片A以及其相邻的某一部分图片B作为输入,预测图B于图A的相对位置。
输入: (A图) +  (B图)
输出:1-8之间的整数,代表图B相对于图A的位置
标签5(对应原图中数字5的部分)
这类辅助任务就旨在训练模型对于局部特征分布位置的识别能力。

1.2 文本类

1.2.1 完形填空
简单的来说就是在原始数据中扣掉一个或多个单词,让模型进行补充。

原始数据:All the world's a stage, and all the men and women merely players.
输入:All the world's a stage, and all the __ and women merely players.
输出:预测的单词     
标签:men

1.2.2 Masked Language Model (MLM)(划重点拉)
MLM模型会随机的选择需要掩盖的单词(大概15%)(主要用于让模型习得语义语法)
ps:由于是随机的一般我们都会指定一个参数max_pred用来表示一个句子最多被掩盖单词的数量

原始数据:All the world's a stage, and all the men and women merely players.
输入:All the world's a stage, and all the MASK and MASK merely players.
输出:预测的单词     
标签:men, women

为了更好的适应下游任务,bert的作者对与MLM的规则进行了一定的微调。
被替换的单词:men :    MASK-------------------80%
                                         apple(随机单词)------10%
                                         men(保持不变--)------10%
依然还是对标注为MASK的单词进行预测。
下面是论文原文对于这段的描述附上中英文对照

        为了训练一个深度双向表示,我们简单地随机遮盖输入标记的一定比例,然后预测这些被遮盖的标记。我们称这个过程为“遮盖语言建模”(Masked Language Modeling,MLM),尽管文献中通常称之为Cloze任务(Taylor, 1953)。在这种情况下,对应于遮盖标记的最终隐藏向量被馈送到一个标准语言模型中的词汇表上的输出softmax层。在所有实验中,我们随机遮盖每个序列中所有WordPiece标记的15%。与去噪自编码器(Vincent et al., 2008)不同,我们仅预测遮盖的单词,而不是重构整个输入。

        In order to train a deep bidirectional representation, we simply mask some percentage of the input tokens at random, and then predict those masked tokens. We refer to this procedure as a “masked LM” (MLM), although it is often referred to as a Cloze task in the literature (Taylor, 1953). In this case, the final hidden vectors corresponding to the mask tokens are fed into an output softmax over the vocabulary, as in a standard LM. In all of our experiments, we mask 15% of all WordPiece tokens in each sequence at random. In contrast to denoising auto-encoders (Vincent et al., 2008), we only predict the masked words rather than reconstructing the entire input.
        尽管这使我们能够获得一个双向预训练模型,但其缺点是在预训练和微调之间创建了不匹配,因为在微调过程中不存在[MASK]标记。为了减轻这一问题,我们并不总是用实际的[MASK]标记替换“遮盖”的单词。训练数据生成器随机选择15%的标记位置进行预测。如果选择第i个标记,则有80%的概率将第i个标记替换为[MASK]标记,10%的概率将其替换为随机标记,以及10%的概率保持不变。然后,使用交叉熵损失来预测原始标记。我们在附录C.2中比较了这一过程的变化。

        Although this allows us to obtain a bidirectional pre-trained model, a downside is that we are creating a mismatch between pre-training and fine-tuning, since the [MASK] token does not appear during fine-tuning. To mitigate this, we do not always replace “masked” words with the actual [MASK] token. The training data generator chooses 15% of the token positions at random for prediction. If the i-th token is chosen, we replace the i-th token with (1) the [MASK] token 80% of the time (2) a random token 10% of the time (3) the unchanged i-th token 10% of the time. Then, T i will be used to predict the original token with cross entropy loss. We compare variations of this procedure in Appendix C.2.


2.NSP任务

Bert中的NSP实质上就是一个二分类任务。
主要就是预测句子2是否是句子1的下一句,其中句子2有50%是真,50%是从句库中随机挑选的句子。目的就是为了让模型学习到句子之间的关系。
输入:句子1  'esp'  句子2
ps:esp是词向量层中的特殊符号,表示一句话的结束,也常用来分割句子
输出:0或1
标签:0或1

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 你有多自律就有多自由
  • Perl语言入门学习指南
  • 跟代码执行流程,读Megatron源码(二)训练入口pretrain_gpt.py
  • Sql Server缓冲池、连接池等基本知识(附Demo)
  • Docker 基本管理
  • 【漏洞复现】泛微E-Cology WorkflowServiceXml SQL注入漏洞
  • 探索NVM:让Node.js开发如虎添翼的利器
  • 如何检查我的网站是否支持HTTPS
  • 爬虫学习2:爬虫爬取网页的信息与图片的方法
  • 京准:GPS北斗卫星授时信号安全隔离防护装置
  • 15Kg级无人机降落伞系统技术详解
  • 用Python爬虫能实现什么?
  • windows docker nvidia wsl2
  • SQL面试题练习 —— 统计最大连续登录天数区间
  • HTTPServer改进思路2(mudou库核心思想融入)
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • 【个人向】《HTTP图解》阅后小结
  • ➹使用webpack配置多页面应用(MPA)
  • Angular2开发踩坑系列-生产环境编译
  • C++类中的特殊成员函数
  • docker-consul
  • ECMAScript入门(七)--Module语法
  • GitUp, 你不可错过的秀外慧中的git工具
  • leetcode98. Validate Binary Search Tree
  • php的插入排序,通过双层for循环
  • Promise面试题,控制异步流程
  • ReactNative开发常用的三方模块
  • redis学习笔记(三):列表、集合、有序集合
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 爱情 北京女病人
  • 创建一个Struts2项目maven 方式
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 收藏好这篇,别再只说“数据劫持”了
  • 手机端车牌号码键盘的vue组件
  • 小程序01:wepy框架整合iview webapp UI
  • 【云吞铺子】性能抖动剖析(二)
  • JavaScript 新语法详解:Class 的私有属性与私有方法 ...
  • Java性能优化之JVM GC(垃圾回收机制)
  • ​1:1公有云能力整体输出,腾讯云“七剑”下云端
  • # Kafka_深入探秘者(2):kafka 生产者
  • # 日期待t_最值得等的SUV奥迪Q9:空间比MPV还大,或搭4.0T,香
  • #include
  • (C++17) optional的使用
  • (Java入门)抽象类,接口,内部类
  • (Java数据结构)ArrayList
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (三)模仿学习-Action数据的模仿
  • (详细版)Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • (自适应手机端)行业协会机构网站模板
  • .NET Core中Emit的使用