Example 1
Arguments: [
[
[
1,
2
],
[
9,
9
]
],
[
true,
false
]
]
Expected result: [
1,
2
]Only [1,2] is valid, so the pooled vector is [1,2].
Tokenization and attention · Easy
Problem 12 of 50 · Python and NumPy
Return the mean embedding over token rows whose mask entry is true. A false mask means padding and contributes neither values nor count. If all rows are masked, return a D-wide zero vector.
def masked_mean_pool(embeddings, mask):Arguments: [
[
[
1,
2
],
[
9,
9
]
],
[
true,
false
]
]
Expected result: [
1,
2
]Only [1,2] is valid, so the pooled vector is [1,2].
Arguments: [
[
[
1,
2
],
[
3,
4
]
],
[
false,
false
]
]
Expected result: [
0,
0
]No token is valid, so return one zero for each of the two features.