Gemma 3 tokenizer vocabulary in reviewable .spm text form
Browse filesConverted id for id from Google's Gemma 3 tokenizer.model (MD5 00d2276cbec4474f6cf3df98fbc18cbb), preserving every piece, score and SentencePiece piece type. EmbeddingGemma ships this vocabulary byte-identically. Includes the Gemma Terms of Use, the required NOTICE and a modification notice.
LICENSE
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Gemma Terms of Use
|
| 2 |
+
|
| 3 |
+
The terms below apply to Gemma models listed in the Appendix at bottom of this page. For Gemma 4 terms, see the Gemma 4 license.
|
| 4 |
+
|
| 5 |
+
Last modified: April 1, 2026
|
| 6 |
+
|
| 7 |
+
By using, reproducing, modifying, distributing, performing or displaying any
|
| 8 |
+
portion or element of Gemma, Model Derivatives including via any Hosted Service,
|
| 9 |
+
(each as defined below) (collectively, the "Gemma Services") or otherwise
|
| 10 |
+
accepting the terms of this Agreement, you agree to be bound by this Agreement.
|
| 11 |
+
|
| 12 |
+
Section 1: DEFINITIONS
|
| 13 |
+
|
| 14 |
+
1.1 Definitions
|
| 15 |
+
|
| 16 |
+
(a) "Agreement" or "Gemma Terms of Use" means these terms and conditions
|
| 17 |
+
that govern the use, reproduction, Distribution or modification of the Gemma
|
| 18 |
+
Services and any terms and conditions incorporated by reference.
|
| 19 |
+
|
| 20 |
+
(b) "Distribution" or "Distribute" means any transmission, publication,
|
| 21 |
+
or other sharing of Gemma or Model Derivatives to a third party, including by
|
| 22 |
+
providing or making Gemma or its functionality available as a hosted service via
|
| 23 |
+
API, web access, or any other electronic or remote means ("Hosted Service").
|
| 24 |
+
|
| 25 |
+
(c) "Gemma" means the set of machine learning language models, trained model
|
| 26 |
+
weights and parameters identified in the Appendix,
|
| 27 |
+
regardless of the source that you obtained it from.
|
| 28 |
+
|
| 29 |
+
(d) "Google" means Google LLC.
|
| 30 |
+
|
| 31 |
+
(e) "Model Derivatives" means all (i) modifications to Gemma, (ii) works based
|
| 32 |
+
on Gemma, or (iii) any other machine learning model which is created by transfer
|
| 33 |
+
of patterns of the weights, parameters, operations, or Output of Gemma, to that
|
| 34 |
+
model in order to cause that model to perform similarly to Gemma, including
|
| 35 |
+
distillation methods that use intermediate data representations or methods based
|
| 36 |
+
on the generation of synthetic data Outputs by Gemma for training that model.
|
| 37 |
+
For clarity, Outputs are not deemed Model Derivatives.
|
| 38 |
+
|
| 39 |
+
(f) "Output" means the information content output of Gemma or a Model
|
| 40 |
+
Derivative that results from operating or otherwise using Gemma or the Model
|
| 41 |
+
Derivative, including via a Hosted Service.
|
| 42 |
+
|
| 43 |
+
1.2
|
| 44 |
+
|
| 45 |
+
As used in this Agreement, "including" means
|
| 46 |
+
"including without limitation".
|
| 47 |
+
|
| 48 |
+
Section 2: ELIGIBILITY AND USAGE
|
| 49 |
+
|
| 50 |
+
2.1 Eligibility
|
| 51 |
+
|
| 52 |
+
You represent and warrant that you have the legal capacity to enter into this
|
| 53 |
+
Agreement (including being of sufficient age of consent). If you are accessing
|
| 54 |
+
or using any of the Gemma Services for or on behalf of a legal entity, (a) you
|
| 55 |
+
are entering into this Agreement on behalf of yourself and that legal entity,
|
| 56 |
+
(b) you represent and warrant that you have the authority to act on behalf of
|
| 57 |
+
and bind that entity to this Agreement and (c) references to "you" or
|
| 58 |
+
"your" in the remainder of this Agreement refers to both you (as an
|
| 59 |
+
individual) and that entity.
|
| 60 |
+
|
| 61 |
+
2.2 Use
|
| 62 |
+
|
| 63 |
+
You may use, reproduce, modify, Distribute, perform or display any of the Gemma
|
| 64 |
+
Services only in accordance with the terms of this Agreement, and must not
|
| 65 |
+
violate (or encourage or permit anyone else to violate) any term of this
|
| 66 |
+
Agreement.
|
| 67 |
+
|
| 68 |
+
Section 3: DISTRIBUTION AND RESTRICTIONS
|
| 69 |
+
|
| 70 |
+
3.1 Distribution and Redistribution
|
| 71 |
+
|
| 72 |
+
You may reproduce or Distribute copies of Gemma or Model Derivatives if you meet
|
| 73 |
+
all of the following conditions:
|
| 74 |
+
|
| 75 |
+
- You must include the use restrictions referenced in Section 3.2 as an
|
| 76 |
+
enforceable provision in any agreement (e.g., license agreement, terms of use,
|
| 77 |
+
etc.) governing the use and/or distribution of Gemma or Model Derivatives and
|
| 78 |
+
you must provide notice to subsequent users you Distribute to that Gemma or
|
| 79 |
+
Model Derivatives are subject to the use restrictions in Section 3.2.
|
| 80 |
+
|
| 81 |
+
- You must provide all third party recipients of Gemma or Model Derivatives a
|
| 82 |
+
copy of this Agreement.
|
| 83 |
+
|
| 84 |
+
- You must cause any modified files to carry prominent notices stating that you
|
| 85 |
+
modified the files.
|
| 86 |
+
|
| 87 |
+
- All Distributions (other than through a Hosted Service) must be accompanied
|
| 88 |
+
by a "Notice" text file that contains the following notice:
|
| 89 |
+
"Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms".
|
| 90 |
+
|
| 91 |
+
You may add your own intellectual property statement to your modifications and,
|
| 92 |
+
except as set forth in this Section, may provide additional or different terms
|
| 93 |
+
and conditions for use, reproduction, or Distribution of your modifications, or
|
| 94 |
+
for any such Model Derivatives as a whole, provided your use, reproduction,
|
| 95 |
+
modification, Distribution, performance, and display of Gemma otherwise complies
|
| 96 |
+
with the terms and conditions of this Agreement. Any additional or different
|
| 97 |
+
terms and conditions you impose must not conflict with the terms of this
|
| 98 |
+
Agreement.
|
| 99 |
+
|
| 100 |
+
3.2 Use Restrictions
|
| 101 |
+
|
| 102 |
+
You must not use any of the Gemma Services:
|
| 103 |
+
|
| 104 |
+
- for the restricted uses set forth in the Gemma Prohibited Use Policy at
|
| 105 |
+
ai.google.dev/gemma/prohibited_use_policy
|
| 106 |
+
("Prohibited Use Policy"), which is hereby incorporated by reference into
|
| 107 |
+
this Agreement; or
|
| 108 |
+
|
| 109 |
+
- in violation of applicable laws and regulations.
|
| 110 |
+
|
| 111 |
+
To the maximum extent permitted by law, Google reserves the right to restrict
|
| 112 |
+
(remotely or otherwise) usage of any of the Gemma Services that Google
|
| 113 |
+
reasonably believes are in violation of this Agreement.
|
| 114 |
+
|
| 115 |
+
3.3 Generated Output
|
| 116 |
+
|
| 117 |
+
Google claims no rights in Outputs you generate using Gemma. You and your users
|
| 118 |
+
are solely responsible for Outputs and their subsequent uses.
|
| 119 |
+
|
| 120 |
+
Section 4: ADDITIONAL PROVISIONS
|
| 121 |
+
|
| 122 |
+
4.1 Updates
|
| 123 |
+
|
| 124 |
+
Google may update Gemma from time to time.
|
| 125 |
+
|
| 126 |
+
4.2 Trademarks
|
| 127 |
+
|
| 128 |
+
Nothing in this Agreement grants you any rights to use Google's trademarks,
|
| 129 |
+
trade names, logos or to otherwise suggest endorsement or misrepresent the
|
| 130 |
+
relationship between you and Google. Google reserves any rights not expressly
|
| 131 |
+
granted herein.
|
| 132 |
+
|
| 133 |
+
4.3 DISCLAIMER OF WARRANTY
|
| 134 |
+
|
| 135 |
+
UNLESS REQUIRED BY APPLICABLE LAW, THE GEMMA SERVICES, AND OUTPUTS, ARE PROVIDED
|
| 136 |
+
ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
|
| 137 |
+
EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OR CONDITIONS OF TITLE,
|
| 138 |
+
NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE
|
| 139 |
+
SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING, REPRODUCING,
|
| 140 |
+
MODIFYING, PERFORMING, DISPLAYING OR DISTRIBUTING ANY OF THE GEMMA SERVICES
|
| 141 |
+
OR OUTPUTS AND ASSUME ANY AND ALL RISKS ASSOCIATED WITH YOUR USE OR DISTRIBUTION
|
| 142 |
+
OF ANY OF THE GEMMA SERVICES OR OUTPUTS AND YOUR EXERCISE OF RIGHTS AND
|
| 143 |
+
PERMISSIONS UNDER THIS AGREEMENT.
|
| 144 |
+
|
| 145 |
+
4.4 LIMITATION OF LIABILITY
|
| 146 |
+
|
| 147 |
+
TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO
|
| 148 |
+
LEGAL THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY,
|
| 149 |
+
CONTRACT, OR OTHERWISE, UNLESS REQUIRED BY APPLICABLE LAW, SHALL GOOGLE OR ITS
|
| 150 |
+
AFFILIATES BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT, INDIRECT,
|
| 151 |
+
SPECIAL, INCIDENTAL, EXEMPLARY, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR LOST
|
| 152 |
+
PROFITS OF ANY KIND ARISING FROM THIS AGREEMENT OR RELATED TO, ANY OF THE GEMMA
|
| 153 |
+
SERVICES OR OUTPUTS EVEN IF GOOGLE OR ITS AFFILIATES HAVE BEEN ADVISED OF THE
|
| 154 |
+
POSSIBILITY OF SUCH DAMAGES.
|
| 155 |
+
|
| 156 |
+
4.5 Term, Termination, and Survival
|
| 157 |
+
|
| 158 |
+
The term of this Agreement will commence upon your acceptance of this Agreement
|
| 159 |
+
(including acceptance by your use, modification, or Distribution, reproduction,
|
| 160 |
+
performance or display of any portion or element of the Gemma Services) and will
|
| 161 |
+
continue in full force and effect until terminated in accordance with the terms
|
| 162 |
+
of this Agreement. Google may terminate this Agreement if you are in breach of
|
| 163 |
+
any term of this Agreement. Upon termination of this Agreement, you must delete
|
| 164 |
+
and cease use and Distribution of all copies of Gemma and Model Derivatives in
|
| 165 |
+
your possession or control. Sections 1, 2.1, 3.3, 4.2 to 4.9 shall survive the
|
| 166 |
+
termination of this Agreement.
|
| 167 |
+
|
| 168 |
+
4.6 Governing Law and Jurisdiction
|
| 169 |
+
|
| 170 |
+
This Agreement will be governed by the laws of the State of California without
|
| 171 |
+
regard to choice of law principles. The UN Convention on Contracts for the
|
| 172 |
+
International Sale of Goods does not apply to this Agreement. The state and
|
| 173 |
+
federal courts of Santa Clara County, California shall have exclusive
|
| 174 |
+
jurisdiction of any dispute arising out of this Agreement.
|
| 175 |
+
|
| 176 |
+
4.7 Severability
|
| 177 |
+
|
| 178 |
+
If any provision of this Agreement is held to be invalid, illegal or
|
| 179 |
+
unenforceable, the remaining provisions shall be unaffected thereby and remain
|
| 180 |
+
valid as if such provision had not been set forth herein.
|
| 181 |
+
|
| 182 |
+
4.8 Entire Agreement
|
| 183 |
+
|
| 184 |
+
This Agreement states all the terms agreed between the parties and supersedes
|
| 185 |
+
all other agreements between the parties as of the date of acceptance relating
|
| 186 |
+
to its subject matter.
|
| 187 |
+
|
| 188 |
+
4.9 No Waiver
|
| 189 |
+
|
| 190 |
+
Google will not be treated as having waived any rights by not exercising (or
|
| 191 |
+
delaying the exercise of) any rights under this Agreement.
|
| 192 |
+
|
| 193 |
+
Appendix
|
| 194 |
+
|
| 195 |
+
- Gemma 1
|
| 196 |
+
|
| 197 |
+
- Gemma 1.1
|
| 198 |
+
|
| 199 |
+
- Gemma 2
|
| 200 |
+
|
| 201 |
+
- Gemma 3
|
| 202 |
+
|
| 203 |
+
- Gemma 3n
|
| 204 |
+
|
| 205 |
+
- FunctionGemma
|
| 206 |
+
|
| 207 |
+
- EmbeddingGemma
|
| 208 |
+
|
| 209 |
+
- PaliGemma
|
| 210 |
+
|
| 211 |
+
- PaliGemma 2
|
| 212 |
+
|
| 213 |
+
- ShieldGemma
|
| 214 |
+
|
| 215 |
+
- ShieldGemma 2
|
| 216 |
+
|
| 217 |
+
- CodeGemma
|
| 218 |
+
|
| 219 |
+
- CodeGemma 1.1
|
| 220 |
+
|
| 221 |
+
- Gemma 2 JPN
|
| 222 |
+
|
| 223 |
+
- DataGemma RIG
|
| 224 |
+
|
| 225 |
+
- DataGemma RAG
|
| 226 |
+
|
| 227 |
+
- RecurrentGemma
|
| 228 |
+
|
| 229 |
+
- Gemma Scope
|
| 230 |
+
|
| 231 |
+
- Gemma-APS
|
| 232 |
+
|
| 233 |
+
- T5Gemma
|
| 234 |
+
|
| 235 |
+
- VaultGemma
|
| 236 |
+
|
| 237 |
+
- FunctionGemma
|
| 238 |
+
|
| 239 |
+
- T5Gemma 2
|
| 240 |
+
|
| 241 |
+
- TranslateGemma
|
NOTICE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms
|
| 2 |
+
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
MODIFICATION NOTICE
|
| 6 |
+
|
| 7 |
+
`gemma3.spm` in this repository is a MODIFIED form of Google's Gemma 3
|
| 8 |
+
`tokenizer.model`. It is not the original file.
|
| 9 |
+
|
| 10 |
+
What was changed: the SentencePiece protocol-buffer model was converted, id by
|
| 11 |
+
id, into a plain-text format β one line per token id, holding that id's piece,
|
| 12 |
+
score and piece type. Nothing was added, removed, reordered or rounded: all
|
| 13 |
+
262,144 pieces keep their ids, their scores and their SentencePiece piece types,
|
| 14 |
+
and the conversion is checked in both directions before the file is written.
|
| 15 |
+
|
| 16 |
+
What was NOT changed: no vocabulary entry, score, piece type or id assignment
|
| 17 |
+
differs from Google's file in any way.
|
| 18 |
+
|
| 19 |
+
Source: Google's Gemma 3 `tokenizer.model`, MD5 00d2276cbec4474f6cf3df98fbc18cbb
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
Use of Gemma and of Model Derivatives is subject to the use restrictions in
|
| 24 |
+
Section 3.2 of the Gemma Terms of Use, reproduced in the LICENSE file in this
|
| 25 |
+
repository. Those restrictions apply to you, and you must pass them on to anyone
|
| 26 |
+
you distribute this file or any derivative of it to.
|
README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: gemma
|
| 3 |
+
tags:
|
| 4 |
+
- tokenizer
|
| 5 |
+
- sentencepiece
|
| 6 |
+
- vocabulary
|
| 7 |
+
- gemma
|
| 8 |
+
library_name: splintr
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Gemma 3 tokenizer vocabulary, as reviewable text (`.spm`)
|
| 12 |
+
|
| 13 |
+
Google's Gemma 3 `tokenizer.model` converted, id for id, into a plain-text
|
| 14 |
+
format that a human can read, diff and audit β and that a tokenizer can load
|
| 15 |
+
without a protobuf dependency.
|
| 16 |
+
|
| 17 |
+
**This is a modified file.** See [Modification notice](#modification-notice)
|
| 18 |
+
below and the `NOTICE` file. **Use is subject to the Gemma Terms of Use**,
|
| 19 |
+
including the Section 3.2 use restrictions β see [Licence](#licence).
|
| 20 |
+
|
| 21 |
+
Nothing here is a model. This is a tokenizer vocabulary: the list of pieces a
|
| 22 |
+
tokenizer splits text on, with the scores that decide merge order.
|
| 23 |
+
|
| 24 |
+
The same conversion for Gemma 2 is at
|
| 25 |
+
[`fs90/gemma-2-tokenizer-spm`](https://huggingface.co/fs90/gemma-2-tokenizer-spm).
|
| 26 |
+
|
| 27 |
+
## Why this exists
|
| 28 |
+
|
| 29 |
+
A SentencePiece `tokenizer.model` is a protocol buffer. That makes it opaque:
|
| 30 |
+
you cannot diff two of them, grep one, or see in a pull request what a change
|
| 31 |
+
did. It also means anything that wants to read one needs a protobuf parser and
|
| 32 |
+
the SentencePiece schema.
|
| 33 |
+
|
| 34 |
+
The obvious alternative β the `.tiktoken` format, `base64(token) rank` per line
|
| 35 |
+
β is **lossy for SentencePiece**, in three separate ways:
|
| 36 |
+
|
| 37 |
+
1. **Scores are destroyed.** SentencePiece merges by score, not by id order.
|
| 38 |
+
Recovering merge order from id order is not an approximation, it is
|
| 39 |
+
sometimes an inversion.
|
| 40 |
+
2. **Byte-fallback spelling is destroyed.** A real SentencePiece piece is
|
| 41 |
+
spelled `<0x41>`; storing the raw byte forces a reader to _reconstruct_ that
|
| 42 |
+
spelling by scanning for a run of 256 consecutive ids.
|
| 43 |
+
3. **Piece type is destroyed.** SentencePiece matches `USER_DEFINED` pieces
|
| 44 |
+
verbatim, before merging; they are never merge candidates. `CONTROL` pieces
|
| 45 |
+
are never matched from text at all. Both score `0.0` and both are spelled
|
| 46 |
+
`<...>`, so neither the score nor the spelling tells them apart.
|
| 47 |
+
|
| 48 |
+
**Gemma 3 is the vocabulary where that third point bites hardest.** It declares
|
| 49 |
+
**6,410** `USER_DEFINED` pieces β HTML markers such as `<blockquote>`, and, unlike
|
| 50 |
+
Gemma 2, the whitespace and newline runs (`\n`, `\n\n`, β¦, and runs of spaces).
|
| 51 |
+
Drop the type and every one of them is re-merged from its parts: `<blockquote>`
|
| 52 |
+
becomes `<` + `blockquote` + `>`, and an indent becomes several shorter runs.
|
| 53 |
+
Measured against `sentencepiece` over 1,380 real documents of English and mixed
|
| 54 |
+
source code, that mistokenized **11.0%** of them. The same test on Gemma 2, with
|
| 55 |
+
only 245 user-defined pieces, was 5.6%.
|
| 56 |
+
|
| 57 |
+
This format keeps all three.
|
| 58 |
+
|
| 59 |
+
## Format
|
| 60 |
+
|
| 61 |
+
One line per token id, in ascending id order, no gaps:
|
| 62 |
+
|
| 63 |
+
```
|
| 64 |
+
<base64 of the piece, UTF-8 encoded> <score> <type>
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
PHBhZD4= 0.0 3 # <pad> score 0.0 CONTROL
|
| 69 |
+
PGVvcz4= 0.0 3 # <eos> score 0.0 CONTROL
|
| 70 |
+
PGJvcz4= 0.0 3 # <bos> score 0.0 CONTROL
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
- **piece** β SentencePiece's own `id_to_piece(i)`, so `<0x41>` keeps its real
|
| 74 |
+
byte-fallback spelling and `β` word-boundary runs keep theirs. Base64 because
|
| 75 |
+
a piece may contain spaces, newlines or invalid-looking bytes.
|
| 76 |
+
- **score** β `get_score(i)`, written as the shortest decimal that round-trips
|
| 77 |
+
the IEEE-754 value.
|
| 78 |
+
- **type** β SentencePiece's own `ModelProto.SentencePiece.Type` enum:
|
| 79 |
+
`1` NORMAL, `2` UNKNOWN, `3` CONTROL, `4` USER_DEFINED, `6` BYTE.
|
| 80 |
+
|
| 81 |
+
The id is the line's position, so ids cannot be duplicated or non-monotonic by
|
| 82 |
+
construction β there is no id field to disagree with the ordering.
|
| 83 |
+
|
| 84 |
+
## What is in this vocabulary
|
| 85 |
+
|
| 86 |
+
| | |
|
| 87 |
+
| ------------ | ----------------------------- |
|
| 88 |
+
| pieces | 262,144 |
|
| 89 |
+
| NORMAL | 255,474 |
|
| 90 |
+
| USER_DEFINED | 6,410 |
|
| 91 |
+
| BYTE | 256 |
|
| 92 |
+
| CONTROL | 3 (`<pad>`, `<eos>`, `<bos>`) |
|
| 93 |
+
| UNKNOWN | 1 (`<unk>`) |
|
| 94 |
+
|
| 95 |
+
Two properties worth knowing before you write a loader:
|
| 96 |
+
|
| 97 |
+
- **`add_dummy_prefix` is `false`.** Gemma does not prepend a word-boundary
|
| 98 |
+
marker to the input, unlike Llama and Mistral. Prepending one anyway shifts
|
| 99 |
+
the first piece of every input to a different token.
|
| 100 |
+
- **`byte_fallback` is `true`**, and the 256 `<0xNN>` pieces are how it is
|
| 101 |
+
reached.
|
| 102 |
+
|
| 103 |
+
## Relationship to other Gemma generations
|
| 104 |
+
|
| 105 |
+
- **EmbeddingGemma** ships this exact vocabulary β all 262,144 pieces *and*
|
| 106 |
+
scores are byte-identical, so this file serves it too.
|
| 107 |
+
- **Gemma 2** is a genuinely different vocabulary: 256,000 pieces, and only 245
|
| 108 |
+
user-defined ones.
|
| 109 |
+
- **Gemma 4** shares this generation's merge structure but reassigns 6,206
|
| 110 |
+
marker ids, promoting reserved `<unusedN>` slots into named markers. It is
|
| 111 |
+
**not** interchangeable with this file, and it is licensed separately under
|
| 112 |
+
Apache-2.0.
|
| 113 |
+
|
| 114 |
+
## Verifying this file
|
| 115 |
+
|
| 116 |
+
The conversion is checked in both directions before the file is written β every
|
| 117 |
+
piece, score and type is read back and compared against the source model, and
|
| 118 |
+
each score is round-tripped through `f32` to confirm it survives a
|
| 119 |
+
single-precision parse. To repeat that yourself against your own copy of
|
| 120 |
+
Google's `tokenizer.model`:
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
python extract_spm_vocab.py --model tokenizer.model --output gemma3.spm --verify
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
The script is [`scripts/extract_spm_vocab.py` in
|
| 127 |
+
splintr](https://github.com/ml-rust/splintr). Any SentencePiece implementation
|
| 128 |
+
will do the same job; the format is simple enough to re-derive in a few lines.
|
| 129 |
+
|
| 130 |
+
## Using it
|
| 131 |
+
|
| 132 |
+
```python
|
| 133 |
+
import base64
|
| 134 |
+
|
| 135 |
+
pieces, scores, types = [], [], []
|
| 136 |
+
for line in open("gemma3.spm"):
|
| 137 |
+
b64, score, kind = line.split()
|
| 138 |
+
pieces.append(base64.b64decode(b64).decode("utf-8"))
|
| 139 |
+
scores.append(float(score))
|
| 140 |
+
types.append(int(kind))
|
| 141 |
+
|
| 142 |
+
# USER_DEFINED (4) pieces are matched verbatim, never merged.
|
| 143 |
+
user_defined = {p for p, t in zip(pieces, types) if t == 4}
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
## Provenance
|
| 147 |
+
|
| 148 |
+
Extracted from Google's Gemma 3 `tokenizer.model`, MD5
|
| 149 |
+
`00d2276cbec4474f6cf3df98fbc18cbb`.
|
| 150 |
+
|
| 151 |
+
The vocabulary is Google's, not this repository's, and keeps Google's licence.
|
| 152 |
+
|
| 153 |
+
## Modification notice
|
| 154 |
+
|
| 155 |
+
Required by Section 3.1 of the Gemma Terms of Use, and repeated in `NOTICE`:
|
| 156 |
+
|
| 157 |
+
`gemma3.spm` is a **modified** form of Google's Gemma 3 `tokenizer.model` β it
|
| 158 |
+
is not the original file. The protocol-buffer model was converted, id by id,
|
| 159 |
+
into the plain-text format described above. Nothing was added, removed,
|
| 160 |
+
reordered or rounded: all 262,144 pieces keep their ids, scores and piece types,
|
| 161 |
+
and no vocabulary entry differs from Google's file in any way.
|
| 162 |
+
|
| 163 |
+
## Licence
|
| 164 |
+
|
| 165 |
+
Gemma is provided under and subject to the **Gemma Terms of Use**, found at
|
| 166 |
+
[ai.google.dev/gemma/terms](https://ai.google.dev/gemma/terms) and reproduced in
|
| 167 |
+
full in the `LICENSE` file in this repository.
|
| 168 |
+
|
| 169 |
+
**Use of this file is subject to the use restrictions in Section 3.2 of that
|
| 170 |
+
agreement.** If you distribute this file, or anything derived from it, you must
|
| 171 |
+
pass those restrictions on to whoever you distribute to, provide them a copy of
|
| 172 |
+
the agreement, and include the `NOTICE` file.
|
| 173 |
+
|
| 174 |
+
Gemma 2, Gemma 3 and EmbeddingGemma are covered by these terms. **Gemma 4 is
|
| 175 |
+
not** β it is released under Apache-2.0, under a separate licence at
|
| 176 |
+
[ai.google.dev/gemma/apache_2](https://ai.google.dev/gemma/apache_2).
|
gemma3.spm
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|