Spaces:
Sleeping
Sleeping
vkovacs
commited on
Commit
·
db0e152
1
Parent(s):
0b600d9
transposed heatmap
Browse files
app.py
CHANGED
@@ -75,31 +75,23 @@ def get_most_probable_label(probs):
|
|
75 |
|
76 |
|
77 |
def prepare_heatmap_data(data):
|
78 |
-
|
79 |
-
print("DEBUG: Data content:", data)
|
80 |
-
|
81 |
-
heatmap_data = pd.DataFrame(0.0, index=range(len(data)), columns=id2label.values())
|
82 |
|
83 |
for idx, row in enumerate(data):
|
84 |
-
print(f"DEBUG: Item at index {idx}: {row} (type: {type(row)})")
|
85 |
-
|
86 |
-
if not isinstance(row, dict):
|
87 |
-
raise TypeError(f"Expected dict, but got {type(row)} at index {idx}: {row}")
|
88 |
-
|
89 |
confidences = row["emotions"].tolist()
|
90 |
for idy, confidence in enumerate(confidences):
|
91 |
emotion = id2label[idy]
|
92 |
-
heatmap_data.at[
|
93 |
|
94 |
-
heatmap_data.
|
95 |
return heatmap_data
|
96 |
|
97 |
def plot_emotion_heatmap(heatmap_data):
|
98 |
-
fig = plt.figure(figsize=(
|
99 |
-
sns.heatmap(heatmap_data, annot=
|
100 |
plt.title("Sentence-level emotion confidences")
|
101 |
-
plt.xlabel("
|
102 |
-
plt.ylabel("
|
103 |
plt.subplots_adjust(left=0.2, right=0.95, top=0.9, bottom=0.2)
|
104 |
plt.tight_layout()
|
105 |
return fig
|
|
|
75 |
|
76 |
|
77 |
def prepare_heatmap_data(data):
|
78 |
+
heatmap_data = pd.DataFrame(0.0, index=id2label.values(), columns=range(len(data)))
|
|
|
|
|
|
|
79 |
|
80 |
for idx, row in enumerate(data):
|
|
|
|
|
|
|
|
|
|
|
81 |
confidences = row["emotions"].tolist()
|
82 |
for idy, confidence in enumerate(confidences):
|
83 |
emotion = id2label[idy]
|
84 |
+
heatmap_data.at[emotion, idx] = round(confidence, 4)
|
85 |
|
86 |
+
heatmap_data.columns = [item["sentence"][:18]+"..." for item in data]
|
87 |
return heatmap_data
|
88 |
|
89 |
def plot_emotion_heatmap(heatmap_data):
|
90 |
+
fig = plt.figure(figsize=(len(heatmap_data.columns) * 0.5 + 2, 10))
|
91 |
+
sns.heatmap(heatmap_data, annot=False, cmap="coolwarm", cbar=True, linewidths=0.5, linecolor='gray')
|
92 |
plt.title("Sentence-level emotion confidences")
|
93 |
+
plt.xlabel("Sentences")
|
94 |
+
plt.ylabel("Emotions")
|
95 |
plt.subplots_adjust(left=0.2, right=0.95, top=0.9, bottom=0.2)
|
96 |
plt.tight_layout()
|
97 |
return fig
|