# Maskowanie przyczynowe (uwaga tylko wstecz)

EN: **Causal masking in decoder transformers** · id `causalmask` · aliases: causal mask, causal attention, look-ahead mask, maska przyczynowa, masked self-attention, autoregressive masking

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Sieci i modele generatywne](https://aiatlasgraph.com/t/neural.md) › [Transformery i attention](https://aiatlasgraph.com/t/transformers.md) › Maskowanie przyczynowe (uwaga tylko wstecz)

## Description

- PL: Trójkątna maska w samo-uwadze dekodera blokująca dostęp do przyszłych pozycji; umożliwia równoległy trening autoregresyjny i generację token po tokenie.
- EN: A triangular mask in decoder self-attention blocking access to future positions; enables parallel autoregressive training and token-by-token generation.

## In one sentence

- PL: Zasada, że model piszący tekst przy każdym słowie widzi tylko to, co już powstało, nigdy dalszego ciągu.
- EN: The rule that a text-writing model, at each word, sees only what has already been written, never what comes next.

## Problem it solves

- PL: Gdyby model podczas nauki widział następne słowo, uczyłby się ściągać zamiast przewidywać.
- EN: If the model could see the next word during training, it would learn to copy instead of predict.

## What it does

- PL: Jak zasłonięcie dalszej części kartki: uczeń odgaduje kolejne słowo, widząc tylko tekst nad linijką.
- EN: Like covering the rest of the page: the student guesses the next word seeing only the text above the ruler.

## Everyday example

- PL: Asystent pisze odpowiedź słowo po słowie i każde kolejne dobiera wyłącznie na podstawie wcześniejszych.
- EN: An assistant writes its answer word by word, choosing each one only from the words before it.

## This concerns you if you…

- PL: chcesz zrozumieć, dlaczego czat pisze odpowiedź po kawałku
- PL: uczysz się budować mały model językowy od zera
- EN: want to understand why a chatbot writes its answer piece by piece
- EN: are learning to build a small language model from scratch

## Keywords

causal language modeling · look-ahead mask · teacher forcing · attention sinks · prefix LM · is_causal · decoder-only

## How it works

- PL: Przed softmaxem do wyników QKᵀ dodaje się −∞ powyżej przekątnej, więc pozycja i uwzględnia tylko pozycje ≤ i. Cały ciąg trenuje się wtedy równolegle na przewidywaniu następnego tokenu, a przy generacji wcześniejsze klucze i wartości można trzymać w cache.
- EN: Before the softmax, −∞ is added to QKᵀ scores above the diagonal, so position i attends only to positions ≤ i. The whole sequence then trains in parallel on next-token prediction, and during generation earlier keys and values can be cached.

## Limits

- PL: Model widzi kontekst tylko z lewej, co utrudnia zadania wymagające wglądu w całość, np. wypełnianie luk w środku tekstu. Początkowe tokeny przyciągają nieproporcjonalnie dużo uwagi (attention sinks). Generacja pozostaje sekwencyjna.
- EN: The model sees only left context, which hampers tasks needing the whole text, such as filling gaps mid-text. Early tokens attract disproportionate attention (attention sinks). Generation stays sequential.

## Key terms

- PL: **maska trójkątna**: Macierz zakrywająca wszystkie pozycje leżące po bieżącej.
- PL: **teacher forcing**: Trening, w którym model dostaje prawdziwe poprzednie tokeny, nie własne.
- PL: **attention sink**: Początkowy token przyciągający dużą część uwagi niezależnie od treści.
- EN: **triangular mask**: A matrix hiding every position after the current one.
- EN: **teacher forcing**: Training where the model gets the true previous tokens, not its own.
- EN: **attention sink**: An early token drawing much attention regardless of content.

## Know first

- [Mechanizm self-attention (zapytania, klucze, wartości) (Self-attention (queries, keys, values))](https://aiatlasgraph.com/t/selfattention.md)

## Related topics

Untyped, symmetric "see also" links.

- [Przewidywanie następnego tokenu (modele autoregresyjne) (Next-token prediction objective)](https://aiatlasgraph.com/t/nexttoken.md)
- [Zarządzanie KV cache (KV cache management)](https://aiatlasgraph.com/t/kvcache.md)

## Sources

- [Attention Is All You Need](<https://arxiv.org/abs/1706.03762>) `vaswani-attention-2017` · by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, Illia Polosukhin

---

AI Atlas revision 129 (2026-11-05) · HTML: https://aiatlasgraph.com/t/causalmask · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-11-05
