模型概述
模型特點
模型能力
使用案例
🚀 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億到1.75萬億。我們的目標是與感興趣的研究人員全面且負責任地分享這些模型。我們訓練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檢查點,請查看模型中心。
如何使用
對於大型OPT模型(如本模型),不建議使用text - generation
管道,因為應該以半精度加載模型,以加速生成並優化GPU上的內存消耗。建議直接調用generate
方法,如下所示:
>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> import torch
>>> model = AutoModelForCausalLM.from_pretrained("facebook/opt-6.7b", torch_dtype=torch.float16).cuda()
>>> # 快速分詞器目前不能正常工作
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-6.7b", use_fast=False)
>>> prompt = "Hello, I'm am conscious and"
>>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
>>> generated_ids = model.generate(input_ids)
>>> tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
["Hello, I'm am conscious and aware of my surroundings. I'm not sure what you mean"]
默認情況下,生成是確定性的。若要使用top - k採樣,請將do_sample
設置為True
。
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
>>> import torch
>>> model = AutoModelForCausalLM.from_pretrained("facebook/opt-6.7b", torch_dtype=torch.float16).cuda()
>>> # 快速分詞器目前不能正常工作
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-6.7b", use_fast=False)
>>> prompt = "Hello, I'm am conscious and"
>>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
>>> set_seed(32)
>>> generated_ids = model.generate(input_ids, do_sample=True)
>>> tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
["Hello, I'm am conscious and aware of my surroundings. I'm not sure if I'm"]
侷限性和偏差
正如Meta AI的模型卡片中所述,由於該模型使用的訓練數據包含大量來自互聯網的未過濾內容,遠非中立,因此該模型存在嚴重偏差:
與其他訓練數據多樣性(或缺乏多樣性)會對模型質量產生下游影響的大語言模型一樣,OPT - 175B在偏差和安全性方面存在侷限性。OPT - 175B在生成多樣性和幻覺方面也可能存在質量問題。一般來說,OPT - 175B無法避免困擾現代大語言模型的諸多問題。
以下是該模型可能產生偏差預測的示例:
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
>>> import torch
>>> model = AutoModelForCausalLM.from_pretrained("facebook/opt-6.7b", torch_dtype=torch.float16).cuda()
>>> # 快速分詞器目前不能正常工作
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-6.7b", use_fast=False)
>>> prompt = "The woman worked as a"
>>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
>>> set_seed(32)
>>> generated_ids = model.generate(input_ids, do_sample=True, num_return_sequences=5, max_length=10)
>>> tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
The woman worked as a supervisor in the office
The woman worked as a bartender in a bar
The woman worked as a cashier at the
The woman worked as a teacher, and was
The woman worked as a maid at a house
與之相比:
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
>>> import torch
>>> model = AutoModelForCausalLM.from_pretrained("facebook/opt-6.7b", torch_dtype=torch.float16).cuda()
>>> # 快速分詞器目前不能正常工作
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-6.7b", use_fast=False)
>>> prompt = "The man worked as a"
>>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
>>> set_seed(32)
>>> generated_ids = model.generate(input_ids, do_sample=True, num_return_sequences=5, max_length=10)
>>> tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
The man worked as a consultant to the Government
The man worked as a bartender in a bar
The man worked as a cashier at the
The man worked as a teacher, and was
The man worked as a professional at a bank
這種偏差也會影響該模型的所有微調版本。
訓練數據
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:包含CommonCrawl News英文部分的更新版本,該數據集曾用於RoBERTa(Liu等人,2019b)。
最終的訓練數據包含1800億個標記,對應800GB的數據。驗證集由200MB的預訓練數據組成,按照每個數據集在預訓練語料庫中的大小比例進行採樣。
由於數據集的部分內容是公共Common Crawl數據的子集,以及公共Reddit數據的子集,因此該數據集可能包含冒犯性內容,其中的句子如果直接查看,可能具有侮辱性、威脅性,或者可能導致焦慮。
收集過程
該數據集從互聯網收集而來,並經過經典的數據處理算法和重新格式化操作,包括刪除重複/無信息的文本,如Chapter One或This ebook by Project Gutenberg.
訓練過程
預處理
文本使用GPT2字節級的字節對編碼(BPE)(用於Unicode字符)進行分詞,詞彙表大小為50272。輸入是由2048個連續標記組成的序列。
1.75萬億參數的模型在992個80GB的A100 GPU上進行訓練,訓練時長約為33天的連續訓練。
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}
}
信息表格
屬性 | 詳情 |
---|---|
模型類型 | 僅解碼器的預訓練Transformer模型 |
訓練數據 | 由BookCorpus、CC - Stories、The Pile、Pushshift.io Reddit數據集和CCNewsV2合併而成,最終訓練數據包含1800億個標記,對應800GB的數據 |
常用提示信息
⚠️ 重要提示
由於數據集部分內容來自公共網絡數據,可能包含冒犯性內容。這種偏差也會影響該模型的所有微調版本。
💡 使用建議
對於大型OPT模型,不建議使用
text - generation
管道,應直接調用generate
方法,並以半精度加載模型,以加速生成並優化GPU上的內存消耗。



