Choco31415 / Attention_Network_With_Keras

An example attention network with simple dataset.
230 stars 101 forks source link

ids_to_keys() gives incorrect output #2

Closed zhizhang77 closed 5 years ago

zhizhang77 commented 5 years ago

IMO you should sort the list before indexing.

return [sorted(list(vocab.keys()))[id] for id in sentence]

BTW, very helpful tutorial. Thanks for sharing~

Choco31415 commented 5 years ago

Good find, that code is janky - dict's don't give a guaranteed order for keys.

However, sort() won't fix that line as the alphabetic ordering might not match id ordering. In the example, keys just happen to be sorted both alphabetically and by id.

The best option is to build a reverse dictionary (or list, as it just happens to work).

I'll get this in soon, it might take me a day or two to swing around. :/

Choco31415 commented 5 years ago

Fix verified locally and pushed.