Skip to content

Matching sentiment lexicons#

HuSpaCy is shipped with two sentiment lexicons. The component loads up a lexicon and match words with it. The module can use two sentiment lexicons, the default one is the PolText Lab's resource while one can also load the PrecoSenti lexicon.

Load the component#

Load the default sentiment lexicon (poltext)

import huspacy.integrations

nlp.add_pipe("sentiment_lexicon")

Or you can specify the lexicon to be used by passing addition configuration during initialization nlp.add_pipe("sentiment_lexicon", config={"lexicon_id": "precognox"}).

Then you can start discovering sentiment values of spans and tokens:

doc = nlp("Ez szuper jó")

print(doc.spans["sentiment"])  # ["szuper", "jó"]

print(doc[1]._.sentiment)  # 'POS'
print(doc[2]._.sentiment)  # 'POS'

Last update: January 3, 2024