Update only part of the word embedding matrix in Tensorflow

TL;DR: The default implementation of opt.minimize(loss), TensorFlow will generate a sparse update for word_emb that modifies only the rows of word_emb that participated in the forward pass. The gradient of the tf.gather(word_emb, indices) op with respect to word_emb is a tf.IndexedSlices object (see the implementation for more details). This object represents a sparse tensor that … Read more

Tensorflow get all variables in scope

I think you want tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=”my_scope”). This will get all variables in a scope. To pass to an optimizer you do not want all variables you would just want the trainable variables. Those are also kept in a default collection, which is tf.GraphKeys.TRAINABLE_VARIABLES.

ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory

I downloaded cuda 10.0 from the following link CUDA 10.0 Then I installed it using the following commands: sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb sudo apt-key adv –fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub sudo apt-get update sudo apt-get install cuda-10-0 I then installed cudnn v7.5.0 for CUDA 10.0 by going to link CUDNN download and you need to logon using an … Read more

How do I convert a directory of jpeg images to TFRecords file in tensorflow?

I hope this helps: filename_queue = tf.train.string_input_producer([‘/Users/HANEL/Desktop/tf.png’]) # list of files to read reader = tf.WholeFileReader() key, value = reader.read(filename_queue) my_img = tf.image.decode_png(value) # use decode_png or decode_jpeg decoder based on your files. init_op = tf.initialize_all_variables() with tf.Session() as sess: sess.run(init_op) # Start populating the filename queue. coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) for i … Read more

Simple way to visualize a TensorFlow graph in Jupyter?

Here’s a recipe I copied from one of Alex Mordvintsev deep dream notebook at some point from IPython.display import clear_output, Image, display, HTML import numpy as np def strip_consts(graph_def, max_const_size=32): “””Strip large constant values from graph_def.””” strip_def = tf.GraphDef() for n0 in graph_def.node: n = strip_def.node.add() n.MergeFrom(n0) if n.op == ‘Const’: tensor = n.attr[‘value’].tensor size … Read more

Making predictions with a TensorFlow model

In the “Deep MNIST for Experts” example, see this line: We can now implement our regression model. It only takes one line! We multiply the vectorized input images x by the weight matrix W, add the bias b, and compute the softmax probabilities that are assigned to each class. y = tf.nn.softmax(tf.matmul(x,W) + b) Just … Read more