GPT-2 試用總結及感想
hahakity 原創
這兩天各大公眾號都被 OpenAI 的 GPT-2 模型刷屏,我也在第一時間從 GitHub 上下載了模型及預訓練好的參數,試圖調戲一把。結果感覺不是在調戲 GPT-2,而是被 GPT-2 調戲了。如果各位想被 GPT-2 調戲,可以按照下面這些步驟一步步來。
下載,安裝
首先說下這個模型如何下載,安裝。代碼公布在 Github 上,模型參數放在 Google 雲(知道這一點的時候心裡有一萬個?,OpenAI 沒錢搞自己的數據伺服器嗎?為什麼要用Google雲?)。
openai/gpt-2
代碼下載非常容易,簡單的克隆到本機,
git clone https://github.com/openai/gpt-2.git
預訓練的參數,就不是那麼好下載了。OpenAI 聲稱15億參數的大 GPT-2 產生的假新聞太以假亂真,他們不敢面對將其放出的後果,最終只放出了1.17億參數的小獸,命名為 117M。要下載這組預訓練的參數,需要先安裝 gsutil, 這是安裝 Google SDK 的時候,附送的雲端數據下載工具。但是最簡單的安裝方式是使用 python2.7,
pip2 install gsutil --user
安裝成功之後,下載數據的時候一定要記住不能漏掉 117M, 我在下載數據的時候,以為117M代表下載後數據有117兆,就沒複製到命令行,結果每次都告訴我沒許可權下載,說多了都是淚
sh download_model.sh 117M
要想運行這個模型,還要安裝一些python庫,
pip3 install -r requirements.txt
如果一切順利,那麼就可以開始調戲 GPT-2 或被 GPT-2 調戲了。
測試結果
在簡短的說明文檔里,有三種示例運行模式,第一種是無限制亂說模式,
python3 src/generate_unconditional_samples.py | tee samples
這段命令行的意思是,| 這個通道符號之前是主要的調用代碼,無限制生成文本片段,tee 是 linux 下的一個命令行工具,用於將產生的文本重定向到文件 samples 中。第二種運行模式是用幾個參數改變無限制生成文本的特性,
python3 src/generate_unconditional_samples.py --top_k 40 --temperature 0.7 | tee samples
其中最重要的那個參數可能是 temperature (溫度), 這個參數調節輸出的隨機性,溫度越高,隨機性越強,越低,出現copy訓練語料里說過的話的幾率就越大。具體實現應該是從 logits 到字典中字的 index 計算的 softmax 函數中加入溫度參數 T,
第三種運行模式, 互動式按照用戶提示生成文本片段,這種模式最有意思,也是我們要調戲的對象。調用代碼是,
python3 src/interactive_conditional_samples.py
這時,在提示符那裡輸入一些腦洞大開的故事開頭,就可以坐看 GPT-2 如何接下去了。我試了一些例子,如果以中文開頭,接下去幾乎沒正常的,可能訓練語料里根本沒多少中文網頁,比如輸入特朗普和普京在游泳池打起來了:
Model prompt >>> 特朗普和普京在游泳池打起來了
======================================== SAMPLE 1 )(GPT-2接)即面在京在饘到在游泳池。返正 Thursday, Chengjiang * Saturday, Minsk and Moscow *
Monday, Dec 5th ?o Now. Hes filming you at the front of the garden and when your ship arrives he gets angry and tries to rip your leash out of your hand*In this course the picture who gets non-safety hands, are you kidding me?Today he grabbed my 3 month old Daddy and forced him to let me off.By that point I didnt want my leash and Baby tried to get onto Captain Chekas leash that gave up inside her, he grabbed his pitbull tigger from get on the walk and put it around my testicles
This year he tried to tase me drag me off the road and drown in his recycling site three times over (full of worst kind) by pulling my shortsThe dog didnt die out with him but was seriously injured the most, losing a tire with his jaw got to his hand on something and using his tail to do it, he is still missing.
GPT-2 接下來編的故事有些黃暴,但是跟我輸入的故事開頭沒有任何聯繫。換成英文會不會好一點呢?接下來輸入英文:川普想建牆的原因是外星人正在入侵墨西哥
Model prompt >>> Donald Trump wants to build the wall because Aliens are invading Mexico
======================================== SAMPLE 1 (GPT-2接)," he said. Trump believes that border safety as Trump says, that some illegal aliens are good immigrants. Trump claims that the United States is at a disadvantage right now due to the Obama immigration policies. He said that the level of federal spending on wall wall have been partly cut due to that, including American taxpayers cost of the wall. Trump said that information should have been provided by the Department of Homeland Security and it would have handled it with care, asking an audience that the vast majority of Americans didnt get what they wanted from the Mayors for Truth and Justice they signed.
基本上這一段跟 川普有關,跟建牆有關,但是跟外星人入侵墨西哥沒有絲毫關係。此外,後面有一大段對話我沒有貼上來,基本那些對話跟川普,建牆,墨西哥,外星人都毫無關係。嘗試了不少例子,都是能猜到開頭,卻猜不到結尾,117M 小模型GPT-2 會很快的偏離主題,使得接下來的故事語法無大錯,卻無語義,無邏輯。
評論
GPT-2 應該是一個偉大的進步,但是文章不能這樣寫,宣傳不能這樣做。這場遊戲中,如果玩家太少,大家不能復現文章里的結果,這次 OpenAI 的宣傳又要很快涼涼。拿這個117M參數的GPT-2出來,給大家調戲,結果最終變成調戲大家,引起眾怒就得不償失了。當然,OpenAI也可能是在做飢餓營銷,先吊吊大家的胃口,火上一周,再勉為其難的放出15億參數的大模型,給火上澆點油,以期達到BERT那樣的經久不衰的宣傳效果。可能需要中文預訓練模型或多語言預訓練模型出來,OpenAI 放出15億預訓練參數,GPT-2才真的會火上天。事實究竟如何,讓我們拭目以待。
推薦閱讀:
TAG:深度學習(DeepLearning) | 人工智慧 | 自然語言處理 |
