title: AttributeError: 'Tensor' object has no attribute 'size' pretrained bert
body: <p>This is the model that I have defined:</p>
  <pre><code>def build_model():
    input_layer = keras.layers.Input(name=&quot;Input&quot;, shape=(MAX_LEN), dtype='int64')
    bert = BertForPreTraining.from_pretrained('digitalepidemiologylab/covid-twitter-bert-v2')(input_layer)
    bert = bert[0][:,0,:]
    x = keras.layers.Bidirectional(keras.layers.LSTM(256, name=&quot;LSTM&quot;, activation='tanh', dropout=0.3), name=&quot;Bidirectional_LSTM&quot;)(bert)
    x = keras.layers.Dense(64, 'relu')(x)
    output_layer = keras.layers.Dense(1, 'sigmoid', name=&quot;Output&quot;)(x)
  
    model = keras.Model(inputs=input_layer, outputs=output_layer)
  
    model.compile(loss=loss,
                  optimizer=optimizer)
    return model
  </code></pre>
  <p>On running
  <code>model = build_model()</code></p>
  <p>This is the error I am getting.</p>
  <pre><code>AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-57-671884cecb64&gt; in &lt;module&gt;()
  ----&gt; 1 model = build_model()
  
  4 frames
  &lt;ipython-input-56-ef0d67347557&gt; in build_model()
        1 def build_model():
        2   input_layer = keras.layers.Input(name=&quot;Input&quot;, shape=(MAX_LEN), dtype='int64')
  ----&gt; 3   bert = BertForPreTraining.from_pretrained('digitalepidemiologylab/covid-twitter-bert-v2')(input_layer)
        4   bert = bert[0][:,0,:]
        5   x = keras.layers.Bidirectional(keras.layers.LSTM(256, name=&quot;LSTM&quot;, activation='tanh', dropout=0.3), name=&quot;Bidirectional_LSTM&quot;)(bert)
  
  /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
      720             result = self._slow_forward(*input, **kwargs)
      721         else:
  --&gt; 722             result = self.forward(*input, **kwargs)
      723         for hook in itertools.chain(
      724                 _global_forward_hooks.values(),
  
  /usr/local/lib/python3.6/dist-packages/transformers/modeling_bert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, next_sentence_label, output_attentions, output_hidden_states, return_dict, **kwargs)
      938             output_attentions=output_attentions,
      939             output_hidden_states=output_hidden_states,
  --&gt; 940             return_dict=return_dict,
      941         )
      942 
  
  /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
      720             result = self._slow_forward(*input, **kwargs)
      721         else:
  --&gt; 722             result = self.forward(*input, **kwargs)
      723         for hook in itertools.chain(
      724                 _global_forward_hooks.values(),
  
  /usr/local/lib/python3.6/dist-packages/transformers/modeling_bert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, encoder_hidden_states, encoder_attention_mask, output_attentions, output_hidden_states, return_dict)
      793             raise ValueError(&quot;You cannot specify both input_ids and inputs_embeds at the same time&quot;)
      794         elif input_ids is not None:
  --&gt; 795             input_shape = input_ids.size()
      796         elif inputs_embeds is not None:
      797             input_shape = inputs_embeds.size()[:-1]
  
  AttributeError: 'Tensor' object has no attribute 'size'
  </code></pre>