Comments (3)
In the meantime, I've implemented this alternative workaround (using buildstructor
):
struct TokenizerX;
#[buildstructor::buildstructor]
impl TokenizerX {
#[builder]
fn try_new<'a>(
with_model: ModelWrapper,
with_decoder: Option<Decoder<'a>>,
with_normalizer: Option<Normalizer<'a>>,
) -> Result<Tokenizer> {
let mut tokenizer = Tokenizer::new(with_model);
// Handle local enum to remote enum type:
if let Some(decoder) = with_decoder {
let d = DecoderWrapper::try_from(decoder)?;
tokenizer.with_decoder(d);
}
if let Some(normalizer) = with_normalizer {
let n = NormalizerWrapper::try_from(normalizer)?;
tokenizer.with_normalizer(n);
}
Ok(tokenizer)
}
}
Usage:
let mut tokenizer: Tokenizer = TokenizerX::try_builder()
.with_model(model)
.with_decoder(decoder)
.with_normalizer(normalizer)
.build()?;
The local to remote enum logic above is for the related DecoderWrapper
+ NormalizeWrapper
enums which were also a bit noisy to use / grok, so I have a similar workaround for those:
let decoder = Decoder::Sequence(vec![
Decoder::Replace("_", " "),
Decoder::ByteFallback,
Decoder::Fuse,
Decoder::Strip(' ', 1, 0),
]);
let normalizer = Normalizer::Sequence(vec![
Normalizer::Prepend("▁"),
Normalizer::Replace(" ", "▁"),
]);
from tokenizers.
The builder is I believe mostly used fro training
from tokenizers.
@ArthurZucker perhaps you could better document that? Because by naming convention and current docs comment it implies it is the builder pattern for the Tokenizer
struct:
Builder for
Tokenizer
structs.
It provides an API that matches what you'd expect of a builder API, and it's build()
method returns a type that is used to construct a Tokenizer
struct (which also has a From
impl for this type):
tokenizers/tokenizers/src/tokenizer/mod.rs
Lines 464 to 484 in 1ff56c0
tokenizers/tokenizers/src/tokenizer/mod.rs
Lines 419 to 436 in 1ff56c0
tokenizers/tokenizers/src/tokenizer/mod.rs
Lines 408 to 417 in 1ff56c0
As the issue reports though, that doesn't seem to work very well, the builder API is awkward to use. You could probably adapt it to use buildstructor
similar to how I have shown above with my TokenizerX
workaround type (which also does a similar workaround for Decoder
/ Normalizer
inputs to provide a better DX, but that is not required).
Presently, due to the reported issue here the builder offers little value vs creating the tokenizer without a fluent builder API.
from tokenizers.
Related Issues (20)
- How to write custom Wordpiece class? HOT 2
- Link to download the training text in `docs/source/quicktour.rst` is broken HOT 5
- Strange warnings with tokenizer for some models HOT 5
- Bug with `CodeQwen1.5`: `data did not match any variant of untagged enum PyPreTokenizerTypeWrapper` HOT 1
- Converting `tokenizers` tokenizers into `tiktoken` tokenizers HOT 5
- How to Batch-Encode Paired Input Sentences with Tokenizers: Seeking Clarification HOT 1
- How to allow the merging of consecutive newline tokens \n when training a byte-level bpe tokenizer? HOT 3
- [BUG]Might be a bug in Unigram Trainer
- Training HuggingFace tokenizer - ignore_merges HOT 1
- Memory leak for large strings HOT 5
- Deserializing BPE tokenizer failure HOT 4
- llama3 tokenizer doesn't round trip HOT 3
- [BUG] Fast tokenizer does not deal with AddedTokens properly(no problem in Transformers python tokenizer impl.) HOT 2
- How can I get the mapping relationship between byte values and Unicode characters of the fast tokenizer? HOT 5
- "Solution" to memory hogging in train_new_from_iterator with a hack HOT 6
- [Bug?] Modifying normalizer for pretrained tokenizers don't consistently work HOT 1
- Llama-3 offset-mapping needs fixing HOT 4
- `Encoding` object stub doesn't include `__len__` HOT 2
- Progress bar doesn't show in log file. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokenizers.