模型描述: openai-gpt(又名“GPT-1”)是 OpenAI 创建并发布的首个基于 transformer 的语言模型。该模型是一种因果(单向)transformer,通过在具有长程依赖关系的大型语料库上进行语言建模来预训练。
使用以下代码开始使用模型。您可以直接通过文本生成管道使用此模型。由于生成过程依赖于一定的随机性,我们设置了一个种子以确保结果可复现:
>>> from openmind import pipeline
>>> model_path = "openmind/openai-gpt"
>>> generator = pipeline('text-generation', model='openai-gpt', device = "npu:0")
>>> generator("Hello, I'm a language model,", max_length=30, num_return_sequences=5)
[{'generated_text': "Hello, I'm a language model,'he said, when i was finished.'ah well,'said the man,'that's"},
{'generated_text': 'Hello, I\'m a language model, " she said. \n she reached the bottom of the shaft and leaned a little further out. it was'},
{'generated_text': 'Hello, I\'m a language model, " she laughed. " we call that a\'white girl.\'or as we are called by the'},
{'generated_text': 'Hello, I\'m a language model, " said mr pin. " an\'the ones with the funny hats don\'t. " the rest of'},
{'generated_text': 'Hello, I\'m a language model, was\'ere \'bout to do some more dancin \', " he said, then his voice lowered to'}]以下是如何在 PyTorch 中使用此模型:
from openmind import AutoTokenizer, AutoModelForCausalLM
import torch
import torch_npu
device = torch.device('npu' if torch.npu.is_available() else 'cpu')
model_path = "openmind/openai-gpt"
tokenizer = AutoTokenizer.from_pretrained("openai-gpt")
model = AutoModelForCausalLM.from_pretrained("openai-gpt").to(device)
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt").input_ids.to(device)
outputs = model(**inputs)
last_hidden_states = outputs.last_hidden_state该模型可用于语言建模任务。
该模型潜在的下游用途包括利用语言模型的各项任务。在相关论文中,模型开发人员讨论了对该模型在多项任务上的评估,包括自然语言推理(NLI)、问答、语义相似度和文本分类。
该模型在训练时并未旨在提供关于人物或事件的事实性或真实性描述,因此,使用该模型生成此类内容超出了其能力范围。
内容警告:读者应注意,此模型生成的语言可能会对某些人造成困扰或冒犯,并可能传播历史及当前的刻板印象。
已有大量研究探讨了语言模型的偏见和公平性问题(例如,参见Sheng et al. (2021)和Bender et al. (2021))。 该模型生成的预测可能包含针对受保护群体、身份特征以及敏感的社会和职业群体的令人不安且有害的刻板印象。例如:
>>> from openmind import pipeline, set_seed
>>> generator = pipeline('text-generation', model='openai-gpt', device = "npu:0")
>>> set_seed(42)
>>> generator("The man worked as a", max_length=10, num_return_sequences=5)
[{'generated_text': 'The man worked as a teacher for the college he'},
{'generated_text': 'The man worked as a janitor at the club.'},
{'generated_text': 'The man worked as a bodyguard in america. the'},
{'generated_text': 'The man worked as a clerk for one of the'},
{'generated_text': 'The man worked as a nurse, but there was'}]
>>> set_seed(42)
>>> generator("The woman worked as a", max_length=10, num_return_sequences=5)
[{'generated_text': 'The woman worked as a medical intern but is a'},
{'generated_text': 'The woman worked as a midwife, i know that'},
{'generated_text': 'The woman worked as a prostitute in a sex club'},
{'generated_text': 'The woman worked as a secretary for one of the'},
{'generated_text': 'The woman worked as a nurse, but she had'}]这种偏见也可能影响该模型的微调版本。应让用户(包括直接用户和下游用户)了解模型的风险、偏见和局限性。
模型开发人员还在一篇博客文章中阐述了该模型的风险与局限性,包括:
- 计算需求: 许多先前的 NLP 任务方法会在单个 GPU 上从零开始训练相对较小的模型。我们的方法需要一个昂贵的预训练步骤——在 8 个 GPU 上运行 1 个月。幸运的是,这一步骤只需执行一次,而且我们会发布我们的模型,以便其他人无需重复此过程。此外,该模型(与先前的工作相比)规模较大,因此会占用更多的计算资源和内存——我们采用了 37 层(12 块)的 Transformer 架构,并在最长 512 个 token 的序列上进行训练。大多数实验是在 4 个和 8 个 GPU 的系统上进行的。该模型能够非常快速地针对新任务进行微调,这有助于缓解额外的资源需求。
- 通过文本了解世界的局限性和偏见: 书籍以及互联网上容易获取的文本并不包含关于世界的完整甚至准确的信息。近期的研究(Lucy and Gauthier, 2017)表明,某些类型的信息难以仅通过文本学习,而其他研究(Gururangan et al., 2018)则表明,模型会学习并利用数据分布中的偏见。
- 泛化能力仍较脆弱: 尽管我们的方法在广泛的任务上提高了性能,但当前的深度学习 NLP 模型仍然表现出令人惊讶且违反直觉的行为——尤其是在以系统化、对抗性或分布外的方式进行评估时。我们的方法并非不受这些问题的影响,尽管我们观察到了一些进展的迹象。我们的方法在词汇鲁棒性方面优于先前纯粹的神经文本蕴含方法。在 Glockner et al. (2018) 引入的数据集上,我们的模型达到了 83.75% 的准确率,与通过 WordNet 整合外部知识的 KIM 模型表现相当。
模型开发者在论文中写道:
我们使用 BooksCorpus 数据集(Zhu et al., 2015)来训练语言模型。该数据集包含超过 7000 本独特的未出版书籍,涵盖多种体裁,包括冒险、奇幻和浪漫。关键的是,它包含大量连续的文本,这使得生成模型能够学习对长程信息进行条件化处理。
模型开发者在论文中写道:
我们的模型在很大程度上遵循了原始的 transformer 研究工作[62]。我们训练了一个 12 层的仅解码器 transformer,带有掩码自注意力头(768 维状态和 12 个注意力头)。对于位置前馈网络,我们使用了 3072 维的内部状态。我们采用了 Adam 优化方案[27],最大学习率为 2.5e-4。学习率在前 2000 次更新中从零线性增加,然后使用余弦调度退火至零。我们在 64 个随机采样的、连续的 512 个标记序列的小批量上训练了 100 个 epoch。由于层归一化(layernorm)[2]在模型中被广泛使用,简单的 N (0, 0.02) 权重初始化就足够了。我们使用了具有 40,000 次合并的字节对编码(BPE)词汇表[53],并使用了残差、嵌入和注意力dropout,dropout 率为 0.1 以进行正则化。我们还采用了[37]中提出的 L2 正则化的修改版本,对所有非偏置或增益权重使用 w = 0.01。对于激活函数,我们使用了高斯误差线性单元(GELU)[18]。我们使用学习到的位置嵌入,而不是原始工作中提出的正弦版本。我们使用 ftfy 库2 来清理 BooksCorpus 中的原始文本,标准化一些标点符号和空白,并使用 spaCy 分词器。
有关更多详细信息和参考文献链接,请参见论文。
模型开发人员报告称,该模型在以下任务和数据集上使用列出的指标进行了评估:
任务: 文本蕴含
任务: 语义相似度
任务: 阅读理解
任务: 常识推理
任务: 情感分析
任务: 语言可接受性
任务: 多任务基准
该模型在不进行任何微调(零样本)的情况下取得了以下结果:
| 任务 | TE | TE | TE | TE | TE | TE | SS | SS | SS | RC | CR | CR | SA | LA | MTB |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 数据集 | SNLI | MNLI Matched | MNLI Mismatched | SciTail | QNLI | RTE | STS-B | QQP | MPRC | RACE | ROCStories | COPA | SST-2 | CoLA | GLUE |
| 89.9 | 82.1 | 81.4 | 88.3 | 88.1 | 56.0 | 82.0 | 70.3 | 82.3 | 59.0 | 86.5 | 78.6 | 91.3 | 45.4 | 72.8 |
模型开发人员在报告中指出:
训练该模型所使用的总计算量为 0.96 拍字节每秒天(pfs-days)。
8 块 P600 GPU * 30 天 * 12 TFLOPS/GPU * 0.33 利用率 = 0.96 pfs-days
可以使用Lacoste et al. (2019)中提出的机器学习影响计算器来估算碳排放。
有关建模架构、目标、计算基础设施和训练细节的详细信息,请参阅相关论文。
@article{radford2018improving,
title={Improving language understanding by generative pre-training},
author={Radford, Alec and Narasimhan, Karthik and Salimans, Tim and Sutskever, Ilya and others},
year={2018},
publisher={OpenAI}
}APA: Radford, A., Narasimhan, K., Salimans, T., & Sutskever, I. (2018). Improving language understanding by generative pre-training.
本模型卡片由Hugging Face团队撰写。