You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNestProblem Set
🔥Scaled Dot-Product Attention (Transformer Engine)Hard
HardAI & Machine Learning•Acceptance: 42.1%
Scaled Dot-Product Attention (Transformer Engine)
Real-World Engineering Context
The foundational core equation of modern Generative AI driving language generation, image synthesis, and multimodal reasoning.
In Transformer neural networks (GPT-4, Gemini, Claude), given query vector `Q`, key vector `K`, value vector `V`, and dimension `dk`, compute the 1D scaled dot-product attention score `softmax(Q · K / sqrt(dk)) * V`.
For 1D single-token pairs, return the scalar result rounded to 4 decimal places.
Sample Test Cases
Input: [[1,0],[1,0],[10],2]
Expected: 10
Input: [[1,0],[0,1],[5],2]
Expected: 5
Constraints
- q.length == k.length
- 1 <= dk <= 1024
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.