Commit 2e39ffbe authored by seyonechithrananda's avatar seyonechithrananda
Browse files

add load_vocab method

parent eca05f62
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -166,3 +166,14 @@ class BasicSmilesTokenizer(object):
        """
        tokens = [token for token in self.regex.findall(text)]
        return tokens


def load_vocab(vocab_file):
    """Loads a vocabulary file into a dictionary."""
    vocab = collections.OrderedDict()
    with open(vocab_file, "r", encoding="utf-8") as reader:
        tokens = reader.readlines()
    for index, token in enumerate(tokens):
        token = token.rstrip("\n")
        vocab[token] = index
    return vocab
 No newline at end of file