BERT outputs

Yes so BERT (the base model without any heads on top) outputs 2 things: last_hidden_state and pooler_output.

是的,BERT(顶部没有任何头部的基础模型)输出 2 个东西: last_hidden_state 和 pooler_output 。

First question: 第一个问题:

last_hidden_state contains the hidden representations for each token in each sequence of the batch. So the size is (batch_size, seq_len, hidden_size).

last_hidden_state 包含批次中每个序列中每个标记的隐藏表示。因此大小为 (batch_size, seq_len, hidden_size) 。

pooler_output contains a "representation" of each sequence in the batch, and is of size (batch_size, hidden_size). What it basically does is take the hidden representation of the [CLS] token of each sequence in the batch (which is a vector of size hidden_size), and then run that through the BertPooler nn.Module. This consists of a linear layer followed by a Tanh activation function. The weights of this linear layer are already pretrained on the next sentence prediction task (note that BERT is pretrained on 2 tasks: masked language modeling and next sentence prediction). I assume that the authors of the Transformers library have taken the weights from the original TF implementation, and initialized the layer with them. In theory, they would come from BertForPretraining - which is BERT with the 2 pretraining heads on top.

pooler_output 包含批次中每个序列的"表示",大小为 (batch_size, hidden_size) 。它的基本作用是获取批次中每个序列的 [CLS] 标记的隐藏表示(大小为 hidden_size 的向量),然后通过 BertPooler nn.Module 运行。这包括一个线性层,后跟一个 Tanh 激活函数。这个线性层的权重已经在下一个句子预测任务上进行了预训练(请注意,BERT 在 2 个任务上进行了预训练:掩码语言建模和下一个句子预测)。我假设 Transformers 库的作者已经从原始 TF 实现中获取了这个线性层的权重,并用它们初始化了该层。理论上,它们应该来自 BertForPretraining - 这是在顶部具有 2 个预训练头的 BERT。

Second question: 第二个问题:

Yes you can fine-tune them, just like the hidden states, because the weights of the linear layer are updated when you perform a loss.backward().

是的,您可以微调它们,就像隐藏状态一样,因为当您执行 loss.backward() 时,线性层的权重会被更新。

BTW, please ask questions related to BERT/other models (which are not related to bugs) on the forum, rather than posting them here.

顺便说一句,请在论坛上提出与 BERT/其他模型相关的问题(与错误无关),而不是在这里发布。

相关推荐
学好statistics和DS1 小时前
【CV】神经网络中哪些参数需要被学习?
人工智能·神经网络·学习
大千AI助手1 小时前
机器学习特征筛选中的IV值详解:原理、应用与实现
人工智能·机器学习·kl散度·roc·iv·信息值·woe
姜—姜1 小时前
通过构建神经网络实现项目预测
人工智能·pytorch·深度学习·神经网络
Ro Jace1 小时前
模式识别与机器学习课程笔记(4):线性判决函数
人工智能·笔记·机器学习
科研小白_2 小时前
基于遗传算法优化BP神经网络(GA-BP)的数据时序预测
人工智能·算法·回归
互联网江湖3 小时前
蓝桥杯出局,少儿编程的价值祛魅时刻?
人工智能·生活
Elastic 中国社区官方博客3 小时前
根据用户行为数据中的判断列表在 Elasticsearch 中训练 LTR 模型
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
paid槮4 小时前
OpenCV图像形态学详解
人工智能·opencv·计算机视觉
点控云4 小时前
点控云智能短信:重构企业与用户的连接,让品牌沟通更高效
大数据·人工智能·科技·重构·外呼系统·呼叫中心
救救孩子把7 小时前
14-机器学习与大模型开发数学教程-第1章 1-6 费马定理与极值判定
人工智能·数学·机器学习