Commit 968cec84 authored by yuguo's avatar yuguo
Browse files

update readme

parent f8bdf0d1
# Bidirectional Encoder Representation from Transformers(BERT) # BERT
## 模型介绍
BERT的全称为Bidirectional Encoder Representation from Transformers,是一个预训练的语言表征模型。它强调了不再像以往一样采用传统的单向语言模型或者把两个单向语言模型进行浅层拼接的方法进行预训练,而是采用新的**masked language model(MLM)**,以致能生成**深度的双向**语言表征。 ## 论文
`BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding`
- [https://arxiv.org/abs/1810.04805](https://arxiv.org/abs/1810.04805)
## 模型结构 ## 模型结构
以往的预训练模型的结构会受到单向语言模型(*从左到右或者从右到左*)的限制,因而也限制了模型的表征能力,使其只能获取单方向的上下文信息。而BERT利用MLM进行预训练并且采用深层的双向Transformer组件(*单向的Transformer一般被称为Transformer decoder,其每一个token(符号)只会attend到目前往左的token。而双向的Transformer则被称为Transformer encoder,其每一个token会attend到所有的token*)来构建整个模型,因此最终生成**能融合左右上下文信息**的深层双向语言表征。
我们为了用户可以使用OneFlow-Libai快速验证Bert模型预训练,统计性能或验证精度,提供了一个Bert网络示例,主要网络参数如下: 我们为了用户可以使用OneFlow-Libai快速验证Bert模型预训练,统计性能或验证精度,提供了一个Bert网络示例,主要网络参数如下:
...@@ -14,22 +21,31 @@ model.cfg.hidden_layers = 8 ...@@ -14,22 +21,31 @@ model.cfg.hidden_layers = 8
完整的Bert-Large网络配置在configs/common/model/bert.py中 完整的Bert-Large网络配置在configs/common/model/bert.py中
## 数据集 ## 算法原理
我们在libai目录下集成了部分小数据集供用户快速验证,路径为:
BERT的全称为Bidirectional Encoder Representation from Transformers,是一个预训练的语言表征模型。它强调了不再像以往一样采用传统的单向语言模型或者把两个单向语言模型进行浅层拼接的方法进行预训练,而是采用新的**masked language model(MLM)**,以致能生成**深度的双向**语言表征。以往的预训练模型的结构会受到单向语言模型(*从左到右或者从右到左*)的限制,因而也限制了模型的表征能力,使其只能获取单方向的上下文信息。而BERT利用MLM进行预训练并且采用深层的双向Transformer组件(*单向的Transformer一般被称为Transformer decoder,其每一个token(符号)只会attend到目前往左的token。而双向的Transformer则被称为Transformer encoder,其每一个token会attend到所有的token*)来构建整个模型,因此最终生成**能融合左右上下文信息**的深层双向语言表征。
./nlp_data
## Bert预训练
### 环境配置
推荐使用docker方式运行,提供[光源](https://www.sourcefind.cn/#/service-details)拉取的docker镜像:image.sourcefind.cn:5000/dcu/admin/base/oneflow:0.9.1-centos7.6-dtk-22.10.1-py39-latest ## 环境配置
进入docker ### Docker
cd libai ```plaintext
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple docker pull image.sourcefind.cn:5000/dcu/admin/base/oneflow:0.9.1-centos7.6-dtk-22.10.1-py39-latest
pip3 install pybind11 -i https://mirrors.aliyun.com/pypi/simple # <Your Image ID>用上面拉取docker镜像的ID替换
pip3 install -e . -i https://mirrors.aliyun.com/pypi/simple docker run --shm-size 16g --network=host --name=bert_oneflow --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/bert-large_oneflow:/home/bert-large_oneflow -it <Your Image ID> bash
cd bert-large_oneflow
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
pip3 install pybind11 -i https://mirrors.aliyun.com/pypi/simple
pip3 install -e . -i https://mirrors.aliyun.com/pypi/simple
```
## 数据集
我们在libai目录下集成了部分小数据集供用户快速验证,路径为:
./nlp_data
## Bert预训练
### 训练 ### 训练
...@@ -47,7 +63,7 @@ train.dist.pipeline_parallel_size = 1 ...@@ -47,7 +63,7 @@ train.dist.pipeline_parallel_size = 1
预训练命令: 预训练命令:
cd libai cd bert-large_oneflow
bash tools/train.sh tools/train_net.py configs/bert_large_pretrain.py 4 bash tools/train.sh tools/train_net.py configs/bert_large_pretrain.py 4
### 精度 ### 精度
...@@ -62,7 +78,18 @@ train.dist.pipeline_parallel_size = 1 ...@@ -62,7 +78,18 @@ train.dist.pipeline_parallel_size = 1
| :--: | :--------: | :----------------------------------------------------------: | | :--: | :--------: | :----------------------------------------------------------: |
| 4 | Libai-main | total_loss: 6.555 lm_loss: 5.973 sop_loss: 0.583/10000 iters | | 4 | Libai-main | total_loss: 6.555 lm_loss: 5.973 sop_loss: 0.583/10000 iters |
## 应用场景
### 算法类别
`自然语言处理`
### 热点应用行业
`nlp,智能聊天助手,科研`
## 源码仓库及问题反馈 ## 源码仓库及问题反馈
* https://developer.hpccube.com/codes/modelzoo/bert-large_oneflow * https://developer.hpccube.com/codes/modelzoo/bert-large_oneflow
## 参考 ## 参考
......
# 模型唯一标识
modelCode=65
# 模型名称 # 模型名称
modelName=Bert-Large_OneFlow modelName=Bert-Large_OneFlow
# 模型描述 # 模型描述
modelDescription=基于OneFlow框架的Bert-Large模型 modelDescription=基于OneFlow框架的Bert-Large模型
# 应用场景(多个标签以英文逗号分割) # 应用场景
appScenario=训练,推理,train,inference,nlp,智能聊天助手 appScenario=训练,推理,train,inference,nlp,智能聊天助手
# 框架类型(多个标签以英文逗号分割) # 框架类型
frameType=OneFlow,Libai frameType=OneFlow,Libai
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment