Skip to content

Commit 04e43f1

Browse files
committed
[nlp] update Vocabulary, with pad_id
1 parent 386a8d9 commit 04e43f1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tensorlayer/nlp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class Vocabulary(object):
210210
start_id : int of start id
211211
end_id : int of end id
212212
unk_id : int of unk id
213+
pad_id : int of padding id
213214
214215
Vocab_files
215216
-------------
@@ -231,7 +232,8 @@ def __init__(self,
231232
vocab_file,
232233
start_word="<S>",
233234
end_word="</S>",
234-
unk_word="<UNK>"):
235+
unk_word="<UNK>",
236+
pad_word="<PAD>"):
235237
if not tf.gfile.Exists(vocab_file):
236238
tf.logging.fatal("Vocab file %s not found.", vocab_file)
237239
tf.logging.info("Initializing vocabulary from file: %s", vocab_file)
@@ -256,9 +258,11 @@ def __init__(self,
256258
self.start_id = vocab[start_word]
257259
self.end_id = vocab[end_word]
258260
self.unk_id = vocab[unk_word]
261+
self.pad_id = vocab[pad_word]
259262
print(" start_id: %d" % self.start_id)
260263
print(" end_id: %d" % self.end_id)
261264
print(" unk_id: %d" % self.unk_id)
265+
print(" pad_id: %d" % self.pad_id)
262266

263267
def word_to_id(self, word):
264268
"""Returns the integer word id of a word string."""

0 commit comments

Comments
 (0)