How to edit NLTKs VADER sentiment lexicon without modifying a txt file
Asked Answered
F

2

0

I know you can add your own words by manually adding them to the vader_lexicon.txt file. I was wondering if there was another way that you can do it in the python code as I don't want people who use my code need to then go modify other .txt files.

from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA

sia = SIA()
sia.lexicon

This will get the dict. Was thinking something like:

sia.lexicon.update{u'word': 3}
Fathead answered 16/4, 2018 at 17:57 Comment(0)
I
4

For anyone else:

from nltk.sentiment.vader import SentimentIntensityAnalyzer

new_words = {
    'foo': 2.0,
    'bar': -3.4,
}

SIA = SentimentIntensityAnalyzer()

SIA.lexicon.update(new_words)
Invent answered 1/5, 2018 at 14:17 Comment(0)
F
0

I think this is the answer.

 sia.lexicon.update({u'word': 3.1})
Fathead answered 16/4, 2018 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.