commit 1e6e244f0400af38515a26df6b321ae32f44cb0b
parent d5509b1a6efa4fd84eef40c2b61a19fd46eab8a1
Author: Sondre Wold <sondrewold1@gmail.com>
Date: Sat, 12 Jul 2025 20:19:37 +0200
add plot script
Diffstat:
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/experiment.py b/experiment.py
@@ -131,10 +131,10 @@ def find_diff(a: str, b: str) -> list[str] | None:
break
diff_a = words_a[
- prefix_len:len(words_a) - suffix_len if suffix_len > 0 else len(words_a)
+ prefix_len : len(words_a) - suffix_len if suffix_len > 0 else len(words_a)
]
diff_b = words_b[
- prefix_len:len(words_b) - suffix_len if suffix_len > 0 else len(words_b)
+ prefix_len : len(words_b) - suffix_len if suffix_len > 0 else len(words_b)
]
if not diff_a or not diff_b:
diff --git a/load_and_plot.py b/load_and_plot.py
@@ -0,0 +1,38 @@
+import sys
+import pickle
+import numpy
+from torch import histogram
+from experiment import Point
+import matplotlib.pyplot as plt
+
+if __name__ == "__main__":
+ points_path: str = sys.argv[1]
+ with open(points_path, "rb") as file:
+ points: list[Point] = pickle.load(file)
+ n: int = len(points)
+ word_sims: numpy.ndarray = numpy.array([point.phrase_similarity for point in points])
+ context_sims: numpy.ndarray = numpy.array(
+ [point.contextualized_similarity for point in points]
+ )
+
+ epsilons: list[float] = []
+ for i in range(len(word_sims)):
+ if word_sims[i] > 0:
+ epsilons.append(1 - context_sims[i] / word_sims[i])
+ final_epsilon: float = float(numpy.percentile(epsilons, 80))
+
+ plt.scatter((1 - final_epsilon) * word_sims, context_sims)
+ xpoints = ypoints = plt.xlim()
+ plt.plot(
+ xpoints,
+ ypoints,
+ linestyle="--",
+ color="k",
+ lw=3,
+ scalex=False,
+ scaley=False,
+ )
+
+ plt.xlabel("Word similarity")
+ plt.ylabel("Contextualized similarity")
+ plt.show()