Skip to main content

A python package for flexible and transparent sentiment analysis.

Project description

Asent

A python package for flexible and transparent sentiment analysis.

Inspired by Vader, made using SpaCy, by default interpretable.

Tutorial

simple usage on texts

nlp = spacy.load("en_core_web_lg")
nlp.add_pipe("asent_en_v1") 

text = "I am angry 😄"
doc = nlp(text)
doc._.polarity

visualize results

asent.visaulize(doc)

or if you have a long text it might be ideal to split it up into sentences.

text = "The plot was good, but the characters are uncompelling. The dialog on the other hand is great."

doc = nlp(text)
sentences = [sentence for sentence in doc.sents]

asent.visualize(sentences[0]) # visualize only the first sentence

Correcting a model or building a new

  • colab tutorial

Available attributes

Available Models

reference to Lexicons

How does the model work?

Valence:

  1. Look up the word in the lexicon
  2. is the word all caps while the rest of the text is not, add capitilazation factor (0.733) to the valence score

Token polarity

  1. Start of with the token valence
  2. is the word intensified? If one of the three preceeding word is an intensifier add the intensifier score times a discounting constant such that intensifier 3 tokens away are not as influential as an intensifier one token away.
  3. is the word negated? If either of the three previous word is a negation multiply it by a negation factoer (-0.74)

Span or sentence polarity

  1. Sum and normalize the score to be typically between -1 and 1.
  2. If there is a contrastive conjugation (e.g. but) downweight the polarity score before and upweight the following score. E.g. "the cast was horrible, but the storyline was great", here horrible would be downweighted and great wieghted more.
  3. If the sentence use exclamation or question mark amplifiy the polarity scores. Dependent on how many exclamationsmarks is present.

FAQ

How do I test the code and run the test suite?

asent comes with an extensive test suite. In order to run the tests, you'll usually want to clone the repository and build asent from the source. This will also install the required development dependencies and test utilities defined in the requirements.txt.

pip install -r requirements.txt
pip install pytest

python -m pytest

which will run all the test in the asent/tests folder.

Specific tests can be run using:

python -m pytest augmenty/tests/desired_test.py

Code Coverage If you want to check code coverage you can run the following:

pip install pytest-cov

python -m pytest --cov=.


How is the documentation generated?

augmenty uses sphinx to generate documentation. It uses the Furo theme with a custom styling.

To make the documentation you can run:

# install sphinx, themes and extensions
pip install sphinx furo sphinx-copybutton sphinxext-opengraph

# generate html from documentations

make -C docs html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asent-0.0.2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

asent-0.0.2-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file asent-0.0.2.tar.gz.

File metadata

  • Download URL: asent-0.0.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for asent-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3970de6f46a4d4fcd7feb3827f4cfdd6049d6794685b6db17cceb08b297e6aef
MD5 97a6c2b6f50ec89fd4370deca2fa3214
BLAKE2b-256 b3d98293f3d466ef8d0cb37afd81ba5ca5c6bd0fc127ba62f014fd60cf959c38

See more details on using hashes here.

File details

Details for the file asent-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: asent-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for asent-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2fd8288195c9db41606b2f3730c306d3b3754b324a8ac24167b0027d46cabfb
MD5 e5c115289b88c0c5d75fc0fc8ca4cfa9
BLAKE2b-256 147d33239a344a7dd4ffabd89f780786f32f31e65748d2dc6286d28c0325088a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page