0
0
Prompt Engineering / GenAIml~12 mins

Message roles (system, user, assistant) in Prompt Engineering / GenAI - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Message roles (system, user, assistant)

This pipeline shows how a generative AI model processes different message roles: system, user, and assistant. Each role guides the model to understand context, user input, and generate helpful responses.

Data Flow - 4 Stages
1Input messages
3 messages with role and contentCollect messages with roles: system, user, assistant3 messages with role and content
[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is AI?"}, {"role": "assistant", "content": "AI means artificial intelligence."}]
2Preprocessing
3 messages with role and contentConvert messages into tokens and add role embeddingsToken sequences with role embeddings
Tokens for 'What is AI?' plus role info for 'user'
3Model encoding
Token sequences with role embeddingsProcess tokens through transformer layers to understand contextContextual embeddings representing message meaning
Vector representations capturing 'What is AI?' in user context
4Response generation
Contextual embeddingsGenerate next tokens as assistant replyToken sequence for assistant response
Tokens forming 'AI means artificial intelligence.'
Training Trace - Epoch by Epoch
Loss: 2.3 |\
       1.8 | \
       1.3 |  \
       0.9 |   \
       0.6 |    \__
         +----------------
          1  2  3  4  5 Epochs
EpochLoss ↓Accuracy ↑Observation
12.30.25Model starts learning basic message patterns
21.80.40Model improves understanding of roles
31.30.55Better context handling between system and user
40.90.70Assistant responses become more relevant
50.60.80Model converges with good role-based replies
Prediction Trace - 3 Layers
Layer 1: Input message encoding
Layer 2: Transformer encoding
Layer 3: Response generation
Model Quiz - 3 Questions
Test your understanding
Which message role sets the overall behavior of the AI model?
ASystem
BUser
CAssistant
Dnull
Key Insight
Understanding message roles helps the AI model respond appropriately by distinguishing instructions (system), questions (user), and answers (assistant). This role-based context improves conversation quality.