6a5916968838686e332fb68a10cb30222843fbd9,torchnlp/word_to_vector/pretrained_word_vectors.py,_PretrainedWordVectors,__getitem__,#_PretrainedWordVectors#Any#,77

Before Change


        if token in self.stoi:
            return self.vectors[self.stoi[token]]
        else:
            return self.unk_init(torch.Tensor(self.dim))

    def __len__(self):
        return len(self.vectors)

After Change


            return self.unk_init(torch.Tensor(self.dim))

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

    def __len__(self):
        return len(self.vectors)

    def __str__(self):
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: PetrochukM/PyTorch-NLP
Commit Name: 6a5916968838686e332fb68a10cb30222843fbd9
Time: 2018-04-26
Author: florian.joh.schaefer@gmail.com
File Name: torchnlp/word_to_vector/pretrained_word_vectors.py
Class Name: _PretrainedWordVectors
Method Name: __getitem__


Project Name: asappresearch/sru
Commit Name: 6acdbcfffa5674676dc88c94af3e555f3fa64d17
Time: 2019-10-22
Author: taolei@csail.mit.edu
File Name: sru/sru_functional.py
Class Name: tSRUCell
Method Name: __init__


Project Name: asappresearch/sru
Commit Name: fc850582ced2b873507493a7a6eafd7bcc9a24e2
Time: 2019-09-11
Author: taolei@csail.mit.edu
File Name: sru/sru_functional.py
Class Name: tSRUCell
Method Name: __init__