Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model not in eval mode for baselines #8

Open
josephenguehard opened this issue Sep 15, 2022 · 0 comments
Open

Model not in eval mode for baselines #8

josephenguehard opened this issue Sep 15, 2022 · 0 comments

Comments

@josephenguehard
Copy link

Hi,

There seems to be an error when computing the baselines for the state and mimic experiments: the model is not set in eval mode, which affects the results (probably due to the 0.5 dropout). For instance, on the state experiment using deep_lift, AUP improves from around 0.57 to around 0.94, and AUR from 0.17 to 0.35.

The line self.base_model.eval() should be added in the file fit.TSX.explainers for all the baselines. For instance:

class DeepLiftExplainer:
    def __init__(self, model, activation=torch.nn.Softmax(-1)):
        self.device = "cuda" if torch.cuda.is_available() else "cpu"
        self.base_model = model.to(self.device)
        self.explainer = DeepLift(self.base_model)
        self.activation = activation

    def attribute(self, x, y, retrospective=False):
        self.base_model.zero_grad()
        self.base_model.eval()  # Missing line
        if retrospective:
            score = self.explainer.attribute(x, target=y.long(), baselines=(x * 0))
            score = abs(score.detach().cpu().numpy())
        else:
            score = np.zeros(x.shape)
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant