Skip to content

Commit

Permalink
Fixes index_edge2vec_embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
JSybrandt committed May 22, 2020
1 parent 6b731ee commit 82b8588
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
from pathlib import Path
from fire import Fire
import pickle
from typing import Iterable, List
from typing import Iterable, List, Tuple
from tqdm import tqdm


def iterate_vectors(vector_text_path:Path)->Iterable[str, List[float]]:
def iterate_vectors(vector_text_path:Path)->Iterable[Tuple[str, List[float]]]:
assert vector_text_path.is_file()
num_vectors = None
expected_dim = None
Expand All @@ -34,7 +35,7 @@ def iterate_vectors(vector_text_path:Path)->Iterable[str, List[float]]:
num_vectors, expected_dim = [int(t) for t in tokens]
if expected_dim is not None and len(tokens) == expected_dim + 1:
idx = int(tokens[0])
vec = [float(t) for t in tokens]
vec = [float(t) for t in tokens[1:]]
yield idx, vec


Expand All @@ -52,7 +53,7 @@ def main(
# Need an empty output dir
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
assert len(list(output_dir.listdir())) == 0
assert len(list(output_dir.iterdir())) == 0

with open(input_index_path, 'rb') as pkl_file:
node2idx = pickle.load(pkl_file)["node2idx"]
Expand All @@ -62,7 +63,7 @@ def main(
node2vec = {
idx2node[idx]: vec
for idx, vec
in iterate_vectors(input_vector_text_path)
in tqdm(iterate_vectors(input_vector_text_path))
}
setup_embedding_lookup_data(
node2vec,
Expand Down

0 comments on commit 82b8588

Please sign in to comment.