huggingface-transformers 快速上手bert 使用注意
你可能看过这篇:https://blog.csdn.net/qiguanjiezl/article/details/122504454
这个代码就能用,但是注意一点:不要自己下载离线model然后加载
因为:1. 你下载的可能版本不匹配
2. 目前国内应该是有自动镜像,直接 model = BertForMaskedLM.from_pretrained('bert-base-uncased') 就行,下载速度很快。
可能提示:需要什么权限。
退出shell 或者 window cmd,选择sudo,或者window: 以管理员身份运行,打开 cmd窗口
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
官网的例程:https://huggingface.co/docs/transformers/model_doc/bert#transformers.BertForMaskedLM
直接运行。注意结果需要print
可能打印:
只是info不是error,自己翻译一下就行了
Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertForMaskedLM: ['cls.seq_relationship.weight', 'cls.seq_relationship.bias']
- This IS expected if you are initializing BertForMaskedLM from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertForMaskedLM from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
最后给新手推荐一个讲解比较好的:https://www.bilibili.com/video/BV1Ao4y1k7AX/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具