GitRead 中文社区
首页趋势排行榜原创文章严选周刊
更多资源
新手训练营
精选专题热门话题GitHub 文档资源精选实战指南

TencentPretrain

Tencent Pre-training framework in PyTorch & Pre-trained Model Zoo

  • 语言Python
  • 默认分支main
  • 大小42.2 MB
  • 更新2024年8月4日
  • Issues32
在 GitHub 打开
avatarTencent

项目介绍

Tencent/TencentPretrain 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Other 许可证,目前获得 1.1k 个 Star、145 次 Fork。

仓库全名
Tencent/TencentPretrain

README 摘要

English | 中文 TencentPretrain: Tencent Pre-training Framework Pre-training has become an essential part of AI technology. TencentPretrain is a toolkit for pre-training and fine-tuning on data of different modalities (e.g. text and vision). TencentPretrain is characterized by modular design. It facilitates the use of existing pre-training models, and provides interfaces for users to further extend upon. With…

完整内容见 GitHub 原始 README 或本页 。

常见问题

TencentPretrain 用什么语言开发?

主要使用 Python 编写,采用 Other 许可证,目前有 1.1k 个 Star。

TencentPretrain 可以免费商用吗?

仓库标注的许可证为 Other,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 TencentPretrain 的源码?

可以直接克隆仓库:git clone https://github.com/Tencent/TencentPretrain.git,默认分支为 main;安装与运行步骤见仓库 README。

TencentPretrain 最近还在维护吗?

仓库最近一次更新为 2024年8月4日,当前有 32 个未关闭 Issue;Star 数为 1.1k,可作为社区活跃度的参考。

本页面展示项目元数据与原始 README,GitRead 中文社区 编辑团队负责选题收录。

相关仓库

public-apis/public-apis avatar
public-apispublic-apis
2 天前
497.7k
55.6k
2.6k

免费 API 汇总列表

apipublic-apisfree+7
Python
15.5 MB
7
详情
EbookFoundation/free-programming-books avatar
free-programming-booksEbookFoundation
2 天前
401.4k
64.4k
39

免费可获取的编程书籍

bookseducationhacktoberfest+2
Python
21.8 MB
3
详情
donnemartin/system-design-primer avatar
system-design-primerdonnemartin
9月15日
377.5k
57.4k
291

学习如何设计大规模系统。为系统设计面试做准备。包含 Anki 闪卡。

designdesign-patternsdesign-system+10
Python
11.0 MB
0
详情
vinta/awesome-python avatar
awesome-pythonvinta
1 天前
333.6k
28.0k
0

回答“我想用 Python 做 X,该用哪个工具?”的权威清单

awesomeawesome-listpython+3
Python
6.9 MB
2
详情
practical-tutorials/project-based-learning avatar
project-based-learningpractical-tutorials
23 小时前
289.4k
36.8k
238

精选的项目实战教程列表

tutorialprojectbeginner-project+5
Python
472 KB
1
详情
NousResearch/hermes-agent avatar
hermes-agentNousResearch
2 小时前
262.1k
58.4k
54.0k

与你共同成长的智能体

aiai-agentai-agents+10
Python
1.4 GB
3
详情
TheAlgorithms/Python avatar
PythonTheAlgorithms
1 周前
226.0k
51.3k
90

所有算法均用 Python 实现

algorithmalgorithm-competitionsalgorithms-implemented+11
Python
17.9 MB
2
详情
yt-dlp/yt-dlp avatar
yt-dlpyt-dlp
5 天前
206.5k
18.2k
2.8k

功能丰富的命令行音视频下载器

youtube-dlpythonsponsorblock+4
Python
63.5 MB
0
详情

关于

albertbartbertchineseclassificationclueelmofine-tuninggptgpt-2model-zoonatural-language-processingnerpegasuspre-trainingpytorchrobertat5unilmxlm-roberta
  • Other
  • 1.1k Stars
  • 145 Forks
  • 20 Watching

简要分析

热度分
1406
价值分
701
活跃状态
活跃
GitHub

语言占比

Python

贡献者

zhezhaoazhezhaoaydli-aiydli-aihhou435hhou435Eric8932Eric8932JINGZIjingziJINGZIjingziyuzhangogogoyuzhangogogoWinter523Winter523wmpsccwmpsccfengyh3fengyh3eltocieareltociearkarots123karots123SmilencelsySmilencelsy

English | 中文

TencentPretrain: Tencent Pre-training Framework

Pre-training has become an essential part of AI technology. TencentPretrain is a toolkit for pre-training and fine-tuning on data of different modalities (e.g. text and vision). TencentPretrain is characterized by modular design. It facilitates the use of existing pre-training models, and provides interfaces for users to further extend upon. With TencentPretrain, we build a model zoo which contains pre-trained models of different properties. TencentPretrain inherits the open source toolkit UER (https://github.com/dbiir/UER-py/) and extends it to a multimodal pre-training framework.

Full Documentation:https://github.com/Tencent/TencentPretrain/wiki

Table of Contents

  • Features
  • Requirements
  • Quickstart
  • Pre-training data
  • Downstream datasets
  • Modelzoo
  • Instructions
  • Competition solutions
  • Citation
  • Contact information

Features

TencentPretrain has the following features:

  • Reproducibility TencentPretrain has been tested on many datasets and should match the performances of the original pre-training model implementations such as BERT, GPT-2, ELMo, T5, CLIP.
  • Model modularity TencentPretrain is divided into the following parts: embedding, encoder, target embedding (optional), decoder (optional), and target. Ample modules are implemented in each part. Clear and robust interface allows users to combine modules to construct pre-training models with as few restrictions as possible.
  • Multimodal TencentPretrain supports different modalities such as text, vision, and audio.
  • Model training TencentPretrain supports CPU mode, single GPU mode, distributed training mode, and gigantic model training with DeepSpeed.
  • Model zoo With the help of TencentPretrain, we pre-train and release models of different properties. Proper selection of pre-trained models is important to the performances of downstream tasks.
  • SOTA results TencentPretrain supports comprehensive downstream tasks (e.g. classification and machine reading comprehension) and provides winning solutions of many competitions.
  • Abundant functions TencentPretrain provides abundant functions related with pre-training, such as feature extractor and text generation.

Requirements

  • Python >= 3.6
  • torch >= 1.1
  • six >= 1.12.0
  • argparse
  • packaging
  • regex
  • For the pre-trained model conversion (related with TensorFlow) you will need TensorFlow
  • For the tokenization with sentencepiece model you will need SentencePiece
  • For developing a stacking model you will need LightGBM and BayesianOptimization
  • For the pre-training with whole word masking you will need word segmentation tool such as jieba
  • For the use of CRF in sequence labeling downstream task you will need pytorch-crf
  • For the gigantic model training you will need DeepSpeed
  • For the vision model training you will need torchvision
  • For the audio model training you will need torchaudio, and opencv-python is needed for some special settings of specaugment, and editdistance is needed when finetuning a speech2text model

Quickstart

This section uses several commonly-used examples to demonstrate how to use TencentPretrain. More details are discussed in Instructions section. We firstly use BERT (a text pre-training model) on book review sentiment classification dataset. We pre-train model on book review corpus and then fine-tune it on book review sentiment classification dataset. There are three input files: book review corpus, book review sentiment classification dataset, and vocabulary. All files are encoded in UTF-8 and included in this project.

The format of the corpus for BERT is as follows (one sentence per line and documents are delimited by empty lines):

doc1-sent1
doc1-sent2
doc1-sent3

doc2-sent1

doc3-sent1
doc3-sent2

The book review corpus is obtained from book review sentiment classification dataset. We remove labels and split a review into two parts from the middle to construct a document with two sentences (see book_review_bert.txt in corpora folder).

The format of the classification dataset is as follows:

label    text_a
1        instance1
0        instance2
1        instance3

Label and instance are separated by \t . The first row is a list of column names. The label ID should be an integer between (and including) 0 and n-1 for n-way classification.

We use Google’s Chinese vocabulary file models/google_zh_vocab.txt, which contains 21128 Chinese characters.

We firstly pre-process the book review corpus. In the pre-processing stage, the corpus needs to be processed into the format required by the specified pre-training model (–data_processor):

python3 preprocess.py --corpus_path corpora/book_review_bert.txt --vocab_path models/google_zh_vocab.txt \
                      --dataset_path dataset.pt --processes_num 8 --data_processor bert

Notice that six>=1.12.0 is required.

Pre-processing is time-consuming. Using multiple processes can largely accelerate the pre-processing speed (–processes_num). BERT tokenizer is used in default (–tokenizer bert). After pre-processing, the raw text is converted to dataset.pt, which is the input of pretrain.py. Then we download Google’s pre-trained Chinese BERT model google_zh_model.bin (in TencentPretrain format and the original model is from here), and put it in models folder. We load the pre-trained Chinese BERT model and further pre-train it on book review corpus. Pre-training model is usually composed of embedding, encoder, and target layers. To build a pre-training model, we should provide related information. Configuration file (–config_path) specifies the modules and hyper-parameters used by pre-training models. More details can be found in models/bert/base_config.json. Suppose we have a machine with 8 GPUs:

python3 pretrain.py --dataset_path dataset.pt --vocab_path models/google_zh_vocab.txt \
                    --pretrained_model_path models/google_zh_model.bin \
                    --config_path models/bert/base_config.json \
                    --output_model_path models/book_review_model.bin \
                    --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
                    --total_steps 5000 --save_checkpoint_steps 1000 --batch_size 32

mv models/book_review_model.bin-5000 models/book_review_model.bin

Notice that the model trained by pretrain.py is attacted with the suffix which records the training step (–total_steps). We could remove the suffix for ease of use.

Then we fine-tune the pre-trained model on downstream classification dataset. We use embedding and encoder layers of book_review_model.bin, which is the output of pretrain.py:

python3 finetune/run_classifier.py --pretrained_model_path models/book_review_model.bin \
                                   --vocab_path models/google_zh_vocab.txt \
                                   --config_path models/bert/base_config.json \
                                   --train_path datasets/book_review/train.tsv \
                                   --dev_path datasets/book_review/dev.tsv \
                                   --test_path datasets/book_review/test.tsv \
                                   --epochs_num 3 --batch_size 32

The default path of the fine-tuned classifier model is models/finetuned_model.bin . It is noticeable that the actual batch size of pre-training is –batch_size times –world_size ; The actual batch size of downstream task (e.g. classification) is –batch_size . Then we do inference with the fine-tuned model.

python3 inference/run_classifier_infer.py --load_model_path models/finetuned_model.bin \
                                          --vocab_path models/google_zh_vocab.txt \
                                          --config_path models/bert/base_config.json \
                                          --test_path datasets/book_review/test_nolabel.tsv \
                                          --prediction_path datasets/book_review/prediction.tsv \
                                          --labels_num 2

–test_path specifies the path of the file to be predicted. The file should contain text_a column. –prediction_path specifies the path of the file with prediction results. We need to explicitly specify the number of labels by –labels_num. The above dataset is a two-way classification dataset.


The above content provides basic ways of using TencentPretrain to pre-process, pre-train, fine-tune, and do inference. More use cases can be found in complete :arrow_right: quickstart :arrow_left: . The complete quickstart contains abundant use cases, covering most of the pre-training related application scenarios. It is recommended that users read the complete quickstart in order to use the project reasonably.


Pre-training data

This section provides links to a range of :arrow_right: pre-training data :arrow_left: . TencentPretrain can load these pre-training data directly.


Downstream datasets

This section provides links to a range of :arrow_right: downstream datasets :arrow_left: . TencentPretrain can load these datasets directly.


Modelzoo

With the help of TencentPretrain, we pre-trained models of different properties (e.g. models based on different modalities, encoders, and targets). Detailed introduction of pre-trained models and their download links can be found in :arrow_right: modelzoo :arrow_left: . All pre-trained models can be loaded by TencentPretrain directly.


Instructions

TencentPretrain is organized as follows:

TencentPretrain/
    |--tencentpretrain/
    |    |--embeddings/ # contains modules of embedding component
    |    |--encoders/ # contains modules of encoder component such as RNN, CNN, Transformer
    |    |--decoders/ # contains modules of decoder component
    |    |--targets/ # contains modules of target component such as language modeling, masked language modeling
    |    |--layers/ # contains frequently-used NN layers
    |    |--models/ # contains model.py, which combines modules of different components
    |    |--utils/ # contains frequently-used utilities
    |    |--model_builder.py
    |    |--model_loader.py
    |    |--model_saver.py
    |    |--opts.py
    |    |--trainer.py
    |
    |--corpora/ # contains pre-training data
    |--datasets/ # contains downstream tasks
    |--models/ # contains pre-trained models, vocabularies, and configuration files
    |--scripts/ # contains useful scripts for pre-training models
    |--finetune/ # contains fine-tuning scripts for downstream tasks
    |--inference/ # contains inference scripts for downstream tasks
    |
    |--preprocess.py
    |--pretrain.py
    |--README.md
    |--README_ZH.md
    |--requirements.txt
    |--LICENSE

The code is organized based on components (e.g. embeddings, encoders). Users can use and extend upon it with little efforts.

Comprehensive examples of using TencentPretrain can be found in :arrow_right: instructions :arrow_left: , which help users quickly implement pre-training models such as BERT, GPT-2, ELMo, T5, CLIP and fine-tune pre-trained models on a range of downstream tasks.


Competition solutions

TencentPretrain has been used in winning solutions of many competitions. In this section, we provide some examples of using TencentPretrain to achieve SOTA results on competitions, such as CLUE. See :arrow_right: competition solutions :arrow_left: for more detailed information.


Citation

If you are using the work (e.g. pre-trained models) in TencentPretrain for academic work, please cite the system paper published in ACL 2023:
@article{zhao2023tencentpretrain,
  title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
  author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
  journal={ACL 2023},
  pages={217},
  year={2023}
}

评论

登录 后发表评论
暂无评论
GitRead 中文社区
深度解读 · 趋势洞察 · 价值精选

关于

关于我们联系我们编辑准则收录标准赞赏人员

发现

技术趋势新手训练营资源精选实战指南精选专题热门话题GitHub 文档

条款

隐私政策服务条款网站地图
26.9万收录项目
5.5万中文话题
155精选专题
发现技术价值,连接开源智慧
© 2026 GitRead · GitHub 中文社区 本站与 GitHub, Inc. 无隶属关系;GitHub 是 GitHub, Inc. 的商标。