I’m implementing a binary mask at the input level of a logistic regression. This is how I defined it:
new_mask = torch.ones(1, input_dim)

class DropFeatures(nn.Module):
    def __init__(self, input_dim, *kargs, **kwargs):
        super(DropFeatures, self).__init__()
        self.weights = new_mask
        
    def forward(self, x):
        return (x * self.weights)
    
class drop_logit(nn.Module):
    def __init__(self, input_dim, output_dim):
        super(drop_logit, self).__init__()
        self.drop = DropFeatures(input_dim)
        self.fc1 = nn.Linear(input_dim, 1)
        self.fc2 = nn.Sigmoid()
          
    def forward(self, x):
        x = self.drop(x)
        x = self.fc1(x)
        x = self.fc2(x)
        return x
    
model = drop_logit(input_dim = 69, output_dim = 1)

Now I would like to be able to modify the new_mask dynamically inside the training loop to make the model more parsimonious overtime.
But it is not clear to me how I could achieve that.