diff options
| -rw-r--r-- | tokenizer/bpe/special.go | 18 | ||||
| -rw-r--r-- | tokenizer/bpe/utility.go | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tokenizer/bpe/special.go b/tokenizer/bpe/special.go new file mode 100644 index 0000000..405199f --- /dev/null +++ b/tokenizer/bpe/special.go @@ -0,0 +1,18 @@ +package bpe + +// Add helper to ensure special token +// wip-special-tokens + +func EnsureSpecialToken(t *Tokenizer, token string) int { + vocab := Vocab(t) + + for i, v := range vocab { + if v == token { + return i + } + } + + AddToken(t, token) + + return len(vocab) - 1 +} diff --git a/tokenizer/bpe/utility.go b/tokenizer/bpe/utility.go index 79e6faf..cb79d76 100644 --- a/tokenizer/bpe/utility.go +++ b/tokenizer/bpe/utility.go @@ -42,3 +42,13 @@ func Merges(t *Tokenizer) [][2]string { return m.Merges() } + +func AddToken(t *Tokenizer, token string) { + m, ok := t.mbpe.Model().(*mbpe.MBPE) + + if !ok { + panic("unimplemented") + } + + m.AddToken(token) +} |
