Structure confidence heads
Linear-Stack pLDDT Head
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Produce one unnormalized score per pLDDT local-confidence bin for each atom slot of each token. Higher logits favor their corresponding bins; this head returns those scores. Normalize the feature vector, apply two affine hidden layers without activation, then project to atom/bin logits.
Function signature
plddt_linear_stack_head(
activations: dict,
parameters: dict,
masks: dict,
norm_eps: float = 1e-05,
) -> torch.TensorWorked example
Worked example
LayerNorm with norm_eps=3 gives [-0.5, 0.5] and [0.5, -0.5]. Both hidden weights and the output weight are identities; the second bias adds 0.25, giving [-0.25, 0.75] and [0.75, -0.25]. Negative entries stay negative: there is no ReLU in this head.
import torch
activations = {
'single': torch.tensor([[[1.0, 3.0], [2.0, 0.0]]], dtype=torch.float64, requires_grad=True),
'W1': torch.tensor([[1.0, 0.0], [0.0, 1.0]], dtype=torch.float64, requires_grad=True),
'W2': torch.tensor([[1.0, 0.0], [0.0, 1.0]], dtype=torch.float64, requires_grad=True),
}
parameters = {
'single_scale': torch.tensor([1.0, 1.0], dtype=torch.float64, requires_grad=True),
'single_offset': torch.tensor([0.0, 0.0], dtype=torch.float64, requires_grad=True),
'b1': torch.tensor([0.0, 0.0], dtype=torch.float64, requires_grad=True),
'b2': torch.tensor([0.25, 0.25], dtype=torch.float64, requires_grad=True),
'W_plddt': torch.tensor([[[1.0, 0.0]], [[0.0, 1.0]]], dtype=torch.float64, requires_grad=True),
'b_plddt': torch.tensor([[0.0, 0.0]], dtype=torch.float64, requires_grad=True),
}
masks = {
'token_mask': torch.tensor([[True, True]], dtype=torch.bool),
'atom_mask': torch.tensor([[[True], [True]]], dtype=torch.bool),
}
norm_eps = 3.0
result = plddt_linear_stack_head(activations=activations, parameters=parameters, masks=masks, norm_eps=norm_eps)Expected return
torch.tensor([[[[-0.25, 0.75]], [[0.75, -0.25]]]], dtype=torch.float64)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. |
norm_epsfloatDefault 1e-05 | Positive value inside the square root of every configured LayerNorm variance. |
Return
torch.Tensor · [B, N, A, L]
Return Predicted logits in atom-slot/bin order.
Required behavior
- single is
[B,N,Cs]; token_mask is[B,N], atom_mask is[B,N,A], and True means present. Sanitize invalid single-token payloads before the learned head. - Apply affine population LayerNorm to single, then two affine hidden projections with NO intervening activation. For normalized heads use eps=norm_eps (default 1e-5) inside the population-variance square root.
- Project hidden features with
W_{plddt}:[H_2,A,L]and addb_{plddt}:[A,L]. Return[B,N,A,L]in bin-logit order, without softmax or pLDDT scaling. - Zero every output logit whose token is absent or atom slot is absent, including after adding biases. Supply all parameters; do not initialize new layers.
Why this matters
Different heads answer different questions: pLDDT describes local accuracy, a distogram describes distance, and PAE describes error after alignment in a particular residue’s frame. Their probabilities feed separate summaries; they are not interchangeable confidence scales.
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 plddt_linear_stack_head(
activations: dict,
parameters: dict,
masks: dict,
norm_eps: float = 1e-05,
) -> torch.Tensor:
"""Return a tensor with shape (B, N, A, L)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement plddt_linear_stack_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.