SlideShare a Scribd company logo
NLTK: Natural Language Toolkit
  Overview and Application
               Jimmy Lai
          jimmy.lai@oi-sys.com
     Software Engineer @ 引京聚點
              2012/06/09


                                 1
Outline
1.   An application based on NLP: 聚寶評
2.   Introduction to Natural Language Processing
3.   Brief History of NLTK
4.   NLTK




                                                   2
聚寶評 www.ezpao.com

      美食搜尋引擎




搜尋各大部落格食記

                    3
聚寶評 www.ezpao.com

     語意分析搜尋引擎




                    4
評論主題分析




網友分享菜分析




 正評/負評分析




                    5
手機版            網友分享菜+評論分析

m.ezpao.com




              網友分享菜+正負評分析




                            6
Natural Language Processing (NLP)
•    語音識別(Speech recognition)
•    詞性標註(Part-of-speech tagging)
•    句法分析(Parsing)
•    自然語言生成(Natural language generation)
•    文本分類(Text classification)
•    信息抽取(Information extraction)
•    機器翻譯(Machine translation)
•    文字蘊涵(Textual entailment)
    via Wikipedia

                                           7
NLTK: Natural Language Toolkit
• http://www.nltk.org/
• Author: Steven Bird, Edward Loper, Ewan Klein
• Originally developed for class student has
  background either in computer science or
  linguistics.
• Currently:
  – Education: over 100 courses in 23 countries.
  – Research: over 250 papers cites NLTK.

                                                   8
Outline
1.   An application based on NLP: 聚寶評
2.   Introduction to Natural Language Processing
3.   Brief History of NLTK
4.   NLTK:
     a. Installation
     b. Annotated Text Corpora
     c. Text Tokenization, Normalization, Analysis,
        Distribution Analysis
     d. Part-of-speech Tagging
     e. Text Classification
     f. Named Entity Recognition
                                                      9
Install NLTK
Python 2.6+

pip install numpy
pip install matplotlib
pip install nltk




                         10
Annotated Text Corpora (1/3)
           nltk.corpus
• Corpus: 語料庫,含有某種結構化標記的資
  料集合,可能包含多種語言。
• 例如:
 – stopwords: 常見字字典
 – sinica_treebank: 中文語句結構標記語料庫
 – brown: 包含15種分類及詞性標記的英語語料庫
 – wordnet: 包含詞性、同義反義的英語字典



                                  11
Annotated Text Corpora (2/3)
                   nltk.corpus
                                                #Chinese treebank
import nltk                                     nltk.corpus.sinica_treebank
#download corpus on demand
nltk.download()                                 #Examples
                                                (嘉珍, Nba)
#stopwords                                      (和, Caa)
nltk.corpus.stopwords.words()                   (我, Nhaa)
nltk.corpus.stopwords.words('english')          (住在, VC1)
nltk.corpus.stopwords.words('french')           (同一條, DM)
                                                (巷子, Nab)
some_english_stopwords = ['most', 'me',
'below', 'when', 'which', 'what', 'of', 'it',   (我們, Nhaa)
'very', 'our']                                  (是, V_11)
                                                (鄰居, Nab)

                                                (也, Dbb)
                                                (是, V_11)
                                                (同班, Nv3)
                                                (同學, Nab)                     12
Annotated Text Corpora (3/3)
                     nltk.corpus
ACE Named Entity Chunker (Maximum entropy)         Portuguese Treebank
Australian Broadcasting Commission 2006            Gazeteer Lists
                                                   Genesis Corpus
Alpino Dutch Treebank
                                                   Project Gutenberg Selections
BioCreAtIvE (Critical Assessment of Information    NIST IE-ER DATA SAMPLE
Extraction Systems in Biology)                     C-Span Inaugural Address Corpus
Brown Corpus                                       Indian Language POS-Tagged Corpus
Brown Corpus (TEI XML Version)                     JEITA Public Morphologically Tagged Corpus (in
CESS-CAT Treebank                                  ChaSen format)
                                                   PC-KIMMO Data Files
CESS-ESP Treebank
                                                   KNB Corpus (Annotated blog corpus)
Chat-80 Data Files                                 Language Id Corpus
City Database                                      Lin's Dependency Thesaurus
The Carnegie Mellon Pronouncing Dictionary (0.6)   MAC-MORPHO: Brazilian Portuguese news text with
ComTrans Corpus Sample                             part-of-speech tags
                                                   Machado de Assis -- Obra Completa
CONLL 2000 Chunking Corpus
                                                   Sentiment Polarity Dataset Version 2.0
CONLL 2002 Named Entity Recognition Corpus         Names Corpus, Version 1.3 (1994-03-29)
Dependency Treebanks from CoNLL 2007 (Catalan      NomBank Corpus 1.0
and Basque Subset)                                 NPS Chat
Dependency Parsed Treebank                         Paradigm Corpus
Sample European Parliament Proceedings Parallel
Corpus


                                                                                                     13
Text Tokenization
                      nltk.tokenize
Web Text Processing Flow
          HTML               ASCII             Text           Vocabulary

from urllib import urlopen
html = urlopen(url).read()
raw = nltk.clean_html(html)
sents = nltk.sent_tokenize(raw)
tokens = []                         # wordpunct_tokenize: ['3', '.', '33']
for sent in sents:                  # word_tokenize: ['3.33']
    tokens.extend(nltk.word_tokenize(sent))
text = nltk.Text(tokens)
words = [word.lower() for word in text]
vocab = sorted(set(words))

                                                                             14
Text Normalization (1/2)
           nltk.stem
• Stem: 將單字(現在式、過去式、單複數)還
  原成原型。可以將不同形式的單字歸類為
  同一個單字。
• 著名演算法:Porter Stemmer




                               15
Text Normalization (2/2)
       nltk.stem




                           16
Text Analysis
  nltk.text




                17
Text Distribution Analysis
     nltk.probability




                             18
Part-of-speech Tagging (1/3)
               nltk.tag
• Part of Speech Tagging: 詞性標記,
  標記每個單字的詞性。
• 同一單字的不同詞性其語義不同,
  如Book名詞是書,動詞是預定。
• 透過POS Tagging,可以賦予文字更
  多語義資訊。



                                    19
Part-of-speech Tagging (2/3)
          nltk.tag




                               20
Part-of-speech Tagging (3/3)
          nltk.tag




                               21
Text Classification (1/3)
              nltk.classify
• Text Classification: 文字分類,分析文字後將
  文字分到預先定義的類別裡。
• 基於統計的機器學習演算法,著名的演算
  法為:
 – Naïve Bayes Classifier
 – Decision Tree
 – Support Vector Machine



                                    22
Text Classification (2/3)
                      nltk.classify
Machine Learning Approach Work Flow
Training
    Text with      Feature                 Learning    Classifier
                               Features
      Label       Generation              Algorithms    Model



Prediction
      Text                                Classifier
                   Feature
    without                    Features                 Label
                  Generation               Model
     Label




                                                                    23
Text Classification (3/3)
      nltk.classify




                            24
Named Entity Recognition (NER) (1/2)
       nltk.tag, nltk.chunk
• Named Entity Recognition: 從文字中擷取出
  命名實體,命名實體是具有完整語義的複
  合單字。例如:人名、地名、事件。

 NER General Work Flow

  Sentence                                  Named Entity    Relation
               Tokenization   POS tagging
Segmentation                                 Recognition   Recognition




                                                                     25
Named Entity Recognition (NER) (2/2)
       nltk.tag, nltk.chunk




                                   26
Reference
1. Steven Bird, Ewan Klein, and Edward Loper,
   “Natural Language Processing with Python”,
   2009. #includes: Python + NLP + NLTK
2. Jacob Perkins, “Python Text Processing with
   NLTK 2.0 Cookbook”, 2010.
3. Matthew A. Russell, “Mining the Social Web”,
   2011.
4. Loper, E., & Bird, S. (2002). NLTK: The Natural
   Language Toolkit. Proceedings of the ACL02
   Workshop on Effective tools and methodologies
   for teaching natural language processing and
   computational linguistics.
                                                 27
Thank you for your attention.
           Q&A
We are hiring!
• 核心引擎演算法研發工程師
• 系統研發工程師
• 網路應用研發工程師

Oxygen Intelligence Taiwan Limited
引京聚點 知識結構搜索股份有限公司
• 公司簡介: http://www.ezpao.com/about/
• 職缺簡介: http://www.ezpao.com/join/
• 請將履歷寄到 jimmy.lai@oi-sys.com

                                      28

More Related Content

What's hot (20)

PDF
Elements of Text Mining Part - I
Jaganadh Gopinadhan
 
PDF
Basic NLP with Python and NLTK
Francesco Bruni
 
PDF
Sk t academy lecture note
Susang Kim
 
PPT
基于 Google protobuf 的 webgame 网络协议设计
勇浩 赖
 
PDF
Devoxx traitement automatique du langage sur du texte en 2019
Alexis Agahi
 
PDF
Introduction to source{d} Engine and source{d} Lookout
source{d}
 
PDF
Grokking the REST Architectural Style
Ben Ramsey
 
PDF
You Look Like You Could Use Some REST!
Ben Ramsey
 
PPT
Natural Language Processing made easy
Gopi Krishnan Nambiar
 
KEY
Your Own Metric System
Erin Dees
 
PDF
[Reactive] Programming with [Rx]ROS
Andrzej Wasowski
 
PDF
Thnad's Revenge
Erin Dees
 
PDF
2 P Seminar
Linkiby Belarus
 
PPTX
Flower and celery
Rafael Roman Otero
 
PPTX
Natural Intelligence ICCS 2010
fmguler
 
PPTX
2015 bioinformatics databases_wim_vancriekinge
Prof. Wim Van Criekinge
 
PDF
How to make DSL
Yukio Goto
 
PDF
Write Your Own JVM Compiler
Erin Dees
 
PDF
Playfulness at Work
Erin Dees
 
Elements of Text Mining Part - I
Jaganadh Gopinadhan
 
Basic NLP with Python and NLTK
Francesco Bruni
 
Sk t academy lecture note
Susang Kim
 
基于 Google protobuf 的 webgame 网络协议设计
勇浩 赖
 
Devoxx traitement automatique du langage sur du texte en 2019
Alexis Agahi
 
Introduction to source{d} Engine and source{d} Lookout
source{d}
 
Grokking the REST Architectural Style
Ben Ramsey
 
You Look Like You Could Use Some REST!
Ben Ramsey
 
Natural Language Processing made easy
Gopi Krishnan Nambiar
 
Your Own Metric System
Erin Dees
 
[Reactive] Programming with [Rx]ROS
Andrzej Wasowski
 
Thnad's Revenge
Erin Dees
 
2 P Seminar
Linkiby Belarus
 
Flower and celery
Rafael Roman Otero
 
Natural Intelligence ICCS 2010
fmguler
 
2015 bioinformatics databases_wim_vancriekinge
Prof. Wim Van Criekinge
 
How to make DSL
Yukio Goto
 
Write Your Own JVM Compiler
Erin Dees
 
Playfulness at Work
Erin Dees
 

Viewers also liked (15)

PDF
Documentation with sphinx @ PyHug
Jimmy Lai
 
PDF
Data Analyst Nanodegree
Jimmy Lai
 
PDF
Fast data mining flow prototyping using IPython Notebook
Jimmy Lai
 
PDF
[LDSP] Solr Usage
Jimmy Lai
 
PDF
[LDSP] Search Engine Back End API Solution for Fast Prototyping
Jimmy Lai
 
PDF
Software development practices in python
Jimmy Lai
 
PDF
When big data meet python @ COSCUP 2012
Jimmy Lai
 
PDF
Apache thrift-RPC service cross languages
Jimmy Lai
 
PDF
Build a Searchable Knowledge Base
Jimmy Lai
 
PDF
“Why Should I Trust You?” Explaining the Predictions of Any Classifierの紹介
KCS Keio Computer Society
 
PPT
Statistical machine translation for indian language copy
Nakul Sharma
 
PDF
Big data analysis in python @ PyCon.tw 2013
Jimmy Lai
 
PDF
NetworkX - python graph analysis and visualization @ PyHug
Jimmy Lai
 
PDF
Text classification in scikit-learn
Jimmy Lai
 
PDF
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Jimmy Lai
 
Documentation with sphinx @ PyHug
Jimmy Lai
 
Data Analyst Nanodegree
Jimmy Lai
 
Fast data mining flow prototyping using IPython Notebook
Jimmy Lai
 
[LDSP] Solr Usage
Jimmy Lai
 
[LDSP] Search Engine Back End API Solution for Fast Prototyping
Jimmy Lai
 
Software development practices in python
Jimmy Lai
 
When big data meet python @ COSCUP 2012
Jimmy Lai
 
Apache thrift-RPC service cross languages
Jimmy Lai
 
Build a Searchable Knowledge Base
Jimmy Lai
 
“Why Should I Trust You?” Explaining the Predictions of Any Classifierの紹介
KCS Keio Computer Society
 
Statistical machine translation for indian language copy
Nakul Sharma
 
Big data analysis in python @ PyCon.tw 2013
Jimmy Lai
 
NetworkX - python graph analysis and visualization @ PyHug
Jimmy Lai
 
Text classification in scikit-learn
Jimmy Lai
 
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Jimmy Lai
 
Ad

Similar to Nltk natural language toolkit overview and application @ PyCon.tw 2012 (20)

PPTX
Corpus annotation for corpus linguistics (nov2009)
Jorge Baptista
 
PPTX
Open nlp presentationss
Chandan Deb
 
PPTX
Large scale nlp using python's nltk on azure
cloudbeatsch
 
PPTX
Nltk
Anirudh
 
PPTX
Assignment4.pptx
jatinchand3
 
PDF
DataFest 2017. Introduction to Natural Language Processing by Rudolf Eremyan
rudolf eremyan
 
PDF
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Seonghyun Kim
 
PPTX
Natural Language Processing
Nimrita Koul
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PDF
Ai meetup Neural machine translation updated
2040.io
 
PDF
Challenge of Image Retrieval, Brighton, 2000 1 ANVIL: a System for the Retrie...
Petros Tsonis
 
PDF
Natural language processing (Python)
Sumit Raj
 
PDF
Arrays in database systems, the next frontier?
PlanetData Network of Excellence
 
PDF
Grammarly AI-NLP Club #6 - Sequence Tagging using Neural Networks - Artem Che...
Grammarly
 
PPTX
Natural Language Processing_in semantic web.pptx
AlyaaMachi
 
PPTX
Corpus Linguistics :Analytical Tools
Jitendra Patil
 
PDF
Introduction to KotlinNLP
Pier Paolo Grassi
 
PDF
Intro to KotlinNLP
Matteo Grella
 
PPTX
SoDA v2 - Named Entity Recognition from streaming text
Sujit Pal
 
PDF
Understanding Names with Neural Networks - May 2020
Basis Technology
 
Corpus annotation for corpus linguistics (nov2009)
Jorge Baptista
 
Open nlp presentationss
Chandan Deb
 
Large scale nlp using python's nltk on azure
cloudbeatsch
 
Nltk
Anirudh
 
Assignment4.pptx
jatinchand3
 
DataFest 2017. Introduction to Natural Language Processing by Rudolf Eremyan
rudolf eremyan
 
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Seonghyun Kim
 
Natural Language Processing
Nimrita Koul
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
Ai meetup Neural machine translation updated
2040.io
 
Challenge of Image Retrieval, Brighton, 2000 1 ANVIL: a System for the Retrie...
Petros Tsonis
 
Natural language processing (Python)
Sumit Raj
 
Arrays in database systems, the next frontier?
PlanetData Network of Excellence
 
Grammarly AI-NLP Club #6 - Sequence Tagging using Neural Networks - Artem Che...
Grammarly
 
Natural Language Processing_in semantic web.pptx
AlyaaMachi
 
Corpus Linguistics :Analytical Tools
Jitendra Patil
 
Introduction to KotlinNLP
Pier Paolo Grassi
 
Intro to KotlinNLP
Matteo Grella
 
SoDA v2 - Named Entity Recognition from streaming text
Sujit Pal
 
Understanding Names with Neural Networks - May 2020
Basis Technology
 
Ad

More from Jimmy Lai (9)

PDF
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
PDF
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Jimmy Lai
 
PDF
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
PDF
Python Linters at Scale.pdf
Jimmy Lai
 
PDF
EuroPython 2022 - Automated Refactoring Large Python Codebases
Jimmy Lai
 
PDF
Annotate types in large codebase with automated refactoring
Jimmy Lai
 
PDF
The journey of asyncio adoption in instagram
Jimmy Lai
 
PDF
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
PDF
Continuous Delivery: automated testing, continuous integration and continuous...
Jimmy Lai
 
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Jimmy Lai
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
Python Linters at Scale.pdf
Jimmy Lai
 
EuroPython 2022 - Automated Refactoring Large Python Codebases
Jimmy Lai
 
Annotate types in large codebase with automated refactoring
Jimmy Lai
 
The journey of asyncio adoption in instagram
Jimmy Lai
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
Continuous Delivery: automated testing, continuous integration and continuous...
Jimmy Lai
 

Recently uploaded (20)

PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 

Nltk natural language toolkit overview and application @ PyCon.tw 2012

  • 1. NLTK: Natural Language Toolkit Overview and Application Jimmy Lai [email protected] Software Engineer @ 引京聚點 2012/06/09 1
  • 2. Outline 1. An application based on NLP: 聚寶評 2. Introduction to Natural Language Processing 3. Brief History of NLTK 4. NLTK 2
  • 3. 聚寶評 www.ezpao.com 美食搜尋引擎 搜尋各大部落格食記 3
  • 4. 聚寶評 www.ezpao.com 語意分析搜尋引擎 4
  • 6. 手機版 網友分享菜+評論分析 m.ezpao.com 網友分享菜+正負評分析 6
  • 7. Natural Language Processing (NLP) • 語音識別(Speech recognition) • 詞性標註(Part-of-speech tagging) • 句法分析(Parsing) • 自然語言生成(Natural language generation) • 文本分類(Text classification) • 信息抽取(Information extraction) • 機器翻譯(Machine translation) • 文字蘊涵(Textual entailment) via Wikipedia 7
  • 8. NLTK: Natural Language Toolkit • http://www.nltk.org/ • Author: Steven Bird, Edward Loper, Ewan Klein • Originally developed for class student has background either in computer science or linguistics. • Currently: – Education: over 100 courses in 23 countries. – Research: over 250 papers cites NLTK. 8
  • 9. Outline 1. An application based on NLP: 聚寶評 2. Introduction to Natural Language Processing 3. Brief History of NLTK 4. NLTK: a. Installation b. Annotated Text Corpora c. Text Tokenization, Normalization, Analysis, Distribution Analysis d. Part-of-speech Tagging e. Text Classification f. Named Entity Recognition 9
  • 10. Install NLTK Python 2.6+ pip install numpy pip install matplotlib pip install nltk 10
  • 11. Annotated Text Corpora (1/3) nltk.corpus • Corpus: 語料庫,含有某種結構化標記的資 料集合,可能包含多種語言。 • 例如: – stopwords: 常見字字典 – sinica_treebank: 中文語句結構標記語料庫 – brown: 包含15種分類及詞性標記的英語語料庫 – wordnet: 包含詞性、同義反義的英語字典 11
  • 12. Annotated Text Corpora (2/3) nltk.corpus #Chinese treebank import nltk nltk.corpus.sinica_treebank #download corpus on demand nltk.download() #Examples (嘉珍, Nba) #stopwords (和, Caa) nltk.corpus.stopwords.words() (我, Nhaa) nltk.corpus.stopwords.words('english') (住在, VC1) nltk.corpus.stopwords.words('french') (同一條, DM) (巷子, Nab) some_english_stopwords = ['most', 'me', 'below', 'when', 'which', 'what', 'of', 'it', (我們, Nhaa) 'very', 'our'] (是, V_11) (鄰居, Nab) (也, Dbb) (是, V_11) (同班, Nv3) (同學, Nab) 12
  • 13. Annotated Text Corpora (3/3) nltk.corpus ACE Named Entity Chunker (Maximum entropy) Portuguese Treebank Australian Broadcasting Commission 2006 Gazeteer Lists Genesis Corpus Alpino Dutch Treebank Project Gutenberg Selections BioCreAtIvE (Critical Assessment of Information NIST IE-ER DATA SAMPLE Extraction Systems in Biology) C-Span Inaugural Address Corpus Brown Corpus Indian Language POS-Tagged Corpus Brown Corpus (TEI XML Version) JEITA Public Morphologically Tagged Corpus (in CESS-CAT Treebank ChaSen format) PC-KIMMO Data Files CESS-ESP Treebank KNB Corpus (Annotated blog corpus) Chat-80 Data Files Language Id Corpus City Database Lin's Dependency Thesaurus The Carnegie Mellon Pronouncing Dictionary (0.6) MAC-MORPHO: Brazilian Portuguese news text with ComTrans Corpus Sample part-of-speech tags Machado de Assis -- Obra Completa CONLL 2000 Chunking Corpus Sentiment Polarity Dataset Version 2.0 CONLL 2002 Named Entity Recognition Corpus Names Corpus, Version 1.3 (1994-03-29) Dependency Treebanks from CoNLL 2007 (Catalan NomBank Corpus 1.0 and Basque Subset) NPS Chat Dependency Parsed Treebank Paradigm Corpus Sample European Parliament Proceedings Parallel Corpus 13
  • 14. Text Tokenization nltk.tokenize Web Text Processing Flow HTML ASCII Text Vocabulary from urllib import urlopen html = urlopen(url).read() raw = nltk.clean_html(html) sents = nltk.sent_tokenize(raw) tokens = [] # wordpunct_tokenize: ['3', '.', '33'] for sent in sents: # word_tokenize: ['3.33'] tokens.extend(nltk.word_tokenize(sent)) text = nltk.Text(tokens) words = [word.lower() for word in text] vocab = sorted(set(words)) 14
  • 15. Text Normalization (1/2) nltk.stem • Stem: 將單字(現在式、過去式、單複數)還 原成原型。可以將不同形式的單字歸類為 同一個單字。 • 著名演算法:Porter Stemmer 15
  • 16. Text Normalization (2/2) nltk.stem 16
  • 17. Text Analysis nltk.text 17
  • 18. Text Distribution Analysis nltk.probability 18
  • 19. Part-of-speech Tagging (1/3) nltk.tag • Part of Speech Tagging: 詞性標記, 標記每個單字的詞性。 • 同一單字的不同詞性其語義不同, 如Book名詞是書,動詞是預定。 • 透過POS Tagging,可以賦予文字更 多語義資訊。 19
  • 22. Text Classification (1/3) nltk.classify • Text Classification: 文字分類,分析文字後將 文字分到預先定義的類別裡。 • 基於統計的機器學習演算法,著名的演算 法為: – Naïve Bayes Classifier – Decision Tree – Support Vector Machine 22
  • 23. Text Classification (2/3) nltk.classify Machine Learning Approach Work Flow Training Text with Feature Learning Classifier Features Label Generation Algorithms Model Prediction Text Classifier Feature without Features Label Generation Model Label 23
  • 24. Text Classification (3/3) nltk.classify 24
  • 25. Named Entity Recognition (NER) (1/2) nltk.tag, nltk.chunk • Named Entity Recognition: 從文字中擷取出 命名實體,命名實體是具有完整語義的複 合單字。例如:人名、地名、事件。 NER General Work Flow Sentence Named Entity Relation Tokenization POS tagging Segmentation Recognition Recognition 25
  • 26. Named Entity Recognition (NER) (2/2) nltk.tag, nltk.chunk 26
  • 27. Reference 1. Steven Bird, Ewan Klein, and Edward Loper, “Natural Language Processing with Python”, 2009. #includes: Python + NLP + NLTK 2. Jacob Perkins, “Python Text Processing with NLTK 2.0 Cookbook”, 2010. 3. Matthew A. Russell, “Mining the Social Web”, 2011. 4. Loper, E., & Bird, S. (2002). NLTK: The Natural Language Toolkit. Proceedings of the ACL02 Workshop on Effective tools and methodologies for teaching natural language processing and computational linguistics. 27
  • 28. Thank you for your attention. Q&A We are hiring! • 核心引擎演算法研發工程師 • 系統研發工程師 • 網路應用研發工程師 Oxygen Intelligence Taiwan Limited 引京聚點 知識結構搜索股份有限公司 • 公司簡介: http://www.ezpao.com/about/ • 職缺簡介: http://www.ezpao.com/join/ • 請將履歷寄到 [email protected] 28