∞\infty

∞ — infinity

Read "infinity". It is not an ordinary number. It means "grows without limit", and in an attention mask, −∞ means "never allowed".

The attention mask uses −∞-\infty because adding it to any score makes the result −∞-\infty, and e−∞=0e^{-\infty} = 0: the position gets zero weight. Code uses a large finite negative number instead, because true infinities cause NaN ("not a number") in some arithmetic, such as ∞−∞\infty - \infty or 0×∞0 \times \infty. For example, a row where every position is masked with −∞-\infty would give NaN.

Example

e 3+(−∞)=e−∞=0e^{\,3 + (-\infty)} = e^{-\infty} = 0

Whatever the original score, a masked position ends with weight zero.

Where the course uses it

Related terms