Giter Site home page Giter Site logo

fastnlp / cpt Goto Github PK

View Code? Open in Web Editor NEW
477.0 477.0 72.0 1.36 MB

CPT: A Pre-Trained Unbalanced Transformer for Both Chinese Language Understanding and Generation

Python 92.40% Shell 1.38% Makefile 0.01% C++ 4.33% C 0.18% Cuda 1.70%
chinese language-understanding pretrained-models ptms text-generation transformer-architecture

cpt's Introduction

fastNLP

fastNLP是一款轻量级的自然语言处理(NLP)工具包,目标是减少用户项目中的工程型代码,例如数据处理循环、训练循环、多卡运行等。

fastNLP具有如下的特性:

  • 便捷。在数据处理中可以通过apply函数避免循环、使用多进程提速等;在训练循环阶段可以很方便定制操作。
  • 高效。无需改动代码,实现fp16切换、多卡、ZeRO优化等。
  • 兼容。fastNLP支持多种深度学习框架作为后端。

⚠️ 为了实现对不同深度学习架构的兼容,fastNLP 1.0.0之后的版本重新设计了架构,因此与过去的fastNLP版本不完全兼容, 基于更早的fastNLP代码需要做一定的调整:

fastNLP文档

中文文档

安装指南

fastNLP可以通过以下的命令进行安装

pip install fastNLP>=1.0.0alpha

如果需要安装更早版本的fastNLP请指定版本号,例如

pip install fastNLP==0.7.1

另外,请根据使用的深度学习框架,安装相应的深度学习框架。

Pytorch 下面是使用pytorch来进行文本分类的例子。需要安装torch>=1.6.0。
from fastNLP.io import ChnSentiCorpLoader
from functools import partial
from fastNLP import cache_results
from fastNLP.transformers.torch import BertTokenizer

# 使用cache_results装饰器装饰函数,将prepare_data的返回结果缓存到caches/cache.pkl,再次运行时,如果
#  该文件还存在,将自动读取缓存文件,而不再次运行预处理代码。
@cache_results('caches/cache.pkl')
def prepare_data():
    # 会自动下载数据,并且可以通过文档看到返回的 dataset 应该是包含"raw_words"和"target"两个field的
    data_bundle = ChnSentiCorpLoader().load()
    # 使用tokenizer对数据进行tokenize
    tokenizer = BertTokenizer.from_pretrained('hfl/chinese-bert-wwm')
    tokenize = partial(tokenizer, max_length=256)  # 限制数据的最大长度
    data_bundle.apply_field_more(tokenize, field_name='raw_chars', num_proc=4)  # 会新增"input_ids", "attention_mask"等field进入dataset中
    data_bundle.apply_field(int, field_name='target', new_field_name='labels')  # 将int函数应用到每个target上,并且放入新的labels field中
    return data_bundle
data_bundle = prepare_data()
print(data_bundle.get_dataset('train')[:4])

# 初始化model, optimizer
from fastNLP.transformers.torch import BertForSequenceClassification
from torch import optim
model = BertForSequenceClassification.from_pretrained('hfl/chinese-bert-wwm')
optimizer = optim.AdamW(model.parameters(), lr=2e-5)

# 准备dataloader
from fastNLP import prepare_dataloader
dls = prepare_dataloader(data_bundle, batch_size=32)

# 准备训练
from fastNLP import Trainer, Accuracy, LoadBestModelCallback, TorchWarmupCallback, Event
callbacks = [
    TorchWarmupCallback(warmup=0.1, schedule='linear'),   # 训练过程中调整学习率。
    LoadBestModelCallback()  # 将在训练结束之后,加载性能最优的model
]
# 在训练特定时机加入一些操作, 不同时机能够获取到的参数不一样,可以通过Trainer.on函数的文档查看每个时机的参数
@Trainer.on(Event.on_before_backward())
def print_loss(trainer, outputs):
    if trainer.global_forward_batches % 10 == 0:  # 每10个batch打印一次loss。
        print(outputs.loss.item())

trainer = Trainer(model=model, train_dataloader=dls['train'], optimizers=optimizer,
                  device=0, evaluate_dataloaders=dls['dev'], metrics={'acc': Accuracy()},
                  callbacks=callbacks, monitor='acc#acc',n_epochs=5,
                  # Accuracy的update()函数需要pred,target两个参数,它们实际对应的就是以下的field。
                  evaluate_input_mapping={'labels': 'target'},  # 在评测时,将dataloader中会输入到模型的labels重新命名为target
                  evaluate_output_mapping={'logits': 'pred'}  # 在评测时,将model输出中的logits重新命名为pred
                  )
trainer.run()

# 在测试集合上进行评测
from fastNLP import Evaluator
evaluator = Evaluator(model=model, dataloaders=dls['test'], metrics={'acc': Accuracy()},
                      # Accuracy的update()函数需要pred,target两个参数,它们实际对应的就是以下的field。
                      output_mapping={'logits': 'pred'},
                      input_mapping={'labels': 'target'})
evaluator.run()

更多内容可以参考如下的链接

快速入门

详细使用教程

Paddle 下面是使用paddle来进行文本分类的例子。需要安装paddle>=2.2.0以及paddlenlp>=2.3.3。
from fastNLP.io import ChnSentiCorpLoader
from functools import partial

# 会自动下载数据,并且可以通过文档看到返回的 dataset 应该是包含"raw_words"和"target"两个field的
data_bundle = ChnSentiCorpLoader().load()

# 使用tokenizer对数据进行tokenize
from paddlenlp.transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('hfl/chinese-bert-wwm')
tokenize = partial(tokenizer, max_length=256)  # 限制一下最大长度
data_bundle.apply_field_more(tokenize, field_name='raw_chars', num_proc=4)  # 会新增"input_ids", "attention_mask"等field进入dataset中
data_bundle.apply_field(int, field_name='target', new_field_name='labels')  # 将int函数应用到每个target上,并且放入新的labels field中
print(data_bundle.get_dataset('train')[:4])

# 初始化 model 
from paddlenlp.transformers import BertForSequenceClassification, LinearDecayWithWarmup
from paddle import optimizer, nn
class SeqClsModel(nn.Layer):
    def __init__(self, model_checkpoint, num_labels):
        super(SeqClsModel, self).__init__()
        self.num_labels = num_labels
        self.bert = BertForSequenceClassification.from_pretrained(model_checkpoint)

    def forward(self, input_ids, token_type_ids=None, position_ids=None, attention_mask=None):
        logits = self.bert(input_ids, token_type_ids, position_ids, attention_mask)
        return logits

    def train_step(self, input_ids, labels, token_type_ids=None, position_ids=None, attention_mask=None):
        logits = self(input_ids, token_type_ids, position_ids, attention_mask)
        loss_fct = nn.CrossEntropyLoss()
        loss = loss_fct(logits.reshape((-1, self.num_labels)), labels.reshape((-1, )))
        return {
            "logits": logits,
            "loss": loss,
        }
    
    def evaluate_step(self, input_ids, token_type_ids=None, position_ids=None, attention_mask=None):
        logits = self(input_ids, token_type_ids, position_ids, attention_mask)
        return {
            "logits": logits,
        }

model = SeqClsModel('hfl/chinese-bert-wwm', num_labels=2)

# 准备dataloader
from fastNLP import prepare_dataloader
dls = prepare_dataloader(data_bundle, batch_size=16)

# 训练过程中调整学习率。
scheduler = LinearDecayWithWarmup(2e-5, total_steps=20 * len(dls['train']), warmup=0.1)
optimizer = optimizer.AdamW(parameters=model.parameters(), learning_rate=scheduler)

# 准备训练
from fastNLP import Trainer, Accuracy, LoadBestModelCallback, Event
callbacks = [
    LoadBestModelCallback()  # 将在训练结束之后,加载性能最优的model
]
# 在训练特定时机加入一些操作, 不同时机能够获取到的参数不一样,可以通过Trainer.on函数的文档查看每个时机的参数
@Trainer.on(Event.on_before_backward())
def print_loss(trainer, outputs):
    if trainer.global_forward_batches % 10 == 0:  # 每10个batch打印一次loss。
        print(outputs["loss"].item())

trainer = Trainer(model=model, train_dataloader=dls['train'], optimizers=optimizer,
                  device=0, evaluate_dataloaders=dls['dev'], metrics={'acc': Accuracy()},
                  callbacks=callbacks, monitor='acc#acc',
                  # Accuracy的update()函数需要pred,target两个参数,它们实际对应的就是以下的field。
                  evaluate_output_mapping={'logits': 'pred'},
                  evaluate_input_mapping={'labels': 'target'}
                  )
trainer.run()

# 在测试集合上进行评测
from fastNLP import Evaluator
evaluator = Evaluator(model=model, dataloaders=dls['test'], metrics={'acc': Accuracy()},
                      # Accuracy的update()函数需要pred,target两个参数,它们实际对应的就是以下的field。
                      output_mapping={'logits': 'pred'},
                      input_mapping={'labels': 'target'})
evaluator.run()

更多内容可以参考如下的链接

快速入门

详细使用教程

oneflow
jittor

项目结构

fastNLP的项目结构如下:

fastNLP 开源的自然语言处理库
fastNLP.core 实现了核心功能,包括数据处理组件、训练器、测试器等
fastNLP.models 实现了一些完整的神经网络模型
fastNLP.modules 实现了用于搭建神经网络模型的诸多组件
fastNLP.embeddings 实现了将序列index转为向量序列的功能,包括读取预训练embedding等
fastNLP.io 实现了读写功能,包括数据读入与预处理,模型读写,数据与模型自动下载等

cpt's People

Contributors

fdugzc 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  avatar

cpt's Issues

CPT模型是如何预训练的?

从paper上了解到,CPT是两个decoder,但是训练时同一个inputs,有两个对应的label?还是每一个input对应一个label,然后训练时是分开训练的?谢谢

不能扩充vocab

tokenizer=BertTokenizer.from_pretrained(model_args.model_name_or_path) model=CPTForConditionalGeneration.from_pretrained(model_args.model_name_or_path)

在这两行之后, 想添加一些专有词汇, 于是我加了两行代码:
tokenizer.add_tokens(["JU","AZ"])
model.resize_token_embeddings(len(tokenizer))
之后模型就无法运行,并且一直提示报错, 请问这是什么原因呢?
麻烦解答下我的疑惑, 谢谢

CPTForConditionalGeneration使用多GPU报错

如题,在做生成任务时,使用多GPU调用该接口会出现如下报错:

RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. Since `find_unused_parameters=True` is enabled, this likely means that not all `forward` outputs participate in computing loss. You can fix this by making sure all `forward` function outputs participate in calculating loss.
If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's `forward` function. Please include the loss function and the structure of the return value of `forward` of your module when reporting this issue (e.g. list, dict, iterable).
Parameter indices which did not receive grad for rank 2: 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388

需要注意的是,一模一样的代码,我将CPTForConditionalGeneration接口换成BartForConditionalGeneration使用相应模型不会出现任何问题,请检查一下

max_position_embeddings是1024吗

我看fnlp/cpt-base里面config.json的max_position_embeddings写的1024,但实际上1024会报错,512没问题。
发现代码里用了BertModel当encoder,但是没设置对应的max_position_embeddings
手动改成1024会导致预训练参数加载不进来。
所以我的理解是config.json写错了,实际只支持512。希望能提供一版max_position_embeddings=1024的模型,和bart对齐一下

pretrain任务的环境版本

使用bart的pretrain部分code时出现了一些问题,想问一下需要以下环境版本都是多少呢?:
torch版本
cuda版本
gcc版本
非常感谢!

classification/CLUEWSC 2020数据集上效果没达到

您好,我最近在CLUEWSC 2020数据集上跑了您的代码,CPT_u (B) 、CPT_g (B) 、CPT_ug (B) 的准确率分别是87.82、86.84、85.52,而论文给的结果是91.1、87.2、89.8。请问是训练参数,数据预处理,数据集下载或者其它哪方面的问题?

encoder decoder最大位置编码不一致

Hello,我看cpt encoder部分默认使用bert模型,而config文件中的max_position_embedding仅在decoder部分生效,那encoder部分最大还是只支持512的长度,这很不合理啊。huggingface bart中encoder decoder编码长度是一直的。当前大多数seq2seq任务,除了data-to-text这种,都是encoder部分长度比decoder部分长度长很多,或者二者接近。现在decoder有1024,encoder仅有512,对下游seq2seq任务影响很大啊

why BertTokenizer is used instead of BartTokenizer?

Thank you for your nice work!

when preprocessing data, I follow your code to use BertTokenizer to load the cpt-base tokenizer. The tokenizer is load successfully, but I get the following warning message:

"""
The tokenizer class you load from this checkpoint is not the same type as the class this function is called from. It may result in unexpected tokenization.
The tokenizer class you load from this checkpoint is 'BartTokenizer'.
The class this function is called from is 'BertTokenizer'.
"""

Then I tried to use BartTokenizer to load it, but I failed.

The question is whether I should ignore the warning and still use the BertTokenizer? Thank you.

CSL摘要数据集没达到效果。

作者您好,请问CSL摘要数据集你们训练了多少epoch呢?我们复现时ROUGE指标差的有点多。可以提供下微调细节吗,万分感谢!

有关bart-base-chinese的vocab.txt文件

您好,有关你们发布在huggingface的bart-base-chinese预训练模型,词表文件vocab是否有json格式的文件?恳请请告知。
--------因为facebook的vocab文件是json格式的,而你们发布的vocab文件是txt格式的

generation/LCSTS数据集上效果没达到

您好,我最近在LCSTS数据集上跑了您的代码,结果只有rouge-L:31,论文给的结果是38左右,差很多。

数据集直接在网上下载然后处理成如下格式:

{"summarization": "可穿戴技术十大设计原则", "article": "本文总结了十个可穿戴产品的设计原则,而这些原则,同样也是笔者认为是这个行业最吸引人的地方:1.为人们解决重复性问题;2.从人开始,而不是从机器开始;3.要引起注意,但不要刻意;4.提升用户能力,而不是取代人"}

代码只修改了文件路径,其余无改动。
请问问题可能出在哪里呢?
run_gen.py中的默认超参数,是否是最优的超参数呢?

想咨询run_gen.py如何设置GPU运行?

您好!我直接运行 whj_code1/projects/CPT/finetune/generation/run_gen.py 代码,发现是用CPU运行的。我看到日志中输出了 training_args.local_ranktraining_args.devicetraining_args.n_gpu 参数,但是我发现代码中没有提供传参的位置,而且我也无法直接通过args传递这些参数。所以想咨询如何修改代码,使其能够用GPU来运行呢?

有关Decoder的层数问题

  1. CPT中使用了非对称的Encoder-Decoder,您是如何确定这两者的层数比例的,有进行过不同比例的对比试验吗?
  2. 在CPT的生成模式中,我有些担心G-Decoder的层数过小(2层)影响到生成的效果,因为深层Encoder的能力与G-Decoder的能力并不一致。也就是说,我认为G-Decoder的层数应该当更深一些,才能够根据Encoder编码的提示去推理应该生成的文字(U-Decoder不用更深是因为Encoder所做的事与其一致)(现有的生成模型的单向注意力层都相当的多)。这个问题您觉得可能会存在吗?有没有相关的实验?

CSL数据集

作者您好,请问NLG任务用的CSL数据集 train data和dev data的量级分别是多少呀,在网上看到了CSL的好几个版本,不太确定用哪个来复现论文。可以提供数据集链接嘛?非常感谢!另外CPT对我们的业务提供了很大帮助,谢谢你们的开源~

generation子任务咨询

请问是否支持 问答生成 任务呢?即从文本中提取问题答案
如果支持,该怎样修改呢?多谢

可否提供run_gen.py的bart版本?

路径下CPT/blob/master/finetune/generation/run_gen.py是CPT的版本
我自己按照这个改了一个bart版本,但是显示有很多层not used或者not initialized。
Some weights of the model checkpoint at model/bart-base-chinese were not used when initializing BartForConditionalGeneration
Some weights of BartForConditionalGeneration were not initialized
不知道这些警告是否有影响,或者能否提供一个run_gen.py的bart版本?

详细信息如下所示:

loading weights file model/bart-base-chinese/pytorch_model.bin
Some weights of the model checkpoint at model/bart-base-chinese were not used when initializing BartForConditionalGeneration: ['encoder.layers.4.fc1.bias',
 'encoder.layers.0.self_attn.k_proj.bias',
 'encoder.layers.3.fc1.bias',
 'encoder.layers.4.fc1.weight',
 'encoder.layers.1.final_layer_norm.bias',
 'encoder.layers.0.fc2.weight',
 'encoder.layers.0.self_attn.out_proj.bias',
 'encoder.layers.1.self_attn.out_proj.weight',
 'encoder.layers.3.self_attn.k_proj.bias',
 'encoder.layernorm_embedding.weight',
 'encoder.layers.1.fc2.weight',
 'encoder.layers.5.self_attn.q_proj.weight',
 'encoder.layers.5.self_attn.q_proj.bias',
 'encoder.layers.0.final_layer_norm.weight',
 'encoder.layers.1.self_attn.v_proj.weight',
 'encoder.layers.4.self_attn.out_proj.weight',
 'encoder.layers.5.self_attn_layer_norm.bias',
 'encoder.layers.0.self_attn_layer_norm.bias',
 'encoder.layers.3.self_attn.k_proj.weight',
 'encoder.embed_tokens.weight',
 'encoder.layers.1.self_attn.v_proj.bias',
 'encoder.layers.5.final_layer_norm.bias',
 'encoder.layers.1.fc1.weight',
 'encoder.layers.5.self_attn_layer_norm.weight',
 'encoder.layers.2.fc1.weight',
 'encoder.layers.0.final_layer_norm.bias',
 'encoder.layers.1.fc2.bias',
 'encoder.layers.3.self_attn.v_proj.weight',
 'encoder.layers.3.final_layer_norm.bias',
 'encoder.layers.2.fc1.bias',
 'encoder.layers.3.self_attn.q_proj.weight',
 'encoder.layers.1.final_layer_norm.weight',
 'encoder.layers.4.fc2.bias',
 'encoder.layers.4.self_attn.out_proj.bias',
 'encoder.layers.2.self_attn.q_proj.weight',
 'encoder.layers.2.final_layer_norm.weight',
 'encoder.embed_positions.weight',
 'encoder.layers.3.self_attn.out_proj.bias',
 'encoder.layers.3.fc1.weight',
 'encoder.layers.1.fc1.bias',
 'encoder.layers.0.self_attn.k_proj.weight',
 'encoder.layers.1.self_attn.k_proj.bias',
 'encoder.layers.0.fc2.bias',
 'encoder.layers.1.self_attn.k_proj.weight',
 'encoder.layers.5.self_attn.v_proj.bias',
 'encoder.layers.1.self_attn.q_proj.weight',
 'encoder.layers.2.final_layer_norm.bias',
 'encoder.layers.4.self_attn_layer_norm.weight',
 'encoder.layers.4.self_attn.v_proj.bias',
 'encoder.layers.2.self_attn_layer_norm.weight',
 'encoder.layers.0.fc1.weight',
 'encoder.layers.4.self_attn.k_proj.bias',
 'encoder.layers.0.self_attn.q_proj.bias',
 'encoder.layers.4.final_layer_norm.bias',
 'encoder.layers.0.self_attn.v_proj.weight',
 'encoder.layers.3.final_layer_norm.weight',
 'encoder.layers.5.self_attn.out_proj.weight',
 'encoder.layers.4.self_attn.q_proj.weight',
 'encoder.layers.0.self_attn_layer_norm.weight',
 'encoder.layers.5.self_attn.v_proj.weight',
 'encoder.layers.2.self_attn.v_proj.weight',
 'encoder.layers.1.self_attn.out_proj.bias',
 'encoder.layers.2.self_attn.k_proj.bias',
 'encoder.layers.2.self_attn.out_proj.weight',
 'encoder.layers.3.self_attn.v_proj.bias',
 'encoder.layers.2.self_attn.q_proj.bias',
 'encoder.layers.2.self_attn.out_proj.bias',
 'encoder.layers.3.fc2.bias',
 'encoder.layers.5.fc1.weight',
 'encoder.layernorm_embedding.bias',
 'encoder.layers.0.fc1.bias',
 'encoder.layers.3.self_attn_layer_norm.bias',
 'encoder.layers.5.self_attn.k_proj.weight',
 'encoder.layers.5.fc1.bias',
 'encoder.layers.3.fc2.weight',
 'encoder.layers.4.fc2.weight',
 'encoder.layers.0.self_attn.v_proj.bias',
 'encoder.layers.0.self_attn.q_proj.weight',
 'encoder.layers.1.self_attn.q_proj.bias',
 'encoder.layers.3.self_attn_layer_norm.weight',
 'encoder.layers.2.self_attn.k_proj.weight',
 'encoder.layers.2.self_attn.v_proj.bias',
 'encoder.layers.5.final_layer_norm.weight',
 'encoder.layers.5.self_attn.out_proj.bias',
 'encoder.layers.0.self_attn.out_proj.weight',
 'encoder.layers.5.fc2.weight',
 'encoder.layers.5.fc2.bias',
 'encoder.layers.1.self_attn_layer_norm.bias',
 'encoder.layers.4.self_attn.k_proj.weight',
 'encoder.layers.5.self_attn.k_proj.bias',
 'encoder.layers.3.self_attn.q_proj.bias',
 'encoder.layers.4.self_attn.q_proj.bias',
 'encoder.layers.1.self_attn_layer_norm.weight',
 'encoder.layers.2.self_attn_layer_norm.bias',
 'encoder.layers.4.final_layer_norm.weight',
 'encoder.layers.4.self_attn.v_proj.weight',
 'encoder.layers.2.fc2.weight',
 'encoder.layers.2.fc2.bias',
 'encoder.layers.4.self_attn_layer_norm.bias',
 'encoder.layers.3.self_attn.out_proj.weight']
- This IS expected if you are initializing BartForConditionalGeneration from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BartForConditionalGeneration from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of BartForConditionalGeneration were not initialized from the model checkpoint at model/bart-base-chinese and are newly initialized: 
['encoder.encoder.layer.1.output.dense.bias',
 'encoder.encoder.layer.3.attention.self.key.bias',
 'encoder.encoder.layer.3.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.4.attention.self.value.bias',
 'encoder.encoder.layer.2.attention.output.dense.bias',
 'encoder.encoder.layer.4.output.LayerNorm.bias',
 'encoder.encoder.layer.4.output.LayerNorm.weight',
 'encoder.encoder.layer.4.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.0.intermediate.dense.bias',
 'encoder.encoder.layer.5.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.0.output.LayerNorm.bias',
 'encoder.encoder.layer.5.attention.output.LayerNorm.bias',
 'encoder.encoder.layer.2.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.2.attention.self.key.weight',
 'encoder.embeddings.LayerNorm.weight',
 'encoder.encoder.layer.0.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.1.attention.self.key.bias',
 'encoder.encoder.layer.3.intermediate.dense.weight',
 'encoder.encoder.layer.5.intermediate.dense.weight',
 'encoder.encoder.layer.0.output.dense.weight',
 'encoder.encoder.layer.5.output.LayerNorm.bias',
 'encoder.encoder.layer.1.output.dense.weight',
 'encoder.encoder.layer.5.attention.self.query.weight',
 'encoder.encoder.layer.1.output.LayerNorm.weight',
 'encoder.encoder.layer.4.attention.self.key.bias',
 'encoder.encoder.layer.3.output.LayerNorm.bias',
 'encoder.encoder.layer.5.output.dense.bias',
 'encoder.encoder.layer.4.attention.self.key.weight',
 'encoder.encoder.layer.0.attention.self.key.bias',
 'encoder.encoder.layer.0.attention.self.query.weight',
 'encoder.encoder.layer.0.intermediate.dense.weight',
 'encoder.encoder.layer.3.output.LayerNorm.weight',
 'encoder.encoder.layer.3.attention.output.dense.bias',
 'encoder.encoder.layer.5.output.dense.weight',
 'encoder.embeddings.LayerNorm.bias',
 'encoder.encoder.layer.1.attention.self.value.weight',
 'encoder.encoder.layer.2.output.dense.weight',
 'encoder.encoder.layer.4.intermediate.dense.weight',
 'encoder.encoder.layer.2.attention.self.value.weight',
 'encoder.encoder.layer.0.attention.self.value.weight',
 'encoder.encoder.layer.0.attention.output.dense.bias',
 'encoder.encoder.layer.2.attention.output.LayerNorm.bias',
 'encoder.encoder.layer.3.output.dense.bias',
 'encoder.encoder.layer.5.output.LayerNorm.weight',
 'encoder.encoder.layer.5.attention.output.dense.bias',
 'encoder.encoder.layer.4.attention.self.value.weight',
 'encoder.encoder.layer.3.attention.self.query.bias',
 'encoder.encoder.layer.3.attention.self.value.weight',
 'encoder.encoder.layer.3.attention.self.key.weight',
 'encoder.encoder.layer.0.output.dense.bias',
 'encoder.encoder.layer.1.intermediate.dense.bias',
 'encoder.encoder.layer.0.attention.self.query.bias',
 'encoder.encoder.layer.1.intermediate.dense.weight',
 'encoder.encoder.layer.0.attention.output.dense.weight',
 'encoder.encoder.layer.5.attention.self.value.bias',
 'encoder.embeddings.token_type_embeddings.weight',
 'encoder.encoder.layer.1.attention.output.dense.weight',
 'encoder.encoder.layer.2.attention.self.query.bias',
 'encoder.encoder.layer.2.attention.self.query.weight',
 'encoder.encoder.layer.2.attention.output.dense.weight',
 'encoder.encoder.layer.5.attention.self.query.bias',
 'encoder.embeddings.position_ids',
 'encoder.embeddings.position_embeddings.weight',
 'encoder.encoder.layer.3.attention.self.query.weight',
 'encoder.embeddings.word_embeddings.weight',
 'encoder.encoder.layer.4.output.dense.bias',
 'encoder.encoder.layer.1.attention.output.LayerNorm.weight',
 'encoder.encoder.layer.4.attention.self.query.bias',
 'encoder.encoder.layer.3.attention.self.value.bias',
 'encoder.encoder.layer.5.intermediate.dense.bias',
 'encoder.encoder.layer.1.output.LayerNorm.bias',
 'encoder.encoder.layer.3.attention.output.dense.weight',
 'encoder.encoder.layer.3.attention.output.LayerNorm.bias',
 'encoder.encoder.layer.2.output.LayerNorm.weight',
 'encoder.encoder.layer.4.attention.output.dense.weight',
 'encoder.encoder.layer.4.intermediate.dense.bias',
 'encoder.encoder.layer.2.attention.self.value.bias',
 'encoder.encoder.layer.0.attention.self.key.weight',
 'encoder.encoder.layer.1.attention.self.query.weight',
 'encoder.encoder.layer.2.intermediate.dense.bias',
 'encoder.encoder.layer.2.intermediate.dense.weight',
 'encoder.encoder.layer.5.attention.self.key.bias',
 'encoder.encoder.layer.2.attention.self.key.bias',
 'encoder.encoder.layer.2.output.LayerNorm.bias',
 'encoder.encoder.layer.5.attention.self.key.weight',
 'encoder.encoder.layer.0.attention.output.LayerNorm.bias',
 'encoder.encoder.layer.5.attention.self.value.weight',
 'encoder.encoder.layer.4.attention.output.dense.bias',
 'encoder.encoder.layer.1.attention.output.LayerNorm.bias',
 'encoder.encoder.layer.1.attention.output.dense.bias',
 'encoder.encoder.layer.5.attention.output.dense.weight',
 'encoder.encoder.layer.4.output.dense.weight',
 'encoder.encoder.layer.0.attention.self.value.bias',
 'encoder.encoder.layer.1.attention.self.value.bias',
 'encoder.encoder.layer.0.output.LayerNorm.weight',
 'encoder.encoder.layer.1.attention.self.key.weight',
 'encoder.encoder.layer.3.intermediate.dense.bias',
 'encoder.encoder.layer.1.attention.self.query.bias',
 'encoder.encoder.layer.4.attention.self.query.weight',
 'encoder.encoder.layer.3.output.dense.weight',
 'encoder.encoder.layer.2.output.dense.bias',
 'encoder.encoder.layer.4.attention.output.LayerNorm.bias']

index out of range in self

做生成任务时,将CPT换成bart后,在torch.embedding()时报错:index out of range in self

Hardware and computing cost

Could you tell the hardware you pre-trained the CPT and BART-chinese? And how long does it take to pre-train these models?

Thanks~

模型预测输出

生成代码,模型不能单纯的进行预测吗?我把--do_train去掉,模型输出乱七八糟

How to get BLEU4 larger than 30 with BART-large in Adgen ?

您好,
想咨询您提供的BART模型是如何达到30以上的BLEU值,是将所有输入包括title、feature序列化之后直接输入encoder,desc在decoder端么?还是做了什么特殊处理。我用BART只能到10左右的BLEU,感谢回复。

token_type_ids问题

为什么在encoder端没有看到token_type_ids的传递呢,如果要做句子对分类问题我需重新修改源码啊?而且,CPTModel类里面encoder token_type_ids默认为什么给1啊?

token_type_ids=torch.ones_like(input_ids),

用huggingface代码直接进行BART large fineturning出现繁体字

以下为训练集的数据,训练了1000epoch,可以看到不仅预算变成了預算(繁简),而且A=SM变成了a=sm(大小写),也就是连训练集都没有拟合,训练过程loss是接近于0的

生成: 题目:《sm公司全面预算管理问题研究》,句式:a,其中a=sm公园公司的全面預算管辖问题探究
label: 题目:《SM 公司全面预算管理问题研究》,句式:A,其中A=SM 公司全面预算管理问题研究

想问下可能的原因

生成任务的数据

您好,官网上下载的数据格式和模型需要的输入不一致,麻烦您可以也发一下代码能接收的csl和adgen的数据吗?十分感谢~

Originally posted by @fdugzc in #13 (comment)

单个推理脚本

hi,

我已经复线了finetune和评估模块. 想请教一下, 如果有单挑数据做摘要任务,如何做推理呢?

我试着使用huggingface社区提供的范例代码部署sagemaker endpoint脚本, 推理失败了.

Why g-dec will inflect the performance of u-dec?

I am using the u-dec to perform a sequence labeling task. I found the code has to run the g-dec pass. Then I manually skip the g-dec pass since I do not need it. However, the performance of u-dec seems changed. From my understanding, they should be independent, right? Are there any thoughts about this problem? Thank you.

ner模型的问题

按照您提供的运行指令
python -m torch.distributed.launch --nproc_per_node 1 --nnodes 1
train_msra.py
--ptm_name fnlp/cpt-base
--dataset ''
--use_decoder 0
--batch_size 16
--update_every 1
运行以后,会报如下错误:
RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel, and by
making sure all forward function outputs participate in calculating loss.

生成相关问题

我使用bart-base-chinese做生成,编码器输入原始文本,解码器的输入和输出为目标文本偏移,也即是预测下一个token,但是生成的结果全是一个字,请问什么原因造成的呢

run_mrc.py中只有model_type==bert时的代码

在下游任务run_mrc.py中只有model_type为Bert时的代码,readme.md里给的例子是model_type=cpt-base,这里是代码少写了吗?

 if 'bert' == args.model_type:
      if 'large' in args.init_restore_dir or '24' in args.init_restore_dir:
          config_path = 'hfl/chinese-roberta-wwm-ext-large'
      else:
          config_path = 'hfl/chinese-roberta-wwm-ext'
      bert_config = BertConfig.from_pretrained(config_path)
      tokenizer = BertTokenizer.from_pretrained(config_path)
      bert_config.hidden_dropout_prob = args.dropout
      bert_config.attention_probs_dropout_prob = args.dropout
      if 'arch' in args.init_restore_dir:
          config = CPTConfig.from_pretrained(args.init_restore_dir)
          config.cls_mode = args.cls_mode
          config.attention_dropout = args.dropout
          config.activation_dropout = args.dropout
          config.dropout = args.dropout
          print(config)
          model = CPTForQuestionAnswering.from_pretrained(args.init_restore_dir, config=config)
      else:
          model_path = args.init_restore_dir
          model = BertForQuestionAnswering.from_pretrained(model_path, config=bert_config)

使用自定义数据集在bart-base-chinese的继续pretrain

我想要在自己的数据集上使用Huggingface已经开源的bart-base-chinese的继续pretrain流程,但是在training.py中load_checkpoint加载模型步骤遇到了一个问题。
load_checkpoint函数中,需要得到一个tracker file,如果不存在这个文件便会有警告“will not load any checkpoints and will start from random”,但是我希望从bart-base-chinese的基础上进行pretrain,请问这个tracker file应该如何设置?以及后面torch.load是应该直接加载pytorch_model.bin吗?但是它似乎不是代码里提及的model_optim_rng.pt。

中文分词的数据问题

您好,非常感谢您的开源代码!

请问中文分词的数据需要处理成什么样子呢?从SIGHAN上下载的是txt格式的,但是代码里需要的是json格式,我也没有在README里找到样例数据。您可以提供一下处理好之后的数据,或者数据预处理的代码吗?

十分感谢~

Notes Error

fastnlp/CPT/pretrain/pretrain_cpt.py
the 16th line should be
"""Pretrain CPT"""

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.