I'm using a neural network to analyze item choices made by players in a computer game. In the game players can choose between 0 and 7 items. Right now I'm struggling with how I can evaluate my data.

Tensorflow provides a nice method for getting the k highest values.

tf.nn.top_k(input, k=1, sorted=True, name=None)

The input here would be the prediction by my neural network. The output I get by applying top_k to the prediction would then be compared to applying top_k to the correct_output (the one the neural net should have had) and by doing this multiple times and averaging I get the accuracy that I want to have. The problem I'm running into is that k should depend on the amount of 1's in the correct_output. I am lost as to how I can achieve this.

edit: correct output (if I understand how this works correctly) should already be a tensor. It is loaded from a .pickle file and at the beginning of the code it is prepared as follows: correct_output = tf.placeholder('float')

As to what it looks like: it is simply a list of given length of 1's and 0's

  • $\begingroup$ Is correct_output already a tensor (you should be feeding it in to your graph as a tf.placeholder)? Can you include its definition? $\endgroup$ Sep 25, 2016 at 8:17
  • $\begingroup$ @NeilSlater: thanks for your reply, sorry for my late one, I was abroad. I have edited my post, is this what you meant, or is more clarification needed? I could post the whole code, though that is only half finished and might be confusing as it is still filled with bugs. $\endgroup$
    – Hasse Iona
    Oct 1, 2016 at 12:29
  • $\begingroup$ Yes that is what I meant. Ideally you would have something like correct_output = tf.placeholder('float', shape=(None,7)) - setting the shape just protects you a little from some kinds of errors in processing (the processing will fail with a meaningful error if you try to train against incorrect data). I'm pretty sure there is a standard loss function to use in your situation, I'll try to look it up later this weekend and write an answer if no-one else has done by then . . . $\endgroup$ Oct 1, 2016 at 13:17
  • $\begingroup$ Thanks, I'll make sure to change that :) If I understand a loss function is used for training the network, not testing it, right? Because the problem I'm running into here is that I want to test my network. Does that mean the loss function will also have to be different for outputs with a variable amount of 1's in them? Maybe good to clarify that the output list always has a set length, but the amount of 1's in there is what varies. Sorry for being such a bother! $\endgroup$
    – Hasse Iona
    Oct 4, 2016 at 19:55


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.