Skip to content

Commit

Permalink
fix logits2weights if word_logits is empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
aviad-has committed Sep 28, 2023
1 parent 162b821 commit c519b2a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions splade4elastic/elastic_splade.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,17 @@ def transform(self, X: List[str]):

class LinearMLMRewriter(MLMBaseRewriter):
def logits2weights(self, word_logits):
if len(word_logits) == 0:
return word_logits # empty list
min_score = min(w[1] for w in word_logits)
ret = [(w[0], w[1] - min_score) for w in word_logits]
norm_factor = sum(w[1] for w in ret)
ret = [(w[0], w[1]/norm_factor) for w in ret]
return ret
class SpladeRewriter(MLMBaseRewriter):
def logits2weights(self, word_logits):
if len(word_logits) == 0:
return word_logits # empty list
ret = [(w[0], np.exp(w[1])) for w in word_logits]
norm_factor = sum(w[1] for w in ret)
ret = [(w[0], w[1]/norm_factor) for w in ret]
Expand Down

0 comments on commit c519b2a

Please sign in to comment.