From f3c34f9cac0082bf93b34594dba562dc1452df5f Mon Sep 17 00:00:00 2001 From: Saeed Dehqan <31902891+saeeddhqan@users.noreply.github.com> Date: Thu, 6 Apr 2023 18:40:38 +0330 Subject: [PATCH] Implementing __contains__ for Vectors class (#2144) --- torchtext/vocab/vectors.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torchtext/vocab/vectors.py b/torchtext/vocab/vectors.py index a2e5299f94..af60c4f60b 100644 --- a/torchtext/vocab/vectors.py +++ b/torchtext/vocab/vectors.py @@ -64,6 +64,9 @@ def __getitem__(self, token): else: return self.unk_init(torch.Tensor(self.dim)) + def __contains__(self, token): + return token in self.stoi + def cache(self, name, cache, url=None, max_vectors=None): import ssl