chatglm3
mindnlp.transformers.models.chatglm3.ChatGLM3Config
¶
Bases: PretrainedConfig
ChatGLM2Config
Source code in mindnlp/transformers/models/chatglm2/configuration_chatglm2.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
|
mindnlp.transformers.models.chatglm3.ChatGLM3Config.__init__(num_layers=28, padded_vocab_size=65024, hidden_size=4096, ffn_hidden_size=13696, kv_channels=128, num_attention_heads=32, seq_length=2048, hidden_dropout=0.0, classifier_dropout=None, attention_dropout=0.0, layernorm_epsilon=1e-05, rmsnorm=True, apply_residual_connection_post_layernorm=False, post_layer_norm=True, add_bias_linear=False, add_qkv_bias=False, bias_dropout_fusion=True, multi_query_attention=False, multi_query_group_num=1, apply_query_key_layer_scaling=True, attention_softmax_in_fp32=True, fp32_residual_connection=False, quantization_bit=0, pre_seq_len=None, prefix_projection=False, **kwargs)
¶
Initialize a ChatGLM2Config object.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM2Config class.
TYPE:
|
num_layers |
The number of layers in the model. Defaults to 28.
TYPE:
|
padded_vocab_size |
The size of the padded vocabulary. Defaults to 65024.
TYPE:
|
hidden_size |
The size of the hidden layers. Defaults to 4096.
TYPE:
|
ffn_hidden_size |
The size of the feed-forward network hidden layers. Defaults to 13696.
TYPE:
|
kv_channels |
The number of channels in the key-value attention. Defaults to 128.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 32.
TYPE:
|
seq_length |
The maximum sequence length. Defaults to 2048.
TYPE:
|
hidden_dropout |
The dropout probability for the hidden layers. Defaults to 0.0.
TYPE:
|
classifier_dropout |
The dropout probability for the classifier layer. Defaults to None.
TYPE:
|
attention_dropout |
The dropout probability for the attention layers. Defaults to 0.0.
TYPE:
|
layernorm_epsilon |
The epsilon value for layer normalization. Defaults to 1e-05.
TYPE:
|
rmsnorm |
Whether to use RMSNorm for normalization. Defaults to True.
TYPE:
|
apply_residual_connection_post_layernorm |
Whether to apply residual connection after layer normalization. Defaults to False.
TYPE:
|
post_layer_norm |
Whether to apply layer normalization after each sublayer. Defaults to True.
TYPE:
|
add_bias_linear |
Whether to add bias to the linear layer. Defaults to False.
TYPE:
|
add_qkv_bias |
Whether to add bias to the query, key, and value layers. Defaults to False.
TYPE:
|
bias_dropout_fusion |
Whether to fuse bias dropout with linear layer. Defaults to True.
TYPE:
|
multi_query_attention |
Whether to use multi-query attention. Defaults to False.
TYPE:
|
multi_query_group_num |
The number of groups for multi-query attention. Defaults to 1.
TYPE:
|
apply_query_key_layer_scaling |
Whether to apply scaling on query-key layer. Defaults to True.
TYPE:
|
attention_softmax_in_fp32 |
Whether to use FP32 for attention softmax. Defaults to True.
TYPE:
|
fp32_residual_connection |
Whether to use FP32 for residual connection. Defaults to False.
TYPE:
|
quantization_bit |
The number of bits for quantization. Defaults to 0.
TYPE:
|
pre_seq_len |
The length of the prefix sequence. Defaults to None.
TYPE:
|
prefix_projection |
Whether to use prefix projection. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/chatglm2/configuration_chatglm2.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.CHATGLM3_6B_PRETRAINED_MODEL_ARCHIVE_LIST = ['THUDM/chatglm3-6b']
module-attribute
¶
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3Model
¶
Bases: ChatGLM2Model
ChatGLM3Model
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
37 38 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForSequenceClassification
¶
Bases: ChatGLM2ForSequenceClassification
ChatGLM3ForSequenceClassification
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
324 325 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForConditionalGeneration
¶
Bases: ChatGLM2ForConditionalGeneration
ChatGLM3ForConditionalGeneration
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
39 40 41 42 43 44 45 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 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForConditionalGeneration.chat(tokenizer, query, history=None, role='user', max_length=8192, num_beams=1, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs)
¶
This method 'chat' in the class 'ChatGLM3ForConditionalGeneration' is used to generate a response based on the given query in a chat scenario.
PARAMETER | DESCRIPTION |
---|---|
self |
Reference to the current instance of the class.
|
tokenizer |
The tokenizer object used to tokenize the input text.
|
query |
The input query for which a response needs to be generated.
TYPE:
|
history |
A list of dictionaries representing the chat history. Defaults to an empty list.
TYPE:
|
role |
The role of the current user in the conversation. Defaults to 'user'.
TYPE:
|
max_length |
The maximum length of the generated response. Defaults to 8192.
TYPE:
|
num_beams |
The number of beams to be used for beam search. Defaults to 1.
TYPE:
|
do_sample |
Flag indicating whether to sample outputs. Defaults to True.
TYPE:
|
top_p |
The nucleus sampling probability. Defaults to 0.8.
TYPE:
|
temperature |
The temperature for sampling. Defaults to 0.8.
TYPE:
|
logits_processor |
An optional logits processor to post-process the model outputs.
DEFAULT:
|
**kwargs |
Additional keyword arguments to be passed to the generation process.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value explicitly. It generates a response and updates the conversation history. |
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
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 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForConditionalGeneration.process_response(output, history)
¶
Process the response by splitting it into metadata and content, updating the history, and replacing placeholders.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3ForConditionalGeneration class. |
output |
The response string received from the model.
TYPE:
|
history |
The list of previous conversation history.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
41 42 43 44 45 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 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForConditionalGeneration.stream_chat(tokenizer, query, history=None, role='user', past_key_values=None, max_length=8192, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, return_past_key_values=False, **kwargs)
¶
This method streams a chat response based on the given input query and history using the ChatGLM3 model for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
tokenizer |
The tokenizer object used to tokenize the input and decode the outputs.
|
query |
The input text query for generating the chat response.
TYPE:
|
history |
A list of dictionaries representing the chat history. Defaults to None.
TYPE:
|
role |
The role of the user in the conversation. Defaults to 'user'.
TYPE:
|
past_key_values |
The past key values used for generating the response. Defaults to None.
DEFAULT:
|
max_length |
The maximum length of the generated response. Defaults to 8192.
TYPE:
|
do_sample |
Whether to sample from the logits during generation. Defaults to True.
TYPE:
|
top_p |
The nucleus sampling parameter. Defaults to 0.8.
TYPE:
|
temperature |
The temperature parameter for sampling. Defaults to 0.8.
TYPE:
|
logits_processor |
The logits processor used to process the model logits. Defaults to None.
DEFAULT:
|
return_past_key_values |
Whether to return the past key values along with the response. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value explicitly, but yields the generated chat response along with the updated history if return_past_key_values is True. |
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
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 |
|
mindnlp.transformers.models.chatglm3.modeling_chatglm3.ChatGLM3ForConditionalGeneration.stream_generate(input_ids, generation_config=None, logits_processor=None, stopping_criteria=None, prefix_allowed_tokens_fn=None, return_past_key_values=False, **kwargs)
¶
Generate sequences of tokens based on the provided input_ids using the ChatGLM3 model for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLM3ForConditionalGeneration class. |
input_ids |
The input sequence of tokens.
TYPE:
|
generation_config |
The configuration for the generation process. Defaults to None.
TYPE:
|
logits_processor |
The list of logits processors for modifying the logits. Defaults to None.
TYPE:
|
stopping_criteria |
The list of stopping criteria for terminating the generation. Defaults to None.
TYPE:
|
prefix_allowed_tokens_fn |
The function to determine which tokens are allowed as prefixes during generation. Defaults to None.
TYPE:
|
return_past_key_values |
Whether to return the past key values during generation. Defaults to False.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
UserWarning
|
If the |
UserWarning
|
If both |
UserWarning
|
If the input length exceeds the |
Source code in mindnlp/transformers/models/chatglm3/modeling_chatglm3.py
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 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer
¶
Bases: PreTrainedTokenizer
The 'ChatGLM3Tokenizer' class represents a tokenizer for a chat model that inherits from PreTrainedTokenizer. It provides methods for tokenizing, converting tokens to IDs, converting IDs to tokens, building model inputs with special tokens, padding, and saving the vocabulary. The class also provides methods for forwarding chat inputs, building single messages, and extracting prefix tokens. Additionally, it offers properties for accessing special tokens and their IDs, as well as the vocabulary size. Furthermore, it provides a method for converting tokens to a string.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
Name of the tokenizer.
TYPE:
|
vocab_file |
Path to the vocabulary file.
TYPE:
|
tokenizer |
Instance of the SPTokenizer for tokenization.
TYPE:
|
special_tokens |
Dictionary of special tokens and their corresponding IDs.
TYPE:
|
encode_special_tokens |
Flag indicating whether to encode special tokens.
TYPE:
|
- unk_token (str): Property for accessing the unknown token.
- pad_token (str): Property for accessing the padding token.
- eos_token (str): Property for accessing the end-of-sequence token.
- unk_token_id (int): Property for accessing the ID of the unknown token.
- pad_token_id (int): Property for accessing the ID of the padding token.
- eos_token_id (int): Property for accessing the ID of the end-of-sequence token.
- vocab_size (int): Property for accessing the size of the vocabulary.
METHOD | DESCRIPTION |
---|---|
get_command |
Retrieves the ID of a given token. |
get_vocab |
Returns the vocabulary as a dictionary. |
_tokenize |
Tokenizes the input text. |
_convert_token_to_id |
Converts a token to its corresponding ID. |
_convert_id_to_token |
Converts an ID to its corresponding token. |
convert_tokens_to_string |
Converts a list of tokens to a string. |
save_vocabulary |
Saves the vocabulary to a directory. |
get_prefix_tokens |
Retrieves prefix tokens. |
build_single_message |
Constructs a single message with role, metadata, and message. |
build_chat_input |
Constructs chat input from a query and history. |
build_inputs_with_special_tokens |
Builds model inputs with special tokens. |
_pad |
Pads encoded inputs according to specified parameters. |
The 'ChatGLM3Tokenizer' class provides a comprehensive set of methods for tokenization and model input forwardion, making it suitable for use in chat model applications.
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
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 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.eos_token: str
property
writable
¶
Returns the end-of-sentence token as a string.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representing the end-of-sentence token. |
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.eos_token_id
property
¶
Returns the ID of the end-of-sentence (EOS) token in the ChatGLM3Tokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.pad_token: str
property
writable
¶
This method returns the string representation of the padding token used in the ChatGLM3Tokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLM3Tokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
str
|
The string representation of the padding token.
TYPE:
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.pad_token_id: int
property
¶
This method returns the token ID for the padding token within the ChatGLM3Tokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
int
|
The token ID corresponding to the '
TYPE:
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.unk_token: str
property
writable
¶
This method 'unk_token' in the class 'ChatGLM3Tokenizer' retrieves the unknown token from the tokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
str
|
The unknown token retrieved from the tokenizer.
TYPE:
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.unk_token_id: int
property
¶
This method returns the token ID corresponding to the '
PARAMETER | DESCRIPTION |
---|---|
self |
A reference to the instance of the ChatGLM3Tokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
int
|
An integer representing the token ID of the '
TYPE:
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.vocab_size
property
¶
This method retrieves the vocabulary size from the ChatGLM3Tokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLM3Tokenizer class. It represents the tokenizer used for processing the text data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The vocabulary size of the tokenizer. It indicates the total number of unique words present in the tokenizer's vocabulary. |
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.__init__(vocab_file, padding_side='left', clean_up_tokenization_spaces=False, encode_special_tokens=False, **kwargs)
¶
Initialize a ChatGLM3Tokenizer object.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
The path to the vocabulary file.
TYPE:
|
padding_side |
Specifies whether padding should be added to the 'left' or 'right' side of the input sequences. Default is 'left'.
TYPE:
|
clean_up_tokenization_spaces |
If True, clean up tokenization spaces. Default is False.
TYPE:
|
encode_special_tokens |
If True, special tokens will be encoded. Default is False.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
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 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.build_chat_input(query, history=None, role='user')
¶
This method builds input for a chat conversation in the ChatGLM3Tokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLM3Tokenizer class.
|
query |
The user's input for the chat conversation.
TYPE:
|
history |
A list of dictionaries representing the chat history. Each dictionary should have the keys 'role' (str), 'metadata' (str), and 'content' (str).
TYPE:
|
role |
The role of the participant for the current input. It can be either 'user' or 'system'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method builds the input for the chat conversation and does not return any value. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input_ids are not of the expected type. |
ValueError
|
If the return_tensors parameter is not set to 'ms'. |
KeyError
|
If the role provided is not valid (i.e., not 'user' or 'system'). |
JSONDecodeError
|
If there is an error in decoding the JSON content of the message. |
AttributeError
|
If the 'tools' key is missing in the history item when the role is 'system'. |
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.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. A BERT sequence has the following format:
- single sequence:
[CLS] X [SEP]
- pair of sequences:
[CLS] A [SEP] B [SEP]
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/chatglm3/tokenization_chatglm3.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.build_single_message(role, metadata, message)
¶
Builds a single message token for the ChatGLM3Tokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLM3Tokenizer class.
TYPE:
|
role |
The role of the message sender. It should be one of ['system', 'user', 'assistant', 'observation'].
TYPE:
|
metadata |
The metadata associated with the message.
TYPE:
|
message |
The actual message content.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
A list of tokens representing the single message built from the role, metadata, and message. |
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If the 'role' parameter is not one of ['system', 'user', 'assistant', 'observation']. |
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.convert_tokens_to_string(tokens)
¶
Converts a list of tokens into a string representation using the ChatGLM3Tokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
TYPE:
|
tokens |
A list of tokens to be converted into a string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The string representation of the tokens.
TYPE:
|
This method takes in an instance of the ChatGLM3Tokenizer class and a list of tokens as input. It then uses the tokenizer's 'decode_tokens' method to convert the tokens into a string representation. The resulting string is returned as the output.
The 'self' parameter is a reference to the current instance of the ChatGLM3Tokenizer class. It is used to access the tokenizer object and its methods.
The 'tokens' parameter is a list of strings representing the tokens to be converted into a string. The tokens should be in the same order as they were generated by the tokenizer.
The return value is a string representation of the tokens. This can be useful for displaying or manipulating the tokens in a human-readable format.
This method does not raise any exceptions.
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.get_command(token)
¶
Retrieves the command associated with a given token.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLM3Tokenizer class.
TYPE:
|
token |
The token for which the command needs to be retrieved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None. |
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If the token is not a special token for the ChatGLM3Tokenizer instance. |
Note
This method checks if the given token is one of the special tokens stored in the self.special_tokens dictionary. If it is, the corresponding command is returned. Otherwise, an assertion error is raised if the token is not a special token for the ChatGLM3Tokenizer instance.
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.get_prefix_tokens()
¶
This method 'get_prefix_tokens' is defined within the 'ChatGLM3Tokenizer' class and retrieves a list of prefix tokens.
PARAMETER | DESCRIPTION |
---|---|
self |
A reference to the instance of the class. It is used to access the instance variables and methods of the class.
|
RETURNS | DESCRIPTION |
---|---|
Returns a list of prefix tokens which is a combination of the commands '[gMASK]' and 'sop'. |
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.get_vocab()
¶
Returns vocab as a dict
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
510 511 512 513 514 |
|
mindnlp.transformers.models.chatglm3.tokenization_chatglm3.ChatGLM3Tokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary and special tokens file to a directory.
PARAMETER | DESCRIPTION |
---|---|
save_directory |
The directory in which to save the vocabulary.
TYPE:
|
filename_prefix |
An optional prefix to add to the named of the saved files.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/chatglm3/tokenization_chatglm3.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
|