Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File IO modes modified to include UTF-8 format files #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions g2p_seq2seq/g2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def decode(self, output_file_path):
# If path to the output file pointed out, dump decoding results to the file
if output_file_path:
tf.logging.info("Writing decodes into %s" % output_file_path)
outfile = tf.gfile.Open(output_file_path, "w")
outfile = tf.gfile.Open(output_file_path, "wb")

inputs, decodes = self.__decode_from_file(self.test_path, outfile)

Expand Down Expand Up @@ -542,7 +542,7 @@ def _get_inputs(filename, delimiters="\t "):
delimiters_regex = re.compile("[" + delimiters + "]+")

inputs = []
with tf.gfile.Open(filename) as input_file:
with tf.gfile.Open(filename, "rb") as input_file:
lines = input_file.readlines()
for line in lines:
if set("[" + delimiters + "]+$").intersection(line):
Expand Down
4 changes: 2 additions & 2 deletions g2p_seq2seq/g2p_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _init_vocab_from_file(self, filename):
"""
def sym_gen():
"""Symbols generator for vocab initializer from file."""
with tf.gfile.Open(filename) as vocab_file:
with tf.gfile.Open(filename, "rb") as vocab_file:
for line in vocab_file:
sym = line.strip()
yield sym
Expand Down Expand Up @@ -144,7 +144,7 @@ def store_to_file(self, filename):
Args:
filename: Full path of the file to store the vocab to.
"""
with tf.gfile.Open(filename, "w") as vocab_file:
with tf.gfile.Open(filename, "wb") as vocab_file:
for i in range(len(self._id_to_sym)):
vocab_file.write(self._id_to_sym[i] + "\n")

Expand Down
2 changes: 1 addition & 1 deletion g2p_seq2seq/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, model_dir, data_path, flags=None):
self.iterations_per_loop = min(1000, max(10, int(self.batch_size/10)))
if flags.max_epochs > 0:
self.train_steps = max(10000,
int(len(open(data_path).readlines()) /\
int(len(open(data_path, encoding="utf-8").readlines()) /\
self.batch_size) *\
self.iterations_per_loop *\
flags.max_epochs)
Expand Down