Skip to content

Commit

Permalink
Modified function get_id to iterate over dictionary only once. (micro…
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitanand001 authored and xuehui1991 committed Jun 3, 2019
1 parent 5c31530 commit 3745583
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 1 addition & 3 deletions examples/trials/ga_squad/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def get_id(word_dict, word):
'''
Return word id.
'''
if word in word_dict.keys():
return word_dict[word]
return word_dict['<unk>']
return word_dict.get(word, word_dict['<unk>'])


def load_embedding(path):
Expand Down
4 changes: 1 addition & 3 deletions examples/trials/weight_sharing/ga_squad/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ def get_id(word_dict, word):
'''
Given word, return word id.
'''
if word in word_dict.keys():
return word_dict[word]
return word_dict['<unk>']
return word_dict.get(word, word_dict['<unk>'])


def get_buckets(min_length, max_length, bucket_count):
Expand Down

0 comments on commit 3745583

Please sign in to comment.