Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
bert4torch_pytorch
Commits
97993ad3
Commit
97993ad3
authored
Oct 11, 2023
by
yangzhong
Browse files
修改README
parent
4d0a284b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
11 deletions
+53
-11
README.md
README.md
+53
-11
No files found.
README.md
View file @
97993ad3
#
bert4t
orch
#
BERT4T
orch
##
模型介绍
##
论文
bert4torch是一个基于pytorch的训练框架,前期以效仿和实现bert4keras的主要功能为主,方便加载多类预训练模型进行finetune,提供了中文注释方便用户理解模型结构。
Pre-training of Deep Bidirectional Transformers for Language Understanding
https://arxiv.org/abs/1810.04805
## 模型结构
## 模型结构
...
@@ -22,21 +24,50 @@ BERT的主模型是BERT中最重要组件,BERT通过预训练(pre-training
...
@@ -22,21 +24,50 @@ BERT的主模型是BERT中最重要组件,BERT通过预训练(pre-training
-
池化层:取出
`[CLS]`
标记(token)的表示(representation)作为整个序列的表示。
-
池化层:取出
`[CLS]`
标记(token)的表示(representation)作为整个序列的表示。
-
输出:编码器最后一层输出的表示(序列中每个标记的表示)和池化层输出的表示(序列整体的表示)。
-
输出:编码器最后一层输出的表示(序列中每个标记的表示)和池化层输出的表示(序列整体的表示)。
## 算法原理
BERT模型是基于Transformer模型的,但是与原始的Transformer模型不同,它采用了双向(bidirectional)训练方式,并且通过预训练和微调两个步骤来完成自然语言处理任务。
-
预训练(pre-training):先对大量语料进行无监督学习;
-
微调(Fine-tuning):再对少量标注语料进行监督学习,提升模型针对特定任务的表现能力。

## 环境配置
## 环境配置
### Docker
在光源可拉取docker镜像,拉取方式如下:
### Docker(方法一)
```
```
在光源可拉取docker镜像:
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04-py37-latest
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04-py37-latest
```
创建并启动容器:
安装依赖包和bert4torch
docker run -dit --network=host --name=bert4torch --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=16G --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root --ulimit stack=-1:-1 --ulimit memlock=-1:-1 image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04-py37-latest
docker exec -it bert4torch /bin/bash
```
安装依赖包和bert4torch:
pip install -r requirements.txt
pip install -r requirements.txt
cd bert4torch
cd bert4torch
python3 setup.py install
python3 setup.py install
```
```
### Dockerfile(方法二)
```
cd bert4torch/docker
docker build --no-cache -t bert4torch:latest .
docker run --rm --shm-size 16g --network=host --name=bert4torch --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/../../bert4torch:/home/bert4torch -it bert4torch:latest bash
```
### Anaconda(方法三)
```
1.创建conda虚拟环境:
conda create -n bert4torch python=3.7
2.关于本项目DCU显卡所需的工具包、深度学习库等均可从光合开发者社区下载安装:https://developer.hpccube.com/tool/
DTK驱动:dtk23.04
python:python3.7
torch:1.13.1
Tips:以上DTK、python、torch等DCU相关工具包,版本需要严格一一对应
3.其它非特殊库参照requirements.txt安装
```
## 数据集和预训练模型
## 数据集和预训练模型
...
@@ -58,7 +89,7 @@ dataset
...
@@ -58,7 +89,7 @@ dataset
```
```
## 训练
## 训练
###
修改配置文件
修改配置文件
```
```
cd examples/sequence_labeling/
cd examples/sequence_labeling/
...
@@ -79,7 +110,7 @@ cd examples/sequence_labeling/
...
@@ -79,7 +110,7 @@ cd examples/sequence_labeling/
cd examples/sequence_labeling/
cd examples/sequence_labeling/
./multi_train.sh
./multi_train.sh
```
```
## 精度
数据
## 精度
| 卡数 | 类型 | batch_size | f1 | p | r |
| 卡数 | 类型 | batch_size | f1 | p | r |
| ---- | ---- | ---------- | ------ | ------ | ------ |
| ---- | ---- | ---------- | ------ | ------ | ------ |
...
@@ -88,7 +119,18 @@ cd examples/sequence_labeling/
...
@@ -88,7 +119,18 @@ cd examples/sequence_labeling/
| 4 | fp32 | 256 | 0.9459 | 0.9398 | 0.9521 |
| 4 | fp32 | 256 | 0.9459 | 0.9398 | 0.9521 |
| 4 | fp16 | 256 | 0.9438 | 0.9398 | 0.9505 |
| 4 | fp16 | 256 | 0.9438 | 0.9398 | 0.9505 |
## 应用场景
### 算法类别
自然语言处理、文本分类、智能问答
### 热点应用行业
互联网
## 源码仓库及问题反馈
## 源码仓库及问题反馈
-
https://developer.hpccube.com/codes/modelzoo/bert4torch
-
https://developer.hpccube.com/codes/modelzoo/bert4torch
## 参考资料
## 参考资料
-
https://github.com/Tongjilibo/bert4torch
-
https://github.com/Tongjilibo/bert4torch
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment