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:
- Look up the word in the lexicon
- is the word all caps while the rest of the text is not, add capitilazation factor (0.733) to the valence score
Token polarity
- Start of with the token valence
- 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.
- 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
- Sum and normalize the score to be typically between -1 and 1.
- 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.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3970de6f46a4d4fcd7feb3827f4cfdd6049d6794685b6db17cceb08b297e6aef |
|
MD5 | 97a6c2b6f50ec89fd4370deca2fa3214 |
|
BLAKE2b-256 | b3d98293f3d466ef8d0cb37afd81ba5ca5c6bd0fc127ba62f014fd60cf959c38 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2fd8288195c9db41606b2f3730c306d3b3754b324a8ac24167b0027d46cabfb |
|
MD5 | e5c115289b88c0c5d75fc0fc8ca4cfa9 |
|
BLAKE2b-256 | 147d33239a344a7dd4ffabd89f780786f32f31e65748d2dc6286d28c0325088a |