def attack(self, epsilon=1e-06, alpha=0.3, emb_name='embed', is_first_attack=False):
    for (name, param) in self.model.named_parameters():
        if (param.requires_grad and (emb_name in name)):
            if is_first_attack:
                self.emb_backup[name] = param.data.clone()
            norm = torch.norm(param.grad)
            if ((norm != 0) and (not torch.isnan(norm))):
                r_at = ((alpha * param.grad) / norm)
                param.data.add_(r_at)
                param.data = self.project(name, param.data, epsilon)
def attack(self, epsilon=1e-06, alpha=0.3, emb_name='embed', is_first_attack=False):
    for (name, param) in self.model.named_parameters():
        if (param.requires_grad and (emb_name in name)):
            if is_first_attack:
                self.emb_backup[name] = param.data.clone()
            norm = torch.norm(param.grad)
            if ((norm != 0) and (not torch.isnan(norm))):
                r_at = ((alpha * param.grad) / norm)
                param.data.add_(r_at)
                param.data = self.project(name, param.data, epsilon)