"""Markdown tables used in the paper (results/tables.md).""" import re import pandas as pd EU = {"DE", "FR", "GB", "FI", "CH", "PT", "PL", "NL", "SE", "IT", "ES"} out = [] def grp(df): g = pd.DataFrame({"US": df.get("US", 0), "China": df.get("CN", 0), "Europe": df[[c for c in df if c in EU]].sum(1), "Other": df[[c for c in df if c not in EU | {"US", "CN", "unattributed"}]].sum(1), "Unattributed": df.get("unattributed", 0)}) return g rows = [] for f, lab in [("derivatives_by_month_country", "models"), ("capped_by_month_country", "models, capped at 10 per account/family/month"), ("uploaders_by_month_country", "uploader accounts")]: m = pd.read_csv(f"results/{f}.csv", index_col=0) m = m[m.index >= "2023-01"] y = grp(m).groupby(m.index.str[:4]).sum() sh = y.div(y.sum(1), axis=0) * 100 for yr, r in sh.iterrows(): rows.append([lab, yr + (" (to 26 Nov)" if yr == "2026" else "")] + [f"{v:.1f}" for v in r.values]) out.append("| Counted | Year | US | China | Europe | Other | Unattributed |\n|---|---|---:|---:|---:|---:|---:|") out += ["| " + " | ".join(r) + " |" for r in rows] # organisations org = pd.read_csv("results/derivatives_by_organisation.csv", index_col=0).iloc[:, 0] ORG = pd.read_csv("code/root_orgs.csv").drop_duplicates("author") ORG["o"] = ORG.organisation.str.replace(r"\s*\(.*\)$", "", regex=True).replace({"Alibaba Cloud": "Alibaba", "Alibaba Group": "Alibaba"}) cty = ORG.drop_duplicates("o").set_index("o").country out.append("\n| Rank | Organisation | Country | Derivatives | Share (%) | Cumulative (%) |\n|---:|---|---|---:|---:|---:|") cum = 0; tot = org.sum() for i, (o, v) in enumerate(org.head(15).items(), 1): cum += v out.append(f"| {i} | {o} | {cty.get(o, '-')} | {v:,.0f} | {100*v/tot:.1f} | {100*cum/tot:.1f} |") # licence lic = pd.read_csv("results/licence_drift.csv", index_col=0) out.append("\n| Root licence | Descendants | Permissive (%) | Restrictive (%) | None (%) |\n|---|---:|---:|---:|---:|") for l in ["llama2", "llama3", "llama3.1", "llama3.2", "llama3.3", "gemma", "other", "cc-by-nc-4.0", "openrail++", "creativeml-openrail-m"]: if l not in lic.index: continue r = lic.loc[l]; n = r["n"] out.append(f"| {l} | {n:,.0f} | {100*r.get('permissive',0)/n:.1f} | {100*r.get('restrictive',0)/n:.1f} | {100*r.get('none',0)/n:.1f} |") open("results/tables.md", "w", encoding="utf-8").write("\n".join(out)) print("\n".join(out))