Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Implement max pooling over a set of embedding vectors to produce a single fixed-size representation, a common step in embeddings-and-retrieval pipelines. Given multiple embeddings (e.g., from tokens, passages, or chunks), you’ll return a pooled embedding by taking the maximum value per dimension.
The max-pooled embedding is defined as:
where (E) is an (n \times d) matrix of embeddings and (p) is a length-(d) vector.
Implement the function
Rules:
Output:
| Argument | Type |
|---|---|
| embeddings | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Input is a NumPy array
Use np.max with axis=0
Return NumPy array
The input is already a 2D NumPy array, so you can pool efficiently directly.
Pooling is element-wise: take the maximum per dimension across all embeddings (use axis=0).
Compute np.max(arr, axis=0) to get the max-pooled embedding.