xlnet
mindnlp.transformers.models.xlnet.modeling_xlnet
¶
MindSpore XLNet model.
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForMultipleChoice
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForMultipleChoice.forward(input_ids=None, token_type_ids=None, input_mask=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, head_mask=None, inputs_embeds=None, labels=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the multiple choice classification loss. Indices should be in [0, ...,
num_choices-1] where num_choices is the size of the second dimension of the input tensors. (See
input_ids above)
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForMultipleChoiceOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetForMultipleChoice].
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
num_choices is the second dimension of the input tensors. (see input_ids above). Classification scores (before SoftMax).
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnswering
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnswering.forward(input_ids=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, token_type_ids=None, input_mask=None, head_mask=None, inputs_embeds=None, start_positions=None, end_positions=None, is_impossible=None, cls_index=None, p_mask=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
start_positions (mindspore.Tensor of shape (batch_size,), optional):
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.
end_positions (mindspore.Tensor of shape (batch_size,), optional):
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.
is_impossible (mindspore.Tensor of shape (batch_size,), optional):
Labels whether a question has an answer or no answer (SQuAD 2.0)
cls_index (mindspore.Tensor of shape (batch_size,), optional):
Labels for position (index) of the classification token to use as input for computing plausibility of the
answer.
p_mask (mindspore.Tensor of shape (batch_size, sequence_length), optional):
Optional mask of tokens which can't be in answers (e.g. [CLS], [PAD], ...). 1.0 means token should be
masked. 0.0 mean token is not masked.
Returns:
Example:
>>> from transformers import AutoTokenizer, XLNetForQuestionAnswering
>>> import torch
>>> tokenizer = AutoTokenizer.from_pretrained("xlnet/xlnet-base-cased")
>>> model = XLNetForQuestionAnswering.from_pretrained("xlnet/xlnet-base-cased")
>>> input_ids = mindspore.tensor(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True)).unsqueeze(
... 0
... ) # Batch size 1
>>> start_positions = mindspore.tensor([1])
>>> end_positions = mindspore.tensor([3])
>>> outputs = model(input_ids, start_positions=start_positions, end_positions=end_positions)
>>> loss = outputs.loss
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnsweringOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetForQuestionAnswering].
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss as the sum of start token, end token (and is_impossible if provided) classification losses.
TYPE:
|
start_top_log_probs
|
Log probabilities for the top config.start_n_top start token possibilities (beam-search).
TYPE:
|
start_top_index
|
Indices for the top config.start_n_top start token possibilities (beam-search).
TYPE:
|
end_top_log_probs
|
Log probabilities for the top
TYPE:
|
end_top_index
|
Indices for the top
TYPE:
|
cls_logits
|
Log probabilities for the
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnsweringSimple
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnsweringSimple.forward(input_ids=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, token_type_ids=None, input_mask=None, head_mask=None, inputs_embeds=None, start_positions=None, end_positions=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
start_positions (mindspore.Tensor of shape (batch_size,), optional):
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.
end_positions (mindspore.Tensor of shape (batch_size,), optional):
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.
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForQuestionAnsweringSimpleOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetForQuestionAnsweringSimple].
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.
TYPE:
|
start_logits
|
Span-start scores (before SoftMax).
TYPE:
|
end_logits
|
Span-end scores (before SoftMax).
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForSequenceClassification
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForSequenceClassification.forward(input_ids=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, token_type_ids=None, input_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the sequence classification/regression loss. Indices should be in [0, ...,
config.num_labels - 1]. If config.num_labels == 1 a regression loss is computed (Mean-Square loss), If
config.num_labels > 1 a classification loss is computed (Cross-Entropy).
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForSequenceClassificationOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetForSequenceClassification].
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification (or regression if config.num_labels==1) loss.
TYPE:
|
logits
|
Classification (or regression if config.num_labels==1) scores (before SoftMax).
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForTokenClassification
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForTokenClassification.forward(input_ids=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, token_type_ids=None, input_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the multiple choice classification loss. Indices should be in [0, ..., num_choices]
where num_choices is the size of the second dimension of the input tensors. (see input_ids above)
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetForTokenClassificationOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetForTokenClassificationOutput].
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
Classification scores (before SoftMax).
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetLMHeadModel
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetLMHeadModel.forward(input_ids=None, attention_mask=None, mems=None, perm_mask=None, target_mapping=None, token_type_ids=None, input_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_mems=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
labels (mindspore.Tensor of shape (batch_size, num_predict), optional):
Labels for masked language modeling. num_predict corresponds to target_mapping.shape[1]. If
target_mapping is None, then num_predict corresponds to sequence_length.
The labels should correspond to the masked input words that should be predicted and depends on
`target_mapping`. Note in order to perform standard auto-regressive language modeling a *<mask>* token has
to be added to the `input_ids` (see the `prepare_inputs_for_generation` function and examples below)
Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100` are ignored, the loss
is only computed for labels in `[0, ..., config.vocab_size]`
Return:
Examples:
>>> from transformers import AutoTokenizer, XLNetLMHeadModel
>>> import torch
>>> tokenizer = AutoTokenizer.from_pretrained("xlnet/xlnet-large-cased")
>>> model = XLNetLMHeadModel.from_pretrained("xlnet/xlnet-large-cased")
>>> # We show how to setup inputs to predict a next token using a bi-directional context.
>>> input_ids = mindspore.tensor(
... tokenizer.encode("Hello, my dog is very <mask>", add_special_tokens=False)
... ).unsqueeze(
... 0
... ) # We will predict the masked token
>>> perm_mask = ops.zeros((1, input_ids.shape[1], input_ids.shape[1]), dtype=mindspore.float)
>>> perm_mask[:, :, -1] = 1.0 # Previous tokens don't see last token
>>> target_mapping = ops.zeros(
... (1, 1, input_ids.shape[1]), dtype=mindspore.float
... ) # Shape [1, 1, seq_length] => let's predict one token
>>> target_mapping[
... 0, 0, -1
... ] = 1.0 # Our first (and only) prediction will be the last token of the sequence (the masked token)
>>> outputs = model(input_ids, perm_mask=perm_mask, target_mapping=target_mapping)
>>> next_token_logits = outputs[
... 0
... ] # Output has shape [target_mapping.shape[0], target_mapping.shape[1], config.vocab_size]
>>> # The same way can the XLNetLMHeadModel be used to be trained by standard auto-regressive language modeling.
>>> input_ids = mindspore.tensor(
... tokenizer.encode("Hello, my dog is very <mask>", add_special_tokens=False)
... ).unsqueeze(
... 0
... ) # We will predict the masked token
>>> labels = mindspore.tensor(tokenizer.encode("cute", add_special_tokens=False)).unsqueeze(0)
>>> assert labels.shape[0] == 1, "only one word will be predicted"
>>> perm_mask = ops.zeros((1, input_ids.shape[1], input_ids.shape[1]), dtype=mindspore.float)
>>> perm_mask[
... :, :, -1
... ] = 1.0 # Previous tokens don't see last token as is done in standard auto-regressive lm training
>>> target_mapping = ops.zeros(
... (1, 1, input_ids.shape[1]), dtype=mindspore.float
... ) # Shape [1, 1, seq_length] => let's predict one token
>>> target_mapping[
... 0, 0, -1
... ] = 1.0 # Our first (and only) prediction will be the last token of the sequence (the masked token)
>>> outputs = model(input_ids, perm_mask=perm_mask, target_mapping=target_mapping, labels=labels)
>>> loss = outputs.loss
>>> next_token_logits = (
... outputs.logits
... ) # Logits have shape [target_mapping.shape[0], target_mapping.shape[1], config.vocab_size]
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetLMHeadModelOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetLMHeadModel].
| PARAMETER | DESCRIPTION |
|---|---|
logits
|
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetModel
¶
Bases: XLNetPreTrainedModel
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetModel.create_mask(qlen, mlen)
¶
Creates causal attention mask. Float mask where 1.0 indicates masked, 0.0 indicates not-masked.
| PARAMETER | DESCRIPTION |
|---|---|
qlen
|
Sequence length
|
mlen
|
Mask length
|
::
same_length=False: same_length=True: <mlen > < qlen > <mlen > < qlen >
^ [0 0 0 0 0 1 1 1 1] [0 0 0 0 0 1 1 1 1]
[0 0 0 0 0 0 1 1 1] [1 0 0 0 0 0 1 1 1]
qlen [0 0 0 0 0 0 0 1 1] [1 1 0 0 0 0 0 1 1]
[0 0 0 0 0 0 0 0 1] [1 1 1 0 0 0 0 0 1]
v [0 0 0 0 0 0 0 0 0] [1 1 1 1 0 0 0 0 0]
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetModelOutput
dataclass
¶
Bases: ModelOutput
Output type of [XLNetModel].
| PARAMETER | DESCRIPTION |
|---|---|
last_hidden_state
|
Sequence of hidden-states at the last layer of the model.
TYPE:
|
mems
|
Contains pre-computed hidden-states. Can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetRelativeAttention
¶
Bases: Module
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetRelativeAttention.post_attention(h, attn_vec, residual=True)
¶
Post-attention processing.
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
156 157 158 159 160 161 162 163 164 165 166 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetRelativeAttention.rel_attn_core(q_head, k_head_h, v_head_h, k_head_r, seg_mat=None, attn_mask=None, head_mask=None, output_attentions=False)
¶
Core relative positional attention operations.
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.modeling_xlnet.XLNetRelativeAttention.rel_shift(x, klen=-1)
staticmethod
¶
perform relative shift to form the relative attention score.
Source code in mindnlp\transformers\models\xlnet\modeling_xlnet.py
76 77 78 79 80 81 82 83 84 85 86 87 | |
mindnlp.transformers.models.xlnet.configuration_xlnet
¶
XLNet configuration
mindnlp.transformers.models.xlnet.configuration_xlnet.XLNetConfig
¶
Bases: PretrainedConfig
Configuration for XLNet
Source code in mindnlp\transformers\models\xlnet\configuration_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.configuration_xlnet.XLNetConfig.max_position_embeddings
property
writable
¶
This method returns the maximum position embeddings for the XLNet model.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetConfig class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method does not return any specific value, as it only logs a message and returns -1. |
mindnlp.transformers.models.xlnet.configuration_xlnet.XLNetConfig.__init__(vocab_size=32000, d_model=1024, n_layer=24, n_head=16, d_inner=4096, ff_activation='gelu', untie_r=True, attn_type='bi', initializer_range=0.02, layer_norm_eps=1e-12, dropout=0.1, mem_len=512, reuse_len=None, use_mems_eval=True, use_mems_train=False, bi_data=False, clamp_len=-1, same_length=False, summary_type='last', summary_use_proj=True, summary_activation='tanh', summary_last_dropout=0.1, start_n_top=5, end_n_top=5, pad_token_id=5, bos_token_id=1, eos_token_id=2, **kwargs)
¶
Constructs XLNetConfig.
Source code in mindnlp\transformers\models\xlnet\configuration_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet
¶
Tokenization classes for XLNet model.
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer
¶
Bases: PreTrainedTokenizer
Construct an XLNet tokenizer. Based on SentencePiece.
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
SentencePiece file (generally has a .spm extension) that contains the vocabulary necessary to instantiate a tokenizer.
TYPE:
|
do_lower_case
|
Whether to lowercase the input when tokenizing.
TYPE:
|
remove_space
|
Whether to strip the text when tokenizing (removing excess spaces before and after the string).
TYPE:
|
keep_accents
|
Whether to keep accents when tokenizing.
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:
|
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:
|
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:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
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:
|
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:
|
additional_special_tokens
|
Additional special tokens used by the tokenizer.
TYPE:
|
sp_model_kwargs
|
Will be passed to the
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
sp_model |
The SentencePiece processor that is used for every conversion (string, tokens and IDs).
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.vocab_size
property
¶
Returns the vocabulary size of the XLNetTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the XLNetTokenizer class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The vocabulary size of the tokenizer. |
This method calculates and returns the size of the vocabulary used by the XLNetTokenizer. The vocabulary size is determined by the number of unique tokens present in the tokenizer's sp_model.
Note
The vocabulary size represents the number of distinct tokens that the tokenizer can recognize and encode.
Example
>>> tokenizer = XLNetTokenizer()
>>> size = tokenizer.vocab_size()
>>> print(size)
32000
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.__getstate__()
¶
Method 'getstate' in the class 'XLNetTokenizer'.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetTokenizer class. Represents the current XLNetTokenizer object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
This method returns a dictionary representing the state of the XLNetTokenizer object. The 'sp_model' key in the dictionary is set to None before returning. |
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.__init__(vocab_file, do_lower_case=False, remove_space=True, keep_accents=False, bos_token='<s>', eos_token='</s>', unk_token='<unk>', sep_token='<sep>', pad_token='<pad>', cls_token='<cls>', mask_token='<mask>', additional_special_tokens=['<eop>', '<eod>'], sp_model_kwargs=None, **kwargs)
¶
Initialize an XLNetTokenizer object.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
do_lower_case
|
Whether to lowercase the input tokens. Defaults to False.
TYPE:
|
remove_space
|
Whether to remove spaces in the input tokens. Defaults to True.
TYPE:
|
keep_accents
|
Whether to keep accents in the input tokens. Defaults to False.
TYPE:
|
bos_token
|
Beginning of sentence token. Defaults to '
TYPE:
|
eos_token
|
End of sentence token. Defaults to ''.
TYPE:
|
unk_token
|
Unknown token. Defaults to '
TYPE:
|
sep_token
|
Separator token. Defaults to '
TYPE:
|
pad_token
|
Padding token. Defaults to '
TYPE:
|
cls_token
|
Classification token. Defaults to '
TYPE:
|
mask_token
|
Mask token. Defaults to '
TYPE:
|
additional_special_tokens
|
Additional special tokens to include.
Defaults to ['
TYPE:
|
sp_model_kwargs
|
SentencePiece model keyword arguments. Defaults to None.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the mask_token is not a string. |
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.__setstate__(d)
¶
This method setstate is defined in the class XLNetTokenizer and is used to set the internal state of the object based on the provided dictionary 'd'.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetTokenizer class.
TYPE:
|
d
|
A dictionary containing the state information to be set. The keys and values in the dictionary are used to update the internal state of the XLNetTokenizer object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. This method does not return any value. |
| RAISES | DESCRIPTION |
|---|---|
None
|
However, potential exceptions that could be raised include:
|
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLNet sequence has the following format:
- single sequence:
X <sep> <cls> - pair of sequences:
A <sep> B <sep> <cls>
| 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\xlnet\tokenization_xlnet.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (strings for sub-words) in a single string.
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
368 369 370 371 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.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. An XLNet sequence pair mask has the following format:
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If token_ids_1 is None, this method only returns the first portion of the mask (0s).
| 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\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.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\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.get_vocab()
¶
Returns the vocabulary of the XLNetTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetTokenizer class.
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary containing the vocabulary of the XLNetTokenizer. The keys of the dictionary are the tokens, and the values are their corresponding indices. |
Example
>>> tokenizer = XLNetTokenizer()
>>> tokenizer.get_vocab()
{'<s>': 0, '<pad>': 1, '</s>': 2, '<unk>': 3, '<mask>': 4, 'hello': 5, 'world': 6}
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.preprocess_text(inputs)
¶
This method preprocesses the input text according to the specified configuration settings.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetTokenizer class.
TYPE:
|
inputs
|
The input text to be preprocessed. It should be a string representation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The preprocessed text based on the applied configuration settings. |
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary of the XLNetTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the XLNetTokenizer class.
TYPE:
|
save_directory
|
The directory path where the vocabulary will be saved.
TYPE:
|
filename_prefix
|
An optional prefix for the filename of the saved vocabulary. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the path to the saved vocabulary file. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the specified save_directory does not exist. |
PermissionError
|
If the specified save_directory is not accessible for writing. |
Note
- The saved vocabulary file will be named as per the following format:
'
-vocab.txt' if filename_prefix is provided, otherwise 'vocab.txt'. - If the provided save_directory is the same as the current vocabulary file's directory and the vocabulary file already exists, it will be copied to the save_directory.
- If the current vocabulary file does not exist, a new vocabulary file will be created in the save_directory using the serialized model from the sp_model attribute of the tokenizer.
Example
>>> tokenizer = XLNetTokenizer()
>>> save_dir = '/path/to/save'
>>> prefix = 'english'
>>> vocab_file = tokenizer.save_vocabulary(save_dir, prefix)
>>> print(f"Vocabulary saved at: {vocab_file}")
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast
¶
Tokenization classes for XLNet model.
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" XLNet tokenizer (backed by HuggingFace's tokenizers library). Based on Unigram.
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
|
SentencePiece file (generally has a .spm extension) that contains the vocabulary necessary to instantiate a tokenizer.
TYPE:
|
do_lower_case
|
Whether to lowercase the input when tokenizing.
TYPE:
|
remove_space
|
Whether to strip the text when tokenizing (removing excess spaces before and after the string).
TYPE:
|
keep_accents
|
Whether to keep accents when tokenizing.
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:
|
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:
|
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:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
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:
|
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:
|
additional_special_tokens
|
Additional special tokens used by the tokenizer.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
sp_model |
The SentencePiece processor that is used for every conversion (string, tokens and IDs).
TYPE:
|
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet_fast.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast.can_save_slow_tokenizer: bool
property
¶
Checks if the slow tokenizer can be saved.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the XLNetTokenizerFast class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Returns True if the slow tokenizer can be saved, False otherwise.
TYPE:
|
The 'can_save_slow_tokenizer' method checks if the slow tokenizer can be saved by verifying the existence of the vocabulary file. It returns a boolean value indicating whether the slow tokenizer can be saved or not. If the 'vocab_file' attribute is not set or if the file does not exist, the method returns False. Otherwise, it returns True.
Note that this method does not raise any exceptions.
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast.__init__(vocab_file=None, tokenizer_file=None, do_lower_case=False, remove_space=True, keep_accents=False, bos_token='<s>', eos_token='</s>', unk_token='<unk>', sep_token='<sep>', pad_token='<pad>', cls_token='<cls>', mask_token='<mask>', additional_special_tokens=['<eop>', '<eod>'], **kwargs)
¶
init
Initializes an instance of the XLNetTokenizerFast class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
vocab_file
|
The path to the vocabulary file. Defaults to None.
TYPE:
|
tokenizer_file
|
The path to the tokenizer file. Defaults to None.
TYPE:
|
do_lower_case
|
Whether to convert tokens to lowercase. Defaults to False.
TYPE:
|
remove_space
|
Whether to remove spaces from tokens. Defaults to True.
TYPE:
|
keep_accents
|
Whether to keep accents in tokens. Defaults to False.
TYPE:
|
bos_token
|
The beginning of sentence token. Defaults to '
TYPE:
|
eos_token
|
The end of sentence token. Defaults to ''.
TYPE:
|
unk_token
|
The unknown token. Defaults to '
TYPE:
|
sep_token
|
The separator token. Defaults to '
TYPE:
|
pad_token
|
The padding token. Defaults to '
TYPE:
|
cls_token
|
The classification token. Defaults to '
TYPE:
|
mask_token
|
The mask token. Defaults to '
TYPE:
|
additional_special_tokens
|
Additional special tokens. Defaults to ['
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If invalid input is provided for the parameters. |
TypeError
|
If the input type for the parameters is incorrect. |
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet_fast.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLNet sequence has the following format:
- single sequence:
X <sep> <cls> - pair of sequences:
A <sep> B <sep> <cls>
| 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\xlnet\tokenization_xlnet_fast.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast.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. An XLNet sequence pair mask has the following format:
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If token_ids_1 is None, this method only returns the first portion of the mask (0s).
| 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\xlnet\tokenization_xlnet_fast.py
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 | |
mindnlp.transformers.models.xlnet.tokenization_xlnet_fast.XLNetTokenizerFast.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary for a fast tokenizer to a specified directory.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the XLNetTokenizerFast class.
TYPE:
|
save_directory
|
The directory path where the vocabulary will be saved.
TYPE:
|
filename_prefix
|
A prefix for the filename. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the path to the saved vocabulary file. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the fast tokenizer does not have the necessary information to save the vocabulary for a slow tokenizer. |
OSError
|
If the save_directory does not exist or is not a valid directory. |
IOError
|
If an error occurs while copying the vocabulary file to the specified directory. |
Source code in mindnlp\transformers\models\xlnet\tokenization_xlnet_fast.py
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 | |