自然語言處理入門

Python 的 Natural Language Processing(NLP)

Fouad Trad

Machine Learning Engineer

認識講師...

 

講師照片。

 

Fouad Trad

  • 機器學習工程師
  • 研究科學家
  • 資安與醫療的 NLP
Python 的 Natural Language Processing(NLP)

什麼是 NLP?

 

 

  • 語言是人類主要的溝通方式
  • 電腦不懂人類語言

顯示語言所在位置的圖像:書籍、網站、社群貼文與電子郵件。

Python 的 Natural Language Processing(NLP)

什麼是 NLP?

讓電腦能分析人類語言

顯示人對機器說話,NLP 將語句轉換成機器可理解內容的圖像。

Python 的 Natural Language Processing(NLP)

NLP 流程

流程步驟一:原始文字。

  • Raw text: 從推文到書中文字都算
Python 的 Natural Language Processing(NLP)

NLP 流程

流程步驟二:前處理

  • Raw text: 從推文到書中文字都算
  • Preprocessing: 清理文字並移除不必要元素
Python 的 Natural Language Processing(NLP)

NLP 流程

流程步驟三:特徵擷取。

  • Raw text: 從推文到書中文字都算
  • Preprocessing: 清理文字並移除不必要元素
  • Feature extraction: 將文字轉成數字
Python 的 Natural Language Processing(NLP)

NLP 流程

流程步驟四:建模

  • Raw text: 從推文到書中文字都算
  • Preprocessing: 清理文字並移除不必要元素
  • Feature extraction: 將文字轉成數字
  • Model: 分析、預測、分類、產生新內容
Python 的 Natural Language Processing(NLP)

課程規劃

完整流程圖,並標示第 1 章將用 NLTK 介紹前處理

Python 的 Natural Language Processing(NLP)

課程規劃

完整流程圖,並標示第 2 章將用 scikit-learn 與 Gensim 進行特徵擷取。

Python 的 Natural Language Processing(NLP)

課程規劃

完整流程圖,並標示第 3、4 章將用 transformers 函式庫的 pipelines 隱藏三步:前處理、特徵擷取與建模。

Python 的 Natural Language Processing(NLP)

斷詞(Tokenization)

  • 將文字切成 tokens(較小且可處理的片段)

顯示有人在切紅蘿蔔的圖像

Python 的 Natural Language Processing(NLP)

句子斷詞

  • 文字 → 句子
  • 比整段分析更清楚
import nltk

nltk.download('punkt_tab')
text = "NLP is fun. Let's dive into it!"
sentences = nltk.sent_tokenize(text)
print(sentences)
["NLP is fun.", "Let's dive into it!"]

顯示翻譯圖示的圖像。

Python 的 Natural Language Processing(NLP)

詞彙斷詞

  • 文字 → 單字與標點
  • 適用於需要:
    • 辨識關鍵詞
    • 統計詞頻
text = "Claim your free prize now!"

words = nltk.word_tokenize(text)
print(words)
['Claim', 'your', 'free', 'prize', 'now', '!']

顯示垃圾郵件圖示的圖像。

Python 的 Natural Language Processing(NLP)

一起來練習吧!

Python 的 Natural Language Processing(NLP)

Preparing Video For Download...