True ML Talks #20 - المحولات، التضمينات ونماذج اللغة الكبيرة (LLMs) - عالم تعلم الآلة في Turnitin

Built for Speed: ~10ms Latency, Even Under Load
Blazingly fast way to build, track and deploy your models!
- Handles 350+ RPS on just 1 vCPU — no tuning needed
- Production-ready with full enterprise support
We are back with another episode of True ML Talks. In this, we'll delve deep into the main ideas of the fascinating paper titled Analyzing Transformer Dynamics as Movement through Embedding Space. This paper introduces a novel perspective on how Transformers operate, emphasizing that they learn an embedding space and navigate it during the inference process. We are talking with Sumeet Singh
Sumeet is a Distinguished ML Scientist at Turnitin, and the author of the paper we are going to be discussing today. He also comes from a research background.
📌
Our conversations with Sumeet will cover below aspects:
- Understanding Transformer Dynamics
- Demystifying Embedding Space in Transformer Models
- Deciphering the Mechanics of Token Prediction in Transformers
- Unique Abstractions of Transformer Layers
- The Mystery of Repetitive Tokens
- The Misleading Notion of Learning in Transformer Models
- The Interplay of In-Context Learning, Few-Shot Learning, and Fine Tuning in Transformers
- Navigating General-Purpose AI: Model Choices and Practical Insights
Watch the full episode below:
Understanding Transformer Dynamics: A Deep Dive into Embedding Space
In the realm of AI and natural language processing, the Transformer model reigns supreme for text processing and generation. But what lies beneath this impressive architecture? The groundbreaking paper, "Analyzing Transformer Dynamics as Movement to Embedding Space," unravels the mysteries of the Transformer's inner workings.
This research began when developing an auto-grading model for short answers, achieving an impressive 80% accuracy rate across subjects but lacking clarity on its mechanisms. To understand the Transformer's behavior, the study delved deep, initially exploring attention attribution and weight analysis with limited insights, leaving researchers puzzled.
1. A Paradigm Shift: Viewing Transformers in Embedding Space
The turning point in this research came with the realization that the Transformer could be viewed as a series of operators in an embedding space. This space, like a three-dimensional landscape, guides the Transformer's predictions. Instead of seeking attention patterns, the perspective shifted to viewing the Transformer as a river flowing through valleys and canyons, following paths of least entropy.
2. The Fixed Embedding Space
Once the model is trained, the embedding space remains fixed. When presented with the same input sequence, it consistently produces identical embeddings. These embeddings are crucial in predicting the next token, as they determine the probabilities assigned to each token in the sequence.
3. Angular Proximity and Token Prediction
The research uncovered that the embedding space organized itself into a bounded space resembling a ball, thanks to layer normalization. The model's token predictions heavily rely on the angular proximity between the aggregated embedding vector and individual token embeddings.
4. Decoding Walk vs. Encoding Walk
Two distinct walks shape the Transformer's behavior: the decoding walk, which governs stochastic decoding and token sampling, and the encoding walk, a deterministic process that forms soft clusters based on the similarity of token vectors. The encoding walk is a key factor in transforming a sequence of token vectors into a single aggregated embedding vector.
5. Level of Abstraction in Transformers
Unlike conventional neural networks where lower layers work at lower levels of abstraction, Transformers maintain a consistent level of abstraction throughout their layers. This is evident in the shared input and output embedding matrices, highlighting the unique nature of Transformer architecture.
Demystifying Embedding Space in Transformer Models
To grasp the concept of embedding space, we must first recognize it as the vector space of size d_model—the hidden size of the Transformer. In simpler terms, d_model represents the dimensionality of this space. For instance, in GPT models, this dimension can be substantial, reaching up to 12,000.
Now, what's vital to comprehend is that every vector emerging from every layer of the Transformer model resides within this embedding space. This includes not only the input token vectors but also all the vectors generated as you move up the layers, all the way to the top—culminating in the context vector.
It's essential to clarify that the size of the embedding space isn't determined by the number of parameters in the model or the top layer's representation. Instead, it's exclusively defined by the value of d_model. This key distinction ensures that we have a clear understanding of what constitutes the embedding space in Transformer models.
Deciphering the Mechanics of Token Prediction in Transformers
In our quest to comprehend the inner workings of Transformers, we now arrive at a pivotal juncture: the mechanics of token prediction. Sumeet, with his insightful perspective, sheds light on the intricate processes that dictate how Transformers generate sequences of text and make intelligent predictions.
1. The Role of Language Modeling Head:
At its core, this language modeling head is a matrix—a matrix with dimensions d_model by V, where V represents the size of your embeddings, which can be substantial depending on your tokenization scheme. This matrix plays a pivotal role in mapping context vectors to token probabilities.
2. The Magic of Dot Products:
The essence of token prediction lies in the dot product—a similarity metric that governs the Transformer's decision-making. When the context vector, derived from the final layer of the decoder, undergoes matrix multiplication with the language modeling head, it results in a vector of probabilities. This probability distribution determines the likelihood of each token in the sequence.
3. Mapping Sequences into the Neighborhood
Now, let's consider the profound concept of mapping a sequence into the neighborhood of a token. The objective is to transform a sequence of tokens, from W_1 to W_t, into the vicinity of W_t+1. This process is akin to navigating a path that appears intelligent to human observers.
4. The Intelligent Machine
At the heart of this transformation is the creation of an intelligent machine—a machine that takes a sequence and skillfully maps it to the neighborhood of the next token. The intelligence lies in the subtlety and coherence of the path, as each step in the walk is evaluated for its degree of intelligence.
5. The Role of Position Encodings
Unlike Convolutional Neural Networks (CNNs), Transformers do not employ pattern recognition kernels. However, there exists a fascinating element known as relative position encodings within the attention layers. These static encodings influence the aggregation weights and help counter self-bias.
6. Negative Self-Bias
Understanding self-bias is crucial. Without position encodings, a context vector would be inclined to attract vectors similar to itself, resulting in repetitive predictions. Position encodings introduce negative self-bias, suppressing the context vector's affinity for itself and promoting diversity in predictions.
7. Position Kernels
Delving deeper, we discover that position kernels, as revealed in the paper, serve to shape the self-bias disposition. They skew aggregation weights, influencing which positions are favored and which are not.

Here is a really great blog that explains Transformer Architecture one step at a time:
Unique Abstractions of Transformer Layers
As we delve deeper into the fascinating world of Transformer models, a compelling insight is brought forth—one that distinguishes Transformers from conventional neural networks like CNNs. The question at hand is, why do Transformers operate differently, and how can we grasp the concept of layer-by-layer embeddings?
Distinction Between Transformers and CNNs:
- Transformers operate differently from CNNs. In CNNs, lower layers typically capture simpler features like edges, while higher layers build more complex representations.
- In contrast, Transformers work within the same abstract space across all layers, without a clear hierarchy of abstraction like in CNNs.
Understanding the Residual Stream:
- Transformers maintain uniformity in their abstract space partly due to the presence of a residual stream.
- In a Transformer layer (e.g., in the encoder), there is an input followed by an attention layer. A residual link adds the output of the attention layer back to the input.
- Similarly, in the feed-forward layer, transformations are applied, and another shortcut adds the output back to the input.
- This consistent addition of input and output at each layer ensures that dimensions maintain the same meaning, creating a unified abstract space.
The Layer-by-Layer Mental Model:
- To help understand this phenomenon, the concept of "layer-by-layer embeddings" is introduced.
- In CNNs, there's a hierarchical construction of abstraction layers. However, in Transformers, each layer contributes to the same abstract space.
- Transformers challenge the traditional understanding of neural network behavior by presenting a network of layers that work together in a more unified manner.
The Mystery of Repetitive Tokens: Small vs. Large Transformer Modelsa
In the world of Transformers, an intriguing observation is the tendency of smaller models to repeat tokens, while larger models produce more varied output. Sumeet explores this phenomenon, though it lacks a clear theoretical explanation.
- Smaller Models: Smaller Transformers often exhibit token repetition in generated text, highlighting an intriguing link between model size and output quality.
- Richer Embedding Space: A key factor contributing to the difference between small and large models is the richness of the embedding space. Larger models have a more extensive, nuanced feature space for intricate information processing.
- More Parameters for Granular Processing: تتميز النماذج الأكبر بوجود المزيد من الطبقات والمعاملات، خاصة في طبقات التغذية الأمامية. وهذا يعزز قدرتها على معالجة المعلومات بطريقة متطورة.
- استراتيجيات فك الترميز: يمكن التخفيف من تكرار الرموز باختيار استراتيجية فك الترميز الصحيحة. ففك الترميز الجشع والبحث الشعاعي أكثر عرضة للتكرار، بينما تنتج تقنيات مثل أخذ العينات Top-K أو Top-P نتائج متنوعة.
- الجمل المتكررة: حتى في النماذج الأكبر، يحدث تكرار للجمل أحيانًا، مما يكشف عن تعقيد توليد النصوص داخل نماذج المحولات.
المفهوم المضلل للتعلم في نماذج المحولات
في عالم نماذج المحولات، يطرح سؤال جوهري: هل يحدث تعلم حقيقي ضمن السياق في هذه النماذج، أم أنه يوصف بشكل أدق كمفهوم مصاغ بذكاء؟ تتحدى الورقة البحثية المفاهيم التقليدية للتعلم داخل نماذج المحولات وتكشف عن الآليات الكامنة.
يتضمن التعلم التقليدي تعديل الأوزان والمعاملات لتسهيل تكيف النموذج واستجابته للبيانات الجديدة. ومع ذلك، لا يتوافق هذا الفهم التقليدي مع نماذج المحولات. تكمن المشكلة الأساسية في مساحة التضمين الثابتة والمسارات المحددة مسبقًا.
في جوهرها، لا تشارك هذه النماذج في التعلم بالمعنى التقليدي. تظل مساحة التضمين ثابتة، والمسارات، وإن كانت متنوعة، فهي محددة مسبقًا. أثناء الاستدلال، لا يوجد تكيف أو تعديل لأوزان النموذج. بدلاً من ذلك، تتنقل هذه النماذج في مشهد من الاحتمالات، حيث يعمل كل عنصر مفقود كنقطة بداية فريدة.
تتناول الأبحاث أيضًا الجدل الدائر حول ذكاء هذه النماذج وقدراتها على الاستدلال. يجادل البعض بأنها تفتقر إلى آليات الاستدلال الحقيقي، وتعتمد بدلاً من ذلك على التنبؤات المستندة إلى البيانات المحفوظة بدلاً من الفهم الحقيقي.
علاوة على ذلك، تتعمق الورقة في عملية إزالة الضوضاء، وهي عملية أساسية تشترك فيها هذه النماذج. عندما يتم إخفاء الرموز عشوائيًا، تظل شبكة السياق سليمة، بغض النظر عن موضع الرمز المخفي. يقوم النموذج بدمج هذا السياق المزدوج ببراعة في متجه سياق واحد، مما يضمن التشغيل السلس، بغض النظر عن موقع العناصر المفقودة.
لا يوجد تعلم يحدث. أعني، لأن مساحة التضمين ثابتة. جميع المسارات ثابتة. كل ما تفعله هو الاختيار والانتقاء. فأي تعلم هنا؟ أوزانك لا تتغير. لا شيء! - سوميت سينغ
التفاعل بين التعلم ضمن السياق، والتعلم من أمثلة قليلة، والضبط الدقيق في نماذج المحولات
في النموذج الموصوف، حيث تتنقل نماذج المحولات في مسارات محددة مسبقًا ضمن مساحة تضمين ثابتة، تكتسب العلاقات بين "التعلم ضمن السياق" و"التعلم من أمثلة قليلة" و"الضبط الدقيق" منظورات مميزة.
1. التعلم ضمن السياق والتعلم من أمثلة قليلة
ضمن هذا النموذج، يتقارب التعلم ضمن السياق والتعلم من أمثلة قليلة في مفهوم مشترك. سواء كان ذلك سجل محادثة أو مجموعة من الأمثلة، فكلاهما يؤول إلى تسلسلات سياقية. عندما يواجه نموذج محول سياقًا جديدًا، فإنه يختار مسارًا عبر مساحة التضمين بناءً على هذا السياق. تحدد عملية اختيار المسار هذه، التي يمليها السياق، مخرجات النموذج. وبالتالي، يتضمن كل من التعلم ضمن السياق والتعلم من أمثلة قليلة تكيف النموذج مع سياق معين وتوليد استجابات أو مخرجات ذات صلة بالسياق.
2. الضبط الدقيق كتعديل للمسار
يمثل الضبط الدقيق الخاضع للإشراف، في سياق المحولات، عملية لتغيير المسارات المحددة مسبقًا ضمن مساحة التضمين. أثناء الضبط الدقيق، يتم إدخال بيانات إضافية وأهداف محددة، مما يعيد تشكيل الجغرافيا الداخلية للنموذج. بينما تظل الآلية الأساسية — اختيار المسار — ثابتة، يخضع مشهد المسارات المتاحة لتعديلات لتتوافق مع مهمة الضبط الدقيق المطلوبة.
3. RLHF وانتشار الإشارة
في حالة التعلم المعزز من التغذية الراجعة البشرية (RLHF)، يكمن الاختلاف الرئيسي في كيفية انتشار إشارة التعزيز. فبينما يستخدم الضبط الدقيق الخاضع للإشراف خسارة الانتروبيا المتقاطعة على مستوى الرمز، يستفيد RLHF من الإشارات الواردة من نموذج تقييم. ما يميز RLHF هو أن إشارة التعزيز تمتد عبر التسلسل بأكمله، مما يؤثر على مسارات النموذج بشكل شامل. ومع ذلك، يشترك كل من RLHF والضبط الدقيق الخاضع للإشراف في الهدف المشترك المتمثل في إعادة تشكيل خريطة التموجات داخل مساحة التضمين لتحسين الأداء لمهام محددة.
📌
سد الفجوة: نماذج المحولات عبر الوسائط المختلفة
تتمتع نماذج المحولات بقدرة تكيف ملحوظة عبر الوسائط المختلفة. تنتقل هذه النماذج بسلاسة من النصوص إلى الصور والكلام ومجموعات البيانات المتنوعة.
تقليديًا، تتميز التسلسلات بتدفق سياقي خطي، ولكن عند الانتقال إلى الصور، يصبح مفهوم التسلسل الخطي مثيرًا للاهتمام. تتعامل نماذج مثل Bard مع هذا باستخدام إزالة الضوضاء. تحتفظ الرموز الفارغة، بغض النظر عن موقعها، بالسياق. سواء كانت في البداية أو المنتصف أو النهاية، تتشكل شبكة سياقية، ويقوم النموذج بتجميعها في متجه سياقي واحد، متكيفًا بسلاسة.
استكشاف الذكاء الاصطناعي للأغراض العامة: خيارات النماذج ورؤى عملية
- التحول إلى الذكاء الاصطناعي للأغراض العامة: تعامل مع المحولات كآلات ذكاء متعددة الاستخدامات، مما يبسط تعقيدات النماذج.
- اختلافات النماذج أقل أهمية: الفهم العميق يقلل من الفروقات بين النماذج، مع التركيز على الأداء في العالم الحقيقي.
- اختيار النماذج العملي: اختر النماذج بناءً على تقييم المهام في العالم الحقيقي، مع إعطاء الأولوية للكفاءة.
- الاستفادة من هندسة الأوامر (Prompt Engineering): صمم المدخلات لتوجيه فعال دون تعقيدات النموذج.
- الضبط الدقيق الفعال من حيث التكلفة: نماذج أصغر لأداء فعال التكلفة في حالات الازدحام المروري العالي.
- الموازنة بين التكلفة والأداء: عوامل حاسمة لتقديم النماذج المضبوطة بدقة بكفاءة في سيناريوهات الازدحام المروري العالي.
اقرأ مدوناتنا السابقة ضمن سلسلة True ML Talks:
تابع مشاهدة TrueML سلسلة اليوتيوب وقراءة TrueML سلسلة المدونة.
TrueFoundry هي منصة كخدمة (PaaS) لنشر تعلم الآلة (ML) مبنية على Kubernetes لتسريع سير عمل المطورين مع منحهم مرونة كاملة في اختبار ونشر النماذج وضمان الأمان والتحكم الكاملين لفريق البنية التحتية. من خلال منصتنا، نمكّن فرق تعلم الآلة من نشر ومراقبة النماذج في 15 دقيقة بموثوقية 100% وقابلية للتوسع والقدرة على التراجع في ثوانٍ - مما يسمح لهم بتوفير التكلفة وإطلاق النماذج إلى الإنتاج بشكل أسرع، مما يحقق قيمة تجارية حقيقية.
TrueFoundry AI Gateway delivers ~3–4 ms latency, handles 350+ RPS on 1 vCPU, scales horizontally with ease, and is production-ready, while LiteLLM suffers from high latency, struggles beyond moderate RPS, lacks built-in scaling, and is best for light or prototype workloads.
The fastest way to build, govern and scale your AI


















.png)
.webp)










.webp)






