LiqFitBackbone

classliqfit.modeling.LiqFitBackbone

(config: PretrainedConfig, backbone: nn.Module, push_backbone_only: bool = False)

Parameters:

  • config (PretrainedConfig): Backbone configuration.

  • backbone (nn.Module): Pretrained model (backbone).

  • push_backbone_only (bool, optional): Whether to push the wrapped model or only push the backbone model to Hugging Face.

Using LiqFitBackbone class

If you want to customize your backbone model, you wrap your model inside LiqFitBackbone

Example:

from liqfit.modeling import LiqFitBackbone
from transformers import AutoModel

class MyBackboneModel(LiqFitBackbone):
    def __init__(self):
        backbone_model = AutoModel.from_pretrained(...)
        super.__init__(backbone_model.config, backbone_model)
    
    def encode(self, input_ids, attention_mask):
        output = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
        last_hidden_state = output[0]
        return last_hidden_state

# If you want to add your own pooling layer.
from liqfit.modeling.pooling import FirstTokenPooling1D

class MyBackboneModel(LiqFitBackbone):
    def __init__(self):
        backbone_model = AutoModel.from_pretrained(...)
        super.__init__(backbone_model.config, backbone_model)
        self.first_token_pooling = FirstTokenPooling1D()

    def encode(self, input_ids, attention_mask):
        output = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
        last_hidden_state = output[0]
        pooled_output = self.first_token_pooling(last_hidden_state)
        return pooled_output     

Last updated