Scripts for training a sentiment analysis model and serving it.
Test it out here: https://twitter-emotion.herokuapp.com/
Query https://twitter-emotion.herokuapp.com/emotion-analysis with a POST with a body like this:
{
"tweets": [
"Tweet",
"Another tweet",
"Are we done with the tweets already?"
]
}Remeber to use "content-type": "application/json" in the header!
And it will return something like this:
[
{"anger": 6.688, "disgust": 3.302, "fear": 16.631, "joy": 21.477, "sadness": 22.82, "surprise": 19.229},
{"anger": 9.33, "disgust": 6.366, "fear": 15.042, "joy": 22.213, "sadness": 25.334, "surprise": 22.911},
{"anger": 13.476, "disgust": 13.434, "fear": 8.879, "joy": 13.032, "sadness": 28.745, "surprise": 22.029}
]- Clone the repo:
git clone https://github.com/social-barometer/twitter-sentiment.git
- Create a virtual env:
python3 -m venv twitter-emotion
- cd to the folder:
cd twitter-emotion
- Activate teh virtual env:
source bin/activate
- Install requirements:
pip3 install requirements.txt
- Run the server:
pip3 server.py
A trained model is already included in the models folder but you can tweak the train.py script to make a better one!
To do so you must download the data.
Download the Twitter Emotion Corpus from: http://saifmohammad.com/WebPages/SentimentEmotionLabeledData.html and save unzip it to root of the project.
The training script also needs GloVe embeddings to work. Download the glove.twitter.27B.zip embeddings from https://nlp.stanford.edu/projects/glove/ and unzip it to the root of the project.
Now you are ready to train your own models. Once you're done with tweaking the train.py script run the following command to train the model:
pip3 train.py
Have fun!