As I said above, the problem is that the argmax function is not differentiable. You will have to use something else.
You can try to use soft attention where instead of the one hot encoding of the argmax, you use the result of the softmax layer.
But that will depend on your exact problem what will work or not.