Giter Club home page Giter Club logo

gpt2-newstitle's Introduction

我是刘聪NLP

  • 🔭 南京某创业公司,首席算法架构师
  • 🌱 研究方向:QA系统(向量检索、阅读理解)、文本生成(问题生成、对话生成、摘要生成)、预训练语言模型等
  • 💬 微信:logCong
  • 📫 问题:知乎 @刘聪NLP
  • 😄 微信公众号:公众号『 NLP工作站 』
  • 👯 希望可以多多跟大家交流,欢迎关注我的知乎,欢迎添加微信!

gpt2-newstitle's People

Contributors

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

gpt2-newstitle's Issues

输出的转换

您好请问模型的outputs怎么转换为中文文本啊

标题生成速度

我输入一段文本,运行后标题的生成速度非常非常慢,请问应该如何提高标题生成的速度呢?

关于提供的词典

利用提供的中文词典,中文数据集训练模型,训练loss及测试loss看起来正常下降,但预测出来都是英文单词,这个是哪里设置错了呢?

新vocab和预训练模型不匹配问题

楼主你好,感谢分享,代码中有个问题请教:如果加载的config和vocab对应的vocab_size=13317,但是模型预加载预训练模型,岂不是vocab_size冲突了,请问应该如何处理

model_config = GPT2Config.from_json_file(args.config_path)
if args.pretrained_model_path:
model = GPT2LMHeadModel.from_pretrained(args.pretrained_model_path)
else:
model = GPT2LMHeadModel(config=model_config)
tokenizer = BertTokenizer.from_pretrained(args.vocab_path, do_lower_case=True)

预训练模型

为什么不用预训练模型的参数呢?用预训练模型的意义不就在此吗?小白不是很懂,,,,

分享几个有趣的结果,这个用来搞笑是挺不错的!

输入的新闻正文为:参差感,或者说多元化,是今年《创造营2021》带来的一个大惊喜。学员的选角和发起人团的构成中,除了国际化这一特点外,学员们还有街舞、电竞、上班族等不同背景,发起人团成员来自影视、音乐、团体等不同领域——通过十期节目,《创造营2021》真实且深刻地呈现了不同成长背景下,多元文化、多元价值观碰撞与交流的过程。
生成的第1个标题为:“创造营2025”
生成的第2个标题为:《创造营space]营螂》真实于是什么样的?
生成的第3个标题为:学者:国际化的选角和发起人团体

神评论:GPT2新技能:预测未来!坐等创造营2025

输入的新闻正文为:从刘宇身上,能感受到的是十余年**舞学习经历中所习得的文雅;赞多和力丸两位来自日本的世界级街舞舞者,展现出强悍的舞蹈实力,但同时二人身上又始终透露着来到异国他乡的彷徨失措;从夏威夷追梦到日本、再来到**的米卡,则处处透露出对音乐的热爱,对友情的真诚。
生成的第1个标题为:**舞蹈者:用力模仿奇幻
生成的第2个标题为:大写给力量
生成的第3个标题为:刘宇之父:**的米卡

神评论:**的米卡成为了刘宇的父亲,米卡改国籍还可以收获一个儿子!

报错

我的机器是cuda=9.0 pytorch==1.2.0
然后运行过程会报错AttributeError: 'Tensor' object has no attribute 'bool'
我觉得应该是pytorch版本的问题,cuda9.0是否能安装pytorch==1.4.0
在model.py中的
mask = (token_type_ids == title_id).long()
labels = labels * mask这一段可能出现了问题,请问如何解决呢?

model.py

为适应新版本,将model.py中from transformers.modeling_gpt2 import GPT2PreTrainedModel, GPT2Model 替换为from transformers import GPT2PreTrainedModel, GPT2Model 导致生成标题时无报错退出(使用分享的模型权重
eeeee

请问作者为什么生成模型经常连自己的训练集都预测不对呢

输入的新闻正文为:2017“**最好大学排行”公布,展示了**综合实力最强的500所大学。@南京大学 @东南大学 @苏州大学 @南京航空航天大学 @南京理工大学 5所江苏高校强势入围50强。上海9校进百强20校上榜你是哪所大学毕业的?评论里或许能找到童鞋哦!
生成的第1个标题为:**最好大学排行榜:江苏第一 南京高校进入500强
生成的第2个标题为:最强的500强! 南京大学排名第20
生成的第3个标题为:2017**最好大学排行榜公布:南航天高校上榜
训练集标题: "2017年**大学500强公布:5所江苏高校进50强"

python version?

i'm in trouble in installing gevent package, could you please share your python version? thanks very much!

摘要生成

你好,请问一键生成摘要是怎么做的?,为什么运行不起呢

你好,请问ModuleNotFoundError: No module named 'transformers.modeling_gpt2'

出现一下错误怎么解决呢

Traceback (most recent call last):
File "E:\py\gpt1\generate_title.py", line 15, in
from model import GPT2LMHeadModel
File "E:\py\gpt1\model.py", line 14, in
from transformers.modeling_gpt2 import GPT2PreTrainedModel, GPT2Model
ModuleNotFoundError: No module named 'transformers.modeling_gpt2'

是不是会出现 len(title_tokens) > self.max_len 的情况,这样会引起下面的 assert错误?

def convert_feature(self, sample):
...
input_ids = []
token_type_ids = []
# 对新闻正文进行tokenizer.tokenize分词
content_tokens = self.tokenizer.tokenize(sample["content"])
# 对新闻标题进行tokenizer.tokenize分词,注意tokenizer中已经将[Space]作为一个分隔符,不会切割成多个字符
title_tokens = self.tokenizer.tokenize(sample["title"].replace(" ", "[Space]"))
# 判断如果正文过长,进行截断
if len(content_tokens) > self.max_len - len(title_tokens) - 3:
content_tokens = content_tokens[:self.max_len - len(title_tokens) - 3]
...


是不是会出现 len(title_tokens) > self.max_len 的情况,这样会引起下面的 assert错误?

每次生成的标题不一样

作者您好,请问为什么每次生成的标题都不一样呀,有什么办法可以使得生成的标题是一致的吗(我把源代码中生成三个标题改成了只生成一个)

generate_title生成标题,出现错误

wandb: WARNING W&B installed but not logged in. Run wandb login or set the WANDB_API_KEY env variable.
Calling BertTokenizer.from_pretrained() with the path to a single file or url is deprecated
Traceback (most recent call last):
File "generate_title.py", line 210, in
generate_title_GPT2("澳大利亚新闻直播:拜登说普京在乌克兰“背靠墙”;**东方航空公司坠机调查不排除“犯规”")
File "generate_title.py", line 198, in generate_title_GPT2
model = GPT2LMHeadModel.from_pretrained(args.model_path)
File "/home/user/anaconda3/envs/image_text_match_tf_1.15/lib/python3.6/site-packages/transformers/modeling_utils.py", line 672, in from_pretrained
model = cls(config, *model_args, **model_kwargs)
File "/home/user/wjy/Jiagu-master/标题生成/GPT2-NewsTitle-main/model.py", line 26, in init
super(GPT2LMHeadModel).init(config)
TypeError: super() argument 1 must be type, not GPT2Config

#关于BertTokenizer.from_pretrained()函数的一些问题

大佬,请问一下,在文件的实例化tokenizer和model下面的函数
image
这个图里面问题怎么解决
/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py:1656: FutureWarning: Calling BertTokenizer.from_pretrained() with the path to a single file or url is deprecated and won't be possible anymore in v5. Use a model identifier or the path to a directory instead.
FutureWarning,
load model ending!
我在本地运行python http_server.py是没有出现这个问题的,我根据提示将tokenizer = BertTokenizer.from_pretrained(args.vocab_path, do_lower_case=True)改为
tokenizer = BertTokenizer.from_pretrained('vocab/vocab.txt') do_lower_case=True 结果还是一样的结果 改为tokenizer = BertTokenizer.from_pretrained('vocab/vocab.txt')也不正确 改为tokenizer = BertTokenizer.from_pretrained('/cx/GPT2-NewsTitle-main/vocab/vocab.txt')`结果都是一样的,运行代码没有出现网页,求教

想问问这是不是严格意义的GPT模型,个人感觉更像是类似于UniLM的Seq2Seq

感谢您的工作,因为初学所以对一些概念会比较抠字眼想搞明白,大佬见谅哈哈。您在模型优化时只计算了标题的loss,那么优化的就是P(标题|正文),一种条件概率,感觉这是一种seq2seq呀(有条件的语言模型),transformer同时作为了编码器和解码器,就和UniLM一样的**,只是正文和标题您这里都用的GPT的单向注意力,而UniLM正文用双向,标题用单向。如果是严格意义的GPT,我的理解是无条件的语言模型,建模的是P(Y),而不是P(Y|X),会完整地“自己预测自己”,比如将正文标题拼接后作为一个完整的文本,然后错开一位,完整自己预测自己,当然这样的实现没有显式区分二者边界也不太适合实现标题生成,不知我的理解是否有误,谢谢大佬

使用pad_sequence了,是不是就不需要在上面extend了?

def collate_func(batch_data):
"""
DataLoader所需的collate_fun函数,将数据处理成tensor形式
Args:
batch_data: batch数据
Returns:
"""
batch_size = len(batch_data)
# 如果batch_size为0,则返回一个空字典
if batch_size == 0:
return {}
input_ids_list, token_type_ids_list = [], []
# 获取一个batch数据中的最大长度
max_len = max([len(instance["input_ids"]) for instance in batch_data])
for instance in batch_data:
# 按照batch中的最大数据长度,对数据进行padding填充
input_ids_temp = instance["input_ids"]
input_ids_temp.extend([0]*(max_len-len(instance["input_ids"])))
token_type_ids_temp = instance["token_type_ids"]
token_type_ids_temp.extend([0] * (max_len - len(instance["token_type_ids"])))
# 将list数据转换为tensor数据
# input_ids_list.append(torch.from_numpy(np.array(input_ids_temp, dtype=np.int32)).long())
# token_type_ids_list.append(torch.from_numpy(np.array(token_type_ids_temp, dtype=np.int32)).long())
input_ids_list.append(torch.tensor(input_ids_temp, dtype=torch.long))
token_type_ids_list.append(torch.tensor(token_type_ids_temp, dtype=torch.long))
return {"input_ids": pad_sequence(input_ids_list, batch_first=True, padding_value=0),
"token_type_ids": pad_sequence(token_type_ids_list, batch_first=True, padding_value=0)}

这个使用pad_sequence了,是不是就不需要在上面extend了?

关于使用长文本数据集训练的问题

大佬你好,我是纯小白,项目很好,已经star.我所使用的数据集的content的字数普遍在2k字到4k字,那么我在训练时候是否要把config.json 的n_ctx和train.py中的max__len从512改到47k呢?如果需要该,改到4096就会报这个错:
image
又该如何解决?谢谢大佬。

vocab

请问一下不是说tokennizer里面会包含有这个模型所用的词表嘛?还是说做中文的文本生成,都要自己添加词表

checkpoint接着训练问题

您好:

我想使用您在百度云上传的checkpoint接着往后训练几轮,但是报了一个警告好像是因为lr scheduler造成的。UserWarning: To get the last learning rate computed by the scheduler, please use get_last_lr(). warnings.warn("To get the last learning rate computed by the scheduler, " 跳过了第一轮epoch。

想向您请教如何解决这个问题?

非常感谢!

请问下具体配置,在实践代码过程中出现了Segmentation fault (core dumped)问题

您好,想请问下您的具体配置,主要是版本问题,谢谢。
我的情况是,已经按照您给出的requirements进行了预装,其他环境如下:
Python 3.7.6, CUDA 10.0,Tensorflow-gpu 2.0.0, Keras 2.3.1, Pytorch 1.3.1, cudNN 7.6
NVIDIA GeForce RTX 2080 Ti (矩池云)
在进行train.py时出现了Segmentation fault (core dumped)报错,无log文件也无具体报错信息。查询之后发现与TensorFlow等包的版本有关,想麻烦您share下更具体的信息,谢谢!

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.