![](/img/trans.png)
[英]How to edit NLTKs VADER sentiment lexicon without modifying a txt file
[英]Is it possible to edit NLTK's vader sentiment lexicon?
我想在vader_lexicon.txt
添加單詞以指定單詞的極性分數。 這樣做的正確方法是什么?
我在AppData\\Roaming\\nltk_data\\sentiment\\vader_lexicon
看到了這個文件。 該文件包括單詞,它的極性,強度,以及由“10個獨立的人類評價者”給出的10個強度分數的數組。 [1]但是,當我編輯它時,以下代碼的結果沒有任何改變:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sia = SentimentIntensityAnalyzer()
s = sia.polarity_scores("my string here")
我認為當我調用SentimentIntensityAnalyzer的構造函數時,我的代碼會訪問此文本文件。 [2]你對我如何編輯預先制作的詞典有什么想法嗎?
資料來源:
我發現了修復。 我壓縮了包含txt文件的文件夾vader_lexicon
,我應用的更改現在是正在訪問的文件。
對於任何感興趣的人,也可以在不必手動編輯vader lexicon .txt文件的情況下實現。 作為提供由repoleved在這個帖子:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
new_words = {
'foo': 2.0,
'bar': -3.4,
}
SIA = SentimentIntensityAnalyzer()
SIA.lexicon.update(new_words)
如果您想刪除單詞,請使用'.pop'功能:
SIA = SentimentIntensityAnalyzer()
SIA.lexicon.pop('no')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.