(config: PretrainedConfig, backbone: nn.Module, push_backbone_only: bool = False)
Using LiqFitBackbone class
If you want to customize your backbone model, you wrap your model inside LiqFitBackbone
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