Skip to content

Commit

Permalink
switch to torch.concat and torch.unique instead of list.append and set()
Browse files Browse the repository at this point in the history
  • Loading branch information
gumityolcu committed Jun 3, 2024
1 parent 8ac2df0 commit 670f3b8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/metrics/unnamed/top_k_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def __init__(
):
super().__init__(model, train_dataset, *args, **kwargs)
self.top_k = top_k
self.all_top_k_examples = []
self.all_top_k_examples = torch.empty(0,top_k)

def update(
self,
explanations: torch.Tensor,
**kwargs,
):
top_k_indices = torch.topk(explanations, self.top_k).indices
self.all_top_k_examples.append(top_k_indices)
self.all_top_k_examples=torch.concat((self.all_top_k_examples,top_k_indices), dim=0)

def compute(self, *args, **kwargs):
return len(set(self.all_top_k_examples))
return len(torch.unique(self.all_top_k_examples))

def reset(self, *args, **kwargs):
self.all_top_k_examples = []
Expand Down

0 comments on commit 670f3b8

Please sign in to comment.