Commit f95efc57 authored by  Andrei  Serbanescu's avatar Andrei Serbanescu

add comments in utils

parent d4383c88
......@@ -2,6 +2,8 @@ import json
import numpy as np
import os
# reads the sentence embeddings saved to a JSON file
# and returns them as a list
def load_sentence_emb(embs_path):
with open(embs_path) as json_file:
......@@ -9,6 +11,9 @@ def load_sentence_emb(embs_path):
data = [np.asarray(sentence) for sentence in data]
return data
# reads a JSON file containing sentence embeddings
# toghether with sentence information (word vectors, POS tags, is stop word)
# and returns it as a dictionary
def load_sentence_with_word_vecs(word_vecs_path):
with open(word_vecs_path) as json_file:
......@@ -21,14 +26,20 @@ def load_sentence_with_word_vecs(word_vecs_path):
return data
# reads and returns source file
# prefix: train, dev or test
def load_src(data_dir, prefix="train"):
return open(os.path.join(data_dir, "{}.ende.src".format(prefix)), "r", encoding='UTF8')
# reads and returns translation
# prefix: train, dev or test
def load_translation(data_dir, prefix="train"):
return open(os.path.join(data_dir, "{}.ende.mt".format(prefix)), "r", encoding='UTF8')
# reads and returns scores
# prefix: train, dev or test
def load_scores(data_dir, prefix="train"):
scores = open(os.path.join(data_dir, "{}.ende.scores".format(prefix)), "r")
scores = list(scores)
......@@ -36,6 +47,4 @@ def load_scores(data_dir, prefix="train"):
for i in range(len(scores)):
scores[i] = float(scores[i])
return scores
\ No newline at end of file
return scores
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment