Structure confidence heads
PDE Linear Head
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Produce one unnormalized score per distance-error bin for each residue pair. Use pair features directly, with optional pair normalization, for the supplied bin projection. Combine opposite pair directions using the requested symmetry, then zero pairs with absent endpoints.
Function signature
pde_linear_head(
activations: dict,
parameters: dict,
masks: dict,
pde_symmetry: str = 'sum',
norm_eps: float = 1e-05,
normalize_pairs: bool = False,
) -> torch.TensorWorked example
Combine the two directed logit vectors
At the symmetry stage, suppose two valid residues have already projected logits Z[0,1]=[1,3], Z[1,0]=[2,5], and Z[0,0]=[4,6], including their projection biases. Sum symmetry returns [3,8] in both off-diagonal positions and [8,12] on (0,0). Mean symmetry instead gives [1.5,4] and [4,6]. These operations combine logits before any probability conversion; they do not average already-softmaxed probabilities.
Parameters
| Parameter | Shape and meaning |
|---|---|
activationsdict | Supplied intermediate tensors. |
parametersdict | Supplied model parameters, keyed as shown below. |
masksdict | Supplied masks. Each field below defines what True includes or permits. |
pde_symmetrystrDefault 'sum' | "sum" adds transposed pair logits, "mean" averages the two directions, and "none" keeps directed logits. |
norm_epsfloatDefault 1e-05 | Positive value inside the square root of every configured LayerNorm variance. |
normalize_pairsboolDefault False | Normalize pair-confidence features when True. |
Return
torch.Tensor · [B, N, N, P]
Return Distance-error-bin logits under the requested symmetry.
Required behavior
- pair is
[B,N,N,C]; a pair is valid only when both token_mask endpoints are True. Sanitize invalid pair payloads before the head. - Use pair features directly; there is no hidden projection or activation.
- normalize_pairs (default False) optionally applies affine population LayerNorm with pde_scale/pde_offset before the final projection.
- Apply W_pde and b_pde across the feature axis, returning one logit per supplied bin.
- pde_symmetry defaults to "sum": add logits(i,j)+logits(j,i), including doubling diagonal values. "mean" divides that sum by 2. "none" keeps the directional projection unchanged.
- Zero all logits for invalid endpoint pairs after the final bias/symmetrization. Every used LayerNorm places norm_eps (default 1e-5) inside the square root.
- Use CPU float32/float64 tensors with one shared floating dtype/device. Preserve strided layouts and do not mutate supplied tensors.
- Use raw tensor operations, not a ready-made implementation of the requested primitive. Supplied parameters and random variates must not be reinitialized.
Why this matters
PDE estimates how wrong a predicted distance is, rather than predicting the distance itself. This lesson implements its final learned projection; geometric confidence targets and probability summaries are separate.
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 pde_linear_head(
activations: dict,
parameters: dict,
masks: dict,
pde_symmetry: str = 'sum',
norm_eps: float = 1e-05,
normalize_pairs: bool = False,
) -> torch.Tensor:
"""Return a tensor with shape (B, N, N, P)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement pde_linear_head")
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.
Related exercises
Sources and further reading
- www.nature.com
- www.nature.com
- google-deepmind/alphafold · modules.py
- google-deepmind/alphafold · confidence.py
- facebookresearch/esm · esmfold.py
- facebookresearch/esm · esmfold.py
- google-deepmind/alphafold3 · confidence_head.py
- google-deepmind/alphafold3 · confidences.py
- google-deepmind/alphafold3 · confidences.py
- google-deepmind/alphafold3 · confidences.py
- huggingface/transformers · modeling_esmfold2.py
- Biohub/esm · vqvae.py
- Biohub/esm · vqvae.py
- RosettaCommons/RFdiffusion · AuxiliaryPredictor.py
- RosettaCommons/RFdiffusion · RoseTTAFoldModel.py
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.