[go: nahoru, domu]

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

closing file object in read_data() function for word2vec tutorials #1522

Closed
ronrest opened this issue Mar 16, 2016 · 0 comments
Closed

closing file object in read_data() function for word2vec tutorials #1522

ronrest opened this issue Mar 16, 2016 · 0 comments

Comments

@ronrest
Copy link
Contributor
ronrest commented Mar 16, 2016

The read_data() function that appears in the following files:

  • tensorflow/tensorflow/examples/tutorials/word2vec/word2vec_basic.py
  • tensorflow/tensorflow/examples/udacity/5_word2vec.ipynb

Look like this:

def read_data(filename):
  f = zipfile.ZipFile(filename)
  for name in f.namelist():
    return f.read(name).split()
  f.close()
def read_data(filename):
  f = zipfile.ZipFile(filename)
  for name in f.namelist():
    return tf.compat.as_str(f.read(name)).split()
  f.close()

There are two problems that these two versions of the function share:

  1. The for loop is redundant since the return statement exits the loop (and the function) with the first file in the loop. Also, there is only one file within the zip file anyway.
  2. Since the return statement exits the function early, it never executes the f.close() line. Therefore it doesn't get to close the file object properly.

I propose something like this instead:

def read_data(filename):
  """Extract the first file enclosed in a zip file as a list of words"""
  with zipfile.ZipFile(filename) as f:
    data = f.read(f.namelist()[0]).split()
  return data
def read_data(filename):
  """Extract the first file enclosed in a zip file as a list of words"""
  with zipfile.ZipFile(filename) as f:
    data = tf.compat.as_str(f.read(f.namelist()[0])).split()
  return data

I will submit a pull request with the proposed changes.

@vrv vrv closed this as completed in d0a3000 Mar 18, 2016
vrv pushed a commit that referenced this issue Mar 18, 2016
fixes #1522 close file object properly for read_data()
nikste pushed a commit to nikste/tensorflow that referenced this issue Mar 18, 2016
fsx950223 pushed a commit to fsx950223/tensorflow that referenced this issue Nov 28, 2023
…t_1024_workgroup_size_for_mlir_kernels

 Setting the amdgpu-flat-work-group-size attribute to 1024 for MLIR generated kernels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant