Protein sequence and inverse folding
ESM3 multitrack embedding and confidence fusion
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Combine supplied ESM3 sequence, structure, secondary-structure, accessibility, function, annotation, and confidence inputs. Return one fused embedding for each valid token.
Function signature
multitrack_embedding_fusion(
activations: dict,
parameters: dict,
masks: dict,
structure: dict,
) -> torch.TensorWorked example
Add categorical tracks and a nontrivial confidence response
The four main table lookups add to [10, 10]. Function heads concatenate to [5, 6]; two occurrences of annotation 1 add [2, 4]. Confidence values [0, 1] use center 0 and width 1, giving radial features 1 and e^{-1}. Their projection weights are [1, 1] and [2, 3], with zero biases, so confidence contributes [1+2/e,1+3/e]. The final embedding is [18+2/e,21+3/e]. This distinguishes concatenated function heads, counted duplicate annotations, and distance-dependent confidence features.
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. |
structuredict | Fields supplied together in this dictionary. |
Return
torch.Tensor · [B, N, C]
Return float[B,N,C], all track contributions added and observation-masked.
Required behavior
- Fuse the complete supplied ESM3-style multitrack input representation. All token axes are
[B,N],B,N\ge 1, andmask[B,N]isTruemeans valid. - The four main tracks
(\mathrm{sequence},\mathrm{structure},\mathrm{ss8},\mathrm{sasa})each haveint64tokens[B,N]and a floatingtable[V_{\mathrm{track}},C]; add their row lookups. Token0is an ordinary learned category in these four tracks. function_tokens[B,N,H]addressfunction_table[H,\mathrm{Vf},\mathrm{Dh}],H,\mathrm{Dh}\ge 1withC=H\cdot \mathrm{Dh}. Look up each head independently and CONCATENATE head0..H-1embeddings, not sum/average. Function ID0is padding and contributes exact zero even if the supplied table's zero row is nonzero.annotation_tokens[B,N,A]addressannotation_table[\mathrm{Va},C]. SUM annotations within a token, excluding ID0. A may be0and duplicate IDs count repeatedly. Add this bag to the main/function embeddings.confidence[B,N,2]contains average-structure and per-residueconfidencein that order.- For supplied
centers[R]and positive scalarwidth, compute\phi_{\mathrm{bntr}}=\operatorname{exp}(-((\mathrm{confidence\_bnt}-\mathrm{centers\_r})/\mathrm{width})^{2}), withR\ge 1. Eachthas its ownconfidence_weight[2,R,C]andconfidence_bias[2,C]. - Add
\sum_{t}(\phi_{t}\mathbin{@}\mathrm{weight\_t}+\mathrm{bias\_t}). The original open encoder usesR=16,centersevenly spaced from0to1inclusive,width1/16; these resources are supplied so smaller examples and derivatives can be studied. There is no one-half in the exponent and no normalization overcenters. - Return
embedding[B,N,C], the sum of these eight contributions (four main tracks, function concatenation, annotation sum and twoconfidenceprojections). All floating tensors share\mathrm{float32}/64. Valid token IDs must index their table; validconfidence, tables and parameters are finite andwidth> 0. - Scaled
confidencedifferences, their squares, and projection/reduction intermediates must remain finite in the common dtype. Masked token IDs may be arbitrary and maskedconfidencemay beNaN: sanitize before lookup or arithmetic; final output is exact zero.hasno keys. - Tokenizers, structure quantization, annotation retrieval,
confidenceprediction and pretrained parameters are outside this computation.
Why this matters
Different tracks use different aggregation rules: some tables add, function heads concatenate, and repeated residue annotations form a summed bag.
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 multitrack_embedding_fusion(
activations: dict,
parameters: dict,
masks: dict,
structure: dict,
) -> torch.Tensor:
"""Return a tensor with shape (B, N, C)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement multitrack_embedding_fusion")
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.