问题标签 [gpt-2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
118 浏览

python - GPT-2 的 encoder.py 和 train.py 不工作

我正在尝试训练 GPT-2 使用我在文本文件 napoleon.txt 中提供的内容。当我运行编码器时,它似乎可以在命令提示符下工作。

然而,它实际上并没有创建 napoleon.npz。但这只是问题的一部分。更大的问题是 train.py,我训练 GPT-2 真正需要的,每次都会吐出一个错误。

我已经尝试了我在互联网上找到的所有我能想到的解决方案,但我被困住了。请帮忙

0 投票
0 回答
16 浏览

github - 了解存储库 gpt 转换器

对于我的项目,我需要了解并能够使用 GPT 转换器语言模型执行有关常识生成的这个github 存储库。它非常广泛,我没有足够的编程经验来理解这一切。有没有人擅长这些科目可以指导我/帮助我?

或者,还有其他地方我可以发布这个问题吗?

0 投票
1 回答
2098 浏览

tokenize - AttributeError:“GPT2TokenizerFast”对象没有属性“max_len”

我只是在使用 huggingface 转换器库并在运行 run_lm_finetuning.py 时收到以下消息: AttributeError: 'GPT2TokenizerFast' object has no attribute 'max_len'。其他人有这个问题或想法如何解决它?谢谢!

我的完整实验运行:mkdir Experiments

对于 5 中的 epoch,python run_lm_finetuning.py
--model_name_or_path distilgpt2
--model_type gpt2 --train_data_file small_dataset_train_preprocessed.txt --output_dir
Experiments
/epochs_$epoch
--do_train
--overwrite_output_dir
--per_device_train_batch_size 4
--num_train_epochs $epoch done

0 投票
1 回答
218 浏览

python - 使用 beam_search(huggingface 库)生成文本时出现不匹配的张量大小错误

我正在使用 huggingface 库使用预训练的 distilgpt2 模型生成文本。特别是,我正在使用beam_search函数,因为我想包含一个 LogitsProcessorList (不能与generate函数一起使用)。

我的代码的相关部分如下所示:

但是,当我尝试使用小于 20 的 max_length 生成时,beam_search 函数会引发此错误:

我似乎无法弄清楚 20 来自哪里:即使输入长度更长或更短,即使我使用不同的批量大小或光束数量,它也是一样的。我没有将任何内容定义为长度 20,也找不到任何默认值。序列的最大长度确实会影响光束搜索的结果,所以我想弄清楚这一点并能够设置更短的最大长度。

0 投票
1 回答
158 浏览

huggingface-transformers - 使用/指定 attention_mask 使用 Trainer 和 TrainingArguments 训练 GPT2

我正在使用 Trainer & TrainingArguments 来训练 GPT2 模型,但这似乎效果不佳。

我的数据集包含我的语料库标记的 ID 和每个文本的掩码,以指示在何处应用注意力:

我正在使用 Trainer & TrainingArguments 进行培训,传递我的模型和我以前的数据集,如下所示。但是我没有在任何地方指定关于 attention_mask 的任何内容:

我应该如何告诉 Trainer 使用此功能(attention_mask)?如果您查看文件 /transformers/trainer.py ,则没有提及“注意”或“掩码”。

提前致谢!

0 投票
1 回答
163 浏览

python - 了解 gpt-2 如何标记字符串

在这里使用教程,我编写了以下代码:

所以我意识到“输入”由我句子的标记化项目组成。但是我怎样才能得到标记化项目的值呢?(参见例如 ["hello", ",", "my", "dog", "is", "cute"])

我问这个是因为有时我认为如果该词不在其字典中(即,来自另一种语言的词),它会分隔一个词。所以我想在我的代码中检查一下。

0 投票
1 回答
40 浏览

huggingface-transformers - 是否有“未经训练”的 gpt 模型文件夹?

可能是疯狂的问题:但我想下载 gpt-2 模型框架,但我希望权重随机初始化。因此,就好像模型仍然需要在 reddit 内容(包括 json、词汇、元和索引文件等)上进行微调。这可能吗?

亲切的问候!

0 投票
0 回答
174 浏览

nlp - fill-mask usage from transformers pipeline

I fine-tune a gpt2 language model and I am generation the text according to my model by using following lines of code:

generator = pipeline('text-generation', tokenizer='gpt2', model='data/out') print(generator('Once upon a time', max_length=40)[0]['generated_text'])

Now I want to do the prediction of only next word with the probabilities. I know we can do it by using 'fill-mask' but I don't know how to do it. When I put 'fill-mask' inplace of 'text-generation', I am getting this error:

"Unrecognized configuration class <class 'transformers.models.gpt2.configuration_gpt2.GPT2Config'> for this kind of AutoModel: AutoModelForMaskedLM. Model type should be one of BigBirdConfig, Wav2Vec2Config, ConvBertConfig, LayoutLMConfig, DistilBertConfig, AlbertConfig, BartConfig, MBartConfig, CamembertConfig, XLMRobertaConfig, LongformerConfig, RobertaConfig, SqueezeBertConfig, BertConfig, MobileBertConfig, FlaubertConfig, XLMConfig, ElectraConfig, ReformerConfig, FunnelConfig, MPNetConfig, TapasConfig, DebertaConfig, DebertaV2Config, IBertConfig.".

generator = pipeline('fill-mask', tokenizer='gpt2', model='data/out') // this line is giving me the above mentioned error.

Please let me know how can I fix this issue. Any kind of help would be greatly appreciated. Thanks in advance.

The whole code for better understanding.

from transformers import ( GPT2Tokenizer, DataCollatorForLanguageModeling, TextDataset, GPT2LMHeadModel, TrainingArguments, Trainer, pipeline)

train_path = 'parsed_data.txt' test_path = 'parsed_data.txt'

tokenizer = GPT2Tokenizer.from_pretrained("gpt2")

data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)

train_dataset = TextDataset(tokenizer=tokenizer, file_path=train_path, block_size=128) test_dataset = TextDataset(tokenizer=tokenizer, file_path=test_path, block_size=128)

model = GPT2LMHeadModel.from_pretrained('gpt2')

training_args = TrainingArguments(output_dir = 'data/out', overwrite_output_dir = True, per_device_train_batch_size = 32, per_device_eval_batch_size = 32, learning_rate = 5e-5, num_train_epochs = 3,)

trainer = Trainer(model = model, args = training_args, data_collator=data_collator, train_dataset = train_dataset, eval_dataset = test_dataset)

trainer.train()

trainer.save_model() generator = pipeline('fill-mask', tokenizer='gpt2', model='data/out')

0 投票
0 回答
44 浏览

pytorch - 一些批次后的 Pytorch 推断 OOM

我正在尝试在大型数据集(26k 个样本)上使用类似 GPT2 的模型进行推理。为了加快速度,我想分批进行,但是尝试这样做后,它会在一些批次后进入 Cuda OOM。它仅在某些批次后才消失的事实对我来说听起来很奇怪,因为我认为内存使用在不同批次中应该或多或少保持不变。这是我的代码:

可能是什么问题呢?

0 投票
0 回答
92 浏览

nlp - 如何使用未标记数据微调 GPT2 语言模型

我正在使用 GPT2 创建一个语言模型(即下一个单词预测器)。我已关注此博客https://www.analyticsvidhya.com/blog/2019/08/comprehensive-guide-language-model-nlp-python-code/ 并使用此代码创建语言模型。

现在我想知道如何微调模型或进行迁移学习以在我自己的数据集上训练模型。我有一个与药物和医疗保健相关的数据集。所以,我希望我的模型根据我的数据集进行下一个单词预测。

希望你明白我想做什么。任何形式的帮助将不胜感激。提前致谢。