Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Remove changes to __contains__() method
Browse files Browse the repository at this point in the history
  • Loading branch information
floscha committed Apr 26, 2018
1 parent 6a59169 commit 1b69c0a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
4 changes: 0 additions & 4 deletions tests/word_to_vector/test_fast_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def test_fasttext_list_arguments(mock_urlretrieve):
list(vectors[['the', 'of']].shape) == [2, 300]
list(vectors[('the', 'of')].shape) == [2, 300]

# Test implementation of __contains()__ for token list and tuple
assert ['the', 'of', 'a'] in vectors == [True, True, False]
assert ('the', 'of', 'a') in vectors == [True, True, False]

# Clean up
os.remove(os.path.join(directory, 'wiki.simple.vec.pt'))

Expand Down
11 changes: 2 additions & 9 deletions torchnlp/word_to_vector/pretrained_word_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,8 @@ def __init__(self,
self.name = name
self.cache(name, cache, url=url)

def __contains__(self, tokens):
if isinstance(tokens, list) or isinstance(tokens, tuple):
return [token in self.stoi for token in tokens]
elif isinstance(tokens, str):
token = tokens
return token in self.stoi
else:
raise TypeError("'__contains__' method can only be used with types"
"'str', 'list', or 'tuple' as parameter")
def __contains__(self, token):
return token in self.stoi

def _get_token(self, token):
"""Return embedding for token or for UNK if token not in vocabulary"""
Expand Down

0 comments on commit 1b69c0a

Please sign in to comment.