Access the output of several layers of pretrained DistilBERT model

Bullfraud

I am trying to access the output embeddings from several different layers of the pretrained "DistilBERT" model. ("distilbert-base-uncased")

bert_output = model(input_ids, attention_mask=attention_mask)

The bert_output seems to return only the embedding values of the last layer for the input tokens.

erip

If you want to get the output of all the hidden layers, you need to add the output_hidden_states=True kwarg to your config.

Your code will look something like

from transformers import DistilBertModel, DistilBertConfig

config = DistilBertConfig.from_pretrained('distilbert-base-cased', output_hidden_states=True)
model = DistilBertModel.from_pretrained('distilbert-base-cased', config=config)

The hidden layers will be made available as bert_output[2]

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to use the first layers of a pretrained model to extract features inside a Keras model (Functional API)

分類Dev

eroding several layers of an array

分類Dev

BERT how to run pretrained model in windows anaconda

分類Dev

How to load the saved tokenizer from pretrained model in Pytorch

分類Dev

Getting model class labels from torchvision pretrained models

分類Dev

Multiple Embedding layers for Keras Sequential model

分類Dev

Gensim Word2Vec select minor set of word vectors from pretrained model

分類Dev

save several bash screens of program input/output

分類Dev

Add more layers in seq2seq model

分類Dev

Keras model not training layers, validation accuracy always 0.5

分類Dev

LSTM, Keras : How many layers should the inference model have?

分類Dev

How to extract the output of tensorflow model?

分類Dev

Error in lmer model and lsmeans output

分類Dev

fastai.textのpretrained_model = URLs.WT103を使用できません

分類Dev

Get access to regression train model

分類Dev

Access MVC model property in Javascript

分類Dev

Why do Keras Conv1D layers' output tensors not have the input dimension?

分類Dev

What if we do not apply activation to the hidden layers and only to the output layer of a feed forward neural network?

分類Dev

How to ignore some input layer, while predicting, in a keras model trained with multiple input layers?

分類Dev

What does the "[0][0]" of the layers connected to in keras model.summary mean?

分類Dev

ValueError: You are trying to load a weight file containing 6 layers into a model with 0

分類Dev

How to find the number of layers from the saved h5 file of pre-trained model?

分類Dev

TensorFlow-tf.keras.layers.Layerとtf.keras.Modelの違い

分類Dev

Keras.modelでtf.keras.layersを使用する

分類Dev

Several aRFC with WAIT, how to synchronize access to variable in callback?

分類Dev

Google Chrome unable to access internet for several minutes after hibernate

分類Dev

output model.params to csv in pandas

分類Dev

Tensorflow classification model returns incorrect output shape

分類Dev

How to model multiple inputs to single output in classification?

Related 関連記事

  1. 1

    How to use the first layers of a pretrained model to extract features inside a Keras model (Functional API)

  2. 2

    eroding several layers of an array

  3. 3

    BERT how to run pretrained model in windows anaconda

  4. 4

    How to load the saved tokenizer from pretrained model in Pytorch

  5. 5

    Getting model class labels from torchvision pretrained models

  6. 6

    Multiple Embedding layers for Keras Sequential model

  7. 7

    Gensim Word2Vec select minor set of word vectors from pretrained model

  8. 8

    save several bash screens of program input/output

  9. 9

    Add more layers in seq2seq model

  10. 10

    Keras model not training layers, validation accuracy always 0.5

  11. 11

    LSTM, Keras : How many layers should the inference model have?

  12. 12

    How to extract the output of tensorflow model?

  13. 13

    Error in lmer model and lsmeans output

  14. 14

    fastai.textのpretrained_model = URLs.WT103を使用できません

  15. 15

    Get access to regression train model

  16. 16

    Access MVC model property in Javascript

  17. 17

    Why do Keras Conv1D layers' output tensors not have the input dimension?

  18. 18

    What if we do not apply activation to the hidden layers and only to the output layer of a feed forward neural network?

  19. 19

    How to ignore some input layer, while predicting, in a keras model trained with multiple input layers?

  20. 20

    What does the "[0][0]" of the layers connected to in keras model.summary mean?

  21. 21

    ValueError: You are trying to load a weight file containing 6 layers into a model with 0

  22. 22

    How to find the number of layers from the saved h5 file of pre-trained model?

  23. 23

    TensorFlow-tf.keras.layers.Layerとtf.keras.Modelの違い

  24. 24

    Keras.modelでtf.keras.layersを使用する

  25. 25

    Several aRFC with WAIT, how to synchronize access to variable in callback?

  26. 26

    Google Chrome unable to access internet for several minutes after hibernate

  27. 27

    output model.params to csv in pandas

  28. 28

    Tensorflow classification model returns incorrect output shape

  29. 29

    How to model multiple inputs to single output in classification?

ホットタグ

アーカイブ