<commit_before>class Vocabulary:
  def __init__(self, tokens):
    self.tokens     = sorted(set(tokens))
    self.idx_lookup = dict((tok, idx) for idx, tok in enumerate(self.tokens))
    self.size       = len(self.tokens)

  def get_token(self, idx):
    if idx in range(0, self.size):
      return self.tokens[idx]
    raise AssertionError('Index out of bounds (%d)' % idx)

  def get_index(self, token):
    if token in self.idx_lookup:
      return self.idx_lookup[token]
    raise AssertionError('Token "%s" not found from vocabulary' % token)<commit_msg>Add “.has(token)” <commit_after>class Vocabulary:
  def __init__(self, tokens):
    self.tokens     = sorted(set(tokens))
    self.idx_lookup = dict((tok, idx) for idx, tok in enumerate(self.tokens))
    self.size       = len(self.tokens)

  def get_token(self, idx):
    if idx in range(0, self.size):
      return self.tokens[idx]
    raise AssertionError('Index out of bounds (%d)' % idx)

  def get_index(self, token):
    if token in self.idx_lookup:
      return self.idx_lookup[token]
    raise AssertionError('Token "%s" not found from vocabulary' % token)

  def has(self, token):
    return token in self.idx_lookup
{'fraction_non_alphanumeric': 0.12162162162162163, 'fraction_numerical': 0.0016891891891891893, 'mean_word_length': 3.505703422053232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4301145', 'n_tokens_mistral': 388, 'n_tokens_neox': 377, 'n_words': 110}