Skip to content

Commit

Permalink
intercepter fix + heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJDen committed Oct 18, 2023
1 parent 5d02b3d commit 9781ea9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions decryptoai/decryptoai/players/unsupervised/naive_heuristics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np

def cosine_similarity(embedding, clue_index, keyword_index):
clue_embedding = embedding[clue_index.squeeze()].transpose()
keyword_embedding = embedding[keyword_index.squeeze()]
return np.expand_dims(keyword_embedding.dot(clue_embedding), axis=-1)

# simple heuristics

def log_square_cosine_similarity(embedding, clue_index, keyword_index):
similarity = cosine_similarity(embedding, clue_index, keyword_index)
return 2 * np.log(np.abs(similarity))

def log_normalized_cosine_similarity(embedding, clue_index, keyword_index):
similarity = cosine_similarity(embedding, clue_index, keyword_index)
normalized_similiarity = (1 + similarity) / 2
return np.log(normalized_similiarity)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
import numpy_guesser as npg
import decryptoai.players.unsupervised.numpy_guesser as npg
from functools import partial
# shape-preserving normalization

Expand Down

0 comments on commit 9781ea9

Please sign in to comment.