项目作者: nikicc

项目描述 :
Models for predicting emotions from English tweets.
高级语言: Python
项目地址: git://github.com/nikicc/twitter-emotion-recognition.git
创建时间: 2017-03-28T10:34:36Z
项目社区:https://github.com/nikicc/twitter-emotion-recognition

开源协议:GNU Affero General Public License v3.0

下载


Binder

Twitter Emotion Recognition

Trained recurrent neural network (RNN) models for predicting emotions from English tweets.
Our models work on characters hence we pass the whole tweet without any preprocessing as an input to the RNN.
We are predicting three emotion classifications:

  • Ekman’s six basic emotions,
  • Plutchik’s eight basic emotions,
  • Profile of Mood States (POMS) six mood states.

Files and Folders:

  • demo.ipynb: script is showing how to use our models for predicting emotions or embedding tweets in Jupyter Notebook.
  • demo.py: script is showing how to use our models for predicting emotions or embedding tweets in Python.
  • emotion_prediction.py: helper scripts that defines EmotionPredictor class.
  • models/: contains trained RNN models.

Example Usage

Binder

The easiest way to play around is to open Binder.

Notice: Loading a model on Binder can take some time so please be patient!

In Jupyter Notebook

Execute it locally using Jupyter Notebook by opening the demo.ipynb file.

In Python

The following examples show how to predict Ekman’s emotions from tweet’s content.
First let’s import EmotionPredictor.

  1. >>> from emotion_predictor import EmotionPredictor

Next we instantiate the model and define our tweets.
In this example we will work with Ekman’s emotions.
Use plutchik to predict Plutchik’s emotions or poms for Profile of Mood States.
To use models in multilabel setting instead of multiclass provide ml as the setting argument.

  1. >>> model = EmotionPredictor(classification='ekman', setting='mc')
  2. >>> tweets = [
  3. "Watching the sopranos again from start to finish!",
  4. "Finding out i have to go to the dentist tomorrow",
  5. "I want to go outside and chalk but I have no chalk",
  6. "I HATE PAPERS AH #AH #HATE",
  7. "My mom wasn't mad",
  8. "Do people have no Respect for themselves or you know others peoples homes",
  9. ]

We obtain model’s predictions by calling predict_classes method:

  1. >>> model.predict_classes(tweets)
  2. Tweet Emotion
  3. 0 Watching the sopranos again from start to finish! Joy
  4. 1 Finding out i have to go to the dentist tomorrow Fear
  5. 2 I want to go outside and chalk but I have no chalk Sadness
  6. 3 I HATE PAPERS AH #AH #HATE Anger
  7. 4 My mom wasn't mad Surprise
  8. 5 Do people have no Respect for themselves or you know others peoples homes Disgust

To observe probabilities for each class use predict_probabilities method:

  1. >>> model.predict_probabilities(tweets)
  2. Tweet Anger Disgust Fear Joy Sadness Surprise
  3. 0 Watching the sopranos again from start to finish! 0.000717 0.000244 0.003829 0.946539 0.005610 0.043061
  4. 1 Finding out i have to go to the dentist tomorrow 0.007705 0.000039 0.783890 0.198629 0.008950 0.000787
  5. 2 I want to go outside and chalk but I have no c... 0.002772 0.000095 0.004137 0.025035 0.963712 0.004249
  6. 3 I HATE PAPERS AH #AH #HATE 0.956343 0.006368 0.031387 0.000350 0.004375 0.001176
  7. 4 My mom wasn't mad 0.063969 0.004990 0.013971 0.079884 0.218708 0.618478
  8. 5 Do people have no Respect for themselves or yo... 0.070003 0.801428 0.067724 0.003646 0.038480 0.018718

If you would rather just use the final hidden state representation call embed:

  1. >>> model.embed(tweets)
  2. Tweet Dim1 Dim2 ... Dim798 Dim799 Dim800
  3. 0 Watching the sopranos again from start to finish! -0.128762 -0.000000 ... -0.260896 -0.009062 -0.110209
  4. 1 Finding out i have to go to the dentist tomorrow -0.525602 0.407847 ... -0.000088 -0.001489 0.142871
  5. 2 I want to go outside and chalk but I have no c... -0.057850 0.566420 ... -0.091341 -0.003914 -0.037481
  6. 3 I HATE PAPERS AH #AH #HATE 0.019670 -0.288512 ... 0.100234 0.013350 -0.014305
  7. 4 My mom wasn't mad -0.004135 0.657584 ... -0.029319 -0.007455 -0.066208
  8. 5 Do people have no Respect for themselves or yo... -0.246179 0.069080 ... 0.029919 0.011467 -0.000520
  9. [6 rows x 801 columns]

Citing:

If you use our models in a scientific publication, we would appreciate citations to the following paper:

Colnerič, N., & Demšar, J. (2018). Emotion Recognition on Twitter: Comparative Study and Training a Unison Model. IEEE Transactions on Affective Computing, PP (99), 1. https://doi.org/10.1109/TAFFC.2018.2807817