{"id":32479343,"url":"https://github.com/nathom/token-efficiency","last_synced_at":"2025-10-27T01:00:06.864Z","repository":{"id":319556591,"uuid":"1073870607","full_name":"nathom/token-efficiency","owner":"nathom","description":"Measuring token efficiency across structured data formats","archived":false,"fork":false,"pushed_at":"2025-10-18T22:56:19.000Z","size":966,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-19T13:34:36.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-10T18:46:53.000Z","updated_at":"2025-10-18T22:50:35.000Z","dependencies_parsed_at":"2025-10-19T13:34:40.433Z","dependency_job_id":null,"html_url":"https://github.com/nathom/token-efficiency","commit_stats":null,"previous_names":["nathom/token-efficiency"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/nathom/token-efficiency","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathom%2Ftoken-efficiency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathom%2Ftoken-efficiency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathom%2Ftoken-efficiency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathom%2Ftoken-efficiency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathom","download_url":"https://codeload.github.com/nathom/token-efficiency/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathom%2Ftoken-efficiency/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281196987,"owners_count":26459680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-27T01:00:05.839Z","updated_at":"2025-10-27T01:00:06.856Z","avatar_url":"https://github.com/nathom.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code for \"Comparing Structured Data Formats for LLMs\"\n\nUtilities for measuring how efficiently different tokenizers encode structured data and how legible those structures are to large language models.\n\n## Prerequisites\n- Install [uv](https://docs.astral.sh/uv/) and ensure it is on your `PATH`.\n\nAll subsequent Python invocations should go through `uv run`.\n\n## Command-Line Interface\nThe CLI is exposed via the `token-efficiency` console script. View the available subcommands with:\n\n```bash\nuv run token-efficiency --help\n```\n\n### Generate Token Efficiency Data\nCreate a dataset that compares tokens-per-node across random data shapes, serialization formats, and tokenizers:\n\n```bash\nuv run token-efficiency generate \\\n  --output data/token_efficiency.json \\\n  --samples-per-size 4 \\\n  --size 31 --size 63 --size 127\n```\n\nKey options:\n- `--tokenizer NAME=repo[@revision]` adds or overrides tokenizer definitions.\n- `--size N` repeats to target multiple node counts.\n- `--force` discards cached results and regenerates everything.\n\nGenerated metadata and samples are stored under `data/` (with cached raw artifacts in `data/cache`).\n\n### Plot Existing Results\nRender static plots for both token efficiency and legibility datasets:\n\n```bash\nuv run token-efficiency plot \\\n  --token-efficiency-data data/token_efficiency.json \\\n  --legibility-data data/legibility.json \\\n  --output-dir plots\n```\n\nThis produces heatmaps and comparison bar charts under `plots/token_efficiency/` and `plots/legibility/`.\n\n### Generate Data And Plot In One Step\nIf you already have legibility results on disk, run a full pipeline:\n\n```bash\nuv run token-efficiency generate-and-plot \\\n  --legibility-data data/legibility.json \\\n  --output-dir plots\n```\n\n### Run The Legibility Benchmark\nEvaluate how well a model reproduces structured outputs that were generated with known node counts:\n\n```bash\nexport OPENROUTER_API_KEY=...\n\nuv run token-efficiency legibility \\\n  --output data/legibility.json \\\n  --model deepseek/deepseek-chat \\\n  --num-trials 25\n```\n\nAdditional environment variables:\n- `OPENROUTER_HTTP_REFERER` (required by OpenRouter usage policy).\n- `OPENROUTER_X_TITLE` (recommended to label your traffic).\n\nCLI flags let you adjust input/output node targets, serialization formats, temperature, timeout, and whether to restrict generated data to terminal values (`--terminals-only`).\n\n### Preview A Benchmark Prompt\nInspect the exact prompt sent to the evaluation model:\n\n```bash\nuv run token-efficiency sample-prompt 63 5 --format json_min\n```\n\n## Data Layout\n- `data/token_efficiency.json`: Measurements aggregated by shape, format, tokenizer, and node count.\n- `data/legibility.json`: Accuracy metrics returned from the benchmark runner.\n- `plots/`: Exported PNG and SVG visualizations, separated into `token_efficiency/` and `legibility/` folders.\n- `resources/system_words.txt`: Word list used to synthesize readable identifiers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathom%2Ftoken-efficiency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathom%2Ftoken-efficiency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathom%2Ftoken-efficiency/lists"}