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/其他模型相关的问题(与错误无关),而不是在这里发布。

相关推荐
zkmall3 分钟前
ZKmall模块商城批发电商平台搭建方案,多商户支持 + 订单管理功能全覆盖
大数据·人工智能
Codebee5 分钟前
OneCode图生代码技术深度解析:从可视化设计到注解驱动实现的全链路架构
css·人工智能·算法
刘大猫267 分钟前
Datax安装及基本使用
java·人工智能·算法
攻城狮7号7 分钟前
北京中小学打响第一枪:2025年9月开始实行AI通识课
人工智能·ai通识课
中杯可乐多加冰34 分钟前
【AI落地应用实战】AIGC赋能职场PPT汇报:从效率工具到辅助优化
人工智能·深度学习·神经网络·aigc·powerpoint·ai赋能
东临碣石8243 分钟前
【AI论文】BlenderFusion:基于三维场景的视觉编辑与生成式合成
人工智能
正在走向自律44 分钟前
第二章-AIGC入门-开启AIGC音频探索之旅:从入门到实践(6/36)
人工智能·aigc·音视频·语音识别·ai音乐·ai 音频·智能语音助手
Trent19851 小时前
影楼精修-智能修图Agent
图像处理·人工智能·计算机视觉·aigc
烟锁池塘柳01 小时前
【大模型】解码策略:Greedy Search、Beam Search、Top-k/Top-p、Temperature Sampling等
人工智能·深度学习·机器学习
盼小辉丶1 小时前
PyTorch实战(14)——条件生成对抗网络(conditional GAN,cGAN)
人工智能·pytorch·生成对抗网络