Skip to main content

Track Deep-Thinking Tokens in Transformer Models

Project description

Deep Think Tokens

Track deep thinking tokens and logit lenses in transformer models.

Example Divergences

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep_think_tokens-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deep_think_tokens-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for deep_think_tokens-0.1.0.tar.gz
Algorithm Hash digest
SHA256 32ef9a5c8acc5769709e42566b6e7250267b76341e164305ca5831aab7d37a7c
MD5 7359cee1283be8dfd1290369c4bc4657
BLAKE2b-256 187e6c16ee3b643b5c49779a61cc7914112b057c0d2490ab2d3b77094bc44ba6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deep_think_tokens-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for deep_think_tokens-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 358d21a3666267e3f28f6779369811530f25f9dba03b2a1cd9e31c94492eaa5a
MD5 4afbae7f998c30dbccb737a19da9a067
BLAKE2b-256 26884e448585ee69d977ff9a87448dbc6f506c8e25ef61e43d3719878c3a6905

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page