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

相关推荐
亚马逊云开发者4 小时前
Q CLI 助力合合信息实现 Aurora 的升级运营
人工智能
全栈胖叔叔-瓜州5 小时前
关于llamasharp 大模型多轮对话,模型对话无法终止,或者输出角色标识User:,或者System等角色标识问题。
前端·人工智能
坚果派·白晓明5 小时前
AI驱动的命令行工具集x-cmd鸿蒙化适配后通过DevBox安装使用
人工智能·华为·harmonyos
GISer_Jing5 小时前
前端营销技术实战:数据+AI实战指南
前端·javascript·人工智能
Dekesas96956 小时前
【深度学习】基于Faster R-CNN的黄瓜幼苗智能识别与定位系统,农业AI新突破
人工智能·深度学习·r语言
大佐不会说日语~6 小时前
Spring AI Alibaba 的 ChatClient 工具注册与 Function Calling 实践
人工智能·spring boot·python·spring·封装·spring ai
CeshirenTester6 小时前
Playwright元素定位详解:8种定位策略实战指南
人工智能·功能测试·程序人生·单元测试·自动化
世岩清上7 小时前
AI驱动的智能运维:从自动化到自主化的技术演进与架构革新
运维·人工智能·自动化
K2_BPM7 小时前
告别“单点智能”:AI Agent如何重构企业生产力与流程?
人工智能
TMT星球7 小时前
深业云从人工智能产业投资基金设立,聚焦AI和具身智能相关产业
人工智能