Giter VIP home page Giter VIP logo

cino's Introduction

中文说明 | English



GitHub

在自然语言处理领域中,预训练语言模型(Pre-trained Language Model, PLM)已成为重要的基础技术,在多语言的研究中,预训练模型的使用也愈加普遍。为了促进**少数民族语言信息处理的研究与发展,哈工大讯飞联合实验室(HFL)发布少数民族语言预训练模型CINO (Chinese mINOrity PLM)。


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

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

新闻

2022/10/29 我们提出了一种融合语言学信息的预训练模型LERT。查看:https://github.com/ymcui/LERT

2022/8/23 CINO被国际重要会议COLING 2022录用为长文。camera-ready结束后,我们将更新论文最终版并发布相应资源。

2022/02/21 更新CINO-small模型,6层transformer结构,参数量148M。

2022/01/25 更新CINO-v2模型与WCM-v2数据集,少数民族语言分类任务效果提升。

2021/12/17 哈工大讯飞联合实验室全新推出模型裁剪工具包TextPruner,欢迎试用。

2021/10/25 CINO-large模型、少数民族语言分类任务数据集Wiki-Chinese-Minority(WCM)数据集已开放下载使用。

内容导引

章节 描述
简介 介绍少数民族语言预训练模型与相关数据集
模型下载 模型下载地址与使用说明
快速加载 介绍了如何使用🤗Transformers快速加载模型
少数民族语言分类数据集 介绍少数民族语言分类数据集
实验结果 列举了模型在NLU任务上的效果
引用 技术报告与引用

简介

多语言预训练模型(Multilingual Pre-trained Language Model),如mBERT、XLM-R等,通过在预训练阶段增加语言数量、采用MLM自监督训练等方式,使预训练模型具备了多语言(multilingual)和跨语言(cross-lingual)理解的能力。然而,由于国内少数民族语言语料的稀缺以及国际上研究的忽视,现有的多语言模型无法很好地处理国内少数民族语言文字。

本项工作的主要贡献:

  • CINO (Chinese mINOrity PLM) 基于多语言预训练模型XLM-R,在多种国内少数民族语言语料上进行了二次预训练。该模型提供了藏语、蒙语(回鹘体)、维吾尔语、哈萨克语(阿拉伯体)、朝鲜语、壮语、粤语等少数民族语言与方言的理解能力。

  • 为了便于评价包括CINO在内的各个多语言预训练模型性能,我们构建了基于维基百科的少数民族语言分类任务数据集Wiki-Chinese-Minority(WCM)。具体见少数民族语言分类数据集

  • 通过实验证明,CINO在Wiki-Chinese-Minority(WCM)以及其他少数民族语言数据集:藏语新闻分类 Tibetan News Classification Corpus (TNCC) 、朝鲜语新闻分类 KLUE-TC (YNAT) 上获得了最好的效果。相关结果详见实验结果

该模型涵盖:

  • Chinese,中文(zh)
  • Tibetan,藏语(bo)
  • Mongolian (Uighur form),蒙语(mn)
  • Uyghur,维吾尔语(ug)
  • Kazakh (Arabic form),哈萨克语(kk)
  • Korean,朝鲜语(ko)
  • Zhuang,壮语
  • Cantonese,粤语(yue)



模型下载

直接下载

目前提供PyTorch版本的CINO-small、CINO-base和CINO-large模型的下载(推荐使用v2版本),后续将陆续更新其他规模与版本的模型。

  • CINO-large-v2:24-layer, 1024-hidden, 16-heads, vocabulary size 136K, 442M parameters
  • CINO-base-v2 12-layer, 768-hidden, 12-heads, vocabulary size 136K, 190M parameters
  • CINO-small-v2 6-layer, 768-hidden, 12-heads, vocabulary size 136K, 148M parameters
  • CINO-large:24-layer, 1024-hidden, 16-heads, vocabulary size 275K, 585M parameters

注意:

  • v1模型(CINO-large)支持XLM-R中的所有语言再加上少数民族语言;
  • v2模型(CINO-large-v2,CINO-base-v2和CINO-small-v2)的词表针对预训练数据做了裁剪,仅支持中文与少数民族语言。
模型简称 模型文件大小 Google下载 百度网盘下载
CINO-large-v2 1.6GB PyTorch模型 PyTorch模型(密码3fjt)
CINO-base-v2 705MB PyTorch模型 PyTorch模型(密码qnvc)
CINO-small-v2 564MB PyTorch模型 PyTorch模型(密码9mc8)
CINO-large 2.2GB PyTorch模型 PyTorch模型(密码wpyh)

通过🤗transformers下载

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

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

模型简称 模型文件大小 transformers模型库地址
CINO-large-v2 1.6GB https://huggingface.co/hfl/cino-large-v2
CINO-base-v2 705MB https://huggingface.co/hfl/cino-base-v2
CINO-small-v2 564MB https://huggingface.co/hfl/cino-small-v2
CINO-large 2.2GB https://huggingface.co/hfl/cino-large

模型使用

PyTorch版本包含3个文件:

pytorch_model.bin        # 模型权重
config.json              # 模型参数
sentencepiece.bpe.model  # 词表

CINO的结构与XLM-R相同,可直接使用Transformers中的XLMRobertaModel模型进行加载:

from transformers import XLMRobertaTokenizer, XLMRobertaModel
tokenizer = XLMRobertaTokenizer.from_pretrained("PATH_TO_MODEL_DIR")
model = XLMRobertaModel.from_pretrained("PATH_TO_MODEL_DIR")

快速加载

依托于🤗Transformers,可轻松调用以上CINO模型。

from transformers import XLMRobertaTokenizer, XLMRobertaModel
tokenizer = XLMRobertaTokenizer.from_pretrained("MODEL_NAME")
model = XLMRobertaModel.from_pretrained("MODEL_NAME")

其中MODEL_NAME对应列表如下:

模型名 MODEL_NAME
CINO-large-v2 hfl/cino-large-v2
CINO-base-v2 hfl/cino-base-v2
CINO-small-v2 hfl/cino-small-v2
CINO-large hfl/cino-large

少数民族语言分类数据集

Wiki-Chinese-Minority(WCM)

我们基于少数民族语言维基百科语料及其分类体系标签,构建了分类任务数据集 Wiki-Chinese-Minority(WCM)。该数据集覆盖了蒙古语、藏语、维吾尔语、粤语、朝鲜语、哈萨克语,中文,包括艺术、地理、历史、自然、自然科学、人物、技术、教育、经济和健康十个类别。

各个语言上取weighted-F1为评测指标。计算所有语言的weighted-F1平均作为总体评价指标。

数据集名称 Google下载 百度网盘下载
Wiki-Chinese-Minority-v2(WCM-v2) Google Drive
Wiki-Chinese-Minority(WCM) Google Drive
注:语料数据无法通过百度网盘分享,请通过Google Drive下载。

WCM-v2版本调整了各类别与语言的样本数量,分布相对更均衡。WCM-v2版本数据分布:

类别 蒙古语 藏语 维吾尔语 粤语 朝鲜语 哈萨克语 中文-Train 中文-Dev 中文-Test
艺术 135 141 3 387 806 348 2657 331 335
地理 76 339 256 1550 1197 572 12854 1589 1644
历史 66 111 0 499 776 491 1771 227 248
自然 7 0 7 606 442 361 1105 134 110
自然科学 779 133 20 336 532 880 2314 317 287
人物 1402 111 0 1230 684 169 7706 953 924
技术 191 163 8 329 808 515 1184 134 152
教育 6 1 0 289 439 1392 936 130 118
经济 205 0 0 445 575 637 922 113 109
健康 106 111 6 272 299 893 551 67 73
总计 2973 1110 300 5943 6558 6258 32000 3995 4000

数据说明:

  • 包含两个文件夹:zh和minority
  • zh:中文的训练集、开发集和测试集
  • minority:所有语言(各少数民族语言与方言)的测试集

该数据集尚处于alpha阶段,之后的版本可能会有一定改动。
后续还将有其他数据集发布,敬请期待。

实验结果

我们在YNAT、TNCC和Wiki-Chinese-Minority三个数据集上比较了不同模型的效果。

对于同一任务上的各个预训练模型,使用统一的训练轮数、学习率等参数。

朝鲜语文本分类(YNAT)

#Train #Dev #Test #Classes Metric
45,678 9,107 9,107 7 macro-F1

实验参数:学习率为1e-5,batch_size为16。

实验结果:

模型 开发集
XLM-R-large[1] 87.3
XLM-R-large[2] 86.3
CINO-small-v2 84.1
CINO-base-v2 85.5
CINO-large-v2 87.2
CINO-large 87.4

[1] 论文中的结果。
[2] 复现结果,与CINO-large使用相同的学习率。

藏语文本分类(TNCC)

#Train[1] #Dev #Test #Classes Metric
7,363 920 920 12 macro-F1

实验参数:学习率为5e-6,batch_size为16。

实验结果:

模型 开发集 测试集
TextCNN 65.1 63.4
XLM-R-large 14.3 13.3
CINO-small-v2 72.1 66.7
CINO-base-v2 70.3 68.4
CINO-large-v2 72.9 71.0
CINO-large 71.3 68.6

注:原论文中未提供train/dev/test的划分方式。因此,我们重新对数据集按8:1:1做了划分。

Wiki-Chinese-Minority

在中文训练集上训练,在其他语言上做zero-shot测试。各语言的评测指标为weighted-F1。

实验参数:学习率为7e-6,batch_size为32。

WCM-v2实验结果:

模型 蒙古语 藏语 维吾尔语 粤语 朝鲜语 哈萨克语 中文 Average
XLM-R-base 41.2 25.7 84.5 66.1 43.1 23.0 88.3 53.1
XLM-R-large 53.8 24.5 89.4 67.3 45.4 30.0 88.3 57.0
CINO-small-v2 60.3 47.9 86.5 64.6 43.2 33.2 87.9 60.5
CINO-base-v2 62.1 52.7 87.8 68.1 45.6 38.3 89.0 63.4
CINO-large-v2 73.1 58.9 90.1 66.9 45.1 42.0 88.9 66.4

示例代码

参见examples目录,目前包括

引用

如果本目录中的内容对你的研究工作有所帮助,欢迎引用下述论文。

@inproceedings{yang-etal-2022-cino,
    title = "{CINO}: A {C}hinese Minority Pre-trained Language Model",
    author = "Yang, Ziqing  and
      Xu, Zihang  and
      Cui, Yiming  and
      Wang, Baoxin  and
      Lin, Min  and
      Wu, Dayong  and
      Chen, Zhigang",
    booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
    month = oct,
    year = "2022",
    address = "Gyeongju, Republic of Korea",
    publisher = "International Committee on Computational Linguistics",
    url = "https://aclanthology.org/2022.coling-1.346",
    pages = "3937--3949"
}

关注我们

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

qrcode.jpg

问题反馈

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

cino's People

Contributors

airaria avatar geekdream-x avatar ymcui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cino's Issues

Source code and dataset

您好!我是一名研究NLP的学生,请问CINO项目的源代码或者训练语料有公开吗?

little wrong

the line 95 in wcm_zeroshot.py need to be modify, the test_pred has the wrong shape

best_cino.pth

求~ best_cino.pth 文件在哪? 还是自己构建的

TNCC数据集上实验例子报错

作者,您好!
我按照环境文档要求,配置了环境变量,在您开源的例子:TNCC数据集上进行finetuning实验复现。 由于电脑配置限制,仅调小了batch_size的值,其余不变。出现以下问题:
Traceback (most recent call last):
File "G:/少数/CINO/Chinese-Minority-PLM-main/examples/TNCC/finetune/run_finetune.py", line 221, in
main()
File "G:/少数/CINO/Chinese-Minority-PLM-main/examples/TNCC/finetune/run_finetune.py", line 218, in main
trainer.run_finetune()
File "G:/少数/CINO/Chinese-Minority-PLM-main/examples/TNCC/finetune/run_finetune.py", line 200, in run_finetune
self.train(model, train_loader, dev_loader, optimizer, schedule)
File "G:/少数/CINO/Chinese-Minority-PLM-main/examples/TNCC/finetune/run_finetune.py", line 169, in train
dev_true, dev_pred = self.predict(model, valid_loader)
File "G:/少数/CINO/Chinese-Minority-PLM-main/examples/TNCC/finetune/run_finetune.py", line 137, in predict
test_true.extend(y.squeeze().cpu().numpy().tolist())
TypeError: 'int' object is not iterable

Process finished with exit code 1

您能看看是什么原因吗?

gradient_acc参数

能帮忙解释一下gradient_acc参数嘛
==loss /= self.config.gradient_acc==代码中,用到了gradient_acc参数,所以不太明白这句代码的意思。在这里插入图片描述

error with TCNN example

Some weights of XLMRobertaModel were not initialized from the model checkpoint at model/ and are newly initialized: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Traceback (most recent call last):
File "tncc_finetune.py", line 175, in
main()
File "tncc_finetune.py", line 172, in main
trainer.run_finetune()
File "tncc_finetune.py", line 155, in run_finetune
self.train(model, train_loader, dev_loader, optimizer, schedule)
File "tncc_finetune.py", line 120, in train
loss.backward()
File "/data/anbo/anaconda3/envs/transformer/lib/python3.7/site-packages/torch/tensor.py", line 221, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/data/anbo/anaconda3/envs/transformer/lib/python3.7/site-packages/torch/autograd/init.py", line 132, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: CUDA error: device-side assert triggered
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [1,0,0] Assertion t >= 0 && t < n_classes failed.

torch等版本的要求也是一致的:
sacremoses==0.0.53
scikit-learn==0.24.2
scipy==1.7.3
sentencepiece==0.1.97
six @ file:///tmp/build/80754af9/six_1644875935023/work
threadpoolctl==3.1.0
tokenizers==0.8.1rc2
torch==1.7.1
torchaudio==0.12.1
torchvision==0.13.1
tqdm==4.64.1
transformers==3.1.0

请问怎么处理?

关于预训练数据

作者,您好!
我想请问下以下两点:
(1)该预训练模型所包含的语言是只有以下几种,还是涵盖了先前xlm-r的上百种语言?
Chinese,中文(zh)Tibetan,藏语(bo)Mongolian (Uighur form),蒙语(mn)Uyghur,维吾尔语(ug)
Kazakh (Arabic form),哈萨克语(kk)Korean,朝鲜语(ko)Zhuang,壮语Cantonese,粤语(yue)
(2)关于少数民族语数据集预训练的数据量大小是多少?
期待您的回复。

预训练数据集规模

请问用来预训练的少数民族语言的规模有多大?大致是什么类型?古代还是现代?

民族语言预处理

你好,与汉语不同,民族语言的字是由不同的部件构成的,请问对于民族语言做了哪些预处理呢?
比如藏文是按照字丁(单独编码)、音节还是其他的文本粒度为单位进行建模学习呢?

Wiki-Chinese-Minority实验

你好,请问为什么说Wiki-Chinese-Minority实验中,除了中文以外的语种是zero-shot测试呢,这个预训练模型不是也包括了那些少数民族语言的么,不应该是finetune么

问题简介

您好,在复原例子的时候,确保了版本与您一样,但在终端运行的时候,出现了如下错误,暂时无法得到有效解决,请问是否可以帮忙看一下问题所在,十分打扰!

python run_finetune.py --params cino-params.json

Traceback (most recent call last):
File "run_finetune.py", line 188, in
main()
File "run_finetune.py", line 182, in main
config = CINO_FT_Configer(load(args.hparam))
AttributeError: 'Namespace' object has no attribute 'hparam'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.