Skip to content

Commit c6a3dfc

Browse files
author
Hiroya Chiba
committed
Fixed 'Character level one-hot encoding'. Indexes and characters were the other way around. Need to cut off sample at max_length.
1 parent 586d5ab commit c6a3dfc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: 6.1-one-hot-encoding-of-words-or-characters.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@
109109
"\n",
110110
"samples = ['The cat sat on the mat.', 'The dog ate my homework.']\n",
111111
"characters = string.printable # All printable ASCII characters.\n",
112-
"token_index = dict(zip(range(1, len(characters) + 1), characters))\n",
112+
"token_index = dict(zip(characters, range(1, len(characters) + 1)))\n",
113113
"\n",
114114
"max_length = 50\n",
115-
"results = np.zeros((len(samples), max_length, max(token_index.keys()) + 1))\n",
115+
"results = np.zeros((len(samples), max_length, max(token_index.values()) + 1))\n",
116116
"for i, sample in enumerate(samples):\n",
117-
" for j, character in enumerate(sample):\n",
117+
" for j, character in enumerate(sample[:max_length]):\n",
118118
" index = token_index.get(character)\n",
119119
" results[i, j, index] = 1."
120120
]

0 commit comments

Comments
 (0)