0 Star 1 Fork 2

科大讯飞 / PERT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

中文 | English



GitHub

在自然语言处理领域中,预训练语言模型(Pre-trained Language Models,PLMs)已成为非常重要的基础技术。在近两年,哈工大讯飞联合实验室发布了多种中文预训练模型资源以及相关配套工具。作为相关工作的延续,在本项目中,我们提出了一种基于乱序语言模型的预训练模型(PERT),在不引入掩码标记[MASK]的情况下自监督地学习文本语义信息。PERT在部分中英文NLU任务上获得性能提升,但也在部分任务上效果较差,请酌情使用。目前提供了中文和英文的PERT模型,包含两种模型大小(base、large)。


中文MacBERT | 中文ELECTRA | 中文XLNet | 中文BERT | 知识蒸馏工具TextBrewer | 模型裁剪工具TextPruner

查看更多哈工大讯飞联合实验室(HFL)发布的资源:https://github.com/ymcui/HFL-Anthology

新闻

2022/5/7 更新了在多个阅读理解数据集上精调的阅读理解专用PERT,并提供了huggingface在线交互Demo,check:模型下载

2022/3/15 技术报告已发布,请参考:https://arxiv.org/abs/2203.06906

2022/2/24 中文、英文的PERT-base和PERT-large已发布。可直接使用BERT结构加载并进行下游任务精调。技术报告待完善后发出,时间预计在3月中旬,感谢耐心等待。

2022/2/17 感谢对本项目的关注,预计下周发出模型,技术报告待完善后发出。

内容导引

章节 描述
简介 PERT预训练模型的基本原理
模型下载 PERT预训练模型的下载地址
快速加载 如何使用🤗Transformers快速加载模型
基线系统效果 在部分中英文NLU任务上的基线系统效果
FAQ 常见问题答疑
引用 本项目的技术报告

简介

面向自然语言理解(NLU)的预训练模型的学习大致分为两类:使用和不使用带掩码标记[MASK]的输入文本。

算法启发:一定程度的乱序文本不影响理解。那么能否从乱序文本中学习语义知识?

大体思想:PERT对原始输入文本进行一定的词序调换,从而形成乱序文本(因此不会引入额外的[MASK]标记)。PERT的学习目标是预测原token所在的位置,具体见下例。

说明 输入文本 输出目标
原始文本 研究表明这一句话的顺序并不影响阅读。 -
WordPiece分词后 研 究 表 明 这 一 句 话 的 顺 序 并 不 影 响 阅 读 。 -
BERT 研 究 表 明 这 一 句 [MASK] 的 顺 [MASK] 并 不 [MASK] 响 阅 读 。 位置7 → 话
位置10 → 序
位置13 → 影
PERT 研 究 这 一 句 话 的 顺 序 并 不 阅 读 。 位置2(明)→位置3(表)
位置3(表)→位置2(明)
位置13(响)→位置14(影)
位置14(影)→位置13(响)

以下是PERT模型在预训练阶段的基本结构和输入输出格式(注意:目前arXiv技术报告中的图片有误,请以下图为准。下次更新论文时会替换为正确图片。)。

pert

模型下载

原版下载地址

这里主要提供TensorFlow 1.15版本的模型权重。如需PyTorch或者TensorFlow2版本的模型,请看下一小节。

开源版本仅包含Transformer部分的权重,可直接用于下游任务精调,或者其他预训练模型二次预训练的初始权重,更多说明见FAQ。

  • PERT-large:24-layer, 1024-hidden, 16-heads, 330M parameters
  • PERT-base 12-layer, 768-hidden, 12-heads, 110M parameters
模型简称 语种 语料 Google下载 百度盘下载
Chinese-PERT-large 中文 EXT数据[1] TensorFlow TensorFlow(密码:e9hs)
Chinese-PERT-base 中文 EXT数据[1] TensorFlow TensorFlow(密码:rcsw)
English-PERT-large (uncased) 英文 WikiBooks[2] TensorFlow TensorFlow(密码:wxwi)
English-PERT-base (uncased) 英文 WikiBooks[2] TensorFlow TensorFlow(密码:8jgq)

[1] EXT数据包括:中文维基百科,其他百科、新闻、问答等数据,总词数达5.4B,约占用20G磁盘空间,与MacBERT相同。
[2] Wikipedia + BookCorpus

以TensorFlow版Chinese-PERT-base为例,下载完毕后对zip文件进行解压得到:

chinese_pert_base_L-12_H-768_A-12.zip
    |- pert_model.ckpt      # 模型权重
    |- pert_model.meta      # 模型meta信息
    |- pert_model.index     # 模型index信息
    |- pert_config.json     # 模型参数
    |- vocab.txt            # 词表(与谷歌原版一致)

其中bert_config.jsonvocab.txt与谷歌原版BERT-base, Chinese完全一致(英文版与BERT-uncased版本一致)。

PyTorch以及TensorFlow 2版本

通过🤗transformers模型库可以下载TensorFlow (v2)和PyTorch版本模型。

下载方法:点击任意需要下载的模型 → 选择"Files and versions"选项卡 → 下载对应的模型文件。

模型简称 模型文件大小 transformers模型库地址
Chinese-PERT-large 1.2G https://huggingface.co/hfl/chinese-pert-large
Chinese-PERT-base 0.4G https://huggingface.co/hfl/chinese-pert-base
Chinese-PERT-large-MRC 1.2G https://huggingface.co/hfl/chinese-pert-large-mrc
Chinese-PERT-base-MRC 0.4G https://huggingface.co/hfl/chinese-pert-base-mrc
English-PERT-large 1.2G https://huggingface.co/hfl/english-pert-large
English-PERT-base 0.4G https://huggingface.co/hfl/english-pert-base

快速加载

由于PERT主体部分仍然是BERT结构,用户可以使用transformers库轻松调用PERT模型。

注意:本目录中的所有模型均使用BertTokenizer以及BertModel加载(MRC模型使用BertForQuestionAnswering)。

from transformers import BertTokenizer, BertModel

tokenizer = BertTokenizer.from_pretrained("MODEL_NAME")
model = BertModel.from_pretrained("MODEL_NAME")

其中MODEL_NAME对应列表如下:

模型名 MODEL_NAME
Chinese-PERT-large hfl/chinese-pert-large
Chinese-PERT-base hfl/chinese-pert-base
Chinese-PERT-large-MRC hfl/chinese-pert-large-mrc
Chinese-PERT-base-MRC hfl/chinese-pert-base-mrc
English-PERT-large hfl/english-pert-large
English-PERT-base hfl/english-pert-base

基线系统效果

以下仅列举部分实验结果。详细结果和分析见论文。实验结果表格中,括号外为最大值,括号内为平均值。

中文任务

在以下10个任务上进行了效果测试。

阅读理解

chinese-mrc

文本分类

chinese-tc

命名实体识别

chinese-ner

文本纠错(乱序)

除了上述任务之外,我们还在文本纠错中的乱序任务上进行了测试,效果如下。

chinese-wor

英文任务

在以下6个任务上进行了效果测试。

english-nlu

FAQ

Q1: 关于PERT的开源版本权重
A1: 开源版本仅包含Transformer部分的权重,可直接用于下游任务精调,或者其他预训练模型二次预训练的初始权重。原始TF版本权重可能包含随机初始化的MLM权重。这是为了:

  • 删去不必要的Adam相关权重(大约会减小至1/3);
  • 与transformers的BERT模型转换一致(此过程会使用原版BERT结构,因此预训练任务部分的权重会丢失,并保留BERT的MLM随机初始化权重)。

Q2: 关于PERT在下游任务上的效果
A2: 初步结论是在阅读理解、序列标注等任务上效果较好,但在文本分类任务上效果较差。具体效果请各位在各自任务上自行尝试。具体细节请参考我们的论文:https://arxiv.org/abs/2203.06906

引用

如果本项目中的模型或者相关结论有助于您的研究,请引用以下文章:https://arxiv.org/abs/2203.06906

@article{cui2022pert,
      title={PERT: Pre-training BERT with Permuted Language Model}, 
      author={Cui, Yiming and Yang, Ziqing and Liu, Ting},
      year={2022},
      eprint={2203.06906},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

关注我们

欢迎关注哈工大讯飞联合实验室官方微信公众号,了解最新的技术动态。

qrcode.png

问题反馈

如有问题,请在GitHub Issue中提交。

  • 在提交问题之前,请先查看FAQ能否解决问题,同时建议查阅以往的issue是否能解决你的问题。
  • 重复以及与本项目无关的issue会被[stable-bot](stale · GitHub Marketplace)处理,敬请谅解。
  • 我们会尽可能的解答你的问题,但无法保证你的问题一定会被解答。
  • 礼貌地提出问题,构建和谐的讨论社区。
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

在自然语言处理领域中,预训练语言模型(Pre-trained Language Models,PLMs)已成为非常重要的基础技术。在近两年,哈工大讯飞联合实验室发布了多种中文预训练模型资源以及相关配套工具。作为相关工作的延续,在本项目中,我们提出了一种基于乱序语言模型的预训练模型(PERT),在不引入掩码标记[MASK]的情况下自监督地学习文本语义信息。 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/iflytek/PERT.git
git@gitee.com:iflytek/PERT.git
iflytek
PERT
PERT
main

搜索帮助