bart
mindnlp.transformers.models.bart.configuration_bart.BartConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [BartModel
]. It is used to instantiate a BART
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the BART
facebook/bart-large architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
Vocabulary size of the BART model. Defines the number of different tokens that can be represented by the
TYPE:
|
d_model |
Dimensionality of the layers and the pooler layer.
TYPE:
|
encoder_layers |
Number of encoder layers.
TYPE:
|
decoder_layers |
Number of decoder layers.
TYPE:
|
encoder_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
decoder_attention_heads |
Number of attention heads for each attention layer in the Transformer decoder.
TYPE:
|
decoder_ffn_dim |
Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
TYPE:
|
encoder_ffn_dim |
Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
TYPE:
|
activation_function |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
dropout |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_dropout |
The dropout ratio for the attention probabilities.
TYPE:
|
activation_dropout |
The dropout ratio for activations inside the fully connected layer.
TYPE:
|
classifier_dropout |
The dropout ratio for classifier.
TYPE:
|
max_position_embeddings |
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
init_std |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
encoder_layerdrop |
The LayerDrop probability for the encoder. See the LayerDrop paper for more details.
TYPE:
|
decoder_layerdrop |
The LayerDrop probability for the decoder. See the LayerDrop paper for more details.
TYPE:
|
scale_embedding |
Scale embeddings by diving by sqrt(d_model).
TYPE:
|
use_cache |
Whether or not the model should return the last key/values attentions (not used by all models).
TYPE:
|
num_labels |
The number of labels to use in [
TYPE:
|
forced_eos_token_id |
The id of the token to force as the last generated token when
TYPE:
|
Example
>>> from transformers import BartConfig, BartModel
>>> # Initializing a BART facebook/bart-large style configuration
>>> configuration = BartConfig()
>>> # Initializing a model (with random weights) from the facebook/bart-large style configuration
>>> model = BartModel(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/bart/configuration_bart.py
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 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 |
|
mindnlp.transformers.models.bart.configuration_bart.BartConfig.__init__(vocab_size=50265, max_position_embeddings=1024, encoder_layers=12, encoder_ffn_dim=4096, encoder_attention_heads=16, decoder_layers=12, decoder_ffn_dim=4096, decoder_attention_heads=16, encoder_layerdrop=0.0, decoder_layerdrop=0.0, activation_function='gelu', d_model=1024, dropout=0.1, attention_dropout=0.0, activation_dropout=0.0, init_std=0.02, classifier_dropout=0.0, scale_embedding=False, use_cache=True, num_labels=3, pad_token_id=1, bos_token_id=0, eos_token_id=2, is_encoder_decoder=True, decoder_start_token_id=2, forced_eos_token_id=2, **kwargs)
¶
Initializes a new instance of BartConfig.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
The size of the vocabulary. Defaults to 50265.
TYPE:
|
max_position_embeddings |
The maximum position index. Defaults to 1024.
TYPE:
|
encoder_layers |
The number of encoder layers. Defaults to 12.
TYPE:
|
encoder_ffn_dim |
The dimension of the encoder's feedforward network. Defaults to 4096.
TYPE:
|
encoder_attention_heads |
The number of encoder attention heads. Defaults to 16.
TYPE:
|
decoder_layers |
The number of decoder layers. Defaults to 12.
TYPE:
|
decoder_ffn_dim |
The dimension of the decoder's feedforward network. Defaults to 4096.
TYPE:
|
decoder_attention_heads |
The number of decoder attention heads. Defaults to 16.
TYPE:
|
encoder_layerdrop |
The probability of dropping an encoder layer. Defaults to 0.0.
TYPE:
|
decoder_layerdrop |
The probability of dropping a decoder layer. Defaults to 0.0.
TYPE:
|
activation_function |
The activation function. Defaults to 'gelu'.
TYPE:
|
d_model |
The model dimension. Defaults to 1024.
TYPE:
|
dropout |
The dropout probability. Defaults to 0.1.
TYPE:
|
attention_dropout |
The attention dropout probability. Defaults to 0.0.
TYPE:
|
activation_dropout |
The activation dropout probability. Defaults to 0.0.
TYPE:
|
init_std |
The standard deviation for weight initialization. Defaults to 0.02.
TYPE:
|
classifier_dropout |
The classifier dropout probability. Defaults to 0.0.
TYPE:
|
scale_embedding |
Whether to scale embeddings. Defaults to False.
TYPE:
|
use_cache |
Whether to use cache. Defaults to True.
TYPE:
|
num_labels |
The number of labels. Defaults to 3.
TYPE:
|
pad_token_id |
The id of the padding token. Defaults to 1.
TYPE:
|
bos_token_id |
The id of the beginning-of-sequence token. Defaults to 0.
TYPE:
|
eos_token_id |
The id of the end-of-sequence token. Defaults to 2.
TYPE:
|
is_encoder_decoder |
Whether the model is an encoder-decoder. Defaults to True.
TYPE:
|
decoder_start_token_id |
The id of the decoder start token. Defaults to 2.
TYPE:
|
forced_eos_token_id |
The id of the forced end-of-sequence token. Defaults to 2.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
Warning
|
If the config does not include forced_bos_token_id in future versions. |
Source code in mindnlp/transformers/models/bart/configuration_bart.py
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 |
|
mindnlp.transformers.models.bart.modeling_bart.BART_PRETRAINED_MODEL_ARCHIVE_LIST = ['facebook/bart-large']
module-attribute
¶
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM
¶
Bases: BartPreTrainedModel
This class represents a Bart model for causal language modeling (LM). It is a subclass of BartPreTrainedModel.
BartForCausalLM is designed for generating text in an autoregressive manner, where the model predicts the next word in a sequence given the previous words. It consists of a decoder component that takes input_ids and attention_mask as inputs, and produces a sequence of predicted logits. The decoder can be configured with various options such as encoder_hidden_states, encoder_attention_mask, head_mask, cross_attn_head_mask, past_key_values, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, and return_dict.
The class provides methods for getting and setting the input and output embeddings, as well as getting and setting the decoder component. The forward method is the main method for generating text. It akes input_ids, attention_mask, and other optional arguments, and returns the predicted logits, along with other optional outputs such as loss, past_key_values, hidden_states, attentions, and cross_attentions.
The prepare_inputs_for_generation method is used to prepare inputs for text generation. It takes input_ids, past_key_values, attention_mask, use_cache, and other optional arguments, and returns a dictionary containing the prepared inputs.
The _reorder_cache method is a static method that is used to reorder the past_key_values cache during beam search.
Example
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")
>>> model = BartForCausalLM.from_pretrained("facebook/bart-base", add_cross_attention=False)
>>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
>>> outputs = model(**inputs)
This example demonstrates how to use the BartForCausalLM class for text generation. The model takes input_ids as input and generates predicted logits as output.
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.__init__(config)
¶
Initializes an instance of BartForCausalLM.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of BartForCausalLM.
|
config |
The configuration parameters for the model. Must contain the necessary settings for the model initialization.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
AttributeError
|
If the provided configuration is missing required attributes. |
TypeError
|
If the configuration is not in the expected format. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.forward(input_ids=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, head_mask=None, cross_attn_head_mask=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [
TYPE:
|
attention_mask |
Mask to avoid performing attention on padding token indices. Mask values selected in
TYPE:
|
encoder_hidden_states |
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder.
TYPE:
|
encoder_attention_mask |
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used
in the cross-attention if the model is configured as a decoder. Mask values selected in
TYPE:
|
head_mask |
Mask to nullify selected heads of the attention modules. Mask values selected in
TYPE:
|
cross_attn_head_mask |
Mask to nullify selected heads of the cross-attention modules. Mask values selected in
TYPE:
|
past_key_values |
Tuple of Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
cross-attention blocks) that can be used (see If
TYPE:
|
labels |
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
use_cache |
If set to
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers. See
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CausalLMOutputWithCrossAttentions]
|
Union[Tuple, CausalLMOutputWithCrossAttentions] |
Example
>>> from transformers import AutoTokenizer, BartForCausalLM
...
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")
>>> model = BartForCausalLM.from_pretrained("facebook/bart-base", add_cross_attention=False)
>>> assert model.config.is_decoder, f"{model.__class__} has to be configured as a decoder."
>>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
>>> outputs = model(**inputs)
...
>>> logits = outputs.logits
>>> expected_shape = [1, inputs.input_ids.shape[-1], model.config.vocab_size]
>>> list(logits.shape) == expected_shape
True
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.get_decoder()
¶
This method returns the decoder component of the model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.get_input_embeddings()
¶
Method to retrieve the input embeddings from the decoder of a BartForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
BartForCausalLM - The instance of BartForCausalLM class. This parameter represents the current instance of the BartForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
embed_tokens
|
This method returns the input embeddings from the decoder of the BartForCausalLM model. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.get_output_embeddings()
¶
Return the output embeddings of the BartForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForCausalLM class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, use_cache=None, **kwargs)
¶
Prepare the inputs for generation in the BartForCausalLM class.
This method takes 5 parameters: self, input_ids, past_key_values, attention_mask, use_cache.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForCausalLM class.
|
input_ids |
Tensor containing the input ids for the generation.
TYPE:
|
past_key_values |
Tuple of past key values for the generation. Default is None.
TYPE:
|
attention_mask |
Tensor containing the attention mask for the input ids. If None, a new attention mask with all ones will be created. Default is None.
TYPE:
|
use_cache |
Whether or not to use past key values cache. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation.
|
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.set_decoder(decoder)
¶
Sets the decoder for the BartForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForCausalLM class.
TYPE:
|
decoder |
The decoder module to be set for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Description
This method allows the user to set the decoder module for the BartForCausalLM model. The decoder module is responsible for generating the output sequence during the model's forward pass.
The self
parameter refers to the instance of the BartForCausalLM class on which the method is called.
The decoder
parameter is of type nn.Module
and represents the decoder module to be set for the model.
The decoder module should be compatible with the BartForCausalLM model architecture.
Note that setting the decoder module will overwrite any previously set decoder module for the model.
Example
>>> model = BartForCausalLM()
>>> decoder = nn.Linear(768, 1024)
>>> model.set_decoder(decoder)
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.set_input_embeddings(value)
¶
Set the input embeddings for the BartForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForCausalLM class.
TYPE:
|
value |
The input embeddings to be set for the model. This should be a torch.Tensor representing the new input embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForCausalLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings of the BartForCausalLM
model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the
|
new_embeddings |
The new embeddings to be set as the output embeddings.
This should be an instance of
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Note
This method replaces the existing output embeddings in the BartForCausalLM
model with the provided
new embeddings. It is useful when fine-tuning the model's output layer or updating the embeddings with
pre-trained weights.
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration
¶
Bases: BartPreTrainedModel
This class represents a BART model for conditional text generation. It inherits from BartPreTrainedModel and provides methods for model initialization, encoder and decoder retrieval, resizing token embeddings, output embeddings, model forwardion, preparing inputs for generation, preparing decoder input ids from labels, and reordering cache. The class includes methods for initializing the model, retrieving encoder and decoder, resizing token embeddings, forwarding the model, preparing inputs for text generation, and reordering cache for efficient generation. Additionally, it provides methods for setting and getting output embeddings and resizing final logits bias. The class also includes a method for preparing decoder input ids from labels for masked language modeling.
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.__init__(config)
¶
Initialize a BART model for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance of the BartForConditionalGeneration class. |
config |
The configuration object for the BART model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.forward(input_ids=None, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, past_key_values=None, inputs_embeds=None, decoder_inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, Seq2SeqLMOutput]
|
Union[Tuple, Seq2SeqLMOutput] |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.get_decoder()
¶
Method to retrieve the decoder module from the BartForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
decoder
|
Returns the decoder module from the BartForConditionalGeneration model. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.get_encoder()
¶
Method to retrieve the encoder from the BartForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the BartForConditionalGeneration class. This parameter refers to the current instance of the class.
|
RETURNS | DESCRIPTION |
---|---|
encoder
|
Returns the encoder obtained from the model. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.get_output_embeddings()
¶
Method to retrieve the output embeddings from the BartForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartForConditionalGeneration class. This parameter is required to access the model's output embeddings. It should always be passed as the first argument when calling this method.
|
RETURNS | DESCRIPTION |
---|---|
lm_head
|
This method returns the lm_head attribute of the BartForConditionalGeneration instance. The lm_head attribute represents the output embeddings of the model. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.prepare_decoder_input_ids_from_labels(labels)
¶
Prepare decoder input IDs from labels.
This method takes in two parameters: self, labels. The 'self' parameter refers to the current instance of the 'BartForConditionalGeneration' class, while the 'labels' parameter is a tensor containing the input labels.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the BartForConditionalGeneration class. |
labels |
A tensor containing the input labels.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.prepare_inputs_for_generation(decoder_input_ids, past_key_values=None, attention_mask=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, use_cache=None, encoder_outputs=None, **kwargs)
¶
Prepare the inputs for generation in the BartForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForConditionalGeneration class. |
decoder_input_ids |
The input tensor representing the decoder input IDs.
TYPE:
|
past_key_values |
Optional. The past key values for generating the output. Default is None.
TYPE:
|
attention_mask |
Optional. The attention mask tensor for the encoder. Default is None.
TYPE:
|
decoder_attention_mask |
Optional. The attention mask tensor for the decoder. Default is None.
TYPE:
|
head_mask |
Optional. The mask tensor for the encoder's attention heads. Default is None.
TYPE:
|
decoder_head_mask |
Optional. The mask tensor for the decoder's attention heads. Default is None.
TYPE:
|
cross_attn_head_mask |
Optional. The mask tensor for the cross-attention heads. Default is None.
TYPE:
|
use_cache |
Optional. Whether to use cache for faster decoding. Default is None.
TYPE:
|
encoder_outputs |
Optional. The tensor representing the encoder outputs. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation. The dictionary has the following keys:
|
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.resize_token_embeddings(new_num_tokens, pad_to_multiple_of=None)
¶
Resize the token embeddings for the BartForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForConditionalGeneration class.
|
new_num_tokens |
The new number of tokens to resize the embeddings to. Specifies the desired number of tokens for the embeddings.
TYPE:
|
pad_to_multiple_of |
The optional value to pad the resize to a multiple of. If provided, the new embeddings size will be padded to the nearest multiple of this value.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Embedding
|
nn.Embedding: The resized token embeddings as an instance of nn.Embedding. Represents the updated embeddings after resizing. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Method
set_output_embeddings
Description
Sets the output embeddings for the BartForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartForConditionalGeneration class. |
new_embeddings |
The new embeddings to be set as the output embeddings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the new_embeddings parameter is not of type Tensor. |
ValueError
|
If the new_embeddings parameter is empty or invalid. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForQuestionAnswering
¶
Bases: BartPreTrainedModel
This class represents a BART model for question answering tasks. It inherits from the BartPreTrainedModel class.
BARTForQuestionAnswering is a fine-tuned version of the BART model, specifically designed for question answering tasks. It takes in input sequences and returns the predicted start and end positions of the answer span within the input sequence.
The BARTForQuestionAnswering class contains the following methods:
- init(self, config): Initializes the BARTForQuestionAnswering model with the provided configuration.
- forward(self, input_ids, attention_mask, decoder_input_ids, decoder_attention_mask, head_mask, decoder_head_mask, cross_attn_head_mask, encoder_outputs, start_positions, end_positions, inputs_embeds, decoder_inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict): forwards the BART model for question answering and returns the predicted start and end positions of the answer span.
The forward method takes the following parameters:
- input_ids (mindspore.Tensor): The input token IDs.
- attention_mask (Optional[mindspore.Tensor]): The attention mask tensor.
- decoder_input_ids (Optional[mindspore.Tensor]): The decoder input token IDs.
- decoder_attention_mask (Optional[mindspore.Tensor]): The decoder attention mask tensor.
- head_mask (Optional[mindspore.Tensor]): The attention head mask tensor.
- decoder_head_mask (Optional[mindspore.Tensor]): The decoder attention head mask tensor.
- cross_attn_head_mask (Optional[mindspore.Tensor]): The cross-attention head mask tensor.
- encoder_outputs (Optional[List[mindspore.Tensor]]): The encoder outputs tensor.
- start_positions (Optional[mindspore.Tensor]): The labels for the start positions of the answer span.
- end_positions (Optional[mindspore.Tensor]): The labels for the end positions of the answer span.
- inputs_embeds (Optional[mindspore.Tensor]): The embedded input tensor.
- decoder_inputs_embeds (Optional[mindspore.Tensor]): The embedded decoder input tensor.
- use_cache (Optional[bool]): Whether to use cache.
- output_attentions (Optional[bool]): Whether to output attentions.
- output_hidden_states (Optional[bool]): Whether to output hidden states.
- return_dict (Optional[bool]): Whether to return a Seq2SeqQuestionAnsweringModelOutput object.
The forward method returns a Seq2SeqQuestionAnsweringModelOutput object that contains the following attributes:
- loss (Optional[mindspore.Tensor]): The total loss.
- start_logits (mindspore.Tensor): The predicted start logits.
- end_logits (mindspore.Tensor): The predicted end logits.
- past_key_values (Optional[mindspore.Tensor]): The past key values.
- decoder_hidden_states (Optional[mindspore.Tensor]): The decoder hidden states.
- decoder_attentions (Optional[mindspore.Tensor]): The decoder attentions.
- cross_attentions (Optional[mindspore.Tensor]): The cross attentions.
- encoder_last_hidden_state (Optional[mindspore.Tensor]): The encoder last hidden state.
- encoder_hidden_states (Optional[mindspore.Tensor]): The encoder hidden states.
- encoder_attentions (Optional[mindspore.Tensor]): The encoder attentions.
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForQuestionAnswering.__init__(config)
¶
Initializes an instance of the 'BartForQuestionAnswering' class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
An instance of the 'BartConfig' class containing the model configuration.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForQuestionAnswering.forward(input_ids=None, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, start_positions=None, end_positions=None, inputs_embeds=None, decoder_inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
start_positions |
Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (sequence_length). Position outside of the sequence are not taken into account for computing the loss.
TYPE:
|
end_positions |
Labels for position (index) of the end of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (sequence_length). Position outside of the sequence are not taken into account for computing the loss.
TYPE:
|
Source code in mindnlp/transformers/models/bart/modeling_bart.py
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForSequenceClassification
¶
Bases: BartPreTrainedModel
The BartForSequenceClassification
class represents a BART model fine-tuned for sequence classification tasks.
It inherits from the BartPreTrainedModel
class and includes methods for model initialization and sequence classification.
This class includes an __init__
method for initializing the BART model and a forward
method for
forwarding the sequence classification outputs.
The forward
method accepts various input and output parameters, including input and output tensors,
attention masks, labels, and cache usage.
It processes the input data through the BART model, computes the classification logits, and calculates the loss
based on the specified problem type.
The class also includes additional methods for handling sequence classification tasks and managing model outputs.
The BartForSequenceClassification
class provides a comprehensive solution for utilizing
BART models for sequence classification applications.
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForSequenceClassification.__init__(config, **kwargs)
¶
Initializes a new instance of BartForSequenceClassification.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration for the BART model. It contains the model architecture and hyperparameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided config is not an instance of BartConfig. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 |
|
mindnlp.transformers.models.bart.modeling_bart.BartForSequenceClassification.forward(input_ids=None, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, inputs_embeds=None, decoder_inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel
¶
Bases: BartPreTrainedModel
BartModel is a class that represents the BART (Bidirectional and Auto-Regressive Transformers) model for sequence-to-sequence tasks. It inherits from BartPreTrainedModel and encapsulates the architecture and functionality of the BART model.
ATTRIBUTE | DESCRIPTION |
---|---|
shared |
Shared embedding layer for both encoder and decoder parts of the model.
TYPE:
|
encoder |
Encoder component of the BART model.
TYPE:
|
decoder |
Decoder component of the BART model.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the BART model with the provided configuration. |
_tie_weights |
Ties the weights of word embeddings if specified in the configuration. |
get_input_embeddings |
Retrieves the shared input embeddings. |
set_input_embeddings |
Sets the shared input embeddings to the provided value. |
get_encoder |
Retrieves the encoder component of the model. |
get_decoder |
Retrieves the decoder component of the model. |
forward |
forwards the BART model for sequence-to-sequence tasks with the specified inputs and configurations. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.__init__(config)
¶
Initialize the BartModel class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartModel class.
|
config |
The configuration object for the BartModel. It specifies the model's settings and hyperparameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type BartConfig. |
ValueError
|
If the provided pad_token_id is not a valid index in the vocabulary. |
ValueError
|
If the provided vocab_size is not a valid vocabulary size. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.forward(input_ids=None, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, past_key_values=None, inputs_embeds=None, decoder_inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
forwards the BartModel.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartModel class.
TYPE:
|
input_ids |
The input sequence tensor. Default: None.
TYPE:
|
attention_mask |
The attention mask tensor. Default: None.
TYPE:
|
decoder_input_ids |
The decoder input sequence tensor. Default: None.
TYPE:
|
decoder_attention_mask |
The decoder attention mask tensor. Default: None.
TYPE:
|
head_mask |
The head mask tensor. Default: None.
TYPE:
|
decoder_head_mask |
The decoder head mask tensor. Default: None.
TYPE:
|
cross_attn_head_mask |
The cross attention head mask tensor. Default: None.
TYPE:
|
encoder_outputs |
The encoder outputs tensor. Default: None.
TYPE:
|
past_key_values |
The past key values tensor. Default: None.
TYPE:
|
inputs_embeds |
The input embeddings tensor. Default: None.
TYPE:
|
decoder_inputs_embeds |
The decoder input embeddings tensor. Default: None.
TYPE:
|
use_cache |
Whether to use cache. Default: None.
TYPE:
|
output_attentions |
Whether to output attentions. Default: None.
TYPE:
|
output_hidden_states |
Whether to output hidden states. Default: None.
TYPE:
|
return_dict |
Whether to return a dictionary. Default: None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, Seq2SeqModelOutput]
|
Union[Tuple, Seq2SeqModelOutput]: A tuple or a Seq2SeqModelOutput object containing the last hidden state, past key values, decoder hidden states, decoder attentions, cross attentions, encoder last hidden state, encoder hidden states, and encoder attentions. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If no |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.get_decoder()
¶
Method get_decoder in class BartModel.
PARAMETER | DESCRIPTION |
---|---|
self |
BartModel instance. Represents the current instance of the BartModel class.
|
RETURNS | DESCRIPTION |
---|---|
decoder
|
This method returns the decoder associated with the BartModel instance. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.get_encoder()
¶
Get the encoder associated with the BartModel.
PARAMETER | DESCRIPTION |
---|---|
self |
BartModel instance. The current instance of BartModel.
|
RETURNS | DESCRIPTION |
---|---|
encoder
|
The encoder associated with the BartModel instance. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.get_input_embeddings()
¶
Method to get the input embeddings for the BartModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartModel class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 |
|
mindnlp.transformers.models.bart.modeling_bart.BartModel.set_input_embeddings(value)
¶
Set input embeddings for the BartModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartModel class.
TYPE:
|
value |
The input embeddings to be set. It should be a torch.Tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/modeling_bart.py
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 |
|
mindnlp.transformers.models.bart.modeling_bart.BartPreTrainedModel
¶
Bases: PreTrainedModel
BartPreTrainedModel class represents a pre-trained BART (Bidirectional and Auto-Regressive Transformers) model for natural language processing tasks. This class inherits from PreTrainedModel and includes methods for initializing weights and generating dummy inputs for the model.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration instance for the BART model.
|
METHOD | DESCRIPTION |
---|---|
_init_weights |
Initializes the weights for the BART model based on the specified cell type, using the provided configuration standard deviation. |
dummy_inputs |
Generates dummy input data for the BART model, including input_ids and attention_mask. |
Example
>>> # Initialize a BART pre-trained model
>>> model = BartPreTrainedModel(config)
...
>>> # Initialize the weights for the model
>>> model._init_weights(cell)
...
>>> # Generate dummy inputs for the model
>>> inputs = model.dummy_inputs()
Source code in mindnlp/transformers/models/bart/modeling_bart.py
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 762 763 764 765 766 767 768 769 770 771 |
|
mindnlp.transformers.models.bart.modeling_bart.BartPreTrainedModel.dummy_inputs
property
¶
Description
This method generates dummy inputs for a BartPreTrainedModel.
PARAMETER | DESCRIPTION |
---|---|
self |
BartPreTrainedModel The instance of BartPreTrainedModel class.
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing dummy inputs for the model with the following keys:
|
This method does not raise any exceptions.
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer
¶
Bases: PreTrainedTokenizer
Constructs a BART tokenizer, which is smilar to the ROBERTa tokenizer, using byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import BartTokenizer
...
>>> tokenizer = BartTokenizer.from_pretrained("facebook/bart-base")
>>> tokenizer("Hello world")["input_ids"]
[0, 31414, 232, 2]
>>> tokenizer(" Hello world")["input_ids"]
[0, 20920, 232, 2]
You can get around that behavior by passing add_prefix_space=True
when instantiating this tokenizer or when you
call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True
, this tokenizer will add a space before each word (even the first one).
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.
TYPE:
|
merges_file |
Path to the merges file.
TYPE:
|
errors |
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
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:
|
add_prefix_space |
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (BART tokenizer detect beginning of words by the preceding space).
TYPE:
|
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
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 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 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.vocab_size
property
¶
Method to retrieve the vocabulary size of the BartTokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The BartTokenizer instance itself. This parameter is required as the method operates on the current instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the vocabulary size, which is the length of the encoder in the BartTokenizer instance. |
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.__init__(vocab_file, merges_file, errors='replace', bos_token='<s>', eos_token='</s>', sep_token='</s>', cls_token='<s>', unk_token='<unk>', pad_token='<pad>', mask_token='<mask>', add_prefix_space=False, **kwargs)
¶
This method initializes an instance of the BartTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_file |
The path to the vocabulary file containing token mappings.
TYPE:
|
merges_file |
The path to the merges file for byte pair encoding.
TYPE:
|
errors |
Controls error handling during tokenization (default is 'replace').
TYPE:
|
bos_token |
Beginning of sentence token (default is '
TYPE:
|
eos_token |
End of sentence token (default is '').
TYPE:
|
sep_token |
Separation token (default is '').
TYPE:
|
cls_token |
Classification token (default is '
TYPE:
|
unk_token |
Token for unknown tokens (default is '
TYPE:
|
pad_token |
Token for padding sequences (default is '
TYPE:
|
mask_token |
Token for masking sequences (default is '
TYPE:
|
add_prefix_space |
Whether to add space to the beginning of the token (default is False).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the vocab_file or merges_file is not found. |
UnicodeDecodeError
|
If an error occurs during decoding the files. |
ValueError
|
If an error occurs during tokenization. |
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.bpe(token)
¶
This method 'bpe' is defined within the class 'BartTokenizer' and performs Byte Pair Encoding (BPE) on a given token.
PARAMETER | DESCRIPTION |
---|---|
self |
Represents the instance of the class 'BartTokenizer'.
|
token |
The input token to be processed using Byte Pair Encoding.
|
RETURNS | DESCRIPTION |
---|---|
token
|
The method returns the processed token after applying Byte Pair Encoding.
|
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.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 BART 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/bart/tokenization_bart.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
384 385 386 387 388 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.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. BART 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/bart/tokenization_bart.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.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/bart/tokenization_bart.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.get_vocab()
¶
Return the vocabulary of the BartTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BartTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary representing the vocabulary of the tokenizer. The keys are the tokens in the vocabulary, and the values are their corresponding integer encodings. |
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.prepare_for_tokenization(text, is_split_into_words=False, **kwargs)
¶
Prepares the input text for tokenization in the BartTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartTokenizer class.
|
text |
The input text to be prepared for tokenization.
TYPE:
|
is_split_into_words |
Flag indicating whether the text is already split into words. Default is False.
TYPE:
|
**kwargs |
Additional keyword arguments. add_prefix_space (bool): Flag indicating whether a space should be added to the beginning of the text.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The prepared text for tokenization. |
Note
The 'is_split_into_words' and 'add_prefix_space' parameters are mutually exclusive. If 'is_split_into_words' is set to True, the 'add_prefix_space' parameter is ignored.
Example
>>> tokenizer = BartTokenizer()
>>> prepared_text = tokenizer.prepare_for_tokenization("Hello, world!")
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart.BartTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary files for the BartTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartTokenizer class.
TYPE:
|
save_directory |
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix |
An optional prefix to be added to the filenames. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths of the saved vocabulary files. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the specified save_directory does not exist. |
IOError
|
If there is an issue writing the vocabulary files. |
ValueError
|
If the provided filename_prefix is not a string. |
Source code in mindnlp/transformers/models/bart/tokenization_bart.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" BART tokenizer (backed by HuggingFace's tokenizers library), derived from the GPT-2 tokenizer, using byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import BartTokenizerFast
...
>>> tokenizer = BartTokenizerFast.from_pretrained("facebook/bart-base")
>>> tokenizer("Hello world")["input_ids"]
[0, 31414, 232, 2]
>>> tokenizer(" Hello world")["input_ids"]
[0, 20920, 232, 2]
You can get around that behavior by passing add_prefix_space=True
when instantiating this tokenizer or when you
call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True
, this tokenizer needs to be instantiated with add_prefix_space=True
.
This tokenizer inherits from [PreTrainedTokenizerFast
] 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.
TYPE:
|
merges_file |
Path to the merges file.
TYPE:
|
errors |
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
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:
|
add_prefix_space |
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (BART tokenizer detect beginning of words by the preceding space).
TYPE:
|
trim_offsets |
Whether the post processing step should trim offsets to avoid including whitespaces.
TYPE:
|
Source code in mindnlp/transformers/models/bart/tokenization_bart_fast.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.mask_token: str
property
writable
¶
str
: Mask token, to use when training a model with masked-language modeling. Log an error if used while not
having been set.
BART tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily
comprise the space before the
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.__init__(vocab_file=None, merges_file=None, tokenizer_file=None, errors='replace', bos_token='<s>', eos_token='</s>', sep_token='</s>', cls_token='<s>', unk_token='<unk>', pad_token='<pad>', mask_token='<mask>', add_prefix_space=False, trim_offsets=True, **kwargs)
¶
This method initializes an instance of the BartTokenizerFast class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartTokenizerFast class.
|
vocab_file |
The path to the vocabulary file. Defaults to None.
TYPE:
|
merges_file |
The path to the merges file. Defaults to None.
TYPE:
|
tokenizer_file |
The path to the tokenizer file. Defaults to None.
TYPE:
|
errors |
The error handling scheme. Defaults to 'replace'.
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 mask token. Defaults to '
TYPE:
|
add_prefix_space |
Whether to add prefix space. Defaults to False.
TYPE:
|
trim_offsets |
Whether to trim offsets. Defaults to True.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bart/tokenization_bart_fast.py
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 |
|
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
This method builds inputs with special tokens for the BartTokenizerFast class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartTokenizerFast class.
|
token_ids_0 |
A list of token IDs representing the first sequence.
|
token_ids_1 |
A list of token IDs representing the second sequence. This parameter is optional and defaults to None.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method modifies the input token lists in place. |
Source code in mindnlp/transformers/models/bart/tokenization_bart_fast.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.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. BART 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/bart/tokenization_bart_fast.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
mindnlp.transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary files for the tokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BartTokenizerFast class.
TYPE:
|
save_directory |
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix |
The prefix to be added to the filename of the saved vocabulary files. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the filenames of the saved vocabulary files. |
RAISES | DESCRIPTION |
---|---|
None
|
Any exceptions raised by the underlying tokenizer model.save method. |
Source code in mindnlp/transformers/models/bart/tokenization_bart_fast.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|