Datawhale干貨 作者:王奧迪,單位:中國移動云能力中心 2022年下半年開始,涌現出一大批“大模型”的優秀應用,其中比較出圈的當屬AI作畫與ChatGPT,刷爆了各類社交平臺,其讓人驚艷的效果,讓AI以一個鮮明的姿態,站到了廣大民眾面前,讓不懂AI的人也能直觀地體會到AI的強大。大模型即大規模預訓練模型,本文就和大家聊一聊 預訓練模型的起源與發展。 1. 前言圖1 NLP模型開發領域的標準范式“pretrain finetune” 近年來,由于預訓練模型(Pretrained Models, PTMs)的蓬勃發展,“預訓練(pretrain) 微調(finetune)”成為了AI模型開發領域的標準范式。預訓練模型的作用可想而知,它極大推進了AI的落地,讓AI模型的開發從手工作坊模式走向工廠模式,快速適應AI市場的定制化需求。但它絕非一個空降神器,預訓練的研究最早起源于遷移學習。遷移學習的核心思想,即運用已有的知識來學習新的知識,通俗來說就是將一個預訓練的模型被重新用在另一個任務中。早期的預訓練模型主要基于有標簽數據,預訓練模型的第一個浪潮發生在CV領域,得益于ImageNet[1]數據集中所富含的強大的視覺信息,其包含了上百萬張上千種類別的圖片,覆蓋了日常生活中的各種物體,在ImageNet上預訓練的模型(比如ResNet50)廣泛應用于圖像領域的各個下游任務,均取得了卓越的進展。而在NLP領域,由于下游任務的多樣性以及數據標注的復雜性,導致無法獲得一個像ImageNet這樣大規模的有標簽數據,所以NLP領域嘗試使用自監督學習的方法來獲取預訓練模型,自監督學習的主要思想就是利用文本間的內在聯系為監督信號。通過自我監督學習,可以利用大量未標記的文本數據來捕獲通用的語言知識。早期NLP領域的NLP模型主要是詞嵌入(word embedding)的研究,比如word2Vec[2],Glove[3]等,它們至今在各種NLP任務中仍發揮著重要的作用。2017年出現的Transformer結構[4],給NLP領域預訓練模型的發展帶來了絕大的突破。Transformer的成功,也誘使CV領域加入了自監督預訓練模型的賽道。如今,自監督預訓練已經成為當前人工智能研究的重點,幾乎所有的最新的 PTM都是采用類Transformer結構與自監督學習的方法,接下來介紹比較有代表性的自監督預訓練語言模型。 圖2 預訓練的起源與發展[5] 2. 模型結構PTM成功的關鍵是自監督學習和Transformer。本節從占主導地位的神經架構 Transformer 開始。然后介紹兩個具有里程碑意義的基于 Transformer 的 PTM,GPT[6]和BERT[7]。所有后續的PTMs基本都是這兩個模型的變體。 2.1 TransformerTransformer是一種序列到序列(seq2seq)架構,由編碼器(encoder)和解碼器(decoder)組成。說起Transformer,就不得不提它的注意力機制(Attention),對于注意力機制的原理解析可參考[5],這里主要總結下transformer中存在的三種注意力機制:
圖3 Transformer網絡結構示意圖[5] 2.2 GPTGPT是第一個在Transformer結構上應用自監督學習目標的PTM,它僅使用了Transformer的decoder作為基礎結構,由于采用自監督學習,所以刪去了cross-attention層。GPT是一個標準的自回歸語言模型,它的學習目標,是根據上文預測下一個詞,因此也往往更適合自然語言生成任務。 圖4 BERT與GPT的區別[5] 2.3 BERTBERT是基于雙向 Transformer 結構構建,僅使用了Transformer的encoder結構。這里的雙向主要是通過它的預訓練目標實現的,BERT設計了一個 masked language modeling (MLM) 預訓練任務,根據上下文來預測masked詞匯。“雙向”即體現在,在進行注意力計算時,BERT會同時考慮被遮蔽詞左右的詞對其的影響。BERT是一種自編碼語言模型,更適合自然語言理解任務。 2.4 后起之秀在GPT和BERT之后,出現了很多基于它們的變體,圖5中羅列了目前預訓練模型家族的主要成員。一部分工作致力于改進模型架構并探索新的預訓練任務;一部分工作致力于探索數據的豐富性,比如多語言和多模態PTMs;還有一部分工作致力于探索更多參數的模型以及PTM計算效率的優化。 圖5 預訓練模型家族[5] 3. 預訓練任務預訓練模型的主要目標是如何利用未標注語料來獲取通用知識,以便快速遷移到各種下游任務中。預訓練任務即學習目標的設計至關重要。前文也提到了GPT和BERT的預訓練任務Autoregressive language modeling和masked language modeling,它們也分別是自回歸語言模型和自編碼語言模型無法替代的預訓練任務,后續的一些PTMs中探索的新的預訓練任務均是在此基礎上追加的。下表中總結了目前一些常見的預訓練任務。對于單資源數據輸入(單語言純文本),往往從挖掘文本間詞匯、句子、篇章的內在聯系設計新的預訓練任務;對于多資源數據輸入,比如多語言和多模態的預訓練模型,往往會從如何構建不同語言和不同模態的統一的特征表示來考慮設計新的預訓練任務。 4. 總結本文整體介紹了預訓練模型起源與發展,文章大部分內容來自于論文[5],在此基礎上做了一些總結和梳理,感興趣的可以去閱讀原文。預訓練模型的發展無疑推進了AI的落地。近年來,隨著神經網絡結構設計技術逐漸成熟并趨于收斂,以及數據和模型參數規模的不斷增大,行業內也掀起了“煉大模型”的熱潮,致力于打造AI領域的基石模型。而對于預訓練模型的應用,除了“pretrain finetune”,逐漸盛行了一種新的范式“pretrain prompt predict',致力于重構不同的下游任務,打造大一統的多任務模型。歸根結底,大家其實都是在解決同一個問題:”如何快速有效地進行AI模型開發“,這也是AI領域一直以來研究的重要課題。 5. 參考文獻[1] Deng J, Dong W, Socher R, et al. Imagenet: A large-scale hierarchical image database[C]//2009 IEEE conference on computer vision and pattern recognition. Ieee, 2009: 248-255. [2] Mikolov T, Chen K, Corrado G, et al. Efficient estimation of word representations in vector space[J]. arXiv preprint arXiv:1301.3781, 2013. [3] Pennington J, Socher R, Manning C D. Glove: Global vectors for word representation[C]//Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP). 2014: 1532-1543. [4] Vaswani A, Shazeer N, Parmar N, et al. Attention is all you need[J]. Advances in neural information processing systems, 2017, 30. [5] Han, Xu, et al. 'Pre-trained models: Past, present and future.' AI Open 2 (2021): 225-250. [6] Radford A, Narasimhan K, Salimans T, et al. Improving language understanding by generative pre-training[J]. 2018. [7] Devlin J, Chang M W, Lee K, et al. Bert: Pre-training of deep bidirectional transformers for language understanding[J]. arXiv preprint arXiv:1810.04805, 2018. [8] https://jalammar./illustrated-transformer/ [9] Yang Z, Dai Z, Yang Y, et al. Xlnet: Generalized autoregressive pretraining for language understanding[J]. Advances in neural information processing systems, 2019, 32. [10] Song K, Tan X, Qin T, et al. Mpnet: Masked and permuted pre-training for language understanding[J]. Advances in Neural Information Processing Systems, 2020, 33: 16857-16867. [11] Liu Y, Ott M, Goyal N, et al. Roberta: A robustly optimized bert pretraining approach[J]. arXiv preprint arXiv:1907.11692, 2019. [12] Joshi M, Chen D, Liu Y, et al. Spanbert: Improving pre-training by representing and predicting spans[J]. Transactions of the Association for Computational Linguistics, 2020, 8: 64-77. [13] Sun Y, Wang S, Li Y, et al. Ernie: Enhanced representation through knowledge integration[J]. arXiv preprint arXiv:1904.09223, 2019. [14] Wei J, Ren X, Li X, et al. Nezha: Neural contextualized representation for chinese language understanding[J]. arXiv preprint arXiv:1909.00204, 2019. [15] Lan Z, Chen M, Goodman S, et al. Albert: A lite bert for self-supervised learning of language representations[J]. arXiv preprint arXiv:1909.11942, 2019. [16] Clark K, Luong M T, Le Q V, et al. Electra: Pre-training text encoders as discriminators rather than generators[J]. arXiv preprint arXiv:2003.10555, 2020. [17] Lample G, Conneau A. Cross-lingual language model pretraining[J]. arXiv preprint arXiv:1901.07291, 2019. [18] Huang H, Liang Y, Duan N, et al. Unicoder: A universal language encoder by pre-training with multiple cross-lingual tasks[J]. arXiv preprint arXiv:1909.00964, 2019. [19] Xu Y, Li M, Cui L, et al. Layoutlm: Pre-training of text and layout for document image understanding[C]//Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. 2020: 1192-1200. [20] Xu Y, Xu Y, Lv T, et al. LayoutLMv2: Multi-modal pre-training for visually-rich document understanding[J]. arXiv preprint arXiv:2012.14740, 2020. [21] Radford A, Kim J W, Hallacy C, et al. Learning transferable visual models from natural language supervision[C]//International Conference on Machine Learning. PMLR, 2021: 8748-8763. [22] Huo Y, Zhang M, Liu G, et al. WenLan: Bridging vision and language by large-scale multi-modal pre-training[J]. arXiv preprint arXiv:2103.06561, 2021. |
|