Compute scaled dot-product attention with a mask that stops queries from attending to future positions. mask[i][j] is True when query i may attend to key j; for causal (autoregressive) attention it is lower triangular. The output is softmax(QK⊤/d+mask)V.
Implement solve(Q,K,V,mask=None).
Returns. Return an array with one output row per query row.
Example 1
Input:
solve([[1.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 1.0]], [[1.0, 2.0], [3.0, 4.0]], [[True, False], [True, True]])
Output:
[[1.0, 2.0], [2.339523, 3.339523]]
Example 2
Input:
solve([[1.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 1.0]], [[1.0, 2.0], [3.0, 4.0]])
Output:
[[1.660477, 2.660477], [2.339523, 3.339523]]
No results yet
Run your code to check it against the examples, or submit to run every test.