Commit 3745583b authored by Mohit Anand's avatar Mohit Anand Committed by xuehui
Browse files

Modified function get_id to iterate over dictionary only once. (#1140)

parent 5c31530e
...@@ -79,9 +79,7 @@ def get_id(word_dict, word): ...@@ -79,9 +79,7 @@ def get_id(word_dict, word):
''' '''
Return word id. Return word id.
''' '''
if word in word_dict.keys(): return word_dict.get(word, word_dict['<unk>'])
return word_dict[word]
return word_dict['<unk>']
def load_embedding(path): def load_embedding(path):
......
...@@ -241,9 +241,7 @@ def get_id(word_dict, word): ...@@ -241,9 +241,7 @@ def get_id(word_dict, word):
''' '''
Given word, return word id. Given word, return word id.
''' '''
if word in word_dict.keys(): return word_dict.get(word, word_dict['<unk>'])
return word_dict[word]
return word_dict['<unk>']
def get_buckets(min_length, max_length, bucket_count): def get_buckets(min_length, max_length, bucket_count):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment