Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter AttentionSink

Definition
ChapterAttentionSink

by leonardopedro · Oct 6, 2026 · Mathlib 0df444a (Lean v4.33.1)

definitionsformalizationtimepiece

Formal definitions for the timepiece Lean 4 formalization (source chapter BookProof/ChapterAttentionSink.lean): generated def bundle for ChapterAttentionSink. See BookProof/ChapterAttentionSink.lean for full context.

Definition code
import Definitions.Def_ChapterAttentionOutput
import Definitions.Def_ChapterAttentionEntropy
import Definitions.Def_ChapterObservableExpectation
import Definitions.Def_ChapterSoftmaxSharpness
import Mathlib


/-!
# Chapter "The Coherent State of Attention": the attention sink

Trained transformers reliably devote a large share of every head's attention to one
distinguished position — the beginning-of-sequence token — which carries no
information.  This "attention sink" is often described as a pathology; the algebra
of the Born measurement says it is a *gauge*: appending one extra key to a head
rescales all the original weights by one common factor and changes nothing else.

Writing `Fin.cons s₀ s : Fin (m+1) → ℝ` for the score family with the sink
prepended, and `w` for the weight the sink receives:

* `sinkWeight_pos`, `sinkWeight_lt_one` — the sink always takes a strictly positive
  share, never all of it.
* `scoreSoftmax_sink_succ` — **the headline**: every original key keeps exactly
  `(1 − w)` times the weight it had, so `sum_scoreSoftmax_sink_succ` gives the keys
  a total budget of `1 − w`.
* `scoreSoftmax_sink_odds` — the odds between two ordinary keys are untouched, and
  `scoreSoftmax_sink_lt` says each of them is strictly diluted.
* `headOutput_sink` — the output is the two-point average `w·v₀ + (1−w)·o` of the
  sink value and the sink-free output: a sink with value `0` simply shrinks the
  head's output by `1 − w`.
* `shannonEntropy_cons_scaled` and `shannonEntropy_sink` — the entropy chain rule
  for the sink: the head's entropy is the binary entropy of the sink share plus
  `(1 − w)` times the entropy of the ordinary keys.

Everything here is `sorry`-free and `axiom`-free (only `propext`,
`Classical.choice`, `Quot.sound`).
-/

open scoped BigOperators

noncomputable section

namespace BookProof.ChapterAttentionSink

open BookProof.ChapterObservableExpectation BookProof.ChapterSoftmaxSharpness
  BookProof.ChapterSoftmaxOrder BookProof.ChapterAttentionEntropy
  BookProof.ChapterAttentionOutput

variable {m : ℕ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]

/-! ## The score family with a sink prepended -/



/-- The weight the sink key receives. -/
def sinkWeight (beta s0 : ℝ) (s : Fin m → ℝ) : ℝ :=
  scoreSoftmax beta (Fin.cons s0 s) 0











/-! ## The sink rescales, it does not reorganize -/









/-! ## The output of a head with a sink -/



/-! ## The entropy chain rule for the sink -/





end BookProof.ChapterAttentionSink
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterAttentionSink.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me