Structure confidence heads

Normalized Linear pLDDT Head

MediumRaw PyTorchAbout 20 min1 public example plus private tests

AlphaFold3ESMFold2

Write and run your solution Sign in

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. Apply affine population LayerNorm and project directly to atom/bin logits.

Function signature

plddt_normalized_linear_head(
    activations: dict,
    parameters: dict,
    masks: dict,
    norm_eps: float = 1e-05,
) -> torch.Tensor

Worked example

Worked example

Each single vector has population variance 1. With illustrative norm_eps=3, normalization divides the centered vector by 2, giving [-0.5, 0.5] and [0.5, -0.5]. The identity projection leaves those bin logits unchanged.

import torch

activations = {
    'single': torch.tensor([[[1.0, 3.0], [2.0, 0.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),
    '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_normalized_linear_head(activations=activations, parameters=parameters, masks=masks, norm_eps=norm_eps)

Expected return

torch.tensor([[[[-0.5, 0.5]], [[0.5, -0.5]]]], dtype=torch.float64)

Parameters

ParameterShape and meaning
activationsdictSupplied intermediate tensors.
parametersdictSupplied model parameters, keyed as shown below.
masksdictSupplied masks. Each field below defines what True includes or permits.
norm_epsfloatDefault 1e-05Positive 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; there are no hidden projections. For normalized heads use eps=norm_eps (default 1e-5) inside the population-variance square root.
  • Project hidden features with W_{plddt}:[C_s,A,L] and add b_{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.
  • 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

This head maps normalized token features to one local-accuracy logit vector per atom slot. Bin probabilities and numerical pLDDT values are computed in separate lessons.

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_normalized_linear_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_normalized_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.

Write and run your solution Sign in

Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.

Related exercises

Sources and further reading

A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.