当前位置:   article > 正文

【huggingface bertmodel类使用理解】_huggingface macbert 获取sequence output

huggingface macbert 获取sequence output

关于在BertModel.from_pretrained 之后如何取bert的输出的理解,参考了huggingface的文档:

先给一个手写图:
请添加图片描述

需要注意的是:pooler_output 和 last_hidden_state [0] 不相等。前者是后者经过一个MLP层得来,这个MLP层是在预训练时经过NSP任务的微调。

所以如果使用单文本分类任务,使用 last_hidden_state [0] 再自己加一个 MLP 层也许更为合适。

引用huggingface文档:

pooler_output (torch.FloatTensor of shape (batch_size, hidden_size)) — Last layer hidden-state of the first token of the sequence (classification token) after further processing through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns the classification token after processing through a linear layer and a tanh activation function. The linear layer weights are trained from the next sentence prediction (classification) objective during pretraining

参考SimCSE代码的写法:

请添加图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号