Representations of emotion for use in AI systems.
Theoretical Overview
Simple Emotional Representations
There are several ways of representing emotion available in this package:
Simple Vectoral Representation
An emotion is given as a vector in a 3D space. Each dimension can have a value from -1 to 1 inclusive, and the dimensions are:
- valence (unpleasant-pleasant): This axis represents how positive or negative an emotion is. For example, happiness has high positive valence, while sadness has high negative valence.
- arousal (deactivated-activated): This axis indicates the level of activation or energy associated with the emotion. For instance, excitement is a high-arousal emotion, while calmness is a low-arousal emotion.
- control (submissive-dominant): This axis describes the degree of control or influence a person feels they have in a given emotional state. Anger and pride are high positive, while helplessness and fear are high negative.
Plutchik's Wheel of Emotions
Plutchik's wheel is shown below:
Here Plutchik identifies eight primary emotions. These primary emotions can be combined to form secondary emotions, which can be combined to form tertiary emotions.
In our package, we represent an emotional state as an 8D vector with one dimension for each primary emotion. Furthermore, the length of the vector can range from 0 to 1 inclusive, representing the intensity of the emotion. The eight primary emotions are:
- joy
- sadness
- trust
- disgust
- fear
- anger
- surprise
- anticipation
Physiological Representation
With inspiration from theories like James-Lange, Cannon-Bard, and Schachter-Singer, we can describe an emotional state using a physiological vector. Each dimension can range from 0 to 1 inclusive, representing the intensity of the physiological response. Here our dimensions are:
- heart_rate
- breathing_rate
- hair_raised
- blood_pressure
- body_temperature
- muscle_tension
- pupil_dilation
- gi_blood_flow
- amygdala_blood_flow
- prefrontal_cortex_blood_flow
- muscle_blood_flow
- genitalia_blood_flow
- smile_muscle_activity
- brow_furrow_activity
- lip_tightening
- throat_tightness
- mouth_dryness
- voice_pitch_raising
- speech_rate
- cortisol_level
- adrenaline_level
- oxytocin_level
Conversion Between Representations
Conversion between representations requires using an LLM. This is because the emotional interpretation of a physiological reaction is context-dependent. Note that converting between different representations is also very inexact, and you will very likely not get the same vector back from doing an inverse operation.
Complex Emotional Representations
Complex emotions may not be easily representable by a single vector. For example, a person may feel exhausted at work and want to watch some TV, but they may also know that watching TV would make them feel anxious and guilty. Simultaneously they may also feel a sense of pride from working on their project.
In this package we represent complex emotions in the following ways:
- Conditional Emotions: The person in this example knows that if they watch TV, they will feel a certain way. This is a prediction about how their emotional state will change in response to a certain action. Thus we provide a transition function on an emotional representation object, allowing the emotion to change in relation to a context and an action.
- Combined Emotions: The physiological representation is a unitary representation, and is a single vector regardless of how complicated a person's emotional state is. The other representations are the sum of weighted vectors.
Examples
This is a simple example of how to use the package. See the examples/ folder for more complex examples.
from dotenv import load_dotenv
import os
from typing import cast
from ai_emotion.complex_emotion import ComplexEmotion
from ai_emotion.conversion import to_plutchik
from ai_emotion.simple_emotion import VectoralEmotion, PlutchikEmotion, PhysiologicalEmotion
from ai_emotion.transition import transition
vectoral_emotion = VectoralEmotion(
valence=0.1,
arousal=0.2,
control=0.8,
)
load_dotenv()
converted_plutchik_emotion = to_plutchik(
vectoral_emotion,
openai_api_key=cast(str, os.getenv("OPENAI_API_KEY")),
context="Getting prepared for a presentation.",
)
complex_emotion = ComplexEmotion([
(0.7, vectoral_emotion),
(0.3, converted_vectoral_emotion),
])
later_complex_emotion = transition(
complex_emotion,
openai_api_key=cast(str, os.getenv("OPENAI_API_KEY")),
context="Started my presentation.",
)
Metadata
Release files for ai-emotion 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_emotion-1.0.1.tar.gz | 7.3 kB | Without provenance | Details for ai_emotion-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_emotion-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for ai_emotion-1.0.1-py3-none-any.whl |
Total release size: 15.8 kB
Release files / ai_emotion-1.0.1.tar.gz
| Download URL | ai_emotion-1.0.1.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7222603ae171abd7d17deef5f2fee284353aaec264c7cd3b32959951463264e
|
|
BLAKE2b-256 checksum How to use checksums |
c649f4dcd5247be365d1dd1cf39b1601e9af0bd349675e6df1cd6ddfafa1e385
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / ai_emotion-1.0.1-py3-none-any.whl
| Download URL | ai_emotion-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9dcc72f86afe8d3040fb41a155497e1900221a5fb940f16a50b3a58db4f32fdc
|
|
BLAKE2b-256 checksum How to use checksums |
30dcf1d5b2a9276bed54f15daa8df9e252759f1e40b9245b2909912cdf53c74b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for ai-emotion 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.