Skip to content

Fine-Tuning Heads

helical.models.base_models.ClassificationHead

Bases: HelicalBaseFineTuningHead

Classification Head for fine-tuning a Helical foundation model.

Parameters:

Name Type Description Default
num_classes int

The number of classes to predict.

required
dropout float

The dropout rate to apply to the input tensor before the linear layer.

0.02

Methods:

Name Description
forward

The forward method of the classification head.

Source code in helical/models/fine_tune/fine_tuning_heads.py
class ClassificationHead(HelicalBaseFineTuningHead):
    """Classification Head for fine-tuning a Helical foundation model.

    Parameters
    ----------
    num_classes : int
        The number of classes to predict.
    dropout : float, optional, default=0.02
        The dropout rate to apply to the input tensor before the linear layer.

    Methods
    -------
    forward(inputs: torch.Tensor) -> torch.Tensor
        The forward method of the classification head.

    """

    def __init__(self, num_classes: int, dropout: float = 0.02):
        super().__init__()
        self.output_size = num_classes
        self.dropout = torch.nn.Dropout(p=dropout)

    def forward(self, inputs: torch.Tensor) -> torch.Tensor:
        """Forward method of the classification head.

        Parameters
        ----------
        inputs : torch.Tensor
            The input tensor to the classification head.

        Returns
        -------
        torch.Tensor
            The output tensor of the classification head.
        """
        drop = self.dropout(inputs)
        output = self.linear(drop)
        return output

    def set_dim_size(self, dim_size: int) -> None:
        """Set the dimension size of the input tensor.

        Parameters
        ----------
        dim_size : int
            The dimension size of the input tensor.
        """
        self.linear = torch.nn.Linear(dim_size, self.output_size)

forward(inputs)

Forward method of the classification head.

Parameters:

Name Type Description Default
inputs Tensor

The input tensor to the classification head.

required

Returns:

Type Description
Tensor

The output tensor of the classification head.

Source code in helical/models/fine_tune/fine_tuning_heads.py
def forward(self, inputs: torch.Tensor) -> torch.Tensor:
    """Forward method of the classification head.

    Parameters
    ----------
    inputs : torch.Tensor
        The input tensor to the classification head.

    Returns
    -------
    torch.Tensor
        The output tensor of the classification head.
    """
    drop = self.dropout(inputs)
    output = self.linear(drop)
    return output

set_dim_size(dim_size)

Set the dimension size of the input tensor.

Parameters:

Name Type Description Default
dim_size int

The dimension size of the input tensor.

required
Source code in helical/models/fine_tune/fine_tuning_heads.py
def set_dim_size(self, dim_size: int) -> None:
    """Set the dimension size of the input tensor.

    Parameters
    ----------
    dim_size : int
        The dimension size of the input tensor.
    """
    self.linear = torch.nn.Linear(dim_size, self.output_size)

helical.models.base_models.RegressionHead

Bases: HelicalBaseFineTuningHead

Regression Head for fine-tuning a Helical foundation model.

Parameters:

Name Type Description Default
num_outputs int

The number of outputs to predict.

required
dropout float

The dropout rate to apply to the input tensor before the linear layer.

0.02

Methods:

Name Description
forward

The forward method of the regression head.

Source code in helical/models/fine_tune/fine_tuning_heads.py
class RegressionHead(HelicalBaseFineTuningHead):
    """Regression Head for fine-tuning a Helical foundation model.

    Parameters
    ----------
    num_outputs : int
        The number of outputs to predict.
    dropout : float, optional, default=0.02
        The dropout rate to apply to the input tensor before the linear layer.

    Methods
    -------
    forward(inputs: torch.Tensor) -> torch.Tensor
        The forward method of the regression head.

    """

    def __init__(self, num_outputs: int, dropout: float = 0.02):
        super().__init__()
        self.output_size = num_outputs
        self.dropout = torch.nn.Dropout(p=dropout)

    def forward(self, inputs: torch.Tensor) -> torch.Tensor:
        """Forward method of the classification head.

        Parameters
        ----------
        inputs : torch.Tensor
            The input tensor to the regression head.

        Returns
        -------
        torch.Tensor
            The output tensor of the regression head.
        """
        drop = self.dropout(inputs)
        output = self.linear(drop)
        return output

    def set_dim_size(self, dim_size: int) -> None:
        """Set the dimension size of the input tensor.

        Parameters
        ----------
        dim_size : int
            The dimension size of the input tensor.
        """
        self.linear = torch.nn.Linear(dim_size, self.output_size)

forward(inputs)

Forward method of the classification head.

Parameters:

Name Type Description Default
inputs Tensor

The input tensor to the regression head.

required

Returns:

Type Description
Tensor

The output tensor of the regression head.

Source code in helical/models/fine_tune/fine_tuning_heads.py
def forward(self, inputs: torch.Tensor) -> torch.Tensor:
    """Forward method of the classification head.

    Parameters
    ----------
    inputs : torch.Tensor
        The input tensor to the regression head.

    Returns
    -------
    torch.Tensor
        The output tensor of the regression head.
    """
    drop = self.dropout(inputs)
    output = self.linear(drop)
    return output

set_dim_size(dim_size)

Set the dimension size of the input tensor.

Parameters:

Name Type Description Default
dim_size int

The dimension size of the input tensor.

required
Source code in helical/models/fine_tune/fine_tuning_heads.py
def set_dim_size(self, dim_size: int) -> None:
    """Set the dimension size of the input tensor.

    Parameters
    ----------
    dim_size : int
        The dimension size of the input tensor.
    """
    self.linear = torch.nn.Linear(dim_size, self.output_size)