Repository Public License Research preview
1% S03-F01 — Figure phare 4 : requêtes, clés, valeurs et masque causal, sur une miniature vérifiée par le code.2% Idée : l'attention est un calcul en trois temps (score = requête · clé ; poids = softmax ; somme pondérée des3% valeurs). À gauche, le calcul complet pour le dernier jeton ; à droite, la matrice de tous les poids, où le4% masque causal interdit à chaque jeton de regarder ceux qui le suivent.5% DONNÉES : S03-F01-donnees.tex, généré par demos/src/atlas_s03/exporter_donnees_figure.py (jamais saisi à la main).6\input{S03-F01-donnees.tex}%7\begin{tikzpicture}[x=1mm, y=1mm]8 % ---------- Partie gauche : le calcul pour « avocat » ----------9 \node[atlas note, anchor=west] at (0,48.6) {Jetons regardés};10 \node[atlas note, anchor=west] at (0,39.6) {\textbf{Clé} : il annonce};11 \node[atlas block strong, text width=22mm, inner ysep=2.6pt, anchor=west] (q) at (0,30.2)12 {\textbf{Requête} d'« avocat » \STval{F01-requete}};13 \node[atlas note, anchor=west] at (0,21.2) {\textbf{Poids} = softmax};14 \node[atlas note, anchor=west] at (0,12.4) {\textbf{Valeur} : il transmet};15 \node[atlas note, anchor=west] at (0,3.2) {\textbf{Somme pondérée}};16 \draw[atlas arrow] (q.east) -- (91.6,30.2);17 \node[atlas note, anchor=west, inner sep=1pt] at (91.8,30.2) {scores};18 \foreach \j/\x in {1/44, 2/64, 3/84} {19 \node[atlas token] (t\j) at (\x,48.6) {\STval{F01-jeton-\j}};20 \node[atlas block, minimum width=17mm, inner ysep=3pt] (k\j) at (\x,39.6) {\STval{F01-cle-\j}};21 \node[atlas block flow, minimum width=9mm, inner ysep=3pt, font=\AtlasSizeLabel\bfseries] (s\j) at (\x,30.2) {\STval{F01-score-\j}};22 \node[atlas label, anchor=south, font=\AtlasTabularFont\AtlasSizeLabel\bfseries] (w\j) at (\x,21.2) {\STval{F01-poids-\j}};23 \draw[atlasRule, line width=1.6mm, line cap=butt] (\x-8,20) -- (\x+8,20);24 \edef\atlasw{\STval{F01-poids-brut-\j}}25 \draw[atlasFlow, line width=1.6mm, line cap=butt] (\x-8,20) -- ({\x-8+16*\atlasw},20);26 \node[atlas block, minimum width=17mm, inner ysep=3pt] (v\j) at (\x,12.4) {\STval{F01-valeur-\j}};27 \draw[atlas arrow muted] (k\j.south) -- (s\j.north);28 \draw[atlas arrow] (s\j.south) -- (\x,25.4);29 \draw[atlas arrow muted] (\x,18.8) -- node[atlas label, right, inner sep=1.5pt] {$\times$} (v\j.north);30 \draw[atlas arrow valid] (v\j.south) -- (\x,6.2);31 }32 \node[atlas step, fill=atlasBg] at (31.4,30.2) {1};33 \node[atlas step] at (31.4,21.2) {2};34 \node[atlas step=atlasValid] at (31.4,3.2) {3};35 \node[atlas block valid, minimum width=57mm, inner ysep=3pt] at (64,3.2)36 {nouveau vecteur d'« avocat » : \textbf{\STval{F01-sortie}}};37 % ---------- Partie droite : la matrice des poids avec masque causal ----------38 \node[atlas heading, anchor=west] at (101.5,48.6) {Matrice avec masque};39 \foreach \j/\x in {1/118.8, 2/128, 3/137.2} {40 \node[atlas note, anchor=south, align=center] at (\x,40.6) {\STval{F01-jeton-\j}};41 }42 \foreach \i/\y in {1/36.6, 2/29.6, 3/22.6} {43 \node[atlas note, anchor=east] at (113.6,\y) {\STval{F01-jeton-\i}};44 \foreach \j/\x in {1/118.8, 2/128, 3/137.2} {45 \ifnum\j>\i\relax46 \draw[atlasRule, line width=.6pt, fill=atlasBg] (\x-4.6,\y-3.5) rectangle (\x+4.6,\y+3.5);47 \draw[atlasRule, line width=.6pt] (\x-4.6,\y-3.5) -- (\x+4.6,\y+3.5);48 \else49 \draw[atlasRule, line width=.6pt, fill=atlasPanel] (\x-4.6,\y-3.5) rectangle (\x+4.6,\y+3.5);50 \node[atlas label, font=\AtlasTabularFont\AtlasSizeLabel] at (\x,\y) {\STval{F01-m-\i-\j}};51 \fi52 }53 }54 \draw[atlasFlow, line width=1.4pt] (114.2,19.1) rectangle (141.8,26.1);55 \node[atlas note, anchor=north west, text width=40mm] at (101.5,17.4)56 {Ligne : jeton qui regarde. Colonne : jeton regardé. Case barrée : masquée, poids 0. Cadre bleu : le calcul de gauche.};57\end{tikzpicture}58