Skip to content

Diffusion

diffusion

DiffusionDecoder(model: InstaNovoPlus)

Bases: Decoder

Class for decoding from a diffusion model by forward sampling.

model: InstaNovoPlus = model instance-attribute

time_steps = self.model.time_steps instance-attribute

residue_set = self.model.residue_set instance-attribute

loss_function = DiffusionLoss(model=(self.model)) instance-attribute

decode(spectra: Float[Spectrum, ' batch'], precursors: Float[PrecursorFeatures, ' batch'], spectra_padding_mask: Bool[SpectrumMask, ' batch'], initial_sequence: Optional[Integer[Peptide, ' batch']] = None, start_step: int = DIFFUSION_START_STEP, eval_steps: tuple[int, ...] = DIFFUSION_EVAL_STEPS, beam_size: int = 1, mass_tolerance: float = 5e-05, max_isotope: int = 1, return_encoder_output: bool = False, encoder_output_reduction: Literal['mean', 'max', 'sum', 'full'] = 'mean', return_beam: bool = False, **kwargs: Any) -> dict[str, Any]

Decoding predictions from a diffusion model by forward sampling.

PARAMETER DESCRIPTION
spectra

A batch of spectra to be decoded.

TYPE: Float[Spectrum, ' batch']

spectra_padding_mask

Padding mask for a batch of variable length spectra.

TYPE: Bool[SpectrumMask, ' batch']

precursors

Precursor mass, charge and m/z for a batch of spectra.

TYPE: Float[PrecursorFeatures, ' batch']

initial_sequence

An initial sequence for the model to refine. If no initial sequence is provided (the value is None), will sample a random sequence from a uniform unigram model. Defaults to None.

TYPE: Optional[Integer[Peptide, ' batch']] DEFAULT: None

start_step

The step at which to insert the initial sequence and start refinement. If initial_sequence is not provided, this will be set to time_steps - 1.

TYPE: int DEFAULT: DIFFUSION_START_STEP

eval_steps

The steps at which to evaluate the loss and compute the log-probabilities.

TYPE: tuple[int, ...] DEFAULT: DIFFUSION_EVAL_STEPS

return_encoder_output

Whether to return the encoder output.

TYPE: bool DEFAULT: False

encoder_output_reduction

The reduction to apply to the encoder output. Valid values are "mean", "max", "sum", "full". Defaults to "mean".

TYPE: Literal['mean', 'max', 'sum', 'full'] DEFAULT: 'mean'

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: The decoded peptides and their log-probabilities for a batch of spectra. Required keys: - "predictions": list[list[str]] - "prediction_log_probability": list[float] - "prediction_token_log_probabilities": list[list[float]] - "encoder_output": list[float] (optional) Example additional keys: - "prediction_beam_0": list[str]