-
Notifications
You must be signed in to change notification settings - Fork 0
/
emotions_similarity_heatmap.py
31 lines (26 loc) · 1.34 KB
/
emotions_similarity_heatmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import nltk
from nltk.corpus import wordnet
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# List of emotions
emotions = ['Euphoria', 'Ecstasy', 'Joy', 'Love', 'Happiness', 'Gratitude', 'Contentment', 'Hope', 'Pride', 'Amusement', 'Wonder', 'Curiosity', 'Awe', 'Nostalgia', 'Serenity', 'Calmness', 'Surprise', 'Anticipation', 'Boredom', 'Ambivalence', 'Confusion', 'Melancholy', 'Longing', 'Disappointment', 'Regret', 'Envy', 'Sadness', 'Anxiety', 'Fear', 'Frustration', 'Anger', 'Resentment', 'Rage', 'Despair', 'Hopelessness']
# Download the WordNet corpus if not already downloaded
nltk.download('wordnet')
# Create a similarity matrix
similarity_matrix = np.zeros((len(emotions), len(emotions)))
# Calculate the similarity between emotions
for i in range(len(emotions)):
for j in range(i+1, len(emotions)):
emotion1 = wordnet.synsets(emotions[i])[0]
emotion2 = wordnet.synsets(emotions[j])[0]
similarity = emotion1.wup_similarity(emotion2)
similarity_matrix[i, j] = similarity
similarity_matrix[j, i] = similarity
# Create a heatmap of the similarity matrix
plt.figure(figsize=(10, 8))
sns.heatmap(similarity_matrix, annot=False, cmap='coolwarm', xticklabels=emotions, yticklabels=emotions)
plt.title('Emotion Similarity Heatmap')
plt.xticks(rotation=90)
plt.yticks(rotation=0)
plt.show()