anushka Singh
anushka Singh

Reputation: 1

Saving pytorch model as checkpoint is giving very bad results after few days

Problem: Loading a saved PyTorch model after few days giving very bad results.

Hamming score suddenly dropped from 75% to 0.1% and flat score dropped from 65% to 0.3%.

torch.save(model, 'models/model_0.pth')
model = torch.load('models/model_0.pth')


class DistilBERTClass(torch.nn.Module):
    def __init__(self):
        super(DistilBERTClass, self).__init__()
        self.l1 = DistilBertModel.from_pretrained("distilbert-base-uncased")
         
        # Unfreeze all layers except the last layer
        for name, param in self.l1.named_parameters():
            param.requires_grad = True
             
        self.pre_classifier = torch.nn.Linear(768, 768)
        self.dropout = torch.nn.Dropout(0.1)
        self.classifier = torch.nn.Linear(768, 26)

    def forward(self, input_ids, attention_mask, token_type_ids):
        output_1 = self.l1(input_ids=input_ids, attention_mask=attention_mask)
        hidden_state = output_1[0]
        pooler = torch.mean(hidden_state, dim=1)
        pooler = self.pre_classifier(pooler)  
        pooler = torch.nn.Tanh()(pooler)
        pooler = self.dropout(pooler)
        output = self.classifier(pooler) 
        output = F.sigmoid(output)
        return output
model = DistilBERTClass()
model.to(device)

Upvotes: 0

Views: 45

Answers (0)

Related Questions