Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions fast/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ unicode-segmentation = "1.12"
regex = "1"
rayon = "1"
rustc-hash = "2"
# For the vendored gigatoken O200k pretokenizer (see src/pretok/).
icu_properties = { version = "2", features = ["compiled_data"] }
17 changes: 14 additions & 3 deletions fast/python/complex_tokenization_fast/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import reduce

from complex_tokenization_fast._rs import Node, Trainer
from complex_tokenization_fast._rs import Node, Trainer, has_cluster_handlers_py, trainer_from_texts
from complex_tokenization_fast.graphs.settings import GraphSettings
from complex_tokenization_fast.graphs.units import characters, register_script, utf8, utf8_clusters
from complex_tokenization_fast.graphs.words import GPTPretokenizer, words
Expand Down Expand Up @@ -42,8 +42,19 @@ def make_trainer(self, texts):
GraphSettings.ONLY_MINIMAL_MERGES = True
GraphSettings.MAX_MERGE_SIZE = self.merge_size

graphs = self._build_graphs(texts)
trainer = Trainer(graphs=graphs)
# Default configuration ingests entirely in Rust (one boundary
# crossing; gigatoken's O200k pretokenizer is byte-identical to
# GPTPretokenizer). Custom pretokenizers/units/script handlers take
# the per-document Python path.
if (
self.units is utf8_clusters
and self.pretokenizer is GPTPretokenizer
and not has_cluster_handlers_py()
):
trainer = trainer_from_texts(list(texts), connected=self.connected)
else:
graphs = self._build_graphs(texts)
trainer = Trainer(graphs=graphs)

for merge_strs in self.merges:
nodes = tuple(Node(value=s.encode("utf-8")) for s in merge_strs)
Expand Down
Loading
Loading