这是变压器 pytorch 库文档中给出的示例
from transformers import BertTokenizer, BertForTokenClassification
import torch
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForTokenClassification.from_pretrained('bert-base-uncased',
output_hidden_states=True, output_attentions=True)
input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute",
add_special_tokens=True)).unsqueeze(0) # Batch size 1
labels = torch.tensor([1] * input_ids.size(1)).unsqueeze(0) # Batch size 1
outputs = model(input_ids, labels=labels)
loss, scores, hidden_states,attentions = outputs
这hidden_states
是一个长度为 13 的元组,包含模型在每层输出的隐藏状态以及初始嵌入输出。我想知道hidden_states[0] 或 hidden_states[12] 是否代表最终的隐藏状态向量?