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

相关推荐
JackLam2 小时前
AI-安装ChatGpt Codex
人工智能
强哥聊算力2 小时前
《算力江湖·英伟达传奇》第七集:ChatGPT出现前夜,英伟达发生了什么?
服务器·人工智能·算法·ai·chatgpt·gpu算力
吴佳浩3 小时前
Run:ai 开源了,我把 GPU 编排摆回 AI 栈里看了一遍
人工智能
IT_Octopus5 小时前
【零基础入门 LLM 开发 · Day 13】:LangChain 的对话记忆——Message 对象版
人工智能·python·langchain
2603_965148115 小时前
社区与学习资源:从入门到精通的API选品学习路径
数据库·人工智能·python·学习·数据挖掘
LiuPig刘皮哥5 小时前
2026年开源3D陪玩对比:xiaoke.ai、AIRI、Open-LLM-VTuber、Amica 有什么、没有什么
人工智能·3d·开源
西柚小萌新5 小时前
【岗位面试】--成都博维数孪 - 工业 AI 解决方案顾问
人工智能·面试·职场和发展
Luminbox紫创测控5 小时前
车载LiDAR强光测试的实验设计方法与数据分析
人工智能·数据挖掘·数据分析·车载系统·安全性测试·太阳光模拟器
建筑工程企业管理系统7 小时前
工程进度统计管理系统自动化汇总数据,解决施工企业手工对账误差难题
大数据·人工智能·自动化
唠点键盘之外的7 小时前
27 存量系统接大模型:旁挂一个 AI 微服务,老架构一行不改
人工智能·微服务·架构