bert 源码解读

一、目录结构

1.预训练三个模块
||—create_pretraining_data.py 构建预训练数据
||—run_pretraining.py 跑预训练文件
||—tokenization.py 各语言分词

2.模型、优化、特征
||—modeling.py 模型文件
||—extract_features.py
||—optimization.py 设置优化器、学习率参数调节

3.fine-tune的两个模块
||—run_classifiter.py
||—run_squad.py

二、预训练
1.构建预训练数据

文件:create_pretraining_data.py
输入为原始文本数据,输出为清洗后的预训练数据的输入数据。
此文件最终的输出为一个.tfrecord 的文件
每个

三、训练
四、微调 fine-tune
1.分类的微调

文件:run_classifiter.py
分类微调主要是使用tf.estimator实现的,tf.estimator实现的四个步骤参考我的另一篇博客。
我们看一下run_classifiter.py文件的架构:


一、无用函数
def input_fn_builder()
def convert_examples_to_features()

二、特征、样本的数据结构定义
class InputExample()

class PaddingInputExample()

class InputFeatures()

def _truncate_seq_pair()


三、不同人物数据处理
# 不同人物数据处理方法
class DataProcessor()

class XnliProcessor()

class MnliProcessor()

class MrpcProcessor()

class ColaProcessor()

四、数据转换
# 将一个样本转换为feature
def convert_single_example()

# 将所有样本转换为feature,并生成tf_record文件
def file_based_convert_examples_to_features()

五、组装estimator
# 生成estimator的input_fn
def file_based_input_fn_builder()

# 引入自定义模型,被model_fn_builder调用
def create_model()

# 生成estimator的model_fn
def model_fn_builder()


# 定义微调流程,
def main()





参考资料:
1.http://fancyerii.github.io/2019/03/09/bert-codes/
2.https://my.oschina.net/u/4290246/blog/3224891/print
estimator相关:
3.https://blog.csdn.net/sgyuanshi/article/details/90574337
4.https://zhuanlan.zhihu.com/p/106400162

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值