How to print out the prediction probabilities in Tensorflow












1















I am new to tf. I have trained an encoder - decoder using tensorflow. The program takes as input a word and prints out its phonemes.



For example: Hello World -> ['h', 'E', 'l', '"', '@U', ' ', 'w', '"', '3`', 'r', '5', 'd']



I would like to have access to the prediction probability of each phoneme chosen.



In the prediction section, the code I am using is the following:



def predict(words, sess):

if len(words) > hp.batch_size:
after = predict(words[hp.batch_size:], sess)
words = words[:hp.batch_size]

else:
after =
x = np.zeros((len(words), hp.maxlen), np.int32) # 0: <PAD>
for i, w in enumerate(words):
for j, g in enumerate((w + "E")[:hp.maxlen]):
x[i][j] = g2idx.get(g, 2)


preds = np.zeros((len(x), hp.maxlen), np.int32)
for j in range(hp.maxlen):

xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
preds[:, j] = xpreds[:, j]


Thank you in advance!



My main problem is where these probabilities are "hidden" and how to access them. For example, the letter "o" in the word "Hello" was mapped with the phoneme "@U". I would like to find out with what probability "@U" was chosen as the ideal phoneme.










share|improve this question

























  • Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

    – Ian Quah
    Nov 21 '18 at 16:13













  • Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

    – Konstantinos Markopoulos
    Nov 21 '18 at 16:27











  • Look at tf.Print or eval stackoverflow questions with answers

    – Ian Quah
    Nov 21 '18 at 16:32











  • Possible duplicate of How to print the value of a Tensor object in TensorFlow?

    – Ian Quah
    Nov 21 '18 at 16:32






  • 1





    The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

    – Konstantinos Markopoulos
    Nov 21 '18 at 19:09


















1















I am new to tf. I have trained an encoder - decoder using tensorflow. The program takes as input a word and prints out its phonemes.



For example: Hello World -> ['h', 'E', 'l', '"', '@U', ' ', 'w', '"', '3`', 'r', '5', 'd']



I would like to have access to the prediction probability of each phoneme chosen.



In the prediction section, the code I am using is the following:



def predict(words, sess):

if len(words) > hp.batch_size:
after = predict(words[hp.batch_size:], sess)
words = words[:hp.batch_size]

else:
after =
x = np.zeros((len(words), hp.maxlen), np.int32) # 0: <PAD>
for i, w in enumerate(words):
for j, g in enumerate((w + "E")[:hp.maxlen]):
x[i][j] = g2idx.get(g, 2)


preds = np.zeros((len(x), hp.maxlen), np.int32)
for j in range(hp.maxlen):

xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
preds[:, j] = xpreds[:, j]


Thank you in advance!



My main problem is where these probabilities are "hidden" and how to access them. For example, the letter "o" in the word "Hello" was mapped with the phoneme "@U". I would like to find out with what probability "@U" was chosen as the ideal phoneme.










share|improve this question

























  • Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

    – Ian Quah
    Nov 21 '18 at 16:13













  • Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

    – Konstantinos Markopoulos
    Nov 21 '18 at 16:27











  • Look at tf.Print or eval stackoverflow questions with answers

    – Ian Quah
    Nov 21 '18 at 16:32











  • Possible duplicate of How to print the value of a Tensor object in TensorFlow?

    – Ian Quah
    Nov 21 '18 at 16:32






  • 1





    The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

    – Konstantinos Markopoulos
    Nov 21 '18 at 19:09
















1












1








1








I am new to tf. I have trained an encoder - decoder using tensorflow. The program takes as input a word and prints out its phonemes.



For example: Hello World -> ['h', 'E', 'l', '"', '@U', ' ', 'w', '"', '3`', 'r', '5', 'd']



I would like to have access to the prediction probability of each phoneme chosen.



In the prediction section, the code I am using is the following:



def predict(words, sess):

if len(words) > hp.batch_size:
after = predict(words[hp.batch_size:], sess)
words = words[:hp.batch_size]

else:
after =
x = np.zeros((len(words), hp.maxlen), np.int32) # 0: <PAD>
for i, w in enumerate(words):
for j, g in enumerate((w + "E")[:hp.maxlen]):
x[i][j] = g2idx.get(g, 2)


preds = np.zeros((len(x), hp.maxlen), np.int32)
for j in range(hp.maxlen):

xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
preds[:, j] = xpreds[:, j]


Thank you in advance!



My main problem is where these probabilities are "hidden" and how to access them. For example, the letter "o" in the word "Hello" was mapped with the phoneme "@U". I would like to find out with what probability "@U" was chosen as the ideal phoneme.










share|improve this question
















I am new to tf. I have trained an encoder - decoder using tensorflow. The program takes as input a word and prints out its phonemes.



For example: Hello World -> ['h', 'E', 'l', '"', '@U', ' ', 'w', '"', '3`', 'r', '5', 'd']



I would like to have access to the prediction probability of each phoneme chosen.



In the prediction section, the code I am using is the following:



def predict(words, sess):

if len(words) > hp.batch_size:
after = predict(words[hp.batch_size:], sess)
words = words[:hp.batch_size]

else:
after =
x = np.zeros((len(words), hp.maxlen), np.int32) # 0: <PAD>
for i, w in enumerate(words):
for j, g in enumerate((w + "E")[:hp.maxlen]):
x[i][j] = g2idx.get(g, 2)


preds = np.zeros((len(x), hp.maxlen), np.int32)
for j in range(hp.maxlen):

xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
preds[:, j] = xpreds[:, j]


Thank you in advance!



My main problem is where these probabilities are "hidden" and how to access them. For example, the letter "o" in the word "Hello" was mapped with the phoneme "@U". I would like to find out with what probability "@U" was chosen as the ideal phoneme.







python tensorflow






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 16:44







Konstantinos Markopoulos

















asked Nov 21 '18 at 16:11









Konstantinos MarkopoulosKonstantinos Markopoulos

185




185













  • Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

    – Ian Quah
    Nov 21 '18 at 16:13













  • Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

    – Konstantinos Markopoulos
    Nov 21 '18 at 16:27











  • Look at tf.Print or eval stackoverflow questions with answers

    – Ian Quah
    Nov 21 '18 at 16:32











  • Possible duplicate of How to print the value of a Tensor object in TensorFlow?

    – Ian Quah
    Nov 21 '18 at 16:32






  • 1





    The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

    – Konstantinos Markopoulos
    Nov 21 '18 at 19:09





















  • Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

    – Ian Quah
    Nov 21 '18 at 16:13













  • Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

    – Konstantinos Markopoulos
    Nov 21 '18 at 16:27











  • Look at tf.Print or eval stackoverflow questions with answers

    – Ian Quah
    Nov 21 '18 at 16:32











  • Possible duplicate of How to print the value of a Tensor object in TensorFlow?

    – Ian Quah
    Nov 21 '18 at 16:32






  • 1





    The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

    – Konstantinos Markopoulos
    Nov 21 '18 at 19:09



















Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

– Ian Quah
Nov 21 '18 at 16:13







Can you format the code correctly? Not sure if everything in the code block is supposed to be within the predict function. What have you tried doing to print out the probabilities? Trying to determine if this is a duplicate question, or if there's more to it

– Ian Quah
Nov 21 '18 at 16:13















Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

– Konstantinos Markopoulos
Nov 21 '18 at 16:27





Thank you for your answer. Actually, I have tried some things found online. I have tried the np.argmax, tf.argmax, tf.nn.top_k and other commands. A part of the problem is that even if the above commands produce something, there is a problem of accessing and reading the data. Mostly because they are tensors

– Konstantinos Markopoulos
Nov 21 '18 at 16:27













Look at tf.Print or eval stackoverflow questions with answers

– Ian Quah
Nov 21 '18 at 16:32





Look at tf.Print or eval stackoverflow questions with answers

– Ian Quah
Nov 21 '18 at 16:32













Possible duplicate of How to print the value of a Tensor object in TensorFlow?

– Ian Quah
Nov 21 '18 at 16:32





Possible duplicate of How to print the value of a Tensor object in TensorFlow?

– Ian Quah
Nov 21 '18 at 16:32




1




1





The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

– Konstantinos Markopoulos
Nov 21 '18 at 19:09







The code that i use is based on: github.com/Kyubyong/g2p The things that I have changed are mostly on preprocessing, in order to use my own data. But the heart remains the same. I used train.py in order to train my model and I am using g2p.py to make predictions. The point of interest is on line 85 of g2p.py. I have to find a way to utilize the information in " _preds = sess.run(graph.preds, {graph.x: x, graph.y: preds}) " to not only make predictions but print the probability of each prediction

– Konstantinos Markopoulos
Nov 21 '18 at 19:09














1 Answer
1






active

oldest

votes


















0














Following the discussion, I think I can point you to where the code should be changed.
In train.py, line 104:



self.preds = tf.to_int32(tf.argmax(logits, -1))


They assign the preds variable to the index with highest probability.
In order to get the softmax predictions, you can change the code as follows:



self.preds = tf.nn.softmax(logits)


I think that should do it.



How to view the probabilities:



preds = np.zeros((len(x), hp.maxlen), np.float32)
for j in range(hp.maxlen):
xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
# print shape of output -> batch_size, max_length,number_of_output_options
print(xpreds.shape)
# print all predictions of the first output
print(xpreds[0, 0])
# print the probabilty of the network prediction
print(xpreds[0, 0, np.argmax(xpreds[0][0])])
# preds[:, j] = _preds[:, j] Need to accumulate the results according to the correct output shape





share|improve this answer


























  • thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 8:48











  • After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

    – Ohad Meir
    Nov 22 '18 at 13:11













  • By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

    – Ohad Meir
    Nov 22 '18 at 13:30











  • Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 14:21











  • The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

    – Ohad Meir
    Nov 22 '18 at 14:51











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416170%2fhow-to-print-out-the-prediction-probabilities-in-tensorflow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Following the discussion, I think I can point you to where the code should be changed.
In train.py, line 104:



self.preds = tf.to_int32(tf.argmax(logits, -1))


They assign the preds variable to the index with highest probability.
In order to get the softmax predictions, you can change the code as follows:



self.preds = tf.nn.softmax(logits)


I think that should do it.



How to view the probabilities:



preds = np.zeros((len(x), hp.maxlen), np.float32)
for j in range(hp.maxlen):
xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
# print shape of output -> batch_size, max_length,number_of_output_options
print(xpreds.shape)
# print all predictions of the first output
print(xpreds[0, 0])
# print the probabilty of the network prediction
print(xpreds[0, 0, np.argmax(xpreds[0][0])])
# preds[:, j] = _preds[:, j] Need to accumulate the results according to the correct output shape





share|improve this answer


























  • thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 8:48











  • After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

    – Ohad Meir
    Nov 22 '18 at 13:11













  • By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

    – Ohad Meir
    Nov 22 '18 at 13:30











  • Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 14:21











  • The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

    – Ohad Meir
    Nov 22 '18 at 14:51
















0














Following the discussion, I think I can point you to where the code should be changed.
In train.py, line 104:



self.preds = tf.to_int32(tf.argmax(logits, -1))


They assign the preds variable to the index with highest probability.
In order to get the softmax predictions, you can change the code as follows:



self.preds = tf.nn.softmax(logits)


I think that should do it.



How to view the probabilities:



preds = np.zeros((len(x), hp.maxlen), np.float32)
for j in range(hp.maxlen):
xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
# print shape of output -> batch_size, max_length,number_of_output_options
print(xpreds.shape)
# print all predictions of the first output
print(xpreds[0, 0])
# print the probabilty of the network prediction
print(xpreds[0, 0, np.argmax(xpreds[0][0])])
# preds[:, j] = _preds[:, j] Need to accumulate the results according to the correct output shape





share|improve this answer


























  • thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 8:48











  • After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

    – Ohad Meir
    Nov 22 '18 at 13:11













  • By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

    – Ohad Meir
    Nov 22 '18 at 13:30











  • Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 14:21











  • The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

    – Ohad Meir
    Nov 22 '18 at 14:51














0












0








0







Following the discussion, I think I can point you to where the code should be changed.
In train.py, line 104:



self.preds = tf.to_int32(tf.argmax(logits, -1))


They assign the preds variable to the index with highest probability.
In order to get the softmax predictions, you can change the code as follows:



self.preds = tf.nn.softmax(logits)


I think that should do it.



How to view the probabilities:



preds = np.zeros((len(x), hp.maxlen), np.float32)
for j in range(hp.maxlen):
xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
# print shape of output -> batch_size, max_length,number_of_output_options
print(xpreds.shape)
# print all predictions of the first output
print(xpreds[0, 0])
# print the probabilty of the network prediction
print(xpreds[0, 0, np.argmax(xpreds[0][0])])
# preds[:, j] = _preds[:, j] Need to accumulate the results according to the correct output shape





share|improve this answer















Following the discussion, I think I can point you to where the code should be changed.
In train.py, line 104:



self.preds = tf.to_int32(tf.argmax(logits, -1))


They assign the preds variable to the index with highest probability.
In order to get the softmax predictions, you can change the code as follows:



self.preds = tf.nn.softmax(logits)


I think that should do it.



How to view the probabilities:



preds = np.zeros((len(x), hp.maxlen), np.float32)
for j in range(hp.maxlen):
xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds})
# print shape of output -> batch_size, max_length,number_of_output_options
print(xpreds.shape)
# print all predictions of the first output
print(xpreds[0, 0])
# print the probabilty of the network prediction
print(xpreds[0, 0, np.argmax(xpreds[0][0])])
# preds[:, j] = _preds[:, j] Need to accumulate the results according to the correct output shape






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 14:53

























answered Nov 21 '18 at 21:15









Ohad MeirOhad Meir

335111




335111













  • thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 8:48











  • After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

    – Ohad Meir
    Nov 22 '18 at 13:11













  • By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

    – Ohad Meir
    Nov 22 '18 at 13:30











  • Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 14:21











  • The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

    – Ohad Meir
    Nov 22 '18 at 14:51



















  • thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 8:48











  • After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

    – Ohad Meir
    Nov 22 '18 at 13:11













  • By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

    – Ohad Meir
    Nov 22 '18 at 13:30











  • Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

    – Konstantinos Markopoulos
    Nov 22 '18 at 14:21











  • The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

    – Ohad Meir
    Nov 22 '18 at 14:51

















thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

– Konstantinos Markopoulos
Nov 22 '18 at 8:48





thank you for your answer. I changed the code as you proposed and i am now retraining my model. any idea on how to access the probabilities when i use the g2p.py script, in order to find them on every data i use as input? thank you in advance

– Konstantinos Markopoulos
Nov 22 '18 at 8:48













After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

– Ohad Meir
Nov 22 '18 at 13:11







After you make this change, after you run xpreds = sess.run(graph.preds, {graph.x: x, graph.y: preds}), the xpreds will contain the probabilities. Print to the console and check.

– Ohad Meir
Nov 22 '18 at 13:11















By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

– Ohad Meir
Nov 22 '18 at 13:30





By the way, you don't need to retrain. you can just use the latest checkpoint that you already have

– Ohad Meir
Nov 22 '18 at 13:30













Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

– Konstantinos Markopoulos
Nov 22 '18 at 14:21





Thank you very much. One last question (i hope the last). I replaced "tf.to_int32" with "tf.nn.softmax" as you proposed above in the train.py. After that i run g2p.py and a ValueError occured: ValueError: could not broadcast input array from shape (97) into shape (1). Should i use an other manipulation in order to make my script run correctly? Thank you in advance

– Konstantinos Markopoulos
Nov 22 '18 at 14:21













The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

– Ohad Meir
Nov 22 '18 at 14:51





The error is here: preds[:, j] = xpreds[:, j] First you can do: print(xpreds.shape) right after session.run to see the shape that you now get. you can also print(xpreds[0]) to see that you now get probabilties. I'll edit the answer

– Ohad Meir
Nov 22 '18 at 14:51


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416170%2fhow-to-print-out-the-prediction-probabilities-in-tensorflow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga