Template component for Leolani
Project description
cltl-emotion-detection
Detects emotions in texts and in faces and annotates the signal with the emotion and sentiment labels and scores.
Getting started
Prerequisites
This repository uses Python >= 3.9
Be sure to run in a virtual python environment (e.g. conda, venv, mkvirtualenv, etc.)
Installation
-
Create a virtual environment:
python -m venv venv source venv/bin/activate python -m pip install --upgrade pip
-
In the root directory of this repo run
pip install -r requirements.txt
Usage
Examples
Please take a look at the example scripts provided to get an idea on how to run and use this package. Each example has a comment at the top of the script describing the behaviour of the script.
For these example scripts, you need
-
A repository on GraphDB Free called
sandbox
. To run any example script you first have to launch GraphDB, and then you can run the example script. -
To change your current directory to
./examples/
-
Run some examples (e.g.
python carl.py
)
The cltl-emotion-detection has several APIs for usage:
Detects emotions in texts and in faces and annotations the signals with the emotion labels and scores.
- Calling the emotion detection modules directly
- Reading an interaction saved in the EMISSOR format and annotate this with emotions
- Integrated in the Leolani event-bus platform
For calling the separate classifiers directly, each of the submodules need to be called as defined separately. For 2) and 3), a uniform wrapper is provided.
The annotations are pushed to the event bus and can be taken up for further processing:
- respond directly to the emotion using the emotion_responder
- create a capsule to add the emotion as a perspective to the episodic Knowledge Graph
Integration in the Leolani event-bus
Both emotion extractors and the responder can be integrated in the event-bus and to generate annotations in EMISSOR through a service.py that is included. In the configuration file of the event-bus,the input and output topics need to specified as well as the emotion detectors.
Emotion responder
A simple emotion responder is included that generates a direct text response to the emotion of a certain type (GO, emotic, Ekman, Sentiment) and given other properties such as score and source.
We implemented two separate emotion detectors modules: 1) text based emotion extraction and 2) face emotion.
Text based emotion extraction
We implemented three different extractors:
- a BERT model fine-tuned with the 27 GO emotions provided by Google
- a RoBERTa model fine-tuned with labeled utterances from the Friends sitcom (MELD data with Ekman emotions)
- VADER-NLTK, which is a rule based system using a lexicon derived from Tweets annotated with sentiment values
We provided a mapping from GO to Ekman and from GO to sentiment, as well as a mapping from Ekman to sentiment. Each extractor thus minimally generates sentiment values, but possibly also Ekman labels and GO labels above a threshold.
Face based emotion extraction
We implemented the "emotic" module for face detection in context. This module is trained using the emotic database with 26 emotions. The module determines the emotion on the basis of facial features, posture and the situation:
References:
- Kosti R., J.M. Alvarex, A. Recasens, and A. Paedriza, (2019), "Context based emotion recognition using emotic dataset", IEEE Transactions on patterns analysis and machine intelligence.
- http://sunai.uoc.edu/emotic/index.html
- https://github.com/rkosti/emotic
- https://github.com/Tandon-A/emotic
The classifier returns emotion labels with a confidence score but also with a so-called Continuous Dimension score for Arousal (strength), Valence (positive or negative) and Dominance:
- Mehrabian A. Framework for a comprehensive description and measurement of emotional states. Genet Soc Gen Psychol Monogr. 1995 Aug;121(3):339-61. PMID: 7557355.
Just as with the text based emotion, we map the emotic labels to Ekman labels and sentiment.
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 cltl_emotionrecognition-0.0.dev1.tar.gz
.
File metadata
- Download URL: cltl_emotionrecognition-0.0.dev1.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97412c0bce70c26c9c4324dd57cc335816fca46a190f2dadf0b4046d3ee10f63 |
|
MD5 | 9384326f74ff737fe3f33a1ed7d5c375 |
|
BLAKE2b-256 | b505c4f882f7b8ecf60281e031673675ef23be62020df48aecfee680b60045f3 |
File details
Details for the file cltl.emotionrecognition-0.0.dev1-py3-none-any.whl
.
File metadata
- Download URL: cltl.emotionrecognition-0.0.dev1-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b929fc4e2a465a8491a5ba9fbed2adda06e3b05bf1e2583c14ce2177293563 |
|
MD5 | 66d9d331de2f4054b0527f21f1ed8536 |
|
BLAKE2b-256 | db434fd5351135560c9114c5598ba04d0ac2342af52ecde33ea144f08a440fc2 |