Last active
August 16, 2019 08:24
-
-
Save goddoe/b7c47b537065e296402f3d2df293413c to your computer and use it in GitHub Desktop.
tsv write and read using csv package.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from collections import namedtuple | |
from ast import literal_eval | |
from os.path import dirname | |
export_path = "path/to/export" | |
# Read & Write using native python | |
# write tsv | |
os.makedirs(dirname(export_path), exist_ok=True) | |
wr = csv.writer(open(export_path, 'wt'), delimiter='\t') | |
for candi in candidate_list: | |
wr.writerow([candi, encoder.get_vector(candi).tolist()]) | |
# read tsv | |
elem = namedtuple('query_space', "query embedding") | |
rdr = csv.reader(open(export_path, 'rt'), delimiter='\t') | |
r = [elem(row[0], literal_eval(row[1])) for row in rdr] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment