Track Deep-Thinking Tokens in Transformer Models
Project description
Deep Think Tokens
Track deep thinking tokens and logit lenses in transformer models.
About
This is an implementation of the paper "Think Deep, Not Just Long: Measuring LLM Reasoning Effort via Deep-Thinking Tokens" by Chen et al.
Deep-thinking tokens are tokens where internal predictions undergo significant revisions in deeper model layers prior to convergence. The deep-thinking ratio (proportion of deep-thinking tokens in a generated sequence) exhibits a robust and consistently positive correlation with accuracy on reasoning tasks, substantially outperforming length-based and confidence-based baselines.
Key applications include:
- Reasoning quality prediction: Better than raw token counts for measuring reasoning effort
- Think@n: Test-time scaling strategy that prioritizes samples with high deep-thinking ratios (DTR)
- Early rejection: Enable early rejection of unpromising generations based on low DTR, reducing inference costs
Installation
pip install deep-think-tokens
Or install directly from GitHub:
pip install git+https://github.com/maxzuo/deep-think-tokens.git
Example Usage
from deep_think_tokens import (
add_deep_thinking_tokens_hooks,
plot_divergences,
deep_thinking_ratio,
)
from transformers import AutoModelForCausalLM
# Load a model
model = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-1.5B-Instruct')
# Or add hooks for deep thinking tokens
tracker = add_deep_thinking_tokens_hooks(model)
# Generate text and collect divergences
# ...
# Collect results
results = tracker.collect()
# Plot divergences
plot_divergences(results, tokens=['token1', 'token2', ...])
# Calculate deep thinking ratio
dtr = deep_thinking_ratio(results, g=0.5, p=0.9)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deep_think_tokens-0.1.0.tar.gz.
File metadata
- Download URL: deep_think_tokens-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ef9a5c8acc5769709e42566b6e7250267b76341e164305ca5831aab7d37a7c
|
|
| MD5 |
7359cee1283be8dfd1290369c4bc4657
|
|
| BLAKE2b-256 |
187e6c16ee3b643b5c49779a61cc7914112b057c0d2490ab2d3b77094bc44ba6
|
Provenance
The following attestation bundles were made for deep_think_tokens-0.1.0.tar.gz:
Publisher:
python-publish.yml on maxzuo/deep-think-tokens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deep_think_tokens-0.1.0.tar.gz -
Subject digest:
32ef9a5c8acc5769709e42566b6e7250267b76341e164305ca5831aab7d37a7c - Sigstore transparency entry: 1083982165
- Sigstore integration time:
-
Permalink:
maxzuo/deep-think-tokens@fb4bc597b6436f35ced05c84ee0dca0906c3d55f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/maxzuo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fb4bc597b6436f35ced05c84ee0dca0906c3d55f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file deep_think_tokens-0.1.0-py3-none-any.whl.
File metadata
- Download URL: deep_think_tokens-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
358d21a3666267e3f28f6779369811530f25f9dba03b2a1cd9e31c94492eaa5a
|
|
| MD5 |
4afbae7f998c30dbccb737a19da9a067
|
|
| BLAKE2b-256 |
26884e448585ee69d977ff9a87448dbc6f506c8e25ef61e43d3719878c3a6905
|
Provenance
The following attestation bundles were made for deep_think_tokens-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on maxzuo/deep-think-tokens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deep_think_tokens-0.1.0-py3-none-any.whl -
Subject digest:
358d21a3666267e3f28f6779369811530f25f9dba03b2a1cd9e31c94492eaa5a - Sigstore transparency entry: 1083982205
- Sigstore integration time:
-
Permalink:
maxzuo/deep-think-tokens@fb4bc597b6436f35ced05c84ee0dca0906c3d55f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/maxzuo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fb4bc597b6436f35ced05c84ee0dca0906c3d55f -
Trigger Event:
workflow_dispatch
-
Statement type: