--- title: 'NLP技術之概論' tags: NLP --- NLP技術之概論 === ## Table of Contents [TOC] ## 學習目標 * 如何分析自然語言? --- 計算語言之父 (Noam Chomsky) --- * 1957年的劃時代巨著:[Syntactic structures (句法結構)](https://scholar.google.com/citations?user=rbgNVw0AAAAJ&hl=en#d=gs_md_cita-d&u=%2Fcitations%3Fview_op%3Dview_citation%26hl%3Den%26user%3DrbgNVw0AAAAJ%26citation_for_view%3DrbgNVw0AAAAJ%3A9yKSN-GCB0IC%26tzom%3D-480) 1. A language to be a set (finite or infinite) of sentences, ==each finite in length== and constructed out of a finite set of elements. > 語言是句子的集合(有限或無限),==每個句子的長度都是有限的==,而且從有限的元素組合。 * "有限的元素組合",代表可以完成並理解句子處理的整個步驟。 2. The structure of language is ==biologically determined==. > 語言結構是被生理結構所確定的。 * 雖然世界上的語言有數千種,然其背後的結構是相同或相似的。 * 因為其背後的結構相似,故在NLP上不論是對何種語系其處理方法也應該是非常相似的。 3. That humans are born with an innate linguistic ability that constitutes a ==Universal Grammar==. > 人類生來就有天生的語言能力,這個能力包含了一種==通用語法==。 * 通用語法 = 語言結構(語法) * 不管何種語言,其背後的結構相似,處理方法也類似。 NLP的基本概念 --- 例句:![](https://i.imgur.com/KAFtXKv.png) NLP步驟: 1. 詞彙分析 Lexical analysis (Part-of Speech Tagging 詞性標註) * 需要知道`This` `is` `the` `best` `thing` `happened` `in` `my` `life`分別是什麼東西?作為何種功用?~~意義~~ * POS Tagging (詞性標註) ![](https://i.imgur.com/KsVpoq2.png) 2. 句法分析 Syntactic analysis (Parsing) * Syntactic analysis = Noam Chomsky 所提出的 ==Syntactic structures (句法結構)== * Universal Grammar * 句子被拆解,且可以組合成一棵樹。 ![](https://i.imgur.com/bYNPdg4.png) * 依據不同詞性,先組合成名詞片語、副詞片語...群組。 * 切成`token`小單位,再分析(演算法:divide and conquer) ![](https://i.imgur.com/L6xkcPy.png) * Parsing -> 用來理解是否輸入字串是否可以透過文法產生 * 透過`Universal Grammar(文法、文法器)`產生跟`輸入字串`幾乎==相等的東西==。 * 概念:==句子== 透過 ==文法的切法(語法結構)== 來表達。 * __文法器 = 解碼器 = 編碼器__ 的`產出`與`輸入`相等 * Parsing並非NLP裡專屬的概念 * 源自:Computer Science裡的編譯器(compiler) * 把人所編的程式語言,轉成機器所能理解的機器語言。 :::info ### Parsing 範例(四則運算編譯器) * 演算法:各個擊破法(divide and conquer) * 文法: 1. `句子` E E :: = ==E op E== | ==- E== | ==(E)== | ==id== * 句子可以一直被拆解成更小的單位 * 最終拆解成`最小單位`id 2. `運算子` op op :: = ==+== | ==-== | ==*== | ==/== * 例句:`a * -( b + c )` ![](https://i.imgur.com/FjFnSU8.png =200x200) ::: 3. 語意分析 Semantic Analysis * 利用`Syntactic analysis (句法分析)`的小片段來理解句子的意思 * 從語意分析資料庫裡得知Rule * 例如:(Event) + best thing + happened -> 理解成發生xxx事 ![](https://i.imgur.com/U9T2TMU.png) 4. 推理 Inference * 利用語意分析的Rule來做推理 ![](https://i.imgur.com/WyMMS50.png) NLP to NLU(Natural Language Understanding) --- * NLP(處理) 不等於 NLU(理解能力) * [NLU vs. NLP vs. ASR](https://nlp.stanford.edu/~wcmac/papers/20140716-UNLU.pdf) ![](https://i.imgur.com/4epvwiF.png) Challenges --- * 做完NLP後,不代表"已經能夠完全了解"別人的自然語言在講什麼。不一定! 1. 斷詞錯誤 * 中/日文,容易發生 * 例句:`下雨天留客天留我不留` ```gherkin= 1. 下雨天"留"客 天"留"我不"留" v. v. v. 2. 下雨天 "留"客天 "留"我"不" "留" => 留 adj. v. 語助詞 v. 3. 下雨天 "留"客天 "留"我"不""留" => 不留 adj. ``` * 1 & 2 詞彙分析 Lexical analysis * `詞性標註`不同,則斷詞不同 * 2 & 3 句法分析 Syntactic analysis 2. 推理錯誤 * 與文化背景有關 * 例句: 1. `玻璃杯碎了一地` -> 玻璃杯不能用了 2. `專家眼鏡碎滿地` -> 專家眼鏡不能用了? 3. 語言的演化 * 電腦可能會斷詞錯誤 * 例句: 1. 安史之亂(唐) 2. 安屎之亂(2018) --- * ##### tags: `NLP技術之概論` * [現代語言學與認知科學之父](http://webarchive.ncl.edu.tw/archive/disk36/28/30/49/76/20/201112073016/20160512/web/case.ntu/sts/index53f0.html?p=1804) * [Noam Chomsky on Language Aquisition](https://www.youtube.com/watch?v=7Cgpfw4z8cw)