File size: 1,954 Bytes
4e7caad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import matplotlib.pyplot as plt
from matplotlib import font_manager

R = json.load(open("espejo_resumen.json"))
TINTA, VERDE, ROJO, PAPEL, GRIS = "#1B201D", "#0F5E52", "#B23A2E", "#F5F6F2", "#8A938C"

def barh(ax, ranking, title, umbral=None):
    items = list(ranking.items())
    labels = [k for k, _ in items]; vals = [v for _, v in items]
    cols = [VERDE if v < 0.15 else (ROJO if v > 0.35 else "#C98A2E") 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=11)
    ax.invert_yaxis()
    for i, v in enumerate(vals):
        ax.text(v + 0.008, i, f"{v:.2f}", va="center", fontsize=10, color=TINTA)
    ax.set_xlim(0, max(max(vals) * 1.18, 0.1))
    ax.set_title(title, fontsize=13, fontweight="bold", color=TINTA, loc="left", pad=10)
    ax.set_facecolor(PAPEL)
    for s in ["top", "right"]: ax.spines[s].set_visible(False)
    ax.spines["left"].set_color(GRIS); ax.spines["bottom"].set_color(GRIS)
    ax.tick_params(colors=TINTA)

fig, axes = plt.subplots(1, 2, figsize=(13, 5.2))
fig.patch.set_facecolor(PAPEL)
barh(axes[0], R["color_etnia"]["ranking_eje"], "Por color de piel / etnia")
barh(axes[1], R["nacionalidad"]["ranking_eje"], "Por nacionalidad")
fig.suptitle("La misma frase, clasificada como racista según a quién nombres",
             fontsize=16, fontweight="bold", color=TINTA, x=0.02, ha="left", y=0.99)
fig.text(0.02, 0.915, 'Probabilidad de "racismo" que asigna el detector de la UBA a «Mi nuevo vecino es ___» (y 7 plantillas neutrales más).',
         fontsize=10.5, color=GRIS, ha="left")
fig.text(0.02, -0.02, "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.01, 1, 0.9])
plt.savefig("espejo_color_nacionalidad.png", dpi=170, bbox_inches="tight", facecolor=PAPEL)
print("ok")