@@ -37,10 +37,10 @@ def padded_accuracy_topk(predictions,
37
37
weights_fn = common_layers .weights_nonzero ):
38
38
"""Percentage of times that top-k predictions matches labels on non-0s."""
39
39
with tf .variable_scope ("padded_accuracy_topk" , values = [predictions , labels ]):
40
- padded_labels = common_layers .pad_with_zeros (predictions , labels )
40
+ padded_predictions , padded_labels = common_layers .pad_with_zeros (predictions , labels )
41
41
weights = weights_fn (padded_labels )
42
- effective_k = tf .minimum (k , tf .shape (predictions )[- 1 ])
43
- _ , outputs = tf .nn .top_k (predictions , k = effective_k )
42
+ effective_k = tf .minimum (k , tf .shape (padded_predictions )[- 1 ])
43
+ _ , outputs = tf .nn .top_k (padded_predictions , k = effective_k )
44
44
outputs = tf .to_int32 (outputs )
45
45
padded_labels = tf .expand_dims (padded_labels , axis = - 1 )
46
46
padded_labels += tf .zeros_like (outputs ) # Pad to same shape.
@@ -61,9 +61,9 @@ def padded_sequence_accuracy(predictions,
61
61
"""Percentage of times that predictions matches labels everywhere (non-0)."""
62
62
with tf .variable_scope (
63
63
"padded_sequence_accuracy" , values = [predictions , labels ]):
64
- padded_labels = common_layers .pad_with_zeros (predictions , labels )
64
+ paded_predictions , padded_labels = common_layers .pad_with_zeros (predictions , labels )
65
65
weights = weights_fn (padded_labels )
66
- outputs = tf .to_int32 (tf .argmax (predictions , axis = - 1 ))
66
+ outputs = tf .to_int32 (tf .argmax (paded_predictions , axis = - 1 ))
67
67
not_correct = tf .to_float (tf .not_equal (outputs , padded_labels )) * weights
68
68
axis = list (range (1 , len (outputs .get_shape ())))
69
69
correct_seq = 1.0 - tf .minimum (1.0 , tf .reduce_sum (not_correct , axis = axis ))
@@ -84,9 +84,9 @@ def padded_accuracy(predictions,
84
84
weights_fn = common_layers .weights_nonzero ):
85
85
"""Percentage of times that predictions matches labels on non-0s."""
86
86
with tf .variable_scope ("padded_accuracy" , values = [predictions , labels ]):
87
- padded_labels = common_layers .pad_with_zeros (predictions , labels )
87
+ padded_predictions , padded_labels = common_layers .pad_with_zeros (predictions , labels )
88
88
weights = weights_fn (padded_labels )
89
- outputs = tf .to_int32 (tf .argmax (predictions , axis = - 1 ))
89
+ outputs = tf .to_int32 (tf .argmax (padded_predictions , axis = - 1 ))
90
90
return tf .to_float (tf .equal (outputs , padded_labels )), weights
91
91
92
92
0 commit comments