def convert_embeddings(out_path, embeddings_path): with open(embeddings_path, "rb") as f: embeddings = np.load(f) embeddings_tensor = tf.convert_to_tensor(embeddings) writer = tf.compat.v2.summary.create_file_writer(out_path) with writer.as_default(): summary.npmi_embeddings(embeddings_tensor, 1) writer.close()
def generate_testdata(self): run_names = ["run_1", "run_2"] ground_truth = { "run_1": [ ["Description", "A", "B"], ["name_1", 1.0, -1.0], ["name_2", -0.5, 0.5], ], "run_2": [ ["Description", "A", "B"], ["name_1", 1.0, -1.0], ["name_2", -0.5, np.nan], ], } embedding_ground_truth = { "run_1": [[1.0, 0.5], [-0.5, 0.5]], "run_2": [[1.0, 0.5], [-0.5, 0.5]], } for run_name in run_names: subdir = os.path.join(self.logdir, run_name) writer = tf.compat.v2.summary.create_file_writer(subdir) data = ground_truth[run_name] python_result = [] python_annotations = [] python_classes = [] for row_index, row in enumerate(data): if row_index > 0: python_result.append([]) for col_index, column in enumerate(row): if row_index == 0: if col_index > 0: python_classes.append(column) else: if col_index == 0: python_annotations.append(column) else: python_result[len(python_result) - 1].append(column) with writer.as_default(): tensor_result = tf.convert_to_tensor(python_result) tensor_annotations = tf.convert_to_tensor(python_annotations) tensor_classes = tf.convert_to_tensor(python_classes) tensor_embeddings = tf.convert_to_tensor( embedding_ground_truth[run_name]) summary.npmi_values(tensor_result, 1) summary.npmi_annotations(tensor_annotations, 1) summary.npmi_metrics(tensor_classes, 1) summary.npmi_embeddings(tensor_embeddings, 1) writer.close()