AttributeError: 'str' object has no attribute 'shape' while encoding tensor using BertModel with PyTorch (Hugging Face). Below is the code
bert_model = BertModel.from_pretrained(r'downloads\bert-pretrained-model')
input_ids
Output is:
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]])
Followed by code below
last_hidden_state, pooled_output = bert_model(
input_ids=encoding['input_ids'],
attention_mask=encoding['attention_mask']
)
Followed by code below
last_hidden_state.shape
Output is
AttributeError Traceback (most recent call last)
<ipython-input-70-9628339f425d> in <module>
----> 1 last_hidden_state.shape
AttributeError: 'str' object has no attribute 'shape'
Complete Code link is 'https://colab.research.google.com/drive/1FY4WtqCi2CQ9RjHj4slZwtdMhwaWv2-2?usp=sharing'