Algorithmically predict public sentiment on a topic using VADER sentiment analysis
Project description
abraham
Algorithmically predict public sentiment on a topic using flair sentiment analysis.
Installation
Installation is simple; just install via pip.
$ pip3 install abraham3k
Basic Usage
You can run the main function, news_sentiment
to get the raw scores. This will return a nested dictionary with keys for each topic.
from abraham3k.prophets import Isaiah
darthvader = Isaiah(news_source="google")
scores = darthvader.news_sentiment(["amd",
"microsoft",
"tesla",
"theranos"],
window=2)
print(scores['tesla']['text'])
'''
desc datetime probability sentiment
0 The latest PassMark ranking show AMD Intel swi... 2021-04-22T18:45:03Z 0.999276 NEGATIVE
1 The X570 chipset AMD offer advanced feature se... 2021-04-22T14:33:07Z 0.999649 POSITIVE
2 Apple released first developer beta macOS 11.4... 2021-04-21T19:10:02Z 0.990774 POSITIVE
3 Prepare terror PC. The release highly anticipa... 2021-04-22T18:00:02Z 0.839055 POSITIVE
4 Stressing ex x86 Canadian AI chip startup Tens... 2021-04-22T13:00:07Z 0.759295 POSITIVE
.. ... ... ... ...
95 Orthopaedic Medical Group Tampa Bay (OMG) exci... 2021-04-21T22:46:00Z 0.979155 POSITIVE
96 OtterBox appointed Leader, proudly 100% Austra... 2021-04-21T23:00:00Z 0.992927 POSITIVE
97 WATG, world's leading global destination hospi... 2021-04-21T22:52:00Z 0.993889 POSITIVE
98 AINQA Health Pte. Ltd. (Headquartered Singapor... 2021-04-22T02:30:00Z 0.641172 POSITIVE
99 Press Release Nokia publish first-quarter repo... 2021-04-22T05:00:00Z 0.894449 NEGATIVE
'''
Changing News Sources
Isaiah
supports two news sources: Google News and NewsAPI. Default is Google News, but you can change it to NewsAPI by passing Isaiah(news_source='newsapi', api_key='<your api key')
when instantiating. I'd highly recommend using NewsAPI. It's much better than the Google News API. Setup is really simple, just head to the register page and sign up to get your API key.
Detailed Usage
Currently, there are a couple extra options you can use to tweak the output.
When instatiating the class, you can pass up to five optional keyword arguments: news_source
and api_key
(as explained above), splitting
, and weights
.
loud
:bool
- Whether or not the classifier prints out each individual average or not. Default:False
.splitting
:bool
- Recursively splits a large text into sentences and analyzes each sentence individually, rather than examining the article as a block. Default:False
.weights
:dict
- This chooses what each individual category (text
,title
,desc
) is weighted as (must add up to 1). Default:weights={"title": 0.1, "desc": 0.1, "text": 0.8}
.
When running the main functions, news_sentiment
and news_sentiment_summary
, there is one requred argument, topics
, and two optional keyword arguments: window
and up_to
.
topics
:list
- The list of the topics (each astr
) to search for.up_to
:str
- The latest day to search for, in ISO format (%Y-%m-%dT%H:%M:%SZ
). Default: current date.window
:int
- How many days back fromup_to
to search for. Default2
.
Updates
I've made it pretty simple (at least for me) to push updates. Once I'm in the directory, I can run $ ./build-push 1.2.0 "update install requirements"
where 1.2.0
is the version and "update install requirements"
is the git commit message. It will update to PyPi and to the github repository.
Notes
Currently, there's another algorithm in progress (SALT), including salt.py
and salt.ipynb
in the abraham3k/
directory and the entire models/
directory. They're not ready for use yet, so don't worry about importing them or anything.
Contributions
Pull requests welcome!
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 abraham3k-1.3.4.tar.gz
.
File metadata
- Download URL: abraham3k-1.3.4.tar.gz
- Upload date:
- Size: 11.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ab34e54b0f51c4347690568f56589c901868b93418c3b14458e2586a73068c |
|
MD5 | e3dc66a2ac692620e72ee8c4e3e8a413 |
|
BLAKE2b-256 | 4196789ad376ce28d4c604aa97883ce8129c0e7cd3cd01af03f04d7a55c04199 |
File details
Details for the file abraham3k-1.3.4-py3-none-any.whl
.
File metadata
- Download URL: abraham3k-1.3.4-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74104e056055767a04d9a0a3de24c12165e6c03e0e769bdb0f2886e081402808 |
|
MD5 | bd3c28020304845d6512665867ab1f6b |
|
BLAKE2b-256 | 23cb6434b5306f1476c87d2511addf5f294166339248e1247ca27fbdf0a7b470 |