Instructions to use google/madlad400-7b-mt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/madlad400-7b-mt with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("translation", model="google/madlad400-7b-mt")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("google/madlad400-7b-mt") model = AutoModelForSeq2SeqLM.from_pretrained("google/madlad400-7b-mt", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Regenerate the tokenizer.json pipeline from spiece.model
spiece.model keeps whitespace (remove_extra_whitespaces: false) and uses byte fallback, but tokenizer.json collapses repeated spaces and has byte_fallback: false, and transformers v5 additionally rebuilds the T5 pipeline with a whitespace split. Tabs and newlines are lost, which matters for translating documents:
| text | spiece.model |
current (transformers v5) |
with this PR |
|---|---|---|---|
a\tb |
▁a, <0x09>, b |
▁a, ▁b |
▁a, <0x09>, b |
line one\nline two |
▁line, ▁one, \n, line, ▁two |
▁line, ▁one, ▁line, ▁two |
▁line, ▁one, \n, line, ▁two |
two spaces |
▁two, ▁, ▁space, s |
▁two, ▁space, s |
▁two, ▁, ▁space, s |
This PR replaces the normalizer, pre-tokenizer and decoder in tokenizer.json with the ones transformers generates from spiece.model (with legacy=True), turns on byte_fallback, and sets "tokenizer_class": "PreTrainedTokenizerFast" in tokenizer_config.json (TokenizersBackend in transformers v5), so the file is used as-is on v4 and v5, as suggested by the transformers maintainers in huggingface/transformers#51269. The vocabulary and the post-processor are unchanged, so token ids do not move, and the <2xx> language tags are tokenized as before.
I checked it on 33,013 texts (FLORES-200 sentences in 205 languages, Hindi/Malayalam code-mixed text, and Unicode edge cases): the texts that tokenize differently from spiece.model go from 4,494 to 11, and decoding matches SentencePiece on all of them. </s> is still appended.