Python data_utils.vocab() Examples
The following are 10
code examples of data_utils.vocab().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
data_utils
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: neural_gpu_trainer.py From DOTA_models with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #2
Source File: neural_gpu_trainer.py From yolo_v2 with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #3
Source File: neural_gpu_trainer.py From Gun-Detector with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #4
Source File: neural_gpu_trainer.py From hands-detection with MIT License | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #5
Source File: neural_gpu_trainer.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #6
Source File: neural_gpu_trainer.py From object_detection_with_tensorflow with MIT License | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #7
Source File: neural_gpu_trainer.py From HumanRecognition with MIT License | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #8
Source File: neural_gpu_trainer.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #9
Source File: neural_gpu_trainer.py From models with Apache License 2.0 | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})
Example #10
Source File: neural_gpu_trainer.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def assign_vectors(word_vector_file, embedding_key, vocab_path, sess): """Assign the embedding_key variable from the given word vectors file.""" # For words in the word vector file, set their embedding at start. if not tf.gfile.Exists(word_vector_file): data.print_out("Word vector file does not exist: %s" % word_vector_file) sys.exit(1) vocab, _ = wmt.initialize_vocabulary(vocab_path) vectors_variable = [v for v in tf.trainable_variables() if embedding_key == v.name] if len(vectors_variable) != 1: data.print_out("Word vector variable not found or too many.") sys.exit(1) vectors_variable = vectors_variable[0] vectors = vectors_variable.eval() data.print_out("Pre-setting word vectors from %s" % word_vector_file) with tf.gfile.GFile(word_vector_file, mode="r") as f: # Lines have format: dog 0.045123 -0.61323 0.413667 ... for line in f: line_parts = line.split() # The first part is the word. word = line_parts[0] if word in vocab: # Remaining parts are components of the vector. word_vector = np.array(map(float, line_parts[1:])) if len(word_vector) != FLAGS.vec_size: data.print_out("Warn: Word '%s', Expecting vector size %d, " "found %d" % (word, FLAGS.vec_size, len(word_vector))) else: vectors[vocab[word]] = word_vector # Assign the modified vectors to the vectors_variable in the graph. sess.run([vectors_variable.initializer], {vectors_variable.initializer.inputs[1]: vectors})