-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmethod_compare_agg.py
More file actions
51 lines (39 loc) · 1.6 KB
/
method_compare_agg.py
File metadata and controls
51 lines (39 loc) · 1.6 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import matplotlib.pyplot as plt
import numpy as np
# Data for the bar chart
categories = ['Unidirectional RNN', 'Bidirectional RNN']
methods = ['Last', 'Average Pooling', 'Max Pooling', 'Attention']
values = {
'Unidirectional RNN': [0.662, 0.654, 0.657, 0.659],
'Bidirectional RNN': [0.664, 0.662, 0.658, 0.69],
}
# Colors for each method
colors = ['#6bb9c7', '#ffb933', '#f35c5b', '#9b59b6'] # Custom colors
# Position of bars on x-axis
x = np.arange(len(categories))
width = 0.18 # Width of each bar
# Create subplots
fig, ax = plt.subplots(figsize=(10, 6))
# Adjust y-axis limits to focus on the data range
ax.set_ylim(0.65, 0.70)
# Plot each method's bars in each category
for i, method in enumerate(methods):
ax.bar(x + i * width - width*1.5, [values[cat][i] for cat in categories], width, label=method, color=colors[i])
# Add labels, title, and custom x-axis tick labels
ax.set_xticks(x)
ax.set_xticklabels(categories, fontsize=12)
ax.set_ylabel('Test Accuracy', fontsize=12)
ax.set_title('Comparison of Sentence Aggregation Methods on RNN Models', fontsize=14)
# Add gridlines for better readability
ax.yaxis.grid(True, linestyle='--', which='major', color='grey', alpha=0.5)
# Annotate each bar with the respective value
for i, method in enumerate(methods):
for j, category in enumerate(categories):
value = values[category][i]
ax.text(j + i * width - width*1.5, value + 0.0005, f'{value:.3f}', ha='center', fontsize=10, color='black')
# Add legend
ax.legend(title="Methods", fontsize=10, title_fontsize=12)
# Tight layout for better spacing
plt.tight_layout()
# Display plot
plt.show()