-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f2439e
commit 568be06
Showing
3 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
from typing import Sequence | ||
|
||
TokenId = int | ||
|
||
class BestChoice: ... | ||
class CountInfo: ... | ||
class InferRequest: ... | ||
class InferResponse: ... | ||
class Prediction: ... | ||
class VocabPrefixAutomaton: ... | ||
|
||
class VocabPrefixAutomaton: | ||
def __init__(self, vocab: Sequence[str]) -> None: ... | ||
def get_order(self) -> Sequence[int]: ... | ||
@property | ||
def vocab_size(self) -> int: ... | ||
|
||
class ReorderedTokenId: ... | ||
class SearchTree: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from mtc_token_healing import VocabPrefixAutomaton | ||
|
||
|
||
def test_vocab_simple(): | ||
vocab = ["bcd", "abc", "cc", "hello", "world", " ", "yes", "no", "."] | ||
order = [5, 8, 1, 0, 2, 3, 7, 4, 6] | ||
|
||
assert len(vocab) == len(order) | ||
|
||
automaton = VocabPrefixAutomaton(vocab) | ||
|
||
assert automaton.vocab_size == len(vocab) | ||
assert automaton.get_order() == order | ||
|
||
assert all(vocab[order[i]] < vocab[order[i + 1]] for i in range(len(order) - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters