blenderbot_small
mindnlp.transformers.models.blenderbot_small.configuration_blenderbot_small.BlenderbotSmallConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [BlenderbotSmallModel
]. It is used to instantiate
an BlenderbotSmall 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 BlenderbotSmall
facebook/blenderbot_small-90M 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 BlenderbotSmall 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:
|
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:
|
forced_eos_token_id |
The id of the token to force as the last generated token when
TYPE:
|
Example
>>> from transformers import BlenderbotSmallConfig, BlenderbotSmallModel
...
>>> # Initializing a BlenderbotSmall facebook/blenderbot_small-90M style configuration
>>> configuration = BlenderbotSmallConfig()
...
>>> # Initializing a model (with random weights) from the facebook/blenderbot_small-90M style configuration
>>> model = BlenderbotSmallModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/blenderbot_small/configuration_blenderbot_small.py
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 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 |
|
mindnlp.transformers.models.blenderbot_small.configuration_blenderbot_small.BlenderbotSmallConfig.__init__(vocab_size=50265, max_position_embeddings=512, encoder_layers=8, encoder_ffn_dim=2048, encoder_attention_heads=16, decoder_layers=8, decoder_ffn_dim=2048, decoder_attention_heads=16, encoder_layerdrop=0.0, decoder_layerdrop=0.0, use_cache=True, is_encoder_decoder=True, activation_function='gelu', d_model=512, dropout=0.1, attention_dropout=0.0, activation_dropout=0.0, init_std=0.02, decoder_start_token_id=1, scale_embedding=False, pad_token_id=0, bos_token_id=1, eos_token_id=2, forced_eos_token_id=2, **kwargs)
¶
Initializes a new instance of the BlenderbotSmallConfig class.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
The size of the vocabulary. Defaults to 50265.
TYPE:
|
max_position_embeddings |
The maximum position of the embeddings. Defaults to 512.
TYPE:
|
encoder_layers |
The number of encoder layers. Defaults to 8.
TYPE:
|
encoder_ffn_dim |
The dimension of the encoder feed-forward network. Defaults to 2048.
TYPE:
|
encoder_attention_heads |
The number of attention heads for the encoder. Defaults to 16.
TYPE:
|
decoder_layers |
The number of decoder layers. Defaults to 8.
TYPE:
|
decoder_ffn_dim |
The dimension of the decoder feed-forward network. Defaults to 2048.
TYPE:
|
decoder_attention_heads |
The number of attention heads for the decoder. 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:
|
use_cache |
Whether to use cache. Defaults to True.
TYPE:
|
is_encoder_decoder |
Determines if the model is an encoder-decoder. Defaults to True.
TYPE:
|
activation_function |
The activation function to be used. Defaults to 'gelu'.
TYPE:
|
d_model |
The dimension of the model. Defaults to 512.
TYPE:
|
dropout |
The dropout probability. Defaults to 0.1.
TYPE:
|
attention_dropout |
The dropout probability for attention layers. Defaults to 0.0.
TYPE:
|
activation_dropout |
The dropout probability for activation layers. Defaults to 0.0.
TYPE:
|
init_std |
The standard deviation for weight initialization. Defaults to 0.02.
TYPE:
|
decoder_start_token_id |
The ID of the start token for the decoder. Defaults to 1.
TYPE:
|
scale_embedding |
Whether to scale the embeddings. Defaults to False.
TYPE:
|
pad_token_id |
The ID of the padding token. Defaults to 0.
TYPE:
|
bos_token_id |
The ID of the beginning-of-sequence token. Defaults to 1.
TYPE:
|
eos_token_id |
The ID of the end-of-sequence token. Defaults to 2.
TYPE:
|
forced_eos_token_id |
The ID of the forced end-of-sequence token. Defaults to 2.
TYPE:
|
kwargs |
Additional keyword arguments.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/configuration_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM
¶
Bases: BlenderbotSmallPreTrainedModel
Represents the BlenderbotSmallForCausalLM class, which is designed for causal language modeling with the BlenderbotSmall model architecture. This class inherits from BlenderbotSmallPreTrainedModel and provides methods for initializing the model, setting and getting input and output embeddings, setting and getting the decoder, forwarding the model, and preparing inputs for generation. It also includes a method for reordering cache during generation. The class includes detailed information about the arguments and returns for the 'forward' and 'prepare_inputs_for_generation' methods. Additionally, example usage and expected outputs are provided for the 'forward' method.
This class encapsulates the functionality for utilizing the BlenderbotSmall model for causal language modeling tasks and provides a comprehensive interface for model manipulation and generation.
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
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 1897 1898 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 2040 2041 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.__init__(config)
¶
Initializes a new instance of the BlenderbotSmallForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself. |
config |
The configuration object containing settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of the expected type. |
AttributeError
|
If the config parameter does not have the required attributes. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.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, BlenderbotSmallForCausalLM
...
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot_small-90M")
>>> model = BlenderbotSmallForCausalLM.from_pretrained("facebook/blenderbot_small-90M", 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/blenderbot_small/modeling_blenderbot_small.py
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.get_decoder()
¶
This method returns the decoder component of the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method returns the decoder component of the BlenderbotSmallForCausalLM model. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.get_input_embeddings()
¶
This method retrieves the input embeddings from the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForCausalLM class. |
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None as it retrieves the input embeddings from the model and does not perform any additional processing. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.get_output_embeddings()
¶
Returns the output embeddings for the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BlenderbotSmallForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
lm_head
|
The method returns the output embeddings for the model, which are used for downstream tasks or further analysis. |
Note
The output embeddings are a representation of the model's internal hidden states after processing the input data. They capture the semantic information learned by the model during training and can be useful for various natural language processing tasks.
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, use_cache=None, **kwargs)
¶
This method prepares inputs for generation in the BlenderbotSmallForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
input_ids |
The input tensor containing token IDs for the input sequence.
TYPE:
|
past_key_values |
A tuple of past key values used in model inference.
TYPE:
|
attention_mask |
A tensor specifying which elements in the input sequence should be attended to.
TYPE:
|
use_cache |
A flag indicating whether to use caching for faster generation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation including 'input_ids', 'attention_mask', 'past_key_values', and 'use_cache'. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input_ids shape is incompatible with past_key_values. |
IndexError
|
If an index error occurs during input_ids manipulation. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.set_decoder(decoder)
¶
Sets the decoder for the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForCausalLM class. |
decoder |
The decoder object to be set for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.set_input_embeddings(value)
¶
Set the input embeddings for the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForCausalLM class. |
value |
The input embeddings to be set for the model. It should be a torch.Tensor of appropriate shape and size.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForCausalLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the BlenderbotSmallForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForCausalLM class. |
new_embeddings |
The new output embeddings to be set for the model. It should be a tensor representing the new embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the new_embeddings is not of type Tensor. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration
¶
Bases: BlenderbotSmallPreTrainedModel
This class represents a small Blenderbot model for conditional generation tasks. It is designed to generate responses based on given inputs in a conversational setting. The class provides methods for initializing the model, resizing token embeddings, forwarding the model output, preparing inputs for generation, and reordering cache during inference. It inherits from BlenderbotSmallPreTrainedModel and includes functionalities such as getting encoder and decoder, setting output embeddings, and manipulating final logits bias. The class is equipped to handle various input parameters for generating responses and computing loss during training.
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
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 1544 1545 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.__init__(config)
¶
init
Initialize the BlenderbotSmallForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForConditionalGeneration class.
|
config |
An instance of the BlenderbotSmallConfig class containing the configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.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[Tensor], Seq2SeqLMOutput]
|
|
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.get_decoder()
¶
This method returns the decoder component from the BlenderbotSmallForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BlenderbotSmallForConditionalGeneration class. |
RETURNS | DESCRIPTION |
---|---|
None
|
The decoder component retrieved from the model. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.get_encoder()
¶
Description: Returns the encoder component of the BlenderbotSmallForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
BlenderbotSmallForConditionalGeneration The instance of the BlenderbotSmallForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.get_output_embeddings()
¶
Method to retrieve the output embeddings of the model.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the BlenderbotSmallForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the output embeddings of the model stored in the 'lm_head' attribute. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.prepare_inputs_for_generation(decoder_input_ids, past_key_values=None, attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, use_cache=None, encoder_outputs=None, **kwargs)
¶
Prepare inputs for generation.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BlenderbotSmallForConditionalGeneration class. |
decoder_input_ids |
The input tensor of decoder tokens. Shape: (batch_size, sequence_length).
TYPE:
|
past_key_values |
The cached key-value states of the decoder. Default: None.
TYPE:
|
attention_mask |
The attention mask tensor. Shape: (batch_size, sequence_length).
TYPE:
|
head_mask |
The mask tensor for hiding heads of the encoder. Shape: (num_layers, num_heads).
TYPE:
|
decoder_head_mask |
The mask tensor for hiding heads of the decoder. Shape: (num_layers, num_heads).
TYPE:
|
cross_attn_head_mask |
The mask tensor for hiding heads of the cross-attention. Shape: (num_layers, num_heads).
TYPE:
|
use_cache |
Whether to use cache for decoding. Default: None.
TYPE:
|
encoder_outputs |
The output tensor of the encoder. Default: None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation. The keys are as follows:
|
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.resize_token_embeddings(new_num_tokens, pad_to_multiple_of=None)
¶
Resize the token embeddings for the BlenderbotSmallForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class BlenderbotSmallForConditionalGeneration.
|
new_num_tokens |
The new number of tokens to resize the embedding to.
TYPE:
|
pad_to_multiple_of |
If provided, the new embedding size will be padded to a multiple of this value.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Embedding
|
nn.Embedding: The resized token embeddings as an instance of nn.Embedding. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the BlenderbotSmallForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallForConditionalGeneration class. |
new_embeddings |
The new output embeddings to be set for the model. It should be a tensor of shape (vocab_size, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the new_embeddings parameter is not a torch.Tensor. |
ValueError
|
If the shape of new_embeddings does not match the expected shape (vocab_size, hidden_size). |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel
¶
Bases: BlenderbotSmallPreTrainedModel
This class represents the BlenderbotSmallModel, which is a Python implementation of the Blenderbot Small model for chat-based language generation.
The BlenderbotSmallModel is a Seq2Seq model that consists of an encoder and a decoder. The encoder encodes the input text into hidden states, while the decoder generates the output text based on the encoded information. The model uses shared embeddings for both the encoder and the decoder.
This class inherits from the BlenderbotSmallPreTrainedModel.
Example
>>> from transformers import AutoTokenizer, BlenderbotSmallModel
...
>>> model = BlenderbotSmallModel.from_pretrained("facebook/blenderbot_small-90M")
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot_small-90M")
...
>>> inputs = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")
>>> decoder_inputs = tokenizer("Studies show that", return_tensors="pt") # Batch size 1
>>> outputs = model(input_ids=inputs.input_ids, decoder_input_ids=decoder_inputs.input_ids)
...
>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
[1, 3, 512]
METHOD | DESCRIPTION |
---|---|
__init__ |
BlenderbotSmallConfig): Initializes the BlenderbotSmallModel with the provided configuration. |
get_input_embeddings |
Returns the shared input embeddings. |
set_input_embeddings |
Sets the shared input embeddings. |
get_encoder |
Returns the encoder of the model. |
get_decoder |
Returns the decoder of the model. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.__init__(config)
¶
Initializes a new instance of BlenderbotSmallModel with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallModel class.
TYPE:
|
config |
The configuration object containing model settings. It must be an instance of BlenderbotSmallConfig class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type BlenderbotSmallConfig. |
ValueError
|
If any of the required parameters from the config object are missing or invalid. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.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)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], Seq2SeqModelOutput]
|
Union[Tuple[mindspore.Tensor], Seq2SeqModelOutput] |
Example
>>> from transformers import AutoTokenizer, BlenderbotSmallModel
...
>>> model = BlenderbotSmallModel.from_pretrained("facebook/blenderbot_small-90M")
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot_small-90M")
...
>>> inputs = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")
>>> decoder_inputs = tokenizer("Studies show that", return_tensors="pt") # Batch size 1
>>> outputs = model(input_ids=inputs.input_ids, decoder_input_ids=decoder_inputs.input_ids)
...
>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
[1, 3, 512]
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.get_decoder()
¶
This method returns the decoder attribute of the BlenderbotSmallModel.
PARAMETER | DESCRIPTION |
---|---|
self |
BlenderbotSmallModel - The instance of the BlenderbotSmallModel class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the decoder attribute of the BlenderbotSmallModel. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.get_encoder()
¶
Method to retrieve the encoder of the BlenderbotSmallModel instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallModel class. It is required to access the encoder.
|
RETURNS | DESCRIPTION |
---|---|
NoneType
|
The method returns the encoder associated with the BlenderbotSmallModel instance. The encoder is used for encoding input data in the model. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.get_input_embeddings()
¶
Method to retrieve the input embeddings from the BlenderbotSmallModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallModel class. Type: class instance. Purpose: Represents the current instance of the BlenderbotSmallModel class. Restrictions: None.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallModel.set_input_embeddings(value)
¶
Sets the input embeddings for the BlenderbotSmallModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallModel class.
TYPE:
|
value |
The input embeddings to be set. It should be a tensor of shape [vocab_size, embedding_dim].
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.py
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallPreTrainedModel
¶
Bases: PreTrainedModel
This class represents a small version of the Blenderbot model that has been pre-trained on a specific task.
It is a subclass of the PreTrainedModel
class.
The BlenderbotSmallPreTrainedModel
class provides methods for initializing the weights of the model
and generating dummy inputs for testing purposes.
To initialize the weights, the _init_weights
method is called with a specified cell
object.
If the cell
is of type nn.Linear
, the weights are initialized using the normal distribution with a
standard deviation of self.config.init_std
.
If the cell
has biases, they are initialized to zeros.
If the cell
is of type nn.Embedding
, the weights are initialized using a normal distribution with a
mean of 0.0 and a standard deviation of self.config.init_std
.
If a padding index is provided, the corresponding weights are set to 0.
The dummy_inputs
property returns a dictionary of dummy inputs that can be used for testing.
It includes 'attention_mask', 'input_ids', and 'decoder_input_ids'. The 'input_ids' tensor contains two rows,
with the second row having a padding token represented by self.config.pad_token_id
.
The 'attention_mask' tensor is obtained by checking if each element of 'input_ids' is not equal to the padding token.
The 'decoder_input_ids' tensor is the same as the 'input_ids' tensor.
Note
This docstring does not include signatures or any other code.
Source code in mindnlp/transformers/models/blenderbot_small/modeling_blenderbot_small.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 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 |
|
mindnlp.transformers.models.blenderbot_small.modeling_blenderbot_small.BlenderbotSmallPreTrainedModel.dummy_inputs
property
¶
This method returns a dictionary of dummy inputs for the BlenderbotSmallPreTrainedModel.
PARAMETER | DESCRIPTION |
---|---|
self |
BlenderbotSmallPreTrainedModel The instance of the BlenderbotSmallPreTrainedModel class.
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing dummy inputs with the following keys:
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer
¶
Bases: PreTrainedTokenizer
Constructs a Blenderbot-90M tokenizer based on BPE (Byte-Pair-Encoding)
This tokenizer inherits from [PreTrainedTokenizer
] which contains most of the main methods. Users should refer to
the superclass for more information regarding methods.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
File containing the vocabulary.
TYPE:
|
merges_file |
Path to the merges file.
TYPE:
|
bos_token |
The beginning of sentence token.
TYPE:
|
eos_token |
The end of sentence token.
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:
|
kwargs |
Additional keyword arguments passed along to [
TYPE:
|
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.default_chat_template
property
¶
A very simple chat template that just adds whitespace between messages.
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.vocab_size: int
property
¶
Returns the size of the vocabulary used by the BlenderbotSmallTokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallTokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
int
|
An integer representing the size of the vocabulary. |
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.__init__(vocab_file, merges_file, bos_token='__start__', eos_token='__end__', unk_token='__unk__', pad_token='__null__', **kwargs)
¶
Initializes a BlenderbotSmallTokenizer instance with the provided parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallTokenizer class.
TYPE:
|
vocab_file |
The file path to the vocabulary file containing encoding information.
TYPE:
|
merges_file |
The file path to the merges file containing BPE merges information.
TYPE:
|
bos_token |
The beginning of sentence token. Defaults to 'start'.
TYPE:
|
eos_token |
The end of sentence token. Defaults to 'end'.
TYPE:
|
unk_token |
The unknown token. Defaults to 'unk'.
TYPE:
|
pad_token |
The padding token. Defaults to 'null'.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method initializes the BlenderbotSmallTokenizer instance with the provided parameters. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If either vocab_file or merges_file is not found. |
JSONDecodeError
|
If there is an issue decoding the vocabulary file. |
IndexError
|
If there is an issue accessing elements during initialization. |
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.bpe(token)
¶
The 'bpe' method in the 'BlenderbotSmallTokenizer' class performs Byte Pair Encoding (BPE) on a given token.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BlenderbotSmallTokenizer class.
TYPE:
|
token |
The input token to be processed with BPE.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The token after BPE processing.
TYPE:
|
This method applies the following steps to perform BPE:
- Checks if the token exists in the cache. If yes, returns the cached value.
- Applies regular expression substitution to separate certain punctuation marks from the token.
- Replaces single quotes with spaces around them.
- Reduces consecutive whitespace characters to a single space.
- If the token contains a newline character, replaces it with 'newln'.
- Splits the token into a list of individual words.
-
Processes each word in the list:
- Converts the word to lowercase.
- Converts the word into a tuple.
- Appends '' to the last character of the tuple.
- Retrieves the pairs of characters in the word.
- If no pairs are found, appends the original word to the final list and continues to the next word.
- Continues to find and merge the most frequent pair of characters in the word until no more relevant pairs are found.
- Joins the merged characters with '@@ ' and removes the '' suffix.
- Caches the processed word for future use.
- Appends the processed word to the final list.
-
Joins all the words in the final list with a space separator and returns the result.
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens in a single string.
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
266 267 268 269 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.get_vocab()
¶
Retrieve the vocabulary of the BlenderbotSmallTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BlenderbotSmallTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict
|
A dictionary representing the vocabulary of the tokenizer, containing the encoder and added tokens encoder.
TYPE:
|
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small.BlenderbotSmallTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary and merge files for the BlenderbotSmallTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BlenderbotSmallTokenizer class.
TYPE:
|
save_directory |
The directory where the vocabulary and merge files will be saved.
TYPE:
|
filename_prefix |
A prefix to be added to the filename. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths of the saved vocabulary and merge files. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the specified save_directory does not exist. |
TypeError
|
If the save_directory is not of type str. |
ValueError
|
If the save_directory is not a valid directory path. |
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small.py
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 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small_fast.BlenderbotSmallTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" BlenderbotSmall tokenizer (backed by HuggingFace's tokenizers library).
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small_fast.py
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 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small_fast.BlenderbotSmallTokenizerFast.default_chat_template
property
¶
A very simple chat template that just adds whitespace between messages.
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small_fast.BlenderbotSmallTokenizerFast.__init__(vocab_file=None, merges_file=None, unk_token='<|endoftext|>', bos_token='<|endoftext|>', eos_token='<|endoftext|>', add_prefix_space=False, trim_offsets=True, **kwargs)
¶
Initializes a BlenderbotSmallTokenizerFast object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_file |
Path to the vocabulary file. Default is None.
TYPE:
|
merges_file |
Path to the merges file. Default is None.
TYPE:
|
unk_token |
The unknown token. Default is 'endoftext'.
TYPE:
|
bos_token |
The beginning of sentence token. Default is 'endoftext'.
TYPE:
|
eos_token |
The end of sentence token. Default is 'endoftext'.
TYPE:
|
add_prefix_space |
Whether to add prefix space. Default is False.
TYPE:
|
trim_offsets |
Whether to trim offsets. Default is True.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the vocab_file or merges_file is not provided. |
TypeError
|
If unk_token, bos_token, eos_token are not strings. |
ValueError
|
If add_prefix_space or trim_offsets are not boolean values. |
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small_fast.py
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 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small_fast.BlenderbotSmallTokenizerFast.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
This method builds inputs with special tokens for the BlenderbotSmallTokenizerFast class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
token_ids_0 |
The token IDs for the first input sequence.
TYPE:
|
token_ids_1 |
The token IDs for the second input sequence. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method modifies the input sequences by adding special tokens. |
Source code in mindnlp/transformers/models/blenderbot_small/tokenization_blenderbot_small_fast.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
mindnlp.transformers.models.blenderbot_small.tokenization_blenderbot_small_fast.BlenderbotSmallTokenizerFast.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. BlenderbotSmall 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/blenderbot_small/tokenization_blenderbot_small_fast.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|