首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >bert模型中以字符串形式返回的张量类型属性

bert模型中以字符串形式返回的张量类型属性
EN

Stack Overflow用户
提问于 2020-12-27 07:22:42
回答 1查看 192关注 0票数 0

我是自然语言处理的新手,我想为情绪分析建立一个bert模型,所以我遵循这个教程https://curiousily.com/posts/sentiment-analysis-with-bert-and-hugging-face-using-pytorch-and-python/,但我得到了下面的错误

代码语言:javascript
复制
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作为字符串而不是张量。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-12-27 08:08:17

从版本3到版本4的转换是在拥抱面孔中完成的,似乎有几个变化被引入了,可以像下面这样解决

代码语言:javascript
复制
bert_model = BertModel.from_pretrained(PRE_TRAINED_MODEL_NAME, return_dict=False)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65461593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档