title: AttributeError: 'str' object has no attribute 'shape' while encoding tensor using BertModel with PyTorch (Hugging Face)
body: <p><strong>AttributeError: 'str' object has no attribute 'shape' while encoding tensor using BertModel with PyTorch (Hugging Face). Below is the code</strong></p>
  <pre><code>bert_model = BertModel.from_pretrained(r'downloads\bert-pretrained-model')
  input_ids
  </code></pre>
  <p>Output is:</p>
  <pre><code>tensor([[  101,   156, 13329,  ...,     0,     0,     0],
          [  101,   156, 13329,  ...,     0,     0,     0],
          [  101,  1302,  1251,  ...,     0,     0,     0],
          ...,
          [  101, 25456,  1200,  ...,     0,     0,     0],
          [  101,   143,  9664,  ...,     0,     0,     0],
          [  101,  2586,  7340,  ...,     0,     0,     0]])
  </code></pre>
  <p>Followed by code below</p>
  <pre><code>last_hidden_state, pooled_output = bert_model(
    input_ids=encoding['input_ids'],
    attention_mask=encoding['attention_mask']
  )
  </code></pre>
  <p>Followed by code below</p>
  <pre><code>last_hidden_state.shape
  </code></pre>
  <p>Output is</p>
  <pre><code>AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-70-9628339f425d&gt; in &lt;module&gt;
  ----&gt; 1 last_hidden_state.shape
  
  AttributeError: 'str' object has no attribute 'shape'
  </code></pre>
  <p>Complete Code link is '<a href="https://colab.research.google.com/drive/1FY4WtqCi2CQ9RjHj4slZwtdMhwaWv2-2?usp=sharing" rel="nofollow noreferrer">https://colab.research.google.com/drive/1FY4WtqCi2CQ9RjHj4slZwtdMhwaWv2-2?usp=sharing</a>'</p>