<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[NLP-trend-and-review - Medium]]></title>
        <description><![CDATA[整理NLP中的觀念及閱讀最新及經典論文 - Medium]]></description>
        <link>https://medium.com/nlp-tsupei?source=rss----1ce1bc30383f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>NLP-trend-and-review - Medium</title>
            <link>https://medium.com/nlp-tsupei?source=rss----1ce1bc30383f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:44:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/nlp-tsupei" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[DistilBERT — 更小更快的BERT模型]]></title>
            <link>https://medium.com/nlp-tsupei/distilbert-%E6%9B%B4%E5%B0%8F%E6%9B%B4%E5%BF%AB%E7%9A%84bert%E6%A8%A1%E5%9E%8B-eec345d17230?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/eec345d17230</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 08:49:04 GMT</pubDate>
            <atom:updated>2020-02-07T08:49:04.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>DistilBERT — 更小更快的BERT模型</h3><h4>使用蒸餾(Distillation)技術來幫BERT瘦身</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zia8q3mA6-vRtCWQIjWkYQ.png" /></figure><h3>介紹</h3><p>今天要介紹的是 Distilled BERT，是由hugging face在今年(2019)所提出的一篇論文，相信用pytorch來做BERT的朋友一定對 hugging face 不陌生，他們在 Github上開源的<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiz-bCDg7_nAhVhJaYKHT7sCxEQFjAAegQICBAC&amp;url=https%3A%2F%2Fgithub.com%2Fhuggingface%2Ftransformers&amp;usg=AOvVaw2tFvUqz2_mjqk4l73AGqMY">transformers</a>專案</p><p>回到今天的主題，Distill的意思是蒸餾，我們可以從字面上猜測，我們要從一個很大的模型，蒸餾成比較小的模型，也可以用一種角度想，我們讓大的模型當作小的模型的老師，而小模型這個學生，只會盡可能的學老師的每個動作</p><p>大致上Distilled BERT的思想就是這樣簡單，根據作者的實驗數據，DistilBERT的參數大約只有BERT的40%，而速度快了60%，並保有一定一精準度</p><h4><strong>訓練</strong></h4><p>很多人剛看到這個的想法，可能會直覺想說直接拿現成的BERT來訓練小的DistilBERT模型應該不太耗費效能，不過由於Distillation Loss需拿BERT跟DistilBERT的結果相互比較，因此仍需要對BERT做forward pass，再計算出Triple Loss後進行Backward Propagation。</p><h3>方法</h3><p>所以我們實際上到底怎麼訓練的，作者提出的DistilBERT的架構，層數為BERT的一半，這邊的重點其實是Loss Function，訓練採用的Loss Function為三種的結合(Triple Loss)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LHW0twNHbs0POcoeYgy6IA.png" /><figcaption>Distillation Loss</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDN6XlwxPyR1up5iRursSA.png" /><figcaption>Softmax-temperature</figcaption></figure><ol><li><strong>Distillation Loss</strong>: 從圖中可以看出，當BERT預測(ti)越高，而DistilBERT預測(si)越低，產生的Loss就會越高，而機率是通過 softmax-temperature (Hinton et al., 2015) 計算</li><li><strong>Masked Language Modeling Loss</strong>: 參考BERT</li><li><strong>Cosine Embedding Loss</strong>: 用於讓DistilBERT能趨向產生跟BERT更像的hidden vector</li></ol><h4>Student Architecture</h4><ol><li><strong>Linear layer and Layer Normalization</strong>: 已被高度優化且證明有效(Highly optimized)，因此不更動</li><li><strong>The size of hidden vector of last layer</strong>: 根據實驗發現減少 hidden vector size 並不太影響效能</li><li><strong>Number of layers</strong>: 影響效能、推理速度較多，因此作者注重在此參數</li></ol><h4>Student Initialization</h4><p>因爲層數為BERT的一半，直接使用BERT的參數當作初始值</p><h4>Compute Power</h4><p>8 16GB V100 GPUs for approximately 90hrs on Toronto Book Corpus(原先BERT使用的資料集)</p><h3>Evaluation</h3><p><strong>GLUE</strong>: DistilBERT retrain 97% of BERT performance，有些甚至超越BERT Base</p><p><strong>IMDb accuracy</strong>: BERT(93.46) DistilBERT(92.82)</p><p><strong>Speed(A full pass of GLUE task)</strong>: BERT(668s) ELMo(895s) DistilBERT(410s)</p><h3>On device computation</h3><p>將容量縮小後，也可以直接將模型放在設備端(i.e. APP)，論文中的DistilBERT大約<strong>207MB</strong>大</p><ol><li>Building a mobile application for QA</li><li>207 MB, could be further reduced with quantization</li></ol><h3>運行在下游任務(Downstream tasks)</h3><blockquote>We also studied whether we could add another step of distillation during the adaptation phase by fine-tuning DistilBERT on SQuAD using a BERT model previously fine-tuned on SQuAD as a teacher for an additional term in the loss (knowledge distillation). In this setting, there are thus two successive steps of distillation, one during the pre-training phase and one during the adaptation phase.</blockquote><p>從上面的段落看來，在問答任務(屬於一種下游任務)中，將DistilBERT再跟Fine-tuned BERT進行一次蒸餾，就可以達到不錯效果</p><h3><strong>結論</strong></h3><p>DistilBERT整體來說很適合使用在應用層面，我們只需完成蒸餾的動作，就可以大幅增進推理速度，以及減少模型大小，可以減低伺服器的成本</p><h3><strong>Reference</strong></h3><ol><li><a href="https://arxiv.org/abs/1503.02531">Distilling the Knowledge in a Neural Network</a></li><li><a href="https://arxiv.org/abs/1910.01108">DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eec345d17230" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/distilbert-%E6%9B%B4%E5%B0%8F%E6%9B%B4%E5%BF%AB%E7%9A%84bert%E6%A8%A1%E5%9E%8B-eec345d17230">DistilBERT — 更小更快的BERT模型</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[論文整理] Joint Extraction of Entities and Relations Based on a Novel Tagging Scheme]]></title>
            <link>https://medium.com/nlp-tsupei/%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-joint-extraction-of-entities-and-relations-based-on-a-novel-tagging-scheme-29a36a2bf37e?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/29a36a2bf37e</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Fri, 31 Jan 2020 09:17:46 GMT</pubDate>
            <atom:updated>2020-01-31T10:52:47.063Z</atom:updated>
            <content:encoded><![CDATA[<h4>命名實體關係抽取的三元組標記架構</h4><h3>Preview</h3><p>對於非結構化文本（e.g.新聞、網頁等），我們想透過模型來抽取實體間的關係，以做後需更多應用，比如說知識圖譜（Knowledge Graph），對於這樣的任務，過往研究大致分為兩個方向，一為拆分成兩步驟，先做命名實體識別(NER)，再做關係分類(RC)，二為使用單一端到端的模型（End-to-End model），比如使用<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjJlNP11a3nAhWLJaYKHaf5DqEQFjABegQIAxAB&amp;url=https%3A%2F%2Farxiv.org%2Fabs%2F1601.00770&amp;usg=AOvVaw1cVfdT16jQXDShF1ODafwf">LSTM-based model（Miwa and Bansal, 2016）</a></p><p>此篇論文提出了一個新的標記架構(Tagging Scheme)將實體關係抽取(Joint Extraction of entities and relations) 轉換成一般的標注任務，並且透過 Bias Objective Function 對輸出的關係標籤(relational tags)加以權重，換句話說，讓輸出標籤的 Loss 能被加重，而輸出其他(The ‘O’ tag)的標籤則會相對減輕權重</p><p>這篇2017發表的論文中採取的是 <strong>LSTM-based </strong>的方法，不過我認為可以試試看使用基於<strong>Transformer </strong>或 <strong>BERT </strong>的方法來試試看，應該會有不錯的效果，接下來會約略帶過本篇論文我認為的重點</p><ol><li>Tagging Scheme</li><li>The Bias Objective Function</li></ol><h3>Tagging Scheme</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dmxssalt5KYKJUF9QjoUbQ.png" /><figcaption>來源:<a href="https://www.aclweb.org/anthology/P17-1113"> Joint Extraction of Entities and Relations Based on a Novel Tagging Scheme</a></figcaption></figure><p>從上圖中可以看出，如同NER一樣，每個字開頭會有B, I, E表示該字屬於 Entity 中的哪個位置，中間表示關係，例如CP即表示Country-President，最後數字1或2則表示在關係中為前項或後項，透過這樣的標記架構，我們可以將命名實體關係抽取轉為一般的標記任務(Tagging Task)，而當我們訓練完這樣的模型，我們只要能找到一個有效的CP-1實體及CP-2實體，組合起來即能得到一個三元關係組(Entity1, RelationType, Entity2)，當有衝突的情況以最接近的為主，當然，現實中也有相隔很遠的關係存在，但此篇論文不討論這個問題，留到Future Work</p><h3>The Bias Objective Function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*SU3ZDLjnZx8UY2xNLygAQg.png" /><figcaption>The Bias Objective Function</figcaption></figure><p>由於每個字我們都會輸出一個標籤，並且在訓練途中計算Loss用以訓練參數，但在這個任務上，無用(The ‘O’ tag)的數目遠大於有用的標籤，換句話說，我們的負樣本(Negative Sample)數目比正樣本(True Sample)多很多，這樣可能會導致模型最後訓練不平均，只會輸出Negative，造成 Recall 太小，於是，我們給正樣本計算 Loss 的時候施加一個權重α，以平衡正樣本在訓練資料的數量較少的問題</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rx61YM_emk5YYb9u3DGi1Q.png" /><figcaption>比較不同模型的表現</figcaption></figure><p>第三部分為此篇論文模型及標記架構的實驗數據，可以看出在 LSTM-LSTM-Bias的項目，也就是施加α權重的結果，Recall優於其他兩者，F1-score也比較優</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*RdxXp1KCdp5vR9wzdRfO9A.png" /><figcaption>不同α配置下的Precision, Recall, F1-score比較</figcaption></figure><p>測試設定不同的α來訓練模型，可以得出設定為10的時候，較能在Precision與Recall之間取得一個平衡，得到較高的F1-score</p><h3><strong>Reference</strong></h3><p><a href="https://www.aclweb.org/anthology/P17-1113">1. Joint Extraction of Entities and Relations Based on a Novel Tagging Scheme</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a36a2bf37e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-joint-extraction-of-entities-and-relations-based-on-a-novel-tagging-scheme-29a36a2bf37e">[論文整理] Joint Extraction of Entities and Relations Based on a Novel Tagging Scheme</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[深入介紹及比較ROC曲線及PR曲線]]></title>
            <link>https://medium.com/nlp-tsupei/roc-pr-%E6%9B%B2%E7%B7%9A-f3faa2231b8c?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/f3faa2231b8c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[evaluation]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Mon, 30 Dec 2019 13:57:46 GMT</pubDate>
            <atom:updated>2023-04-28T04:00:42.638Z</atom:updated>
            <content:encoded><![CDATA[<h4>詳細介紹整體衡量分類模型的方法：ROC曲線以及PR曲線</h4><p>此文章完整發佈在我的<a href="https://tsupei.github.io/nlp/2019/12/30/prcurve.html">個人網頁</a>，此處不會再更新</p><h3>Introduction</h3><p>在一個二分類模型中，我們的模型通常不會直接輸出0,1直接預測出分類，而是對每個分類輸出一個機率，例如加上<em>softmax</em>對各分類輸出機率，這樣讓我們能夠自己設定一個門檻(<em>threshold</em>)來決定機率大於多少時我們判定為正樣本，反之為負樣本。而 <em>ROC Curves </em>和 <em>PR Curves </em>可以幫助我們分析這樣的 <em>probablistic forcast</em></p><h4>Terminology</h4><ol><li><strong>Skill</strong> — 我們稱一個模型是 <em>skillful</em>，表示模型更能夠給定一個正樣本更高的機率，反之負樣本更低的機率</li><li><strong>No-Skill</strong> — 沒有 <em>skill </em>的模型，在任何的門檻下，給正負樣本的機率都為0.5，我們從模型中無法獲得任何有用資訊，在 <em>ROC </em>曲線中以左下到右上的對角線表示</li></ol><h4><strong>Points</strong></h4><ol><li><em>ROC Curves</em> 適合類別平均的情況，而 <em>PR Curves</em> 適合於類別不平均的情況</li><li><em>AUC (Area under curve)</em> 可以當作一個判斷整體模型能力(<em>skill</em>)的指標</li><li>可以直接比較不同模型在不同<em>Threshold</em>下的<em>Skill</em></li></ol><h3>ROC Curve(Receiver Operating Characteristic Curve)</h3><p><em>ROC </em>曲線以 <em>FPR </em>為 <em>X </em>軸，TPR為 <em>Y</em> 軸，每一個點代表設定不同的門檻值所得到的不同的 <em>FPR</em> 及 <em>TPR </em>，最後繪製成一條曲線。建議可以參考我另一篇文章所介紹的<a href="https://medium.com/nlp-tsupei/%E6%B7%B7%E6%B7%86%E7%9F%A9%E9%99%A3-confusion-matrix-%E4%BB%8B%E7%B4%B9-5eecd6da02ba">混淆矩陣</a>，以下會再介紹如何計算出 <em>FPR</em> 及 <em>TPR</em></p><h4>偽陽性率：FPR (False Positive Rate)</h4><p>FPR表示成 1-特異度 而特異度(specificity)意指<a href="https://estat.pixnet.net/blog/post/61795603-roc%E6%9B%B2%E7%B7%9A-(receiver-operating-characteristic-curve)">正確判斷出負樣本</a>，故特異度越高、FPR越低，模型越能夠正確判斷負樣本、表現越好</p><pre>Specificity = True Negatives / (True Negatives + False Positives)</pre><pre>FPR = 1 - Specificity<br>    = False Positives / (False Positives + True Negatives)</pre><h4>真陽性率：TPR (True Positive Rate)</h4><p>TPR又稱為敏感度(Sensitivity)，它也是我們熟知的召回率(Recall)，也就是正確判斷出正樣本，故TPR越高則模型越能夠正確判斷正樣本、表現越好</p><pre>TPR = Sensitivity<br>    = True Positives / (True Positives + False Negatives)</pre><h4>曲線下面積：AUC(Area under curve)</h4><blockquote>When using normalized units, the area under the curve (often referred to as simply the AUC) is equal to <strong>the probability that a classifier will rank a randomly chosen positive instance higher than a randomly chosen negative one</strong> (assuming ‘positive’ ranks higher than ‘negative’) — from wikipedia</blockquote><p><em>AUC</em>(曲線下面積)，所代表的意義為隨機抽取一個正樣本，分類器會正確判斷為正樣本的機率高於判斷為負樣本的機率，所以 <em>AUC</em> 越高則分類器正確率會越高。而如何計算出 <em>AUC</em> 有幾種逼近求近似值的方法，有興趣的讀者可以參考<a href="https://en.wikipedia.org/wiki/Receiver_operating_characteristic">維基百科</a>更深入了解</p><h4>Problem of AUC</h4><p><em>AUC</em> 常常被應用於機器學習來比較不同模型的優劣，然而其存在一些問題</p><ol><li>估計方法所造成的問題<a href="https://academic.oup.com/bioinformatics/article/26/6/822/244957">[1]</a><a href="https://semanticscholar.org/paper/1bab3a1af6d1fbad02385d13b64b05045110c86b">[2]</a><a href="https://doi.org/10.1007%2Fs10994-009-5119-5">[3]</a></li><li><em>ROC AUC</em> 將整條 <em>ROC curve</em> 歸納到一個單一的值上，忽略了不同系統之間的 <em>Tradoff</em>（不同門檻值）</li></ol><h4>(0, 1), (0, 0), (1, 1)</h4><p><strong>(0,1)</strong>這個點代表 <em>FPR</em> 為 0 ，<em>TPR</em> 為 1，代表能夠<strong>完美預測</strong>，也就是只要把門檻設定為該點的門檻，即得到一個完美的預測器</p><p><strong>(0,0)</strong>這個點代表 <em>FPR</em> 為 0，<em>TPR</em> 為 0，若將門檻設定為1，那麼<em>TP</em>, <em>FP</em>都為0</p><p><strong>(1,1)</strong>這個點代表 <em>FPR</em> 為 1，<em>TPR</em> 為 1，若將門檻設定為0，那麼<em>FP</em>, <em>TN</em>都為0</p><h4>Example</h4><p>使用<em>sklearn</em>，可以幫我們計算 <em>AUC</em> 和 <em>ROC</em>曲線</p><pre># -- Algorithm --<br># No skill   : ROC AUC=0.500<br># Algorithm 1: ROC AUC=0.843</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAgW7LiQ0U8L0Jd22gpJyw.png" /><figcaption>計算ROC曲線範例</figcaption></figure><h4>怎麼從ROC Curve來看出哪個模型表現較好</h4><p>我們已知(0,1)這個點特異度(Specificity)及敏感度(Sensitivity)為1，是完美預測的點，因此曲線越往(0,1)上凸表示該模型整體有較好的表現，如果ROC Curve A 曲線整體大於或包含 ROC Curve B，那麼A算法可以說是表現優於B算法</p><p>也可以利用AUC來概略地衡量模型整體表現，根據<a href="https://estat.pixnet.net/blog/post/61795603-roc%E6%9B%B2%E7%B7%9A-(receiver-operating-characteristic-curve)">這篇文章指出</a></p><ol><li>AUC = 0.5 (no discrimination 無鑑別力)</li><li>0.7≦AUC≦0.8 (acceptable discrimination 可接受的鑑別力)</li><li>0.8≦AUC≦0.9 (excellent discrimination 優良的鑑別力)</li><li>0.9≦AUC≦1.0 (outstanding discrimination 極佳的鑑別力)</li></ol><h3><strong>PR Curve(Precision-Recall Curves)</strong></h3><p><em>PR </em>曲線以 <em>Recall </em>為 <em>X </em>軸，<em>Precision </em>為 <em>Y</em> 軸，每一個點代表設定不同的門檻值所得到的不同的 <em>Recall</em> 及 <em>Precision </em>，最後繪製成一條曲線。建議可以參考我另一篇文章所介紹的 <a href="https://medium.com/nlp-tsupei/precision-recall-f1-score%E7%B0%A1%E5%96%AE%E4%BB%8B%E7%B4%B9-f87baa82a47"><em>Recall</em> 及 <em>Precision</em></a></p><p>這邊特別注意的是，<em>Recall</em> 及 <em>Precision </em>都適合用於類別不平均的資料集，因為在算式中並沒有考慮 <em>True Negatives (TN)</em> ，只專注於正確判斷正樣本，因此，就算資料集中負樣本的數目遠大於正樣本，<em>Recall</em> 及 <em>Precision</em>仍是有效的參考指標。反之，<em>FPR </em>則會受到影響，當我們負樣本很多，模型若全部預測為負樣本，會得到 <em>FPR</em> = 0，但這樣的模型並非好的模型</p><h4>AUC vs. F-measure</h4><p>和 <em>ROC AUC</em> 一樣，曲線下面積可以代表該模型整體在各門檻下的表現，而F-measure則是針對特定某個門檻值的 <em>Recall</em> 及 <em>Precision </em>所計算出來的調和平均數</p><p><strong>(1,1)完美預測</strong></p><p>(1,1) 代表 <em>Precision, Recall = 1 </em>也就是<strong>完美預測</strong>，因此我們的PR曲線越往右上角凸起則代表更好的模型表現，反之越平則代表越差</p><h4>Example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkBY910fW0Np3QNCTyNHqA.png" /><figcaption>PR Curve Example</figcaption></figure><p>我們將不同門檻值所算出來的值計算 <em>F1-score</em> 也繪製成一條線</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2y7-uswGAlAGru3Dfx4NKg.png" /><figcaption>F1-scores of different thresholds</figcaption></figure><h3>Conclusion</h3><p><em>ROC</em> 曲線同時考慮了正例以及負例，因此適用於評估分類器整體的效能，而 <em>PR</em> 曲線則專注於正例，若是在類別平均且正例及負例的判斷都重要的情況下，<em>ROC</em> 曲線是不錯的選擇</p><p>由於 <em>ROC</em> 曲線的 <em>X</em> 軸使用到了 <em>FPR</em>，在類別不平均的情況下(負樣本較多)，使得 <em>FPR</em> 的增長會被稀釋，會導致 <em>ROC </em>曲線呈現出過度樂觀的結果，因此在類別不平均的情況下，<em>PR</em> 曲線會是較好的選擇</p><h3>Reference</h3><ol><li><a href="https://machinelearningmastery.com/roc-curves-and-precision-recall-curves-for-classification-in-python/">How to Use ROC Curves and Precision-Recall Curves for Classification in Python — Jason Brownlee</a></li><li><a href="https://zh.wikipedia.org/wiki/ROC%E6%9B%B2%E7%BA%BF">ROC曲線/維基百科</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html">sklearn.metrices.roc_curve</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html">sklearn.metrices.precision_recall_curve</a></li><li><a href="https://zhuanlan.zhihu.com/p/34655990">机器学习之类别不平衡问题 (2) — — ROC和PR曲线</a> — wdmad</li><li><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4349800/">The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3faa2231b8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/roc-pr-%E6%9B%B2%E7%B7%9A-f3faa2231b8c">深入介紹及比較ROC曲線及PR曲線</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[機器學習怎麼切分資料：訓練、驗證、測試集]]></title>
            <link>https://medium.com/nlp-tsupei/%E6%A9%9F%E5%99%A8%E5%AD%B8%E7%BF%92%E6%80%8E%E9%BA%BC%E5%88%87%E5%88%86%E8%B3%87%E6%96%99-%E8%A8%93%E7%B7%B4-%E9%A9%97%E8%AD%89-%E6%B8%AC%E8%A9%A6%E9%9B%86-f5a92576d1aa?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/f5a92576d1aa</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 03:00:57 GMT</pubDate>
            <atom:updated>2019-12-17T04:57:52.694Z</atom:updated>
            <content:encoded><![CDATA[<p>訓練集、驗證集、測試集分別代表什麼含義，又該怎麼劃分</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XSJua7etAhQDFUC_kBbGgA.jpeg" /><figcaption>機器學習就像一個學生在學習</figcaption></figure><h4>訓練及測試資料</h4><p>對於Supervised Learning來說，我們必須使用標註資料(Labeled Data)來做訓練，例如一個CNN(Convolutional Neural Network)，因此我們需要訓練資料(Training Data)</p><p>但我們好不容易搜集到的資料卻不能全部拿來做訓練，因為我們必須要保留一些當作測試資料(Testing Data)來評估我們的模型表現</p><p>這些資料必須跟訓練資料是完全不同的，否則就有作弊的嫌疑，想想如果在考試前就先拿到考題的話，這樣就算出來的成績很高，也並不能代表這個學生真的很了解這個科目，對於機器來說也是一樣的道理</p><p>所以最簡單的方式，我們會把我們的資料切分成測試集跟訓練集，通常會保留比較多當作訓練資料(60%~80%)，其餘作測試資料</p><h4>驗證集</h4><p>大部分的情況下，我們還會需要驗證資料集(Validation Dataset)，例如在<strong>K-fold</strong>方法中，我們會訓練K次模型，這樣的話我們怎麼知道要選擇哪個模型呢？這時候就需要驗證集的幫助，例如10-fold中，我們將<strong>90%的訓練資料</strong>當作訓練集，而<strong>10%的資料</strong>當作驗證集，每次訓練完一個模型後，我們使用10%的資料來驗證，並得到一些評估的指摽(例如: Accuracy, F1-score等)，再選擇最好當作我們的模型，在這之後，才使用測試集(Test Dataset)來評估此模型的效能</p><p>驗證集也可以是拿來調參數的依據，由於驗證集的資料並不被模型所見，所以選擇一組參數使得在驗證集上得到最好的表現，大部分情況會比單純使用訓練集表現來得好。</p><p>整體來說，驗證集讓我們能以一個客觀的角度評估目前模型學習的狀況，例如判斷模型是否過擬合(Overfitting)，以及用來調整模型參數等，驗證集並不會被模型所學習，所得出的分數也不會是最後評估模型的好壞的指標，而是由測試集來評估</p><h4>總結</h4><p>舉一個例子來說，把我們的模型想成一個<strong>高中生</strong>，平常上課學習時吸收的資料，像是課本、講義等，我們稱為訓練集，而模擬考，就好像是驗證集，從模擬考中，我們可以有一個概略的指標來看哪個學生學的比較好，對於學生來說，從模擬考的成績好壞，進而調整學習的方向，而測試集就是學測或指考，得到的分數就直接評估了學生的優劣</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5a92576d1aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/%E6%A9%9F%E5%99%A8%E5%AD%B8%E7%BF%92%E6%80%8E%E9%BA%BC%E5%88%87%E5%88%86%E8%B3%87%E6%96%99-%E8%A8%93%E7%B7%B4-%E9%A9%97%E8%AD%89-%E6%B8%AC%E8%A9%A6%E9%9B%86-f5a92576d1aa">機器學習怎麼切分資料：訓練、驗證、測試集</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Perplexity（困惑度）是什麼？]]></title>
            <link>https://medium.com/nlp-tsupei/perplexity%E6%98%AF%E4%BB%80%E9%BA%BC-426f52897513?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/426f52897513</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Mon, 16 Dec 2019 15:45:14 GMT</pubDate>
            <atom:updated>2019-12-30T15:35:49.159Z</atom:updated>
            <content:encoded><![CDATA[<h4>Perplexity是通常可以拿來衡量一個語言模型(Language Model)的一個方法</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJQD5UN3C6845p-w3Wtbtw.jpeg" /><figcaption>Language Model Trying to model how a language is generated - Photo by <a href="https://unsplash.com/@romankraft?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Roman Kraft</a> on <a href="https://unsplash.com/s/photos/language?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4><strong>Perplexity與語言模型</strong></h4><p>Perplexity是通常拿來衡量一個語言模型(Language Model)的一個方法，那語言模型又是什麼呢？簡單來說，語言模型計算一句話的機率，一個越好的語言模型，對我們人類給出的一句通順的話，會給出越高的機率</p><p>以<strong>Unigram</strong>為例子，每個字的機率都是獨立的，我們可以用以下的式子來表示一個句子的機率</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/65/1*Y5MYBaQpoAbsbKm8vY2bmw.png" /><figcaption>每個字為獨立機率，相乘後等於該句子機率</figcaption></figure><p><em>P(wi)</em>為第<em>i</em>個字的機率，而怎麼計算這個機率就是不同語言模型的工作。例如<em>unigram</em>可以表示成 <em>P(wi)</em>，該字出現的機率跟其他字出現是獨立的。而bigram可以表示成 <em>P(wi|wi-1)</em>，每個字的機率都依賴於前一個字</p><h4>Perplexity數學公式</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*O2SO0SUNg49nmRw-hAcgBg.png" /><figcaption>Perplexity的計算公式</figcaption></figure><p>我們將上面的公式細部拆解來看</p><blockquote>1. 整個句子的機率<br>2. 取 log，因為 log 為嚴格遞增函數，所以不影響比較結果<br>3. 除以 M做平均 <br>4. 取負號，所以會變成值越小原本的機率越大<br>5. 取2的指數，一樣為嚴格遞增函數，所以不影響比較結果</blockquote><p>從第一步推到最後，當Perplexity越小，則原本句子的機率就越高，所以對於一個<strong>包含合理通順語句的資料集</strong>，假設我們有兩個語言模型，以訓練集來訓練語言模型A與語言模型B，再以測試集來評估兩者的Perplexity，平均Perplexity越小的語言模型表示能更高的機率，因此會認為它較好</p><p><em>註：不影響比較結果的意思是，當今天有多個模型用Perplexity來進行比較時，取對數跟指數並不會影響原本的排名結果</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=426f52897513" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/perplexity%E6%98%AF%E4%BB%80%E9%BA%BC-426f52897513">Perplexity（困惑度）是什麼？</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[中文自然語言處理整理]]></title>
            <link>https://medium.com/nlp-tsupei/%E5%BE%9E%E9%9B%B6%E9%96%8B%E5%A7%8B%E5%AD%B8%E7%BF%92%E8%87%AA%E7%84%B6%E8%AA%9E%E8%A8%80%E8%99%95%E7%90%86-a729bccecda?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/a729bccecda</guid>
            <category><![CDATA[text-mining]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Sun, 08 Dec 2019 13:08:56 GMT</pubDate>
            <atom:updated>2020-08-25T02:38:33.029Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>從開始接觸自然語言處理(Natural Language Processing)也已經過了一年多了，我想藉由這篇文章來整理一些我學習的資源</blockquote><p><em>更新時間: 2020/05/20</em></p><p>一開始，若是一個完全沒接觸過NLP領域的人，要怎麼開始呢？又該具備什麼樣？讓我們先來聊聊什麼是自然語言吧</p><p>自然語言顧名思義，所有我們人類日常生活中使用到「語言」的地方都是自然語言，包括文字、語音等，文字細分下去像是聊天訊息、論壇的留言、新聞、FB貼文，甚至在古文明中刻在石板的文字，也是自然語言，也有很多研究是關於古時候中國使用的文言文、詩詞等等。</p><p>在Line上發了一則訊息給朋友，這就是一個自然語言的場域，還有像是智慧音箱跟語音助理等，這些都是自然語言處理可以做到的應用。自然語言處理也可以是一種數據分析的技術，像是在批踢踢上討論熱度、假新聞的分析，只要是牽扯到<strong>「文字」</strong>、<strong>「語言」</strong>的地方，基本上都能夠被處理，只不過是難易度的差別而已</p><h3>學習材料</h3><p>接觸一個新領域時，我們通常需要一些教科書來讓我們有系統地學習，在自然語言中，有兩本聖經級的課本是被大家所推崇的</p><ol><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiXsqb53pvmAhVdIqYKHWsZCngQFjABegQIBhAB&amp;url=https%3A%2F%2Fweb.stanford.edu%2F~jurafsky%2Fslp3%2F&amp;usg=AOvVaw1-UUinkA3xYvwJWb0XDiBu">Speech and Language Processing(Jurafsky)</a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiRp9WK35vmAhX0wosBHe9lBN4QFjABegQIBhAC&amp;url=http%3A%2F%2Fusers.isr.ist.utl.pt%2F~wurmd%2FLivros%2Fschool%2FBishop%2520-%2520Pattern%2520Recognition%2520And%2520Machine%2520Learning%2520-%2520Springer%2520%25202006.pdf&amp;usg=AOvVaw2j0fMGPbFfpcwGzqELtiRU">Pattern Recognition and Machine Learning(Christopher M. Bishop)</a></li></ol><p>不過，閱讀厚厚的原文書是相當累人的，可以先挑一些有興趣的章節，跳過較為艱澀的部分，搭配線上課程來學習，下面是我常常會去看的線上課程</p><ol><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjS-_bK35vmAhUFK6YKHW0IAQMQFjAAegQIEBAC&amp;url=https%3A%2F%2Fzh-tw.coursera.org%2Flearn%2Fmachine-learning&amp;usg=AOvVaw3_bqeUHmI6CJ_MbrfUT7sR">Machine Learning(Coursera, taught by Andrew Ng)</a></li><li><a href="https://www.youtube.com/watch?v=8rXD5-xhemo&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z">CS224N: Natural Language Processing with Deep Learning(Stanford)</a></li><li><a href="https://www.youtube.com/channel/UC2ggjtuuWvxrHHHiaDH1dlQ">台大李弘毅老師的Youtube頻道</a></li></ol><h3>程式工具</h3><p>程式的部分，我大部分都是使用<strong>Python</strong>來撰寫，在深度學習方面的套件及工具大部分也都是支援Python，這邊概略地介紹一些有名的套件</p><h4>TensorFlow&amp;Pytorch</h4><p>在深度學習中，基本上就是分Tensorflow跟Pytorch這兩派，近期也都各自推出了新版本TensorFlow 2.0以及Pytorch1.3，我個人是喜歡使用Pytorch，因為它整體的邏輯跟Python較類似，也因此比較容易上手，大家可以找一個適合自己的學習</p><p>Google最近釋出一個 <a href="https://github.com/google/trax">trax</a> 的新框架，有興趣的人也能看看</p><h4><strong>Pytorch-lightning (*update)</strong></h4><p><a href="https://pytorch-lightning.readthedocs.io/">pytorch-lightning</a>是一個建立在Pytorch之上的框架，原本使用Pytorch讓我們可以制定模型，不過整個訓練的過程還包含像是Train, Evaluation, Test，還要處理各種超參數、使用GPU或CPU訓練，有些時候甚至還要考慮支不支援float16精度的訓練等等，使用pytorch-lightning讓我們可以制定好這些繁雜的步驟，讓我們可以更方便的訓練並使用模型，不過我目前還沒實際使用的經驗，有待使用過再回來補充</p><h4>Numpy</h4><p>Numpy是在Python中進行向量以及矩陣運算相當好用的工具，底層是由c語言所實作，記憶體用量及效能都比用Python內建的list來得好，如果是進行數值運算的話，使用numpy不會是錯誤的選擇，且Numpy跟Pytorch也有非常好的相容性，可直接使用numpy來創建Tensor，也能透過<em>.numpy()</em>轉換回去(tensorflow我較不熟悉)</p><p>想要更深入了解為什麼使用Numpy比內建的list好可以參考這篇<a href="https://medium.com/@t0915290092/%E7%94%A8%E8%A8%98%E6%86%B6%E9%AB%94%E7%AE%A1%E7%90%86%E8%AC%9B%E8%A7%A3%E7%82%BA%E4%BD%95-python-%E7%9A%84-list-%E9%82%A3%E9%BA%BC%E6%85%A2-bf2cd80bbf72">優質文章</a></p><h4>Pandas</h4><p>Pandas是一個拿來處理CSV檔案常用的工具，在處理文字中常常需要跟CSV檔打交道，有很多資料集也是以CSV為形式，這時候可以考慮使用Pandas作為讀取的工具</p><h4>scikit-learn</h4><p>scikit-learn包含一些非監督學習的工具，像是PCA, TSNE等等，也有監督學習的工具像是 SVM</p><h4>gensim</h4><p>我使用<a href="https://en.wikipedia.org/wiki/Gensim">gensim</a>這個套件主要是它所支援的LDA模型跟word vector詞向量模型，通常訓練或者讀取預訓練的詞向量模型都會使用到這個套件</p><h4>huggingface/transformers</h4><p>近年來(2018~)ELMo, BERT, GPT相繼發表，儼然為NLP開啟了一個新的時代，<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjE-9GRnZzmAhWHGaYKHQCVCAwQFjABegQIBRAB&amp;url=https%3A%2F%2Fgithub.com%2Fhuggingface%2Ftransformers&amp;usg=AOvVaw2tFvUqz2_mjqk4l73AGqMY">huggingface</a>為Pytorch的廣大使用者包裝好使用這些模型的介面，甚至也提供轉換TensorFlow Checkpoint成為可讀取的Pytorch模型的腳本，非常推薦能夠到huggingface的網站探索一下，除了BERT以外，目前也支援像XLNet, ALBERT, DistilBERT等更多大型預訓練模型</p><h4>matplotlib</h4><p><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwirh-_rnZzmAhWIHqYKHXq9BJsQFjAAegQIChAB&amp;url=https%3A%2F%2Fmatplotlib.org%2F&amp;usg=AOvVaw0YgZr7XYZzco6IDaGIE2sw">matplotlib</a>是一個繪圖套件，在論文中見到的圖表像是折線圖、熱度圖、散佈圖等，常常都是藉由這個套件所繪製而成。除了matplotlib以外，像是<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiOuKTdnZzmAhUJyosBHY0HDgwQFjAAegQIBxAB&amp;url=https%3A%2F%2Fplot.ly%2Fpython%2F&amp;usg=AOvVaw1FX3Yim1C_OUvwDgq0vdAK">plotly</a>, <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjYvJ7WnZzmAhURL6YKHdmJDdAQFjABegQIBRAB&amp;url=https%3A%2F%2Fwww.tensorflow.org%2Ftensorboard%2Fget_started&amp;usg=AOvVaw2zoEfsLy_AcckWcLnf6tdT">tensorboard</a>也是常見用於深度學習的視覺化套件</p><h4>Jieba</h4><p>Jieba是一個大家提到中文一定會提到的分詞工具，提供自定義詞表，是個簡單好上手的中文分詞工具，不過，中文分詞工具網路上可以找到很多種，誰的效果比較好是眾說紛紜，也有<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwimu7Gp-r7mAhWCHqYKHdJZBHAQFjAAegQIAxAB&amp;url=https%3A%2F%2Fwww.aclweb.org%2Fanthology%2FP19-1314&amp;usg=AOvVaw16iCLgAO5nhcEIkhJua9op">論文提出中文不分詞</a>也能達到相當好的表現，大家可以視情況使用</p><h4>OpenCC</h4><p><a href="https://github.com/BYVoid/OpenCC">OpenCC</a>是一個用來繁簡轉換非常好用的工具，可以直接透過終端機指令來操作，裡面也有做一些中港臺不同用語之間的轉換，像是<strong>巴士</strong>轉成<strong>公車</strong>等，有了這個讓我們也得以使用各種簡體中文的語料了</p><h3>經典論文</h3><p>這邊主要是以我自己閱讀過的論文為主，難以兼顧到每個研究分支</p><blockquote><strong>LDA(2003): </strong><a href="http://www.jmlr.org/papers/volume3/blei03a/blei03a.pdf">Latent Dirichlet Allocation — Journal of Machine Learning</a></blockquote><blockquote><strong>Siamese Network(2005): </strong><a href="http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf">Learning a Similarity Metric Discriminatively, with Application to Face Verification</a></blockquote><blockquote><strong>Word Vector(2014): </strong><a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf">Distributed Representations of Words and Phrases and their Compositionality</a></blockquote><blockquote><strong>TextCNN(2014): </strong><a href="https://www.aclweb.org/anthology/D14-1181.pdf">Convolutional Neural Networks for Sentence Classification</a></blockquote><blockquote><strong>S2S(2014): </strong><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjYyNfmo5zmAhWxHqYKHdxFAboQFjAAegQIAhAB&amp;url=https%3A%2F%2Farxiv.org%2Fabs%2F1409.3215&amp;usg=AOvVaw0eZ3h-yfGTyHX56bxNW6X2">Sequence to Sequence Learning with Neural Networks</a></blockquote><blockquote><strong>ConvS2S(2017, Facebook AI): </strong><a href="https://arxiv.org/pdf/1705.03122.pdf">Convolutional Sequence to Sequence Learning</a></blockquote><blockquote><strong>Transformer(2017, Google): </strong><a href="https://arxiv.org/pdf/1706.03762.pdf">Attention is All You Need</a></blockquote><blockquote><strong>ELMo(2018): </strong><a href="https://arxiv.org/abs/1802.05365">Deep contextualized word representations</a></blockquote><blockquote><strong>BERT(2018, Google): </strong><a href="https://arxiv.org/pdf/1810.04805.pdf">BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</a></blockquote><blockquote><strong>Transformer-XL(2019, CMU, Google Brain):</strong> <a href="https://arxiv.org/abs/1901.02860">Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context</a></blockquote><p>以上這些論文，是我個人主觀認為經典的好論文，像是2014年的詞向量，提出之後讓我們可以基於預訓練的詞向量來進行下游任務，是非常大的突破，而<strong>Seq2Seq</strong>則是為文本生成開啟了序章，尤其是在像是<strong>機器翻譯</strong>或者<strong>QA問答</strong>中是非常重要的里程碑。其他還有相當相當多的重要且經典的論文，雖然我沒有列在其中，但大家還是可以視研究需求去閱讀，像是Distilling蒸餾模型、CRF條件隨機場、Dropout、Pointer Network等等，這個領域其實說來博大精深，有語言學的觀點（像是文法樹、Propbank），有統計的觀點，有機器學習的觀點，也有深度學習的觀點，要說是說不完的，就視每個人的研究需求去學習！</p><h3>應用展示</h3><blockquote>看到這邊你可能想說，我都還沒開始，你用那麼多文鄒鄒的術語我怎麼懂？這個小節讓我們實際看一下NLP可以有什麼應用，跟目前能做到的程度</blockquote><h4>推薦的網站</h4><p>有許多成熟的企業或網站，將他們的成果整理得很好來展示，可以直接在網路上線上試試很多NLP的功能，對於初學者來說，可以先看看實際上NLP個個任務所做出來的成果會是如何？這邊列出幾個我較為熟悉的</p><h4>OpenAI</h4><p><a href="https://openai.com/progress/">OpenAI</a>致力於發展各種AI的應用，近年的有名的GPT2就是他們所提出的，GPT2堆疊了好幾層的解碼器(Decoder)，在自動產生文本上達到非常好的效果，曾經一度OpenAI還不敢釋出模型，因為害怕會被拿來惡意使用，不過現已經釋出最大的模型(<a href="https://openai.com/blog/gpt-2-1-5b-release/">GPT-2-large</a>)</p><h4>AllenAI(AI2)</h4><p><a href="https://allenai.org/">AI2</a>也是一個相當知名的NLP研究組織，在他們網站上也提供<a href="https://demo.allennlp.org/reading-comprehension">DEMO</a>可以體驗各種成果，像是閱讀理解(Reading Comprehension)、指代消解(Coreference Resolution)等等，AllenAI也發表過多篇知名的論文，像是：<a href="https://arxiv.org/abs/1802.05365"><strong>Deep contextualized word representations</strong></a>，非常建議可以去讀看看</p><h4>Huggingface.co</h4><p>前面我們也有提到<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjE-9GRnZzmAhWHGaYKHQCVCAwQFjABegQIBRAB&amp;url=https%3A%2F%2Fgithub.com%2Fhuggingface%2Ftransformers&amp;usg=AOvVaw2tFvUqz2_mjqk4l73AGqMY">huggingface.co</a>所提出的<em>transformers</em>套件，我對他們的認識是從去年底開始，由於他們編寫了Pytorch版本來使用Transformer、BERT這樣的模型，迅速打開知名度，目前他們也提供了很多成熟技術的<a href="https://huggingface.co/">Demo</a>。另外，他們有一間子公司<a href="https://www.meetsam.io/">Sam:)</a>，主要是提供旅遊助理(Travel Assistant)的服務，是非常值得參考的聊天機器人案例，可以到他們的官方網站了解更多</p><h4>中研院 CKIP LAB</h4><p>如果想看一點中文的案例，台灣在NLP上也是有相當多成果的，在中研院<a href="https://ckip.iis.sinica.edu.tw/demo/">CKIP LAB</a>也有提供<a href="https://ckip.iis.sinica.edu.tw/demo/">DEMO</a>像是中文實體判別(Chinese NER)、中文斷詞系統(Tokenization)等</p><h4>騰訊AI LAB</h4><p>中國在自然語言處理這塊，是不可忽視的一大巨人，近年來可在各大Coference上看到他們很多研究成果，<a href="https://ai.tencent.com/ailab/zh/paper/?page=1">騰訊AI LAB</a>雖然沒有提供DEMO網頁可以參考，但可以看到他們的一些研究成果，像是我<a href="https://medium.com/me/stats/post/23f035ae1cef?source=main_stats_page">Review的這篇論文</a>。值得一提的是，在聊天機器人這塊領域，也許是因為中國市場很大，需求也多，如果是研究這方面的可以多往中國的論文或資源去找</p><h3>資料集</h3><blockquote>巧婦難為無米之炊，對於NLP的研究者來說，文字就是我們的米</blockquote><p>自然語言中，雖然算法、模型很重要，但沒有資料驅動還是什麼都做不了，尤其是文字不像圖片一樣不分國界，每個地方用的語言不同，所需要的資料也就不同，英文因為是世界語言，加上論文的發表大部分以研究英文為主，所以資料當然是最多，不過幸運地，中文的語料也算蠻多的，這邊列出幾個好用的中文資料集或預訓練模型</p><h4>NLP-Chinese-Corpus</h4><p><a href="https://github.com/brightmart/nlp_chinese_corpus">NLP_Chinese-Corpus</a> 是在github上由brightmart開源的中文語料統整，裡面包含了一些維基百科、新聞、社區問答等語料，比較多是通用型的中文語料，可以當作詞向量訓練的材料，或者其它應用</p><h4>PTT-Gossiping-Corpus</h4><p><a href="https://github.com/zake7749/Gossiping-Chinese-Corpus">PTT-Gossiping-Corpus</a>是由zake7749在github以及Kaggle上提供的繁體中文問答語料集，一個問句對應到一句鄉民回答，對於想實作中文Sequence2Sequence的朋友，會是蠻不錯的實驗語料</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7m7sVQSyassNibHfzPb6sQ.png" /><figcaption>圖片截自<a href="https://github.com/zake7749">zake7749</a>/<a href="https://github.com/zake7749/Gossiping-Chinese-Corpus">Gossiping-Chinese-Corpus</a> 中的範例說明</figcaption></figure><h4>Wiki-corpus</h4><p>繁體中文的語料，通常就會想到PTT以及中文維基百科，而現在獲取中文維基百科的手段有很多種，維基百科本身也有提供API，大家可以視個人需求來拿到資料</p><h4>Tencent AI LAB</h4><p><a href="https://ai.tencent.com/ailab/zh/index">騰訊AI實驗室</a>非常佛心的釋出相當多有用的中文資料集，像是<a href="https://ai.tencent.com/ailab/nlp/dialogue/">Dialogue Research</a>中包含一些在聊天機器人領域上實用的中文語料，有興趣的朋友可以參考我這篇論文的介紹：<a href="https://medium.com/nlp-tsupei/improving-open-domain-dialogue-systems-via-multi-turn-incomplete-utterance-restoration-%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-6c5697bf4207">Improving Open-Domain Dialogue Systems via Multi-Turn Incomplete Utterance Restoration</a></p><p>此外，騰訊AI也有提供<a href="https://ai.tencent.com/ailab/nlp/embedding.html">預訓練的中文詞向量模型</a>，有興趣的朋友也能試試看</p><h4>BERT</h4><p>BERT就像詞向量模型一樣，需要大量的語料進行預訓練，好處是我們這種一般大眾可以直接使用一些科技巨擘所釋出的預訓練模型，像是Google, HuggingFace, 還有一些開源的github項目都有提供中文的BERT預訓練模型</p><h3>結語</h3><p>如果你很努力地看完這篇文章，但裡面有太多東西記不起來的話，沒關係！直接開始動手做吧！也許可以從最簡單的中文文本分類開始，遇到卡頓的地方也許這篇文章提供的一些資源或建議可以成為你參考的方向</p><p>這篇文章雖寫得有點倉促混亂，不過大致上我把一些常用到的工具以及重要的知識都盡量寫進文章了，若有遺漏也歡迎大家補充，之後這篇文章一定還會持續修訂，我希望能夠以概論的感覺能夠提到各個任務下的基本理論。如果文章裡面有寫錯的地方或者大家有想補充的點，也歡迎留言或寄信告訴我！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a729bccecda" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/%E5%BE%9E%E9%9B%B6%E9%96%8B%E5%A7%8B%E5%AD%B8%E7%BF%92%E8%87%AA%E7%84%B6%E8%AA%9E%E8%A8%80%E8%99%95%E7%90%86-a729bccecda">中文自然語言處理整理</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[論文整理] ALBERT]]></title>
            <link>https://medium.com/nlp-tsupei/%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-albert-328b3984d90?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/328b3984d90</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[bert]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Mon, 02 Dec 2019 09:20:49 GMT</pubDate>
            <atom:updated>2020-01-08T09:45:17.805Z</atom:updated>
            <content:encoded><![CDATA[<h3>介紹</h3><p>今天要整理的這篇ALBERT，利用一些技術減少原先BERT中的參數，並且改進在BERT中使用的NSP，提出了<strong>SOP Loss</strong>有效地提升了下游任務的表現。BERT雖然在很多NLP的任務上取得成功，但是由於其巨大的模型架構，很難被應用在講求速度的實際應用上，像是聊天機器人，所以近期有許多研究都是針對怎麼讓BERT更小，怎麼讓BERT訓練更快等等。ALBERT的預訓練模型以及相關程式碼都已經開源出來了，所以讓我們好好了解一下ALBERT，並且試試看拿它來取代原先我們模型中BERT的部分</p><h3><strong>懶人包</strong></h3><p>一樣地我們提供懶人快速的總結😂，ALBERT利用了參數共享、矩陣分解等技術大大減少模型參數，利用改進的SOP Loss取代NSP Loss提升了下游任務的表現，但是BERT的層數並未減少，因此<strong>推理時間(Inference Time)還是沒有得到改進。</strong>不過，參數減少的確使得訓練變快，ALBERT可以擴展到比BERT更大的模型(ALBERT-xxlarge)，因此得到了更好的表現</p><h4><strong>Abstract</strong></h4><ol><li>Two parameter-reduction techniques</li><li>self-supervised loss that focuses on modeling inter-setence coherence</li><li>establishes new SOTA on the GLUE, RACE, SQuAD benchmarks</li></ol><p>近期的大型預訓練模型帶來一系列突破性的發展，尤其是在Reading Comprehension這一塊，RACE test在2017原始論文被提出時，當時的SOTA僅有44.1%的準確度(Accuracy)，但到了現在的ALBERT已能達到89.4%，進步了<strong>高達45.3%</strong></p><p>這些大型模型往往擁有幾百萬甚至到幾十億的參數，這使得訓練的成本非常高，目前通常透過模型平行化(model parallelization)及聰明的記憶體管理(clever memory management)來解決，但並沒有解決在分佈式運算(distributed learning)中溝通成本(communication overhead)的問題</p><h4><strong>Two Parameters Reduction Techniques</strong></h4><ol><li>factorized embedding parameterization</li><li>cross-layer parameter sharing</li></ol><p>ALBERT使用這兩種減少參數的技術，跟BERT-large相同的設置下，可以減少近18x的參數，訓練速度快了1.7x，同時，這樣的方法也有扮演著正規化(regularization)的角色，也有助於讓訓練更加穩定，並幫助模型更加泛化</p><h4>Self-supervised loss for sentence-order prediction(SOP)</h4><p>SOP主要是為了抓到句子間的關係(inter-sentence coherence)，用來改善原始BERT論文中的NSP loss，在BERT中，NSP loss預測下一個句子是否被置換成其他文章中的句子</p><h3><strong>Factorized embedding parameterization</strong></h3><p>在BERT模型中，隱藏層長度(hidden-layer size)H等於字嵌入長度(Embedding size) E，所以當H越大，E越大，那麼嵌入層(embedding layer)的參數大小就會越大(<em>V * E</em>)，但其實這些參數在訓練過程中只有少量會被更新(sparsely updated)</p><p>所以，ALBERT不直接將原本的one-hot vectors映射到hidden space size of <em>H</em>，而是分解成兩個矩陣，原本參數數量為<em>V*H</em>，分解成兩步驟則減少為<em>V*E + E*H</em>，當<em>H</em>的數量很大的時候，這樣的作法能夠大幅降低參數數量</p><blockquote>VE = 30000 * 768 = 23,040,000</blockquote><blockquote>E(V+H) = 256 * (30000+768) = 7,876,608</blockquote><blockquote>舉個例子，當我們V為30000，H為768，E為256，分解成兩個矩陣後，參數從約2300萬降低到780萬左右</blockquote><h3><strong>Cross-layer parameter sharing</strong></h3><p>也就是直接共享某些權重，像是在每層之間共享FFN、共享Attention、共享所有參數等等，作者這邊分析了每一層input及output的<strong>L2 distance</strong>及<strong>cosine similarity</strong>，並觀察到了相比於BERT-large所呈現的曲線更加平滑，作者認為這表示cross-layer parameter sharing起到的穩定模型參數的效果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PucmbYvzAaATQc8jqZkEtg.png" /></figure><h3><strong>Inter-sentence coherence loss</strong></h3><p>NSP Loss是預測兩個segments是否在原始資料中為連續的兩段話，正樣本直接拿從訓練集裡面拿兩段接續的話，而負樣本則是從不同的文件中取兩段話，以相同的機率去取樣正負樣本。原本NSP是被設計來使BERT能夠加強下游任務的表現，但之後有些研究(Yang et al, 2018; Liu et al., 2019)剔除NSP後反而在一些任務上得到更好的表現</p><p>作者推測NSP的缺失應是該任務難度不夠，NSP任務去分析的話，可以說它包含兩個部分：topic prediction及coherence prediction，這邊我認為：由於正負樣本的兩個segments來自不同文件，通常代表來自不同主題，因此很大一部分透過主題預測就能解決NSP，也因此句子之間的推論關係並沒有學得很好。</p><p>作者提出SOP，不同於NSP產生負樣本的方法是取自不同文件，而是直接將正樣本的兩句話對調，這樣強迫模型專注在<strong>coherence prediction</strong>上，根據實驗顯示，NSP無法解決SOP的問題，但SOP卻能夠在一定程度上解決NSP的問題</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IctSWhH-jVKgYFBc-WNfMQ.png" /><figcaption>可以看出以SOP訓練後，在NSP上還是能有不錯的表現，反之則否</figcaption></figure><h3>Experiment</h3><h4>Setup and Comparision</h4><p>基本上的設定都跟BERT相同，但引進了一些後來用來改進BERT的技巧，像是n-gram masking(Joshi et al, 2019)、LAMB optimizer(You et al., 2019)</p><h4>Ablation Experiment</h4><p>很多研究的會通過Ablation(消融)來證明每個改進方法都是有用的，這邊針對factorized embedding parameterization及cross-layer parameter sharing做消融研究</p><ol><li>Factorized Embedding Parameterization</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfJms8hiNTrY1VjcQS3Nvw.png" /><figcaption>上排是原先BERT-style架構，下排則是ALBERT-style，可以看到在下排表現最好的反而是E=128，且模型參數低於上排近8x</figcaption></figure><p>2. Cross-layer Parameter Sharing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDdosUVwarapIUDCC9U-KQ.png" /><figcaption>我們可以發現大部分的drop都來自於shared-FFN，shared-attention在E=768只有小幅度降低(-0.7)，在E=128甚至小幅度提升(+0.1)</figcaption></figure><p>3. Sentence Order Prediction(SOP)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IctSWhH-jVKgYFBc-WNfMQ.png" /><figcaption>可以看出SOP確實在下游任務中有提昇表現（優於NSP</figcaption></figure><h3><strong>Adding Data and Remove Dropout</strong></h3><p>ALBERT到這邊都是使用跟BERT相同的訓練資料，但是增加訓練資料可以期待會增進模型表現，於是加上STORIES dataset後得到總和約157G的原始資料。另外，訓練到1M步的時候，發現模型還是沒對訓練集overfit，所以直接把dropout移除，結果大幅提升了在MLM上驗證集的accuracy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PRcRlHmAW5pA0-naM7EyMA.png" /><figcaption>Adding data and Removing dropout increase Dev accuracy</figcaption></figure><h3>Discussion</h3><p>作者這邊提到，雖然ALBERT-xxlarge達到比BERT-large更好的效果，但過長的訓練時間跟推論時間(inference time)還是需要再被改進，作者考慮了sparse attention(Child et al., 2019)及block attention(shen et al., 2018)，再來是改進NSP Loss的SOP Loss雖然整體表現優於原先的NSP Loss，但作者仍覺得應有其他更好設計Loss的方式可以捕捉到更多維度來更好的表達</p><h3>Conclusion</h3><p>看完DistilBERT與ALBERT這兩篇近期(2019)以降低BERT模型參數數量為目標的論文，裡頭都提到了一些相關可以用來降低模型參數數量的技術，像是降低精準度(quantization)、模型減枝(weight pruning)、蒸餾(Distilling)、共享模型參數(cross-layer parameter sharing)、分解矩陣(factorized parameters)等等，也提到像BERT此類的大型預訓練模型，除了在訓練時需要極高成本，使用時過長的inference time也很難用於實際應用上。</p><p>不過，ALBERT雖然讓模型參數數量大幅下降，但推理時間(inference time)並未得到改善，因為即使是使用了共享參數機制，還是得跑完12層的Encoder參數，故推理時間跟BERT是差不多的</p><p>自從BERT被提出後，許多NLP任務都有極大幅的效能提升，也讓我們可以用更小的資料就能訓練出極好的效果，因此，接下來如何讓其更小、更快，讓它可以於現實中被應用是近期最重要的目標</p><h3><strong>Reference</strong></h3><p><a href="https://openreview.net/forum?id=H1eA7AEtvS">ALBERT: A Lite BERT for Self-supervised Learning of Language Representations</a></p><p>All photos in this ariticle are screenshot from the paper. Only used for illustration in this article</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=328b3984d90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-albert-328b3984d90">[論文整理] ALBERT</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pointer Generator Network]]></title>
            <link>https://medium.com/nlp-tsupei/pointer-generator-network-5a5a3a2bce3?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/5a5a3a2bce3</guid>
            <category><![CDATA[pointer-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[sequence-to-sequence]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[dialogue-systems]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 09:32:13 GMT</pubDate>
            <atom:updated>2019-11-20T09:33:10.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>介紹</h3><p>Pointer Network在最近看的很多篇論文中有出現，由於原先<strong>Attention + Encoder — Decoder</strong>的方法中，Decoder最後輸出時是要對應到一個詞表，但在實際使用中，像是人名跟地名的用字並不被包含在訓練中的詞表中，最後只能得到像<em>[UNK]</em>這種輸出。而Pointer Generator Network的概念是從原輸入的某一些片段直接擷取過來當作輸出，這麼一來則可以彌補字典的不足</p><p>所以當Decoder在產生輸出時，根據<em>Pgen</em>這個機率來決定是要自己產生輸出呢?還是要拿原輸入的「某個位置」直接當作輸出?</p><p>如果你對Summarization有些接觸的話，會知道大致上分為兩種方法為<strong>Extractive Summarization</strong>跟<strong>Abstractive Summarization</strong>，很神奇的，透過Pointer Generator Network，很奇妙地同時整合了這兩種方法在一起，有時候是直接複製，有時候則是自己產生，這跟我們「人」真正在寫作的情況也更類似😂，如果今天要我們寫一篇讀書心得文，我們常常會引用書中某些話，或者一些地名或者很長的專有名詞時，我們也會直接複製貼上，這些情況應該要直接複製而不是自己產生才更合理。</p><p>作者在<a href="http://www.abigailsee.com/2017/04/16/taming-rnns-for-better-summarization.html">部落格</a>中有提到這一點</p><blockquote>In this way, the pointer-generator network is a best of both worlds, combining both extraction (pointing) and abstraction (generating).</blockquote><h3><strong>架構</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*otAKKdFfOhq0-wlG0rPLAw.png" /><figcaption>Pointer-generator model source: <a href="https://arxiv.org/pdf/1704.04368.pdf">Get To The Point: Summarization with Pointer-Generator Networks</a></figcaption></figure><p>上圖很好的呈現出整體模型的架構，和一般的Seq2Seq model相比，多了一個Pgen，用來決定要不要採取輸入的原文字當作輸出，公式如下，xt是Decoder原始輸入，st是Decoder輸出，h*t是Decoder跟Encoder做完Attention後的輸出</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*6WSVG8B6xI6Xg3XHyDH74A.png" /><figcaption>Source: <a href="https://arxiv.org/pdf/1704.04368.pdf">Get To The Point: Summarization with Pointer-Generator Networks</a></figcaption></figure><p>得出後，再透過第二個公式來決定要拿哪個字當輸出，於是得到一個新的P(w)，所以如果原先的w是一個OOV word，那Pvocab會是0，但新的公式讓我們還是能有機會能夠取到這些字</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*OeZi25NxCXMqk_q4kn66-A.png" /><figcaption>Source: <a href="https://arxiv.org/pdf/1704.04368.pdf">Get To The Point: Summarization with Pointer-Generator Networks</a></figcaption></figure><h3>Coverage Mechanism</h3><p>原始的Seq2Seq模型，除了OOV問題以外，還有Repetition的問題，模型容易產生重複的字，而Converage Mechansim的想法是，把前面時間點的attention做一個累加，並且引進到現在時間點attention的計算當中</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*MTFG6OcMnH5zExUme2s9cQ.png" /><figcaption>現在時間點t的converage，為0~t-1的注意力累加</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*VaNXtA2zzAuwUJ8xVebTtw.png" /><figcaption>引進c到注意力(attention)的計算當中</figcaption></figure><p>Coverage也必須被加入到Loss的計算中，這是根據作者實驗出來的結論，由於如果不額外添加Coverage Loss的話，Repetition的問題依舊會存在</p><blockquote>We tried training the coverage model without the loss function, hoping that the attention mech- anism may learn by itself not to attend repeatedly to the same locations, but we found this to be inef- fective, with no discernible reduction in repetition.</blockquote><p>最後，加入Coverage Loss後，新的Loss Function為</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*Z9O4yW1TWPypaabuF-nDCw.png" /><figcaption>新的Loss Function</figcaption></figure><h3>結論</h3><p>Pointer Generator Network讓我們能夠產生出更好的文本，並且結合了Abstractive及Extractive的優點於一身，像是在文本還原(Restoration)中和文本抽取(Summarization)這些任務上，有需要拷貝原輸入的情況在，Pointer Generator Network會是一個很好的切入點</p><p>如果這篇文章對你有幫助的話，歡迎拍拍手👏👏👏</p><h3><strong>Reference</strong></h3><p>[1]: Paper(ACL2017) — <a href="https://arxiv.org/pdf/1704.04368.pdf">Get To The Point: Summarization with Pointer-Generator Networks</a><br>[2]: Blog Post — <a href="http://www.abigailsee.com/2017/04/16/taming-rnns-for-better-summarization.html">Taming Recurrent Neural Networks for Better Summarization</a><br>[3]: Blog Post — <a href="https://distill.pub/2016/augmented-rnns/">Attention and Augmented Recurrent Neural Networks</a><br>[4]: Tutorial Video -</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a5a3a2bce3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/pointer-generator-network-5a5a3a2bce3">Pointer Generator Network</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[論文整理] Improving Open-Domain Dialogue Systems via Multi-Turn Incomplete Utterance Restoration]]></title>
            <link>https://medium.com/nlp-tsupei/improving-open-domain-dialogue-systems-via-multi-turn-incomplete-utterance-restoration-%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-6c5697bf4207?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/6c5697bf4207</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[dialogue-systems]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 09:50:01 GMT</pubDate>
            <atom:updated>2019-11-21T02:29:44.901Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>介紹</strong></h3><p>今天來分享<strong><em>騰訊</em></strong><em> AI Lab</em>在EMNLP上的一篇論文，主要針對使用者在使用對話系統(dialogue system)的時候，常常會有省略的情況，而根據先前的研究(<em>Reghu et al., 2015; Kumar and Joshi, 2017</em>)顯示，當我們把這些資訊還原後，能夠更好地理解使用者的意圖(intent)</p><h3>主要方法</h3><p>這篇論文主要使用了以下方法</p><p><strong>1. Seq2Seq &amp; Attention mechanism<br>2. Pointer Generative Network<br>3. BERT</strong></p><p>Seq2Seq採取的是Encoder-Decoder加上Attention的版本，而<strong>Pointer Generative Network</strong>則是<a href="https://ai.tencent.com/ailab/nlp/dialogue/">(Abigail et al., 2017)這篇論文</a>，官方也有一篇詳細解說的<a href="http://www.abigailsee.com/2017/04/16/taming-rnns-for-better-summarization.html">部落格文章</a>，建議可以好好了解一下Pointer Network</p><p>作者基於這些方法提出了<strong>Pick and Combine</strong>的模型，利用BERT模型先提取出被省略的字，將提取出的這些字加在原始語句後方，再透過Pointer Generative Network去還原產生最後的輸出，可參考下圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*90mzJr-AmOnpAndonuQzyw.png" /><figcaption>來源: <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi1-MPIvPPlAhXRG6YKHYZzDWoQFjABegQIARAC&amp;url=https%3A%2F%2Fai.tencent.com%2Failab%2Fnlp%2Fdialogue%2Fpapers%2FEMNLP_zhufengpan.pdf&amp;usg=AOvVaw3lx-zT35e7mVsJoilvWAmk">Improving Open-Domain Dialogue Systems via Multi-Turn Incomplete Utterance Restoration</a></figcaption></figure><h3>疑問點</h3><p>在將BERT由前面的Context所提取的「被省略字(omitted word)」加到原語句後方這個動作，而上圖中是加入輸出的標籤，但根據文章內容感覺是加上被提取的字眼</p><blockquote>&gt; the combine stage is straightforward. The selected omitted words are appended to the input sequence as extra guidance（節錄自論文中3.2 Combine）</blockquote><p>這個部分有點模糊，但理論上我認為應是加上被提取的字，因為這樣才能夠被PGN所複製</p><h3><strong>資料集</strong></h3><p>騰訊有提供此論文使用的資料集，是目前網路上相當稀有的中文多輪對話的資料，這邊可以下載</p><p>一個樣本包含8個項目</p><p>- (1)~(4)為上下文<br>- (5)為目標句子，也就是可能發生省略的句子<br>- (6)為回應(5)的一個句子，在我們訓練過程沒有實際作用，當作參考用<br>- (7)為一個0或1的數字，表示(5)是否有省略發生<br>- (8)為還原(5)的句子，只有當(7)為1的時候才會有值</p><p>以下是一些資料的截圖範例</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVOYmsMYAHp_ATFJrj8NyQ.png" /><figcaption>資料來源：<a href="https://ai.tencent.com/ailab/nlp/dialogue/">騰訊AI Lab</a></figcaption></figure><h3><strong>實驗</strong></h3><p>這篇論文中，採取人工檢驗的方式分別對(a)還原句子的品質 (b)還原句子後在單輪對話回應的品質 (c)還原句子後在多輪對話回應的品質 做評價，下圖是(c)的截圖，可以看出使用了還原(restoration)後大幅改善體驗，可以看出單純使用Attention機制，由於會有OOV跟Repetition的問題，在PTR中解決這個問題，而PAC(本模型)表示在restoration中，因為極度不平均的機率，原本句子(5)有100%的字都會出現在還原句子(8)，而上下文(1~4)只會有大約17.7%，因此主要朝這點改善</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*si--ybCKSLZ0T9-8lD8MCQ.png" /><figcaption>來源: <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi1-MPIvPPlAhXRG6YKHYZzDWoQFjABegQIARAC&amp;url=https%3A%2F%2Fai.tencent.com%2Failab%2Fnlp%2Fdialogue%2Fpapers%2FEMNLP_zhufengpan.pdf&amp;usg=AOvVaw3lx-zT35e7mVsJoilvWAmk">Improving Open-Domain Dialogue Systems via Multi-Turn Incomplete Utterance Restoration</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c5697bf4207" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/improving-open-domain-dialogue-systems-via-multi-turn-incomplete-utterance-restoration-%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-6c5697bf4207">[論文整理] Improving Open-Domain Dialogue Systems via Multi-Turn Incomplete Utterance Restoration</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[論文整理] Improving Multi-turn Dialogue Modelling with Utterance ReWriter]]></title>
            <link>https://medium.com/nlp-tsupei/improving-multi-turn-dialogue-modelling-with-utterance-rewriter-%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-23f035ae1cef?source=rss----1ce1bc30383f---4</link>
            <guid isPermaLink="false">https://medium.com/p/23f035ae1cef</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[dialogue-systems]]></category>
            <category><![CDATA[mls]]></category>
            <dc:creator><![CDATA[U]]></dc:creator>
            <pubDate>Thu, 31 Oct 2019 09:34:41 GMT</pubDate>
            <atom:updated>2019-11-21T02:28:40.018Z</atom:updated>
            <content:encoded><![CDATA[<h3>摘要</h3><p>近來的發展已經能夠很好的處理<strong>單輪對話(single-turn dialogue modeling)</strong>，但對於<strong>多輪對話(multi-turn dialogue modeling)</strong>還是差強人意，其中一個原因為多輪對話中有許多<strong>指代(coreference</strong>)還有<strong>省略(information omission)</strong>的出現，讓機器難以單從單輪對話中理解語句，在這篇論文中，作者提出用重寫句子的方法，在句子進到模型被處理前，當作預處理來還原這些指代用字及省略的資訊</p><p>本篇論文被節錄在<a href="https://www.aclweb.org/anthology/">ACL, 2019</a>中，由Hui Su(Pattern Recognition Center, Wechat AI, Tencent Inc, China)等人所提出的</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKIit_TfxCFh-XG-bai8ug.png" /><figcaption>圖片擷取自：<a href="https://www.aclweb.org/anthology/P19-1003/">Improving Multi-turn Dialogue Modelling with Utterance ReWriter</a></figcaption></figure><h3>介紹</h3><p>在中文和日文中，特別容易出現指代及省略的現象，在之前的研究中顯示，在中文的多輪對話情境下大約70%的句子(utterance)都存在指代或資訊省略，若要使機器能理解這些語句，需要對整體的對話有深層的了解。此模型和相似的研究比較，有model-agnostic的優點，能輕易地被整合進其他的對話系統中，對記憶體的負擔也較小，系統不必存下對話紀錄(history)，因為歷史資訊會被反映在重寫的語句中。此篇論文主要使用了<a href="https://arxiv.org/abs/1506.03134">Pointer Network(Vinyals et al., 2015)</a>和<a href="https://arxiv.org/abs/1706.03762">Transformer(Vaswani et al., 2017)</a>的方法，實驗結果在coreference resolution和information completion兩項目的F1 score都達到了超過0.85的成績</p><h3>Coreference Resolution</h3><p>作者在這邊，主要回顧了一下過去做Coreference Resolution的各種方法</p><p>主要有：</p><ol><li>Traditional Approaches. Identify all pronouns and entities + Clustering algorithms</li><li>End-to-end neural coreference resolution system(Lee et al., 2017): Computationally inefficient</li><li>Tranfomer adopted with self-attention machanism(Vaswani et al., 2017): Problems to distinguish multiple coreferences</li></ol><p>方法(2)雖然達到了SOTA的成績（註：在<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi25qq81uPlAhUMq5QKHa5ZCwEQFjAAegQIBBAB&amp;url=https%3A%2F%2Fgithub.com%2Fallenai%2Fallennlp&amp;usg=AOvVaw3THMcJAujLnrXIWl5DCeLb">AllenNLP</a>以及<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwj01cHF1uPlAhWyLqYKHSOcCDEQFjABegQIARAB&amp;url=https%3A%2F%2Fgithub.com%2Fhuggingface&amp;usg=AOvVaw3JXbdGEYg4i_3Zm-0Y_8vc">Huggingface</a>上已經有實現），但根據本篇作者指出，效能上的負擔無法使用在現實世界中的對話系統上，而方法(3)使用了Transformer，並且是屬於非監督式(unsupervised)，不過同時有多種指代結果時，並不能很好地找到指代的對象，在本篇論文中，加入了使用監督方法(supervised way)來解決多種指代結果的問題</p><h3>模型</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BkJONjKZ48HWUQOFFWBbaQ.png" /><figcaption>圖片擷取自：<a href="https://www.aclweb.org/anthology/P19-1003/">Improving Multi-turn Dialogue Modelling with Utterance ReWriter</a></figcaption></figure><p>模型的部分主要承襲Transformer的Encoder-Decoder架構，在Decoder的後面再加上一層Pointer Network的機制，直接擷取input中重複的部分，這邊我就不贅述模型公式的部分，有興趣的讀者可以直接到論文中看</p><p><strong>Encoder</strong></p><p>Encoder的部分和Transformer的架構大致相同，只不過輸入的部分結合了WE(Word Embeddings), PE(Positional Embeddings), TE(Turn Embeddings)，TE是使用來區別每一輪對話的</p><p><strong>Decoder</strong></p><p>每個Decoder Block一樣由三層組合，第一層為本身的Multi-head Attention，第二層為Encoder-Decoder Multihead Attention，比較特別的是，這邊將歷史紀錄(H)及目標語句(Un)分開做Attention，再接起來(concatenate)輸入到第三層，一樣是FNN</p><p><strong>Output Distribution</strong></p><p>最後，我們希望能夠判斷要從歷史紀錄H複製字，還是從原本句子Un複製字，所以再引進soft gating weight λ來決定，關於這件事，推薦可以參考台大<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjm-e6B1uPlAhVJHKYKHcvoBdUQwqsBMAB6BAgJEAQ&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVdOyqNQ9aww&amp;usg=AOvVaw1kxe28adYTlCFKypb6MMZr">李宏毅教授的Pointer Network</a>，相信看完會更了解</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*9UqEL942Pgfn9yIHluyOFw.png" /><figcaption>圖片擷取自：<a href="https://www.aclweb.org/anthology/P19-1003/">Improving Multi-turn Dialogue Modelling with Utterance ReWriter</a></figcaption></figure><h3>評估</h3><p><strong>Accuracy of Generation</strong></p><ol><li>使用BLEU, ROUGE, EM三種方法評估語句生成的好壞</li><li>在正樣本(positive samples)中達到了55.84%的EM，負樣本(negative samples)中達到了98.14%的EM</li></ol><p><strong>Coreference Resolution</strong></p><p>評估重寫語句(rewritten utterance)是否包含正確的指代對象，作者提出的Ptr — λ達到了0.92的F1score</p><p><strong>Information Completion</strong></p><p>評估重寫語句(rewritten utterance)是否包含被省略的資訊，本輪文的模型達到了0.86的F1score，此外還額外加入人工判斷語句的流暢度（fluency)，達到了4.9/5與人類的4.94/5已非常接近</p><h3>結論</h3><p>這篇論文主要提出了一種預處理的方法來還原指代和省略，再經由一般的對話處理，除了在多輪對話這樣的情境中相當重要，對於其他NLP任務，類似的情況也容易造成判斷錯誤，因此使用在別的Tasks上也應該有幫助</p><h3>Reference</h3><p><a href="https://arxiv.org/abs/1506.03134"><em>1.Pointer Network(Vinyals et al., 2015)</em></a></p><p><a href="https://arxiv.org/abs/1706.03762"><em>2. Transformer(Vaswani et al., 2017)</em></a></p><p><a href="https://arxiv.org/abs/1808.04776"><em>3. Retrieve and Refine: Improved Sequence Generation Models For Dialogue</em></a></p><p><a href="https://arxiv.org/abs/1707.07045"><em>4. End-to-end Neural Coreference Resolution(Lee et al. 2017)</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23f035ae1cef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nlp-tsupei/improving-multi-turn-dialogue-modelling-with-utterance-rewriter-%E8%AB%96%E6%96%87%E6%95%B4%E7%90%86-23f035ae1cef">[論文整理] Improving Multi-turn Dialogue Modelling with Utterance ReWriter</a> was originally published in <a href="https://medium.com/nlp-tsupei">NLP-trend-and-review</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>