减少 XLTransformers 的输出层大小

Reduce the output layer size from XLTransformers

我是 运行 以下使用 huggingface 实现的人:

t1 = "My example sentence is really great."

tokenizer = TransfoXLTokenizer.from_pretrained('transfo-xl-wt103')
model = TransfoXLLMHeadModel.from_pretrained("transfo-xl-wt103")

encoded_input = tokenizer(t1, return_tensors='pt', add_space_before_punct_symbol=True) 
output = model(**encoded_input)
tmp = output[0].detach().numpy()
print(tmp.shape)

>>> (1, 7, 267735)

为了获得我将在下游使用的输出嵌入。

最后一个维度/大大/大于我的预期,看起来它是整个 vocab_size 的大小,而不是基于 ECL from the paper 的缩减(这可能是我误解)。

我会提供什么论点 model 来将这个层大小减小到更小的维度 space,更像是 400 或 768 的基本 BERT,并且仍然获得基于预训练的良好性能嵌入?

那是因为您使用了 ...LMHeadModel,它可以预测下一个标记。您可以改用 TransfoXLModel.from_pretrained("transfo-xl-wt103"),然后 output[0] 是形状为 (batch_size, sequence_length, hidden_size).

的最后一个隐藏状态