我是自然语言处理的新手,我想为情绪分析建立一个bert模型,所以我遵循这个教程https://curiousily.com/posts/sentiment-analysis-with-bert-and-hugging-face-using-pytorch-and-python/,但我得到了下面的错误
bert_model = BertModel.from_pretrained(PRE_TRAINED_MODEL_NAME)
last_hidden_state, pooled_output = bert_model(
input_ids=encoding['input_ids'],
attention_mask=encoding['attention_mask']
)
last_hidden_state.shape
pooled_output.shape当我想要执行last_hidden_state.shape时,我得到一个错误:
' str‘对象没有'shape’属性,为什么它返回last_hidden_state和pooled_output作为字符串而不是张量。谢谢。
发布于 2020-12-27 08:08:17
从版本3到版本4的转换是在拥抱面孔中完成的,似乎有几个变化被引入了,可以像下面这样解决
bert_model = BertModel.from_pretrained(PRE_TRAINED_MODEL_NAME, return_dict=False)https://stackoverflow.com/questions/65461593
复制相似问题