MARK CHANG'S BLOG

若發生公式跑掉或無法正常顯示的情形,請在公式上按右鍵設定:math setting-> math render->SVG
  • About Me
  • Archive
  • feeds

Posts match “ nltk ” tag:

almost 9 years ago

Python nltk -- Sinica Treebank

今天我們來談談如何用python nltk做中文的的自然語言處理
nltk有內建的中文treebank,是中研院的sinica treebank
是免費的中文treebank
至於要如何使用呢?
首先 先載入模組

>>> from nltk.corpus import sinica_treebank
>>> import nltk

接下來我們來看看treebank裡面的東西:

Read on →
  • Python
  • natural_language_processing
  • nltk
  • March 09, 2014 15:41
  • Permalink
  • Comments
 
almost 9 years ago

Python nltk -- Tree

今天我們來看看nltk.Tree要怎麼用

先載入模組

>>> from nltk import Tree

1.build syntax tree

舉個例子
Gary plays baseball
此句子的剖析樹(syntax tree)是這樣:
nltk1.png

用nltk.Tree來建構tree:

>>> tree=Tree('S',[Tree('NP',['Gary']),
...           Tree('VP',[Tree('VT',['plays']),
...                     Tree('NP',['baseball'])])])
>>> tree.draw()

即可將剖析樹畫出來
若沒安裝 python-tk,你也可以這樣把tree印出

>>> tree.pprint()
'(S (NP Gary) (VP (VT plays) (NP baseball)))'
Read on →
  • Python
  • nltk
  • natural_language_processing
  • grammar
  • March 01, 2014 00:36
  • Permalink
  • Comments
 
almost 9 years ago

Python nltk -- Logic 2 : Lambda Calculus

本篇介紹如何用python nltk 的應用,邏輯語意與lambda calculus

1.introduction

邏輯語意學在語意推導方面,通常會用到
使用就可以把一個句子的語意,從個別單字中推導出來
至於 是什麼呢?
簡而言之,lambda calculus是一種數學運算,由以下三種元素組成

是
是 ,就是把function中的variable拿到前面,加個
是將另一個 放到 後面
然後可以進行一種運算,叫做 ,如下

還有另一種運算叫做 ,其實就是更改變數名稱而已

Read on →
  • Python
  • nltk
  • semantics
  • logic
  • March 13, 2014 22:09
  • Permalink
  • Comments
 
almost 9 years ago

Python nltk -- Logic 4 : Model and Satisfiability

1.Model and Satisfiability

可滿足性(Satisfiability)是在探討, 邏輯式子所建立出的模型(Model),
可不可以找到一組解, 使得這個 Model 算出來的值可以是
例如:

則當 時,
則 Model 是 Satisfiable
另一例子:

這種情形,不論 或 的值, 永遠都是
則 Model 是 Unsatisfiable

Read on →
  • Python
  • nltk
  • semantics
  • logic
  • March 29, 2014 23:39
  • Permalink
  • Comments
 
almost 9 years ago

Python nltk -- Logic 3 : Discourse Representation Theory

1. Introduction

Discourse 的意思是對話
在對話中,常常會用到 代名詞 ,像是 he, she 或 it.
我們把這種代名詞叫做 anaphoric pronouns
因為要從前面的句子去判斷,這些代名詞代表什麼
比如有個句子 A woman walks. She smokes.
在下一句的 She 是指前一句提到的 A woman

那要怎麼讓電腦去判斷, 代名詞 到底代表前面提到的什麼?
這就要用到 Discourse Representation Theory (DRT) 來處理了
例如 A woman walks 這句話,用 DRT 可以表示成這樣:

Read on →
  • Python
  • nltk
  • semantics
  • logic
  • March 21, 2014 11:58
  • Permalink
  • Comments
 
over 8 years ago

Python nltk -- Dependency Grammar

1. Introduction

在自然語言處理中, Phase-Structured Grammar 這類的文法, 是把一個句子, 剖析成一個 完整的剖析樹 , 它的重點是句子中各個成份的階層關係, 例如 Context-Free Grammar

而所謂的 Dependenct Grammar , 是著重在 字和字之間關係 , 而非整個句子中各種成份階層關係, 例如

用Depedenct Grammar 可以表示成這樣


如上圖, 把詞語和詞語之間的關係, 用箭頭表示, 箭頭的起點為 Head, 終點為 dependents , 標示箭頭上的英文字代表 Head 和 Dependent 之間的 relation

Read on →
  • natural_language_processing
  • grammar
  • parsing
  • dependency_grammar
  • nltk
  • May 03, 2014 23:00
  • Permalink
  • Comments
 
over 8 years ago

Python nltk -- Rule-Based Chunking

Chunking

分析句子的成份, 當句子不符合文法時, 使用 Context-Free Grammar 去做 Parsing , 可能會得不出結果, 而某些應用, 需要的並不是完整的剖析樹, 而是把句子中某些成份給找出來

Chunking 的概念就是, 把句子中的單字分組, 每一組是由一到多個相鄰的單字所組成, 例如, 想要得出句子中有哪些名詞片語, 就可以把相鄰的定冠詞, 名詞修飾語, 以及名詞, 分成一組, 分組所得出的即為名詞片語

舉個例子, 在以下的句子中, 想要找出名詞片語有哪些

首先, 對這個句子進行 Part of speech Tagging

Read on →
  • nltk
  • natural_language_processing
  • chunking
  • information_extraction
  • May 06, 2014 22:46
  • Permalink
  • Comments
 

Copyright © 2013 cpmarkchang . Powered by Logdown.
Based on work at subtlepatterns.com.