bartpho
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer
¶
Bases: PreTrainedTokenizer
Adapted from [XLMRobertaTokenizer
]. Based on SentencePiece.
This tokenizer inherits from [PreTrainedTokenizer
] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
Path to the vocabulary file. This vocabulary is the pre-trained SentencePiece model available from the multilingual XLM-RoBERTa, also used in mBART, consisting of 250K types.
TYPE:
|
monolingual_vocab_file |
Path to the monolingual vocabulary file. This monolingual vocabulary consists of Vietnamese-specialized types extracted from the multilingual vocabulary vocab_file of 250K types.
TYPE:
|
bos_token |
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token. When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the
TYPE:
|
eos_token |
The end of sequence token. When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the
TYPE:
|
sep_token |
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for sequence classification or for a text and a question for question answering. It is also used as the last token of a sequence built with special tokens.
TYPE:
|
cls_token |
The classifier token which is used when doing sequence classification (classification of the whole sequence instead of per-token classification). It is the first token of the sequence when built with special tokens.
TYPE:
|
unk_token |
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
pad_token |
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
mask_token |
The token used for masking values. This is the token used when training this model with masked language modeling. This is the token which the model will try to predict.
TYPE:
|
sp_model_kwargs |
Will be passed to the
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
sp_model |
The SentencePiece processor that is used for every conversion (string, tokens and IDs).
TYPE:
|
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.vocab_size
property
¶
Returns the size of the vocabulary used by the BartphoTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartphoTokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
None |
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.__getstate__()
¶
This method 'getstate' in the class 'BartphoTokenizer' is used to provide the state of the object for pickling.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartphoTokenizer class. Represents the current object whose state needs to be retrieved.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None after setting the 'sp_model' attribute to None and serializing the 'sp_model_proto' attribute. |
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.__init__(vocab_file, monolingual_vocab_file, bos_token='<s>', eos_token='</s>', sep_token='</s>', cls_token='<s>', unk_token='<unk>', pad_token='<pad>', mask_token='<mask>', sp_model_kwargs=None, **kwargs)
¶
Initializes a new instance of the BartphoTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_file |
The path to the vocabulary file.
TYPE:
|
monolingual_vocab_file |
The path to the monolingual vocabulary file.
TYPE:
|
bos_token |
The beginning of sentence token. Defaults to '
TYPE:
|
eos_token |
The end of sentence token. Defaults to ''.
TYPE:
|
sep_token |
The separator token. Defaults to ''.
TYPE:
|
cls_token |
The classification token. Defaults to '
TYPE:
|
unk_token |
The unknown token. Defaults to '
TYPE:
|
pad_token |
The padding token. Defaults to '
TYPE:
|
mask_token |
The masking token. Defaults to '
TYPE:
|
sp_model_kwargs |
Additional keyword arguments for the SentencePieceProcessor. Defaults to None.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.__setstate__(d)
¶
This method 'setstate' is defined within the class 'BartphoTokenizer' and is used to restore the object's state from a dictionary representation. It takes two parameters, 'self' which refers to the instance of the class, and 'd' which is a dictionary representing the state to be restored.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartphoTokenizer class.
TYPE:
|
d |
A dictionary representing the state to be restored. It contains the data necessary to reforward the object's state.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
None
|
However, potential exceptions that could arise during the execution of this method may include, but are not limited to, those related to the initialization of the 'SentencePieceProcessor' instance or its 'LoadFromSerializedProto' method. |
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An BARTPho sequence has the following format:
- single sequence:
<s> X </s>
- pair of sequences:
<s> A </s></s> B </s>
PARAMETER | DESCRIPTION |
---|---|
token_ids_0 |
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (strings for sub-words) in a single string.
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
381 382 383 384 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed to be used in a sequence-pair classification task. BARTPho does not make use of token type ids, therefore a list of zeros is returned.
PARAMETER | DESCRIPTION |
---|---|
token_ids_0 |
List of IDs.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.get_special_tokens_mask(token_ids_0, token_ids_1=None, already_has_special_tokens=False)
¶
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer prepare_for_model
method.
PARAMETER | DESCRIPTION |
---|---|
token_ids_0 |
List of IDs.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
already_has_special_tokens |
Whether or not the token list is already formatted with special tokens for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.get_vocab()
¶
Retrieves the vocabulary dictionary of the BartphoTokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartphoTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
vocab
|
A dictionary containing the vocabulary of the tokenizer. The keys represent the tokens, and the values represent their associated IDs. The dictionary includes both the original vocabulary defined by the tokenizer as well as any additional tokens that have been added.
TYPE:
|
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
mindnlp.transformers.models.bartpho.tokenization_bartpho.BartphoTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Saves the vocabulary files to the specified directory.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartphoTokenizer class.
TYPE:
|
save_directory |
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix |
The prefix to be added to the filenames (default: None).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths of the saved vocabulary files. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the save_directory does not exist. |
IsADirectoryError
|
If the specified save_directory is not a directory. |
Source code in mindnlp/transformers/models/bartpho/tokenization_bartpho.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|