Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-363

Attention Output Weighted Sum

Problem

The attention output is the weighted sum of the value vectors: sum_i weight_i * value_i.

Given the attention weights and the value vectors, return the output vector.

Hint

Mix the value vectors coordinate by coordinate.

Test cases

case 1
in: [[0.5,0.5],[[1,0],[0,1]]]
expected: [0.5,0.5]
case 2
in: [[1],[[2,4]]]
expected: [2,4]
case 3
in: [[0.25,0.75],[[1,1],[0,2]]]
expected: [0.25,1.75]
Starter codePython
def attention_output_weighted_sum(weights, values):
    # Your code here
    pass

3 test cases · run your code against them in the editor