1986年,Michael Lesk 設計出一個簡單的演算法,基本的概念為給定一個詞彙,其周圍的詞彙會傾向於在說明同一個主題,或者說它們分享著相似的概念[1],除了原始的paper外,還可以在wikipedia找到 Lesk 演算法的說明[2]。

接著,我實作了原始 paper 中的演算法[1],wikipedia上的版本[2]跟原始 paper 有著部份的出入,下方我會開始解釋實作的程式碼:

 

整個程式的邏輯是:

1. 先把 Word and its sense 建成資料結構

2. 再把每個 sense 去掉 stopword (stopword 從這裡下載)

3. 然後針對一個 word 並且取其中一個 sense 去跟另一個 word 的所有 sense 計算文字的重複程度。

4. 紀錄最大值

5. 回傳結果

 

接著我針對細部的說明:

Line 21-30, 是取自 wikipedia 的範例,並且建成資料結構。

Line 31 則是將兩個字的資料結構傳入到 LeskAlgorithmWSD 去計算每個字最佳的 sense。

Line 36 則是主要函數 LeskAlgorithmWSD,其中分成三個部分:

Line 40: loadStopWordList,顧名思義就是讀取 stopword,但是這部分還可以改寫,因為 stopword 只需要讀取一次即可,不用每次要做 WSD 都再重新讀取。

Line 44 and 47: createUniqueVocabulary 則是建立每個字每個sense的 bag of words,並且已經去除 stopword

Line 49: overlap 則是計算每個字每個sense對於其他字所有sense重疊性最高的sense。

這部分的程式碼與 Java project 我放在下述 github 中:

https://github.com/x831617/LeskAlgorithmForWSD

 

[Reference]

1. Lesk, M. (1986). Automatic sense disambiguation using machine readable dictionaries: how to tell a pine cone from an ice cream cone. SIGDOC '86 Proceedings of the 5th annual international conference on Systems documentation.

2. https://en.wikipedia.org/wiki/Lesk_algorithm#cite_note-6

 

arrow
arrow
    全站熱搜

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()