In Tensorflow, I have a float tensor T with shape [batch_size, 3]. For example, T[0] = [4, 4, 3]
.
I want to turn that into a size 5 one hot in order to yield entries from an embedding dictionary. In the above case, that would look like
T[0] = [[0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 1, 0]].
If I can get it into this format, then I can multiply it by the embedding dictionary. However, this is in the middle of the graph and I need the gradients to flow through it. Is there a clever way to use stop_gradient a la How Can I Define Only the Gradient for a Tensorflow Subgraph? to make this work? I'm coming up short.