Skip to content

Commit

Permalink
Add special_tokens to Tokenizer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonwillard committed Sep 16, 2023
1 parent ff4ebb3 commit 76e95fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion outlines/models/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import Dict, List, Protocol, Tuple, Union
from typing import Dict, List, Protocol, Set, Tuple, Union

import numpy as np
from numpy.typing import NDArray
Expand All @@ -10,6 +10,7 @@ class Tokenizer(Protocol):
eos_token_id: int
pad_token_id: int
vocabulary: Dict[str, int]
special_tokens: Set[int]

@abstractmethod
def encode(
Expand Down
2 changes: 2 additions & 0 deletions outlines/models/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def __init__(self, model_name: str, **kwargs):
self.pad_token_id = self.tokenizer.pad_token_id
self.pad_token = self.tokenizer.pad_token

self.special_tokens = set(self.tokenizer.special_tokens_map.values())

self.vocabulary = self.tokenizer.get_vocab()
self.is_llama = isinstance(self.tokenizer, get_llama_tokenizer_types())

Expand Down
1 change: 1 addition & 0 deletions tests/text/generate/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Tokenizer:
pad_token_id = -1
vocabulary = {"<EOS>": 0, "-": 1, "1": 2, "0.": 3, "431": 4, "a": 5, "A": 6}
tokens = list(vocabulary.keys())
special_tokens = {"<EOS>"}

def decode(self, token_ids):
decoded = []
Expand Down

0 comments on commit 76e95fe

Please sign in to comment.