复习2
bert结构:BERT-Base, Uncased: 12-layer, 768-hidden, 12-heads, 110M parameters,词典大小:30522
embeding层:
token embeding:30522*768,获取每个token的初始编码
position embeding: 512*768
type embeding:2*768
layer norm:wight+bias 768*2
self_attention层:
query,key,value:(768*768+768)*3
dense:768*768+768
layer norm:wight+bias 768*2
feed_forward:
两层,先升后降
layer norm:wight+bias 768*2
bert.embeddings.word_embeddings.weight torch.Size([30522, 768]) 参数个数为: 23440896
bert.embeddings.position_embeddings.weight torch.Size([512, 768]) 参数个数为: 393216
bert.embeddings.token_type_embeddings.weight torch.Size([2, 768]) 参数个数为: 1536
bert.embeddings.LayerNorm.weight torch.Size([768]) 参数个数为: 768
bert.embeddings.LayerNorm.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.self.query.weight torch.Size([768, 768]) 参数个数为: 589824
bert.encoder.layer.0.attention.self.query.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.self.key.weight torch.Size([768, 768]) 参数个数为: 589824
bert.encoder.layer.0.attention.self.key.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.self.value.weight torch.Size([768, 768]) 参数个数为: 589824
bert.encoder.layer.0.attention.self.value.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.output.dense.weight torch.Size([768, 768]) 参数个数为: 589824
bert.encoder.layer.0.attention.output.dense.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.output.LayerNorm.weight torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.attention.output.LayerNorm.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.intermediate.dense.weight torch.Size([3072, 768]) 参数个数为: 2359296
bert.encoder.layer.0.intermediate.dense.bias torch.Size([3072]) 参数个数为: 3072
bert.encoder.layer.0.output.dense.weight torch.Size([768, 3072]) 参数个数为: 2359296
bert.encoder.layer.0.output.dense.bias torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.output.LayerNorm.weight torch.Size([768]) 参数个数为: 768
bert.encoder.layer.0.output.LayerNorm.bias torch.Size([768]) 参数个数为: 768
__init__ __new__ __call__:
__new__方法中的参数是cls,而__init__中的是self。当我们自己定义了__new__方法的时候,一定要返回一个super(class,cls).__new__(cls)这样的方法,不然会报错的。如下代码中__new__方法不返回内容就不会执行__init__()方法。
这个方法也是比一个特殊但是比较常用的方法,在class对象中写这个方法后,class就变成了callable了。对象可调用。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程