Skip to content

About

Runnable notebooks for TokenPath — token-level attribution for LLM output. Exact-span citation highlighting, attention heatmaps, and more as we ship.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

TokenPath Cookbook

Runnable examples for TokenPath — token-level attribution for LLM output. One API call after generation automatically discovers the source-bearing phrases in a model's answer and maps each one back to the exact source span that produced it, measured from model attention. Not "this answer cites this chunk" — these 6 words came from those 9 words.

curl https://api.tokenpath.ai/v1/attributions \
  -H "Authorization: Bearer $TOKENPATH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": "In Q3, revenue grew 18% year over year.",
    "question": "How fast did revenue grow?",
    "answer":   "Revenue grew 18% year over year."
  }'

Works with output from any model — nothing about your generation stack changes. For advanced workflows that need caller-controlled coverage, such as provenance for every leaf in structured JSON, you can optionally provide exact answer spans.

Cookbooks

Cookbook What it shows
PDF attribution Link statements in an answer to the exact supporting text in a PDF, then highlight that text on the original page. Includes a live Adobe earnings demo and an Adobe PDF Extract pipeline for your own files.

Notebooks

Every recipe here is something we've built and run for real — executed against the live API, outputs included. The collection grows as we ship.

Notebook What it shows
How TokenPath works The internals, hands-on: turn the attention heatmap into a citation, three things string matching can't do (cross-lingual, paraphrase, tables), and an optional section that reproduces the same attention read from raw Transformers on Llama-3.1-8B.
Citation highlighting Perplexity-style citations whose highlights land on the exact words, not the chunk. TokenPath automatically selects the answer phrases; the recipe renders them inline and as standalone HTML.
Structured output attribution Trace every extracted JSON field back to its exact source span — including disambiguating repeated values that naive string search maps to the wrong occurrence.
Transcript Q&A attribution Meeting notes and transcript answers where automatically selected phrases link back to the speaker, timestamp, and exact words behind them.
Heatmap visualization The raw answer-token × document-token attention matrix: densify, plot, and roll up.

Open in Colab: how TokenPath works · citation highlighting · structured output · transcript Q&A · heatmap visualization

On the roadmap

Tracked as issues — comment or 👍 to prioritize:

Running locally

git clone https://github.com/tokenpath/tokenpath-cookbook.git
cd tokenpath-cookbook
pip install -r requirements.txt
export TOKENPATH_API_KEY=...   # free key: https://platform.tokenpath.ai
jupyter lab notebooks/

Every notebook needs a TOKENPATH_API_KEY — sign up at platform.tokenpath.ai for 10M free attributed tokens, no card required. After that it's $1 per 1M attributed tokens, pay as you go.

Getting help

  • 🐛 Bugs & broken examples → open an Issue. Fastest way to get something fixed — include the notebook name and the request_id from any API error.
  • 💬 "How do I…?" questions → start a Discussion. Integration questions, use-case design, "is TokenPath right for X" — anything that isn't a bug.
  • 📚 API reference → docs.tokenpath.ai
  • ✉️ Private/billing questions → support@tokenpath.ai

Contributing

Recipes are welcome. Open an issue describing the use case first (so we can point you at prior art), then PR a notebook that follows the pattern here: self-contained, runnable top-to-bottom with only TOKENPATH_API_KEY set, heavy dependencies behind a guarded cell.

License

MIT

About

Runnable notebooks for TokenPath — token-level attribution for LLM output. Exact-span citation highlighting, attention heatmaps, and more as we ship.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages