From 031e47f5b31ac0377e557a7fd827b5fe1b228842 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Sat, 2 Mar 2024 18:52:40 -0500 Subject: [PATCH 1/3] Change matrix to array to normalize --- convokit/expected_context_framework/expected_context_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convokit/expected_context_framework/expected_context_model.py b/convokit/expected_context_framework/expected_context_model.py index 817dff6a..36abd73f 100644 --- a/convokit/expected_context_framework/expected_context_model.py +++ b/convokit/expected_context_framework/expected_context_model.py @@ -594,7 +594,7 @@ def transform(self, utt_vects): return self._snip(utt_vects * self.term_reprs_full / self.context_s, self.snip_first_dim) def compute_utt_ranges(self, utt_vects): - return np.dot(normalize(utt_vects, norm="l1"), self.term_ranges) + return np.dot(normalize(np.array(utt_vects), norm="l1"), self.term_ranges) def transform_context_utts(self, context_utt_vects): return self._snip(context_utt_vects * self.context_V / self.context_s, self.snip_first_dim) @@ -761,7 +761,7 @@ def _get_default_ids(self, ids, n): def _snip(self, vects, snip_first_dim=True, dim=None): if dim is None: dim = vects.shape[1] - return normalize(vects[:, int(snip_first_dim) : dim]) + return normalize(np.array(vects[:, int(snip_first_dim) : dim])) class ClusterWrapper: From a64b394a1b0e8ee4be2c2b6b643066de541ea871 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Sat, 2 Mar 2024 18:59:10 -0500 Subject: [PATCH 2/3] Set allow pickle true for expected context files --- .../expected_context_model.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/convokit/expected_context_framework/expected_context_model.py b/convokit/expected_context_framework/expected_context_model.py index 36abd73f..9e7061ff 100644 --- a/convokit/expected_context_framework/expected_context_model.py +++ b/convokit/expected_context_framework/expected_context_model.py @@ -698,17 +698,17 @@ def load(self, dirname): self.snip_first_dim = meta_dict["snip_first_dim"] self.cluster_on = meta_dict["cluster_on"] - self.context_U = np.load(os.path.join(dirname, "context_U.npy")) + self.context_U = np.load(os.path.join(dirname, "context_U.npy"), allow_pickle=True) self.train_context_reprs = self._snip(self.context_U, self.snip_first_dim) - self.context_V = np.load(os.path.join(dirname, "context_V.npy")) + self.context_V = np.load(os.path.join(dirname, "context_V.npy"), allow_pickle=True) self.context_term_reprs = self._snip(self.context_V, self.snip_first_dim) - self.context_s = np.load(os.path.join(dirname, "context_s.npy")) - self.context_terms = np.load(os.path.join(dirname, "context_terms.npy")) - self.terms = np.load(os.path.join(dirname, "terms.npy")) - self.term_reprs_full = np.matrix(np.load(os.path.join(dirname, "term_reprs.npy"))) + self.context_s = np.load(os.path.join(dirname, "context_s.npy"), allow_pickle=True) + self.context_terms = np.load(os.path.join(dirname, "context_terms.npy"), allow_pickle=True) + self.terms = np.load(os.path.join(dirname, "terms.npy"), allow_pickle=True) + self.term_reprs_full = np.matrix(np.load(os.path.join(dirname, "term_reprs.npy"), allow_pickle=True)) self.term_reprs = self._snip(self.term_reprs_full, self.snip_first_dim) - self.term_ranges = np.load(os.path.join(dirname, "term_ranges.npy")) - self.train_utt_reprs = np.load(os.path.join(dirname, "train_utt_reprs.npy")) + self.term_ranges = np.load(os.path.join(dirname, "term_ranges.npy"), allow_pickle=True) + self.train_utt_reprs = np.load(os.path.join(dirname, "train_utt_reprs.npy"), allow_pickle=True) try: km_obj = ClusterWrapper(self.n_clusters) @@ -818,7 +818,7 @@ def load(self, dirname): self.random_state = meta_dict["random_state"] self.km_df = pd.read_csv(os.path.join(dirname, "cluster_km_df.tsv"), sep="\t", index_col=0) - self.cluster_names = np.load(os.path.join(dirname, "cluster_names.npy")) + self.cluster_names = np.load(os.path.join(dirname, "cluster_names.npy"), allow_pickle=True) self.km_model = joblib.load(os.path.join(dirname, "km_model.joblib")) def dump(self, dirname): From c1678215696d6824985c117b1fc931f527b9385a Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Sat, 2 Mar 2024 19:27:03 -0500 Subject: [PATCH 3/3] Reformat --- .../expected_context_framework/expected_context_model.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/convokit/expected_context_framework/expected_context_model.py b/convokit/expected_context_framework/expected_context_model.py index 9e7061ff..2b23ea78 100644 --- a/convokit/expected_context_framework/expected_context_model.py +++ b/convokit/expected_context_framework/expected_context_model.py @@ -705,10 +705,14 @@ def load(self, dirname): self.context_s = np.load(os.path.join(dirname, "context_s.npy"), allow_pickle=True) self.context_terms = np.load(os.path.join(dirname, "context_terms.npy"), allow_pickle=True) self.terms = np.load(os.path.join(dirname, "terms.npy"), allow_pickle=True) - self.term_reprs_full = np.matrix(np.load(os.path.join(dirname, "term_reprs.npy"), allow_pickle=True)) + self.term_reprs_full = np.matrix( + np.load(os.path.join(dirname, "term_reprs.npy"), allow_pickle=True) + ) self.term_reprs = self._snip(self.term_reprs_full, self.snip_first_dim) self.term_ranges = np.load(os.path.join(dirname, "term_ranges.npy"), allow_pickle=True) - self.train_utt_reprs = np.load(os.path.join(dirname, "train_utt_reprs.npy"), allow_pickle=True) + self.train_utt_reprs = np.load( + os.path.join(dirname, "train_utt_reprs.npy"), allow_pickle=True + ) try: km_obj = ClusterWrapper(self.n_clusters)