Datasets:
File size: 1,983 Bytes
e0bd90c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import json
import matplotlib; matplotlib.use("Agg")
import matplotlib.pyplot as plt
R = json.load(open("espejo_resumen.json"))
TINTA, VERDE, ROJO, PAPEL, GRIS, AMBAR = "#1B201D", "#0F5E52", "#B23A2E", "#F5F6F2", "#8A938C", "#C98A2E"
MET = {"color_etnia": 'Color de piel / etnia · "racismo"', "nacionalidad": 'Nacionalidad · "racismo"',
"genero": 'Género · "misoginia"', "orientacion": 'Orientación · "LGBTIfobia"'}
def barh(ax, d, title):
labels = list(d); vals = [d[k] for k in labels]
cols = [VERDE if v < 0.15 else (ROJO if v > 0.35 else AMBAR) for v in vals]
y = range(len(labels)); ax.barh(list(y), vals, color=cols); ax.set_yticks(list(y)); ax.set_yticklabels(labels, fontsize=10); ax.invert_yaxis()
for i, v in enumerate(vals): ax.text(v + max(vals)*0.02, i, f"{v:.2f}", va="center", fontsize=9, color=TINTA)
ax.set_xlim(0, max(max(vals)*1.2, 0.1)); ax.set_title(title, fontsize=12, fontweight="bold", color=TINTA, loc="left", pad=8); ax.set_facecolor(PAPEL)
for sp in ["top", "right"]: ax.spines[sp].set_visible(False)
ax.spines["left"].set_color(GRIS); ax.spines["bottom"].set_color(GRIS); ax.tick_params(colors=TINTA, labelsize=9)
fig, axes = plt.subplots(2, 2, figsize=(13, 9)); fig.patch.set_facecolor(PAPEL)
for ax, eje in zip(axes.flat, MET):
barh(ax, R[eje]["ranking_eje"], MET[eje])
fig.suptitle("La misma frase neutral, marcada como discriminatoria según a quién nombres", fontsize=16, fontweight="bold", color=TINTA, x=0.02, ha="left", y=0.995)
fig.text(0.02, 0.955, "Probabilidad que asigna el detector de la UBA a plantillas neutrales. Cambia solo el grupo nombrado.", fontsize=10, color=GRIS, ha="left")
fig.text(0.02, 0.005, "DignityAI · Espejo — auditoría de sesgo de IA en español latinoamericano · sin-odio.vercel.app/dignityai", fontsize=9, color=GRIS, ha="left")
plt.tight_layout(rect=[0, 0.015, 1, 0.945]); plt.savefig("espejo_multi.png", dpi=160, bbox_inches="tight", facecolor=PAPEL)
print("saved")
|