This repository was archived by the owner on Jan 1, 2021. It is now read-only.
Fix one-hot encoding #80
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LT;DR: length calculation is wrong, padded zeros are never ignored.
Note that
vocab_encodeencodes each char as an index in1..vocab_len: that's what is stored inseqbefore it goes through one-hot encodding. It is expected thattf.one_hotwill encode only valid indices and return zeros for paddings (which is0), but it's not what it does. Instead, it will encode every index in0..vocab_len-1and ignorevocab_len. This means that}char will always end the seq, while padded zeros are processed as normal chars.Doing
seq - 1fixes both the padding0(should be invalid) andvocab_len(should be valid) indices.By the way, length calculation can also be simplified to
tf.reduce_sum(tf.reduce_max(seq, 2), 1)