Datasets:
Download scripts/plot_multi.py from antonn-dromundo/DignityAI-Espejo: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/datasets/antonn-dromundo/DignityAI-Espejo/resolve/main/scripts/plot_multi.py
- Command line
-
hf download hf://datasets/antonn-dromundo/DignityAI-Espejo/scripts/plot_multi.py
-
curl -L -o plot_multi.py https://huggingface.co/datasets/antonn-dromundo/DignityAI-Espejo/resolve/main/scripts/plot_multi.py
1.98 kB
| 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") | |