الانتباه الذاتي: Query وKey وValue
اسمح لكل Token بالنظر إلى كل Token آخر
الانتباه الذاتي: Query وKey وValue درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Tokens That Talk
In a sequence, the meaning of one word depends on others. Self-attention lets every token look at every other token to gather the context it needs.
Three Roles per Token
Each token plays three roles: a query that asks, a key that answers, and a value that carries content. These come from the same word, used three ways.
The Query
A token's query describes what it is looking for. Think of it as the question this word is asking about the rest of the sentence.
The Key
Every token also exposes a key, a label advertising what it offers. A query is compared against all keys to find good matches.
The Value
Once a match is found, the value is the actual information that gets passed along. Keys decide how much, values decide what.
Make Q, K, V
You build queries, keys, and values by projecting the input through three learned linear layers. Same input, three different weight matrices.
q = self.W_q(x)
k = self.W_k(x)
v = self.W_v(x)Score by Similarity
To see how well a query matches a key, you take their dot product. A bigger score means the two tokens are more relevant to each other.
scores = q @ k.transpose(-2, -1)Scores to Weights
Raw scores become attention weights with softmax, so each query's weights are positive and sum to one across all keys.
weights = scores.softmax(dim=-1)Blend the Values
The output for each token is a weighted sum of all values, mixed by the attention weights. Relevant tokens contribute more.
out = weights @ vWhy It Beats RNNs
Self-attention connects any two tokens in one step, so distance does not matter. This parallel view is why transformers handle long context so well.
Learned, Not Fixed
The Q, K, V projections are trained by gradient descent. The network learns what to ask, what to advertise, and what to share, all from data.
Quick Check
Let's test how attention combines its pieces.
Recap
You learned that self-attention turns each token into a query, key, and value, scores query-key matches, and blends values by softmax weights. Nice work!
تعلم Python مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «الانتباه الذاتي: Query وKey وValue» مجاني؟
نعم — نص درس «الانتباه الذاتي: Query وKey وValue» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
ماذا ستتعلم في «الانتباه الذاتي: Query وKey وValue»؟
اسمح لكل Token بالنظر إلى كل Token آخر تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟
لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «الانتباه الذاتي: Query وKey وValue»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟
نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الانتباه الذاتي: Query وKey وValue
- الضرب النقطي المُقاس ومتعدد الرؤوس
- الترميز الموضعي للترتيب
- تكديس كتلة Transformer Encoder