matcha.torch.encoders.rnn

Recurrent Neural Network (RNN) encoder for chemical language representations.

Classes

RNN

Recurrent Neural Network (RNN) encoder for modelling chemical language

Module Contents

class matcha.torch.encoders.rnn.RNN(num_layers: int, num_characters: int, embedding_dim: int, rnn_type: str, hidden_dim: int, bidirectional: str, num_heads: int, dropout: float)[source]

Bases: matcha.torch.encoders.base_encoder.BaseEncoder, lightning.pytorch.core.mixins.HyperparametersMixin

Recurrent Neural Network (RNN) encoder for modelling chemical language representations. After processing the input sequence, self attention is used to compute a global representation of the molecule by making the [cls] token attend to each other position in the string. It inherits from lightning.pytorch.core.mixins to save its hyperparameters, and from BaseEncoder to be consistent with other encoders. It is intended to be used inside a matcha.torch.models.classic.base_classic_model.BaseClassicModel instance. References: - https://arxiv.org/abs/2407.12152 - https://www.sciencedirect.com/science/article/pii/S2667318521000143

It is intended to be used inside a BaseClassicModel instance. Check the docs of matcha.torch.models.classic.RNNModel for further details.

Parameters:
  • num_layers (int) – number of RNN layers

  • num_characters (int) – total number of unique tokens in the dataset’s dictionary

  • embedding_dim (int) – number of token embedding features

  • rnn_type (str) – whether to use LSTM or GRU architectures

  • hidden_dim (int) – number of hidden token dimensionality

  • bidirectional (str) – whether to concatenate representation obtained while running RNN in reverse on the string

  • num_heads (int) – number of self attention heads, must divide hidden_dims evenly

  • dropout (float) – dropout noise level

embedding
rnn
layers
attention
norm_in
norm_out
forward(token_ids: list[list[int]]) torch.Tensor[source]

Converts a nested list of integers objects into a (x, self.fp_dim) tensor for further processing.

Parameters:

token_ids (list[list[int]]) – batched input from the dataloader

Return torch.Tensor:

learned representation