MCPcopy Create free account
hub / github.com/LUMIA-Group/MemoryDecoder / knns_to_probs

Method knns_to_probs

knn_utils/saveEmbedMulti.py:188–195  ·  view source on GitHub ↗
(self, knns, neg_dists)

Source from the content-addressed store, hash-verified

186 return output
187
188 def knns_to_probs(self, knns, neg_dists):
189 probs = torch.nn.functional.softmax(neg_dists / self.knn_temperature, dim=-1).to(torch.float32)
190 vals_at_knns = self.vals[knns].squeeze(-1).to(probs.device) # (nonpad batch * time, k)
191 knn_probs = torch.full(size=(vals_at_knns.shape[:-1] + (self.vocab_size,)), fill_value=0.0).to(self.device) \
192 .scatter_add(dim=-1, index=vals_at_knns, src=probs) # (nonpad_batch * time, vocab)
193 knn_probs = F.normalize(knn_probs, p=1, dim=-1)
194
195 return knn_probs
196
197 def knns_to_log_prob(self, knns, neg_dists):
198 probs = torch.nn.functional.softmax(neg_dists / self.knn_temperature, dim=-1)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected