title: How to use a Huggingface BERT model from to feed a binary classifier CNN?
body: <p>I am a bit confused about how to consume huggingface <code>transformers</code> outputs to train a simple language binary classifier model that predicts if Albert Einstein said a sentence or not.</p>
  <pre><code>from transformers import AutoTokenizer, AutoModel
  
  tokenizer = AutoTokenizer.from_pretrained(&quot;bert-base-uncased&quot;)
  model = AutoModel.from_pretrained(&quot;bert-base-uncased&quot;)
  
  inputs = [&quot;Hello World&quot;, &quot;Hello There&quot;, &quot;Bye Bye&quot;, &quot;Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.&quot;]
  for input in inputs:
    inputs = tokenizer(input, return_tensors=&quot;pt&quot;)
    outputs = model(**inputs)
    print(outputs[0].shape, input, len(input))
  </code></pre>
  <p>Output:</p>
  <pre><code>Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertModel: ['cls.predictions.transform.LayerNorm.weight', 'cls.predictions.bias', 'cls.seq_relationship.bias', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.bias', 'cls.predictions.transform.dense.weight', 'cls.predictions.decoder.weight', 'cls.predictions.transform.dense.bias']
  - This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
  - This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
  torch.Size([1, 4, 768]) Hello World 11
  torch.Size([1, 4, 768]) Hello There 11
  torch.Size([1, 4, 768]) Bye Bye 7
  torch.Size([1, 23, 768]) Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. 95
  </code></pre>
  <p>As you can see the dimensions of the output varies with the length of the input. Now assume I would like to train a binary classifier that predicts if Einstein said the input sentence or not and the input of the network will be the prediction of the BERT <code>transformer</code>.</p>
  <p>How could I write a CNN model that takes a tensor <code>[1, None, 768]</code> in pytorch? It seems that the second dimension changes with the length of the input.</p>