Bert 代码详细解读——modeling.py
在官方的bert-github上, git clone https://github.com/google-research/bert.git 主要的文件内容如下图: 主要包括7个主要的python文件,小编要坚持把这7个解读清楚呀! 首先解读的是modeling.py文件,是bert实现的核心代码,主要包括2个类和17个函数, 如下所示: 一、类 1.class BertConfig(object): class BertConfig(object): """Configuration for `BertModel`.""" def __init__(self, vocab_size,“词表中共有多少个词” hidden_size=768,#词嵌入的维度,也是编码层和池化层的维度 num_hidden_layers=12,#transformer隐藏层数个数 num_attention_heads=12,#在encoder层中的注意头个数 intermediate_size=3072,#encoder中间隐藏层神经元数,如feed-forward layer hidden_act="gelu",#encoder和pooler的激活函数 hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position