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

Commit

Permalink
Merge pull request #20 from floscha/embeddings-contains-method
Browse files Browse the repository at this point in the history
Contains method for word vectors
  • Loading branch information
PetrochukM committed Apr 12, 2018
2 parents b0aa81d + f1b4d49 commit 7e0840f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/word_to_vector/test_fast_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def test_fasttext_simple(mock_urlretrieve):
assert 'the' in vectors.stoi
assert len(vectors) == 1

# Test implementation of __contains()__
assert 'the' in vectors

# Test with the unknown characters
assert len(vectors['漢字']) == 300

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

def __contains__(self, token):
return token in self.stoi

def __getitem__(self, token):
if token in self.stoi:
return self.vectors[self.stoi[token]]
Expand Down

0 comments on commit 7e0840f

Please sign in to comment.