Genomics and RNA
Windowed max pooling and coordinate routing
DeepSEADeepBind
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Take channelwise maxima within valid sequence windows. Return pooled values, validity, and the winning original sequence index for every output channel.
Function signature
windowed_max_pool(
x: torch.Tensor,
valid_mask: torch.Tensor,
options: dict,
) -> dict[str, torch.Tensor]Worked example
Different channels can choose different source positions
Use one batch with x=[(1,-2),(3,-5),(3,-1)] and all positions valid. Set window=2, stride=1, and padding=[1,0]. The three source-index windows are [-1,0], [0,1], and [1,2]; index -1 is padding and never competes. The pooled vectors are [(1,-2),(3,-2),(3,-1)], and winning indices are [(0,0),(1,0),(1,2)]. In the last window, channel 0 ties at value 3 and keeps earlier index 1. All output windows are valid, and the negative channel remains negative.
Parameters
| Parameter | Shape and meaning |
|---|---|
xtorch.Tensor | [B, L, C]Sequence features; only valid positions need finite values. |
valid_masktorch.Tensor | [B, L]True includes all channels at this sequence position. |
optionsdict | Scalar settings. Omitted keys use the defaults below. |
Return
dict[str, torch.Tensor]
Return exactly the named fields applicable to this operation.
Required behavior
- For
x [B,L,C]andvalid_mask[B,L], compute independent channel maxima overindicesj\cdot \mathrm{stride}-\mathrm{padding\_left} + k,k=0..\mathrm{window}-1.windowdefaults to4, stride to window, and padding to[0,0]; window/stride are positive and padding nonnegative. O=\operatorname{max}(0,\operatorname{floor}((L+\mathrm{left}+\mathrm{right}-\mathrm{window})/\mathrm{stride})+1). Exclude out-of-range and masked positions, including nonfinite missing payloads, before taking maxima.- Return
y [B,O,C],valid_mask[B,O](any eligible position), andindices[B,O,C]containing the original input index of the first maximum. All-invalid windows returny=0and\mathrm{index}=-1;O=0returns correctly shaped empty outputs. Negative data must not compete with artificial zero padding. - A tied maximum chooses the earliest eligible index, matching the specified subgradient convention.
Why this matters
Pooling changes values and coordinates together; overlapping windows may route several output gradients back to the same input position.
Starter code
You write the body of this function in the BioTorch workspace. Your code runs in an isolated PyTorch sandbox; Run checks the public examples and Submit grades the full test suite, including gradients.
import torch
def windowed_max_pool(
x: torch.Tensor, # (B, L, C)
valid_mask: torch.Tensor, # (B, L)
options: dict,
) -> dict[str, torch.Tensor]:
"""Return dict[str, torch.Tensor]:
y: (B, O, C).
valid_mask: (B, O).
indices: (B, O, C)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement windowed_max_pool")
Ready to implement it?
3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Sources and further reading
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.