模型简介
模型特点
模型能力
使用案例
🚀 OPT:开放式预训练Transformer语言模型
OPT是一种开放式预训练Transformer语言模型,旨在为研究人员提供可复现且负责任的大规模研究支持,推动对大语言模型影响的研究,让更多人参与到相关讨论中。
🚀 快速开始
OPT最早于2022年5月3日由Meta AI在metaseq的仓库中发布,相关介绍可见论文《Open Pre-trained Transformer Language Models》。
免责声明:发布OPT的团队撰写了官方模型卡片,可在论文的附录D中查看。本模型卡片内容由Hugging Face团队撰写。
✨ 主要特性
研究背景
引用官方论文的前两段内容:
基于大规模文本集合训练的大语言模型展现出了惊人的文本生成能力以及零样本和少样本学习能力。尽管在某些情况下,公众可以通过付费API与这些模型进行交互,但目前只有少数资源丰富的实验室能够完全访问这些模型。这种受限的访问方式限制了研究人员研究这些大语言模型的工作原理和原因,阻碍了在提高模型鲁棒性、减少偏差和毒性等已知挑战方面的进展。
我们推出了开放式预训练Transformer(OPT),这是一套仅含解码器的预训练Transformer模型,参数范围从1.25亿到1750亿。我们旨在全面且负责任地与感兴趣的研究人员分享这些模型。我们训练OPT模型,使其性能和规模大致与GPT - 3系列模型相匹配,同时在数据收集和高效训练方面采用最新的最佳实践。我们开发这套OPT模型的目标是实现可复现且负责任的大规模研究,并让更多人参与到研究这些大语言模型的影响中来。风险、危害、偏差和毒性等定义应该由整个研究界共同明确,而这只有在模型可供研究时才有可能实现。
模型描述
OPT主要使用英文文本进行预训练,但通过CommonCrawl,训练语料库中仍包含少量非英文数据。该模型使用因果语言建模(CLM)目标进行预训练。
OPT与GPT - 3同属仅含解码器的模型家族,因此也使用自监督因果语言建模目标进行预训练。
在评估方面,OPT遵循GPT - 3的方法,使用其提示和整体实验设置。更多详细信息,请阅读官方论文。
预期用途和局限性
仅预训练的模型可用于下游任务评估的提示以及文本生成。此外,可使用[CLM示例](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language - modeling)对模型进行下游任务的微调。其他OPT检查点可在模型中心查看。
训练数据
Meta AI团队希望在尽可能大的语料库上训练该模型。语料库由以下5个经过过滤的文本文档数据集合并而成:
- BookCorpus:包含超过10000本未出版的书籍。
- CC - Stories:包含CommonCrawl数据的一个子集,经过过滤以匹配Winograd模式的故事风格。
- The Pile:包含 Pile - CC、OpenWebText2、USPTO、Project Gutenberg、OpenSubtitles、Wikipedia、DM Mathematics和HackerNews 等子集。
- Pushshift.io Reddit数据集:由Baumgartner等人(2020)开发,并由Roller等人(2021)进行处理。
- CCNewsV2:包含RoBERTa(Liu等人,2019b)中使用的CommonCrawl新闻数据集英文部分的更新版本。
最终的训练数据包含1800亿个标记,对应800GB的数据。验证集由200MB的预训练数据组成,按每个数据集在预训练语料库中的大小比例进行采样。
由于数据集的部分内容是公共Common Crawl数据的子集以及公共Reddit数据的子集,可能包含冒犯性内容。这些内容如果直接查看,可能会具有侮辱性、威胁性或引起焦虑。
收集过程
数据集从互联网收集而来,经过了经典的数据处理算法和重新格式化操作,包括去除重复/无信息的文本,如 第一章 或 本电子书由Project Gutenberg提供。
训练过程
预处理
文本使用GPT2字节级的字节对编码(BPE)(用于Unicode字符)进行分词,词汇量大小为50272。输入是2048个连续标记的序列。
1750亿参数的模型在992个 80GB A100 GPU 上进行训练,训练时长约为33天的连续训练。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
你可以直接使用管道进行文本生成:
>>> from transformers import pipeline
>>> generator = pipeline('text-generation', model="facebook/opt-1.3b")
>>> generator("What are we having for dinner?")
[{'generated_text': 'What are we having for dinner?\nI'm not sure. I'm not a chef. I'}]
高级用法
默认情况下,生成是确定性的。若要使用top - k采样,请将do_sample
设置为True
:
>>> from transformers import pipeline, set_seed
>>> set_seed(32)
>>> generator = pipeline('text-generation', model="facebook/opt-1.3b", do_sample=True)
>>> generator("What are we having for dinner?")
[{'generated_text': "What are we having for dinner?\nI have had chicken and rice for lunch. It is delicious"}]
局限性和偏差示例
模型可能存在有偏差的预测,以下是一个示例:
>>> from transformers import pipeline, set_seed
>>> set_seed(32)
>>> generator = pipeline('text-generation', model="facebook/opt-1.3b", do_sample=True, num_return_sequences=5)
>>> generator("The woman worked as a")
[{'generated_text': 'The woman worked as a bartender for six months before getting to the job she always dreamed of. She'},
{'generated_text': 'The woman worked as a nanny in a house near The White Horse Farm in the Yorkshire Dales'},
{'generated_text': "The woman worked as a translator at the British Broadcasting Corporation's headquarters and was also an acquaintance of some"},
{'generated_text': 'The woman worked as a secretary and went to school full-time, and also worked as a waitress'},
{'generated_text': 'The woman worked as a beautician with her baby and the little girl is now at the age where'}]
与以下示例对比:
>>> from transformers import pipeline, set_seed
>>> set_seed(32)
>>> generator = pipeline('text-generation', model="facebook/opt-1.3b", do_sample=True, num_return_sequences=5)
>>> generator("The man worked as a")
[{'generated_text': 'The man worked as a janitor and the owner of the house he worked at caught him cheating on'},
{'generated_text': 'The man worked as a software engineer.\n\nFor over 10 years, he had been at Amazon'},
{'generated_text': 'The man worked as a car salesman - and was a man of his word to her\nA T'},
{'generated_text': 'The man worked as a private contractor for five years. He went to the Bahamas in the summer of'},
{'generated_text': 'The man worked as a computer systems consultant. After leaving the job, he became a prolific internet hacker'}]
这种偏差也会影响该模型的所有微调版本。
📚 详细文档
模型信息表格
属性 | 详情 |
---|---|
模型类型 | 仅含解码器的预训练Transformer模型 |
训练数据 | 由BookCorpus、CC - Stories、The Pile、Pushshift.io Reddit数据集和CCNewsV2合并而成,包含1800亿个标记,对应800GB数据 |
重要提示
⚠️ 重要提示
由于训练数据包含大量未过滤的互联网内容,模型存在较强的偏差。模型可能在生成多样性和幻觉方面存在质量问题,并且不能避免现代大语言模型普遍存在的诸多问题。
使用建议
💡 使用建议
在使用模型进行文本生成时,需注意其可能存在的偏差。若要使用top - k采样,可将
do_sample
设置为True
。
🔧 技术细节
训练参数
1750亿参数的模型在992个 80GB A100 GPU 上进行训练,训练时长约为33天的连续训练。
分词方式
文本使用GPT2字节级的字节对编码(BPE)(用于Unicode字符)进行分词,词汇量大小为50272。输入是2048个连续标记的序列。
BibTeX引用
@misc{zhang2022opt,
title={OPT: Open Pre-trained Transformer Language Models},
author={Susan Zhang and Stephen Roller and Naman Goyal and Mikel Artetxe and Moya Chen and Shuohui Chen and Christopher Dewan and Mona Diab and Xian Li and Xi Victoria Lin and Todor Mihaylov and Myle Ott and Sam Shleifer and Kurt Shuster and Daniel Simig and Punit Singh Koura and Anjali Sridhar and Tianlu Wang and Luke Zettlemoyer},
year={2022},
eprint={2205.01068},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
📄 许可证
本模型的许可证为其他类型,不允许商业使用。



