bessyhuang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: NLP - NLP入門基礎知識 tags: self-learning, NLP --- {%hackmd BkVfcTxlQ %} # **_NLP - NLP入門基礎知識_** > [name=BessyHuang] [time=Sat, Apr 4, 2020] # **課程大綱** [TOC] :::warning **_Reference:_** * 塗銘、劉祥、劉樹春(2018)。**Python自然語言處理實戰:核心技術與算法**。北京:機械工業出版社。 * [斷開中文的鎖鍊!自然語言處理 (NLP)](https://research.sinica.edu.tw/nlp-natural-language-processing-chinese-knowledge-information/) ::: --- ## **基礎概念** * 什麼是NLP? * 自然語言處理 (Natural Language Processing) * 結合「語言學」和「計算機科學」的綜合學科,需要語言學、統計學、最佳化理論、機器學習、深度學習、NLP相關理論模型知識作為基礎。 * ==研究目標:讓電腦來處理、理解、運用人類語言,達到人機間的有效通訊。== * 程式語言 VS. 自然語言 * 程式語言:人類為了與計算機溝通,而設計的人工語言。 * 自然語言:人們溝通時自然地發展出來的語言。 * [NLP的技術類型](https://www.find.org.tw/index/wind/browse/0e2d08a0d66b773918afec8837eb42d4/) * 自然語言理解 NLU:將人類語言轉成內部計算表示式。 * [音韻學](https://www.bilibili.com/video/av41826732/):研究某一語言的音位的學問。(發音差異與語義的關係) * Ex: cat, rat, hat。包、拋、貓。 * 「永」遠-> 聲調變成二聲 * [詞法學](https://zh.wikipedia.org/wiki/%E8%AF%8D%E6%B3%95%E5%AD%A6):研究單詞(word)構成及相互之間的關係。 * [句法學](https://zh.wikipedia.org/wiki/%E8%AF%AD%E6%B3%95):探究句子的文法規則。 * [語義學](https://zh.wikipedia.org/wiki/%E8%AF%AD%E4%B9%89%E5%AD%A6):研究自然語言(詞彙、句子、篇章等不同級別之語言單位)的意義。 * [語用學](https://zh.wikipedia.org/wiki/%E8%AF%AD%E7%94%A8%E5%AD%A6):研究語境中的語言意義。 * 研究語言行為(招呼、回答、勸說)的文化準繩與發言規則。 * Ex: 話裡有話,從中識別其目的為何? * 自然語言生成 NLG:將內部計算表示式轉成人類語言。 * [自然語言文本](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/676254/) * NLP的三個層面 1. 詞彙分析 (lexical analysis) * 包含分詞 (Segment)、詞性標註 (Part-of-speech Tagging, POS Tagging) 2. 句法分析 (syntactic analysis) * 對輸入的文本以句子為單位,進行分析以得到句子的句法結構的處理過程。 * 目的 * 理解句子含意 * 為更高級的NLP任務(機器翻譯、情緒分析...)提供支持 3. 語義分析 (semantic analysis) * 理解句子表達的真實語義。 * 語義該採用何種表示形式?至今未有定論 ![](https://i.imgur.com/oMfxEaB.png) * NLP的研究任務 * 機器翻譯、情緒分析、文摘生成、智能回答、文本分類 ![](https://i.imgur.com/0YcBUXK.png) ![](https://i.imgur.com/4XHhCXf.png) ![](https://i.imgur.com/iNzHAXS.png) * 輿論分析:自動判斷目前輿論的導向。 * Ex: [用AI中的自然語言處理(NLP)技術,架設一個新聞分析網站「島民衛星」](https://islander.cc/latest/) * 知識圖譜:知識點相互連接而成的語義網路。 * 把所有不同種類的信息(Heterogeneous Information)連接在一起而得到的一個關係網絡。知識圖譜提供了從「關係」的角度去分析問題的能力。 * Ex: [Google knowledge graph](http://geocyber.org/blog/?p=1335) * NLP的困難與挑戰 ![](https://i.imgur.com/Lc4lRql.png) --- ## **[發展歷程](http://hemingwang.blogspot.com/2019/01/history-of-natural-language-processing.html)** * 對於自然語言處理的發展歷程,可以從哲學中的經驗主義和理性主義說起。 * 經驗主義:基於統計的NLP * 理性主義:基於規則的NLP * 哲學領域中經驗主義與理性主義的鬥爭一直是此消彼長,這種矛盾與鬥爭也反映在NLP上。 ### 萌芽期 (1956年以前) 1. ==早期:「經驗主義(基於統計)」== * 1913年:馬爾科夫提出馬爾科夫隨機過程與馬爾科夫模型的基礎就是「手工查頻」,具體說就是統計了《歐根·奧涅金》長詩中元音與輔音出現的頻度。 * 1948年:香農把離散馬爾科夫的機率模型應用於語言的自動機,同時採用手工方法統計英語字母的頻率。 2. ==++喬姆斯基時期++出現轉變:「理性主義(基於規則)」算是完勝,「經驗主義」被全盤否定== * 1956年,建立自然語言的有限狀態模型:借鑑香農,喬姆斯基把有限狀態機作為刻畫語法的工具,用「代數」和「集合」將語言轉化為符號序列,建立有關語法的數學模型。 > ![](https://i.imgur.com/2WRgzut.png) > 喬姆斯基為自然語言和形式語言找到了一種統一的數學描述理論。 > 一個「形式語言理論」的新領域誕生。 > 隨後,他否定有線狀態模型在自然語言的適用性, > 然後主張採用有限的、嚴格的規則去描述無限的語言現象, > 提出風靡一時的轉換生成語法。 3. ==1950末-1960中:主流仍是「理性主義(基於規則)」,但「經驗主義」漸漸東山再起== * 普遍認為:只有詳盡的歷史語料才能帶來靠譜的結論。 * 著名的理論與算法誕生:貝葉斯方法(Bayesian Method)、隱馬爾可夫、最大熵、Viterbi算法、支援向量機... * 世界上第一個百萬字的英語電子語料庫誕生:布朗語料庫 (Brown Corpus) > 1961年在布朗大學創建,內含500個文本,並且按類型進行分類(如:新聞、社論…),用於研究體裁之間的差異,這是一種稱為文體學(stylistics)的語言探究。 ### 快速發展期 (1980~1999年) * ==1990年代以來:「經驗主義(基於統計)」大放異彩== * 機器翻譯領域取得突破,因為引入基於語料庫的方法。 * 1990年:在芬蘭赫爾辛基舉辦的第13屆國際計算語言學會議確定的主題是「處理大規模真實文本的理論、方法與工具」,重心開始轉向大規模真實文本。 > 學者們認為,大規模語料至少是對基於規則方法有效的補充。 * 1994-1999年:經驗主義開始空前繁榮。 > 句法剖析、詞類標註、參照消解、話語處理的演算法 > 幾乎把「機率」與「數據」作為標準方法,成為NLP的主流。 * 1990中期:促進NLP研究的復甦與發展 1. 電腦運算速度與儲存量大幅增加 2. 1994年Internet商業化、網路技術發展 > 使得基於自然語言的資訊檢索與資訊抽取需求突增, > 也讓NLP不再侷限於機器翻譯、語音控制等早期領域了。 * 1990末-2000初:各種處理技術開始融合,NLP再次繁榮。 * 意識到僅用基於規則或統計的方法,是無法成功處理自然語言的。 ### 突飛猛進期 (2000年至今) * 2006年:Hinton成功設計第一個多層結構的神經網路++演算法++:[深度學習](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/585610/)。 > 一種將原始數據通過一些簡單但是非線性的模型轉變成更高層次、更加抽象表達的特徵學習方法,一定程度上解決了人類處理「抽象概念」這個亙古難題。 * 下列的NLP任務,在深度學習的使用下取得不錯成果: * [命名實體識別 (Named Entity Recognition, NER)](https://www.chainnews.com/zh-hant/articles/690356109154.htm) * [詞性標註 (Part-of-speech Tagging, POS Tagging)](https://kknews.cc/zh-tw/education/rlv43kx.html) * [情感分析 (Sentiment Analysis)](https://twgreatdaily.com/1o7BXW4BMH2_cNUgv02-.html) > [Deep Learning for Sentiment Analysis : A Survey](https://arxiv.org/abs/1801.07883) * 機器翻譯 * 問答系統 --- ## **基本術語** ### 分詞(Segment) * 字詞(word) * 具有獨立語意或扮演特定語法功能、有意義的最小語言單位。 * 中、英文皆有分詞的需求。 * 英文:以空白隔開單詞,方便處理。 * 中文:詞語之間沒有明顯的區隔,相對而言較難處理。 * 處理手段 * 基於字典的最長串匹配,解決85%的問題。 * 但是,歧義分詞難處理 > Ex: 「美國會通過對台售武法案」 > 可以切分為「美國/會/通過對台售武法案」或「美/國會/通過對台售武法案」 ### 詞性標註 (Part-of-speech Tagging, POS Tagging) * 詞性 * 指動詞、名詞、形容詞...等。 * 標註的目的:表徵詞的一種隱藏狀態。 * 正確地解析出字詞詞性分類的歧異性,即從所有可能的詞性標註組合之中,決定並挑選出最有可能且最符合所有字詞在句法結構或語言形態行為的一種。 > Ex:我/r 愛/v 台灣/ns 牛肉麵/n > ns代表名詞,v代表動詞,ns、v都是標註。 * [機器人要理解中文(兩種做法)](https://www.ithome.com.tw/news/128778) * 目前多採混合,純以深度學習方式來完成比較少見。 1. 先斷詞,對於中文語意理解先建立一套自動化標記方式,再利用這套標記判斷方法,來分析句子語法、語義結構和以前類似句子的標記是否一致。 > 基於機器學習的方法,往往需要對詞的詞性進行標註。 2. 將詞彙轉換成詞向量(Word Vector)來表達,每一個詞彙直接就是一個輸入,然後經過計算各個字詞之間的相似程度,得出這個詞所要表達的語義,也就是輸出。 > 當前NLP最熱門的研究:類神經網路深度學習技術 > 通過建立深度學習NLP模型,從大量中文語料學習不同詞彙所要表達的語義。 > > 不需經過任何複雜的語法拆解、語義分析的標記,甚至也不一定要先斷詞。 ### 命名實體識別 (Named Entity Recognition, NER) * 指從文本中識別具有特定類別的實體(通常是名詞) * Ex: 人名、地名、機構名、專有名詞... ### 句法分析 (Syntax Parsing) * 往往是一種基於規則的專家系統。也不是說它不能用統計學的方法進行構建。 * 最初的句法分析:利用語言學專家的知識來構建,最終生成一棵句法分析樹。 * 目的:解析句子中各個成分的依賴關係。 * 解決傳統詞袋模型不考慮上下文的問題。 > Ex: 「我欠你一個人情」和「你欠我一個人情」 > 這兩句話,用詞袋模型(Bag-of-words model) 是完全相同的, > 但是句法分析可以分析出其中的主從關係,真正理清句子的關係。 > [詞袋模型:文件表示法的一種。](http://terms.naer.edu.tw/detail/1679006/) > 其將文件中出現的詞彙,想像是放在袋子裡零散而獨立的物件,如此一個袋子代表一篇文件。Ex: 文件A中的內容:「病人與醫生的糾紛研究」,以詞袋模型表示,則該文件可以表達成:「病人、糾紛、醫生、研究」這四個獨立的詞彙。 > * 特性:字的順序並不重要。 ### 指代消解 (Anaphora Resolution) * 中文的代詞出現頻率很高,作用為用來表徵前文出現過的人名、地名等。 ### 語言模型 (Language Model, LM) * 語言模型 * 對語言建立基於機率統計的模型 * 核心目的:找到待評測資料中,最符合語言習慣的表達(機率最大)。 > Ex: [N-grams model](https://www.youtube.com/watch?v=GiyMGBuu45w)是最常用的建模技術,採用馬爾科夫假設: > 一個詞的出現僅僅依賴與它前面出現的有限的一個或者幾個詞。 > > [![](https://i.imgur.com/wmzlIxq.png)](https://www.analyticsvidhya.com/blog/2019/08/comprehensive-guide-language-model-nlp-python-code/) ==語言模型這 4 個字看似很博大精深,但是它僅僅指的就是「一個句子的機率」。== > [語言模型 (Language Model) 與 N-gram 原理](https://medium.com/%E6%89%8B%E5%AF%AB%E7%AD%86%E8%A8%98/%E8%87%AA%E7%84%B6%E8%AA%9E%E8%A8%80%E8%99%95%E7%90%86-%E4%BD%BF%E7%94%A8-n-gram-%E5%AF%A6%E7%8F%BE%E8%BC%B8%E5%85%A5%E6%96%87%E5%AD%97%E9%A0%90%E6%B8%AC-10ac622aab7a)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully