|
|
import numpy as np |
|
|
import pandas as pd |
|
|
import matplotlib.pyplot as plt |
|
|
import json |
|
|
from matplotlib import font_manager as fm |
|
|
from matplotlib.font_manager import FontProperties |
|
|
|
|
|
font_path = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf" |
|
|
font_bold_path = "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf" |
|
|
fm.fontManager.addfont(font_path) |
|
|
fm.fontManager.addfont(font_bold_path) |
|
|
plt.rcParams["font.family"] = "Arial" |
|
|
plt.rcParams["font.weight"] = "bold" |
|
|
plt.rcParams["axes.labelweight"] = "bold" |
|
|
plt.rcParams["axes.titleweight"] = "bold" |
|
|
plt.rcParams["font.size"] = 12 |
|
|
plt.rcParams["xtick.labelsize"] = 12 |
|
|
plt.rcParams["ytick.labelsize"] = 12 |
|
|
bold_font = FontProperties(fname=font_bold_path, weight="bold") |
|
|
|
|
|
|
|
|
''' |
|
|
数据获取和统计 |
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = { |
|
|
"Difficulty": {"Extreme": 440, "Hard": 289, "Moderate": 289, "Easy": 482}, |
|
|
"Length": {"8k": 250, "16k": 250, "32k": 250, "64k": 250, "128k": 250, "256k": 250}, |
|
|
"Context\nRequirement": {"Full": 840, "Partial": 660}, |
|
|
"Language": {"English": 750, "Chinese": 750}, |
|
|
"Text Type": { |
|
|
"Literature (Novel)": 320, |
|
|
"Literature (Other)": 179, |
|
|
"Law": 176, |
|
|
"Social": 121, |
|
|
"Finance": 115, |
|
|
"Technology": 113, |
|
|
"Science": 107, |
|
|
"History": 103, |
|
|
"News": 69, |
|
|
"Policy": 55, |
|
|
"Education": 51, |
|
|
"Structured": 41, |
|
|
"Medicine": 27, |
|
|
"Other": 23, |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
all_categories = [] |
|
|
for dimension_data in data.values(): |
|
|
for category in dimension_data.keys(): |
|
|
if category not in all_categories: |
|
|
all_categories.append(category) |
|
|
|
|
|
df = pd.DataFrame([{c: d.get(c, 0) for c in all_categories} for d in data.values()], |
|
|
index=list(data.keys()), columns=all_categories) |
|
|
difficulty_categories = set(data["Difficulty"].keys()) |
|
|
|
|
|
row_sums = df.sum(axis=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(figsize=(16, 4)) |
|
|
|
|
|
y_spacing = 0.8 |
|
|
y_pos = np.arange(len(df)) * y_spacing |
|
|
left = np.zeros(len(df)) |
|
|
|
|
|
|
|
|
category_colors = { |
|
|
|
|
|
"Extreme": "#DA7B89", |
|
|
"Hard": "#E6C875", |
|
|
"Moderate": "#C5DB80", |
|
|
"Easy": "#92C56A", |
|
|
|
|
|
"8k": "#d2e3f3", |
|
|
"16k": "#aacee4", |
|
|
"32k": "#68abd5", |
|
|
"64k": "#3788bf", |
|
|
"128k": "#0f5ba6", |
|
|
"256k": "#09336f", |
|
|
|
|
|
"Full": "#495481", |
|
|
"Partial": "#e3882f", |
|
|
|
|
|
"English": "#80a492", |
|
|
"Chinese": "#d23918", |
|
|
|
|
|
"Literature (Novel)": "#393B79", |
|
|
"Law": "#5254A3", |
|
|
"Literature (Other)": "#6B6ECF", |
|
|
"Social": "#9C9EDE", |
|
|
"Technology": "#637939", |
|
|
"Finance": "#8CA252", |
|
|
"Science": "#B5CF6B", |
|
|
"History": "#CEDB9C", |
|
|
"News": "#8C6D31", |
|
|
"Policy": "#BD9E39", |
|
|
"Education": "#E7BA52", |
|
|
"Structured": "#E7CB94", |
|
|
"Medicine": "#843C39", |
|
|
"Other": "#AD494A", |
|
|
} |
|
|
|
|
|
for i, cat in enumerate(all_categories): |
|
|
values = df[cat].values |
|
|
bar_color = category_colors[cat] |
|
|
ax.barh(y_pos, values, left=left, color=bar_color, edgecolor="white", height=0.45) |
|
|
|
|
|
|
|
|
for j, val in enumerate(values): |
|
|
if val >= 52: |
|
|
percentage = (val / row_sums[j]) * 100 if row_sums[j] > 0 else 0 |
|
|
text_x = left[j] + val / 2 |
|
|
text_y = y_pos[j] |
|
|
text_color = "white" |
|
|
ax.text(text_x, text_y + 0.08, cat, |
|
|
va="center", ha="center", fontsize=10, color=text_color, |
|
|
fontproperties=bold_font) |
|
|
ax.text(text_x, text_y - 0.08, f"{percentage:.1f}%", |
|
|
va="center", ha="center", fontsize=8, color=text_color, |
|
|
fontproperties=bold_font) |
|
|
|
|
|
left += values |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ax.set_yticks(y_pos) |
|
|
ax.set_yticklabels(df.index, fontsize=12, fontweight="bold") |
|
|
for label in ax.get_yticklabels(): |
|
|
label.set_horizontalalignment("center") |
|
|
label.set_fontproperties(bold_font) |
|
|
ax.tick_params(axis='y', pad=40, labelsize=12) |
|
|
ax.set_xlim(0, max(row_sums)) |
|
|
xlabel = ax.set_xlabel("Percentage of Samples (Total Samples = 1,500)", fontsize=12, fontweight="bold") |
|
|
xlabel.set_fontproperties(bold_font) |
|
|
ax.set_xticks([]) |
|
|
ax.tick_params(axis='x', bottom=False, labelbottom=False, labelsize=12) |
|
|
|
|
|
|
|
|
ax.legend().remove() |
|
|
|
|
|
plt.tight_layout() |
|
|
plt.show() |
|
|
|
|
|
save_path = "/cpfs/user/chenziyang/LongBenchmark/draw/images/data_source_distribution.png" |
|
|
plt.savefig(save_path, dpi=600, bbox_inches='tight', facecolor='white', edgecolor='none') |
|
|
print(f"Figure saved to: {save_path}") |
|
|
|