{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# code-pii v3 exploratory data analysis\n", "Cross-document coreference release (70 shards, seed 2). This notebook reads the small aggregated `stats_summary.json` and the cluster-complete `sample.jsonl`; it does not scan 11.92 GB of Parquet.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "source": [ "import json, collections, pathlib\n", "root = pathlib.Path(\"..\")\n", "stats = json.load(open(root / \"notebooks/stats_summary.json\"))\n", "summary, totals = stats[\"summary\"], stats[\"totals\"]\n", "summary, totals\n" ], "outputs": [ { "data": { "text/plain": [ "{'summary': {'shards': 70, 'files': 5278400, 'bytes': 47856733695, 'spans': 7936370, 'hard_negatives': 4950684, 'clusters': 2379311, 'entities': 3914548, 'seconds': 963.5, 'MB_per_s': 49.67, 'workers': 4, 'config': {'seed': 2, 'inject_frac': 0.75, 'cluster_cap': 8, 'singleton_frac': 0.35, 'p_reuse': 0.7, 'p_repeat': 0.15, 'p_owner': 0.5, 'no_persons': False}}, 'totals': {'files': 5278400, 'injected_files': 3491739, 'clean_files': 1786661, 'bytes': 47856733695, 'spans': 7936370, 'negs': 4950684, 'skipped_license': 3136065, 'skipped_size': 470285, 'clusters': 2379311, 'entities': 3914548, 'owned_entities': 500980, 'recurring_entities': 1167239, 'multi_entities': 2885220}}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Release totals\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "source": [ "print(f\"{totals['files']:,} records in {totals['clusters']:,} clusters\")\n", "print(f\"{totals['entities']:,} embedded entities; {totals['recurring_entities']:,}/{totals['multi_entities']:,} ({totals['recurring_entities']/totals['multi_entities']:.1%}) recur across files in multi-file clusters\")\n", "print(f\"{totals['spans']:,} labeled spans; {totals['negs']:,} hard negatives\")\n", "print(f\"{totals['bytes']/1e9:.2f} GB JSONL; 11.92 GB Parquet\")\n" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5,278,400 records in 2,379,311 clusters\n3,914,548 embedded entities; 1,167,239/2,885,220 (40.5%) recur across files in multi-file clusters\n7,936,370 labeled spans; 4,950,684 hard negatives\n47.86 GB JSONL; 11.92 GB Parquet\n" ] } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Distributions\n", "The aggregate file includes labels, entity types, cluster kinds/sizes, documents and mentions per entity, surface forms, contexts, languages and generator value types.\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "source": [ "for key in [\"label\", \"entity_type\", \"records_by_kind\", \"cluster_size\", \"docs_per_entity\", \"surface_form\"]:\n", " print(\"\\n\", key, stats[key])\n" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "label: {'api_key': 2939108, 'username': 376372, 'password': 1424697, 'token': 1045257, 'email': 943133, 'private_key': 630969, 'person_name': 576834}\nentity_type: {'person': 717813, 'api_key': 1384896, 'token': 498684, 'password': 674978, 'email': 341310, 'private_key': 296867}\nrecords_by_kind: {'singleton': 1161632, 'bundle': 2157603, 'repo': 1959165}\ncluster_size: {'1': 1161785, '2': 562133, '5': 94680, '3': 249362, '4': 135923, '8': 64955, '7': 44693, '6': 65780}\ndocs_per_entity: {'1': 2747309, '2': 807464, '3': 249818, '4': 80686, '5': 23140, '6': 6131}\nsurface_form: {'literal': 6509816, 'username': 354633, 'email': 217690, 'first_name': 108611, 'handle': 21739, 'full_name': 435636, 'escaped_literal': 255658, 'last_name': 32587}\n" ] } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sample integrity\n", "The sample contains complete clusters. The checks below re-assert offsets, cluster ordering, entity resolution and gold replacements. Full validation is performed by `validate.py`; the release reported zero failures.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "source": [ "rows = [json.loads(line) for line in open(root / \"sample.jsonl\")]\n", "clusters = collections.defaultdict(list)\n", "for r in rows: clusters[r[\"cluster_id\"]].append(r)\n", "assert all([r[\"doc_index\"] for r in rs] == list(range(len(rs))) for rs in clusters.values())\n", "for rs in clusters.values():\n", " entities = {e[\"entity_id\"]: e for e in rs[0][\"entities\"]}\n", " for r in rs:\n", " for sp in r[\"spans\"]:\n", " assert r[\"text\"][sp[\"start\"]:sp[\"end\"]] == sp[\"value\"]\n", " assert sp[\"entity_id\"] in entities\n", " assert sp[\"replacement\"] != sp[\"value\"]\n", "len(rows), len(clusters)\n" ], "outputs": [ { "data": { "text/plain": [ "(488, 221)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusions\n", "- The release preserves v2 secret-format priors while adding person identities and cross-document entity reuse.\n", "- 40.5% of entities in multi-file clusters recur in at least two files; singletons and one-document entities remain coreference negatives.\n", "- Exact anonymization is gradable from the per-span `replacement`; consistency is gradable from shared `entity_id`.\n", "- Evaluate detection on CredData, but evaluate coreference/anonymization on held-out synthetic clusters because exact recurrence is rare in CredData.\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.12" } }, "nbformat": 4, "nbformat_minor": 5 }