pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::ContactPredictor Class Reference

Contacts from a masked LM's attention, the way ESM predicts them: one forward pass over <cls> + the sequence + <eos>, every head's map turned into ContactFeatures, then combined. Each map is used as its layer finishes, so a pass holds one layer's at a time. Sequences are run one at a time, with no padding. More...

#include <protein_contacts.hpp>

Public Member Functions

 ContactPredictor (EncoderLM &model, const TextTokenizer &tokenizer, DeviceBackend *backend, ContactOptions options={})
 
ContactMap predict (std::string_view sequence, const EsmContactHead &head)
 ESM's contact head: contact probabilities, L x L, symmetric. Matches transformers' EsmForMaskedLM.predict_contacts.
 
ContactMap average_heads (std::string_view sequence, const std::vector< AttentionHead > &heads)
 The mean of heads' ContactFeatures: an unsupervised predictor with no regression. Scores rank pairs; they aren't probabilities. Pick the heads with RankContactHeads.
 
void for_each_head (std::string_view sequence, const std::function< void(AttentionHead, const ContactMap &)> &visit)
 Calls visit with every head's ContactFeatures, layer by layer, from one pass.
 

Detailed Description

Contacts from a masked LM's attention, the way ESM predicts them: one forward pass over <cls> + the sequence + <eos>, every head's map turned into ContactFeatures, then combined. Each map is used as its layer finishes, so a pass holds one layer's at a time. Sequences are run one at a time, with no padding.

Constructor & Destructor Documentation

◆ ContactPredictor()

pulsatrix::ContactPredictor::ContactPredictor ( EncoderLM &  model,
const TextTokenizer &  tokenizer,
DeviceBackend *  backend,
ContactOptions  options = {} 
)
Parameters
backendWhere the model runs. The model, tokenizer and backend must outlive this.

Member Function Documentation

◆ average_heads()

ContactMap pulsatrix::ContactPredictor::average_heads ( std::string_view  sequence,
const std::vector< AttentionHead > &  heads 
)

The mean of heads' ContactFeatures: an unsupervised predictor with no regression. Scores rank pairs; they aren't probabilities. Pick the heads with RankContactHeads.

Exceptions
std::invalid_argumentas predict(), or for no heads or one outside the model.

◆ for_each_head()

void pulsatrix::ContactPredictor::for_each_head ( std::string_view  sequence,
const std::function< void(AttentionHead, const ContactMap &)> &  visit 
)

Calls visit with every head's ContactFeatures, layer by layer, from one pass.

◆ predict()

ContactMap pulsatrix::ContactPredictor::predict ( std::string_view  sequence,
const EsmContactHead &  head 
)

ESM's contact head: contact probabilities, L x L, symmetric. Matches transformers' EsmForMaskedLM.predict_contacts.

Exceptions
std::invalid_argumentfor an empty sequence, a character the tokenizer doesn't know, a head that doesn't fit the model, or a pass over max_pass_bytes.

The documentation for this class was generated from the following file: