luke
mindnlp.transformers.models.luke.modeling_luke
¶
MindSpore LUKE model.
mindnlp.transformers.models.luke.modeling_luke.BaseLukeModelOutput
dataclass
¶
Bases: BaseModelOutput
Base class for model's outputs, with potential hidden states and attentions.
| PARAMETER | DESCRIPTION |
|---|---|
last_hidden_state
|
Sequence of hidden-states at the output of the last layer of the model.
TYPE:
|
entity_last_hidden_state
|
Sequence of entity hidden-states at the output of the last layer of the model.
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.BaseLukeModelOutputWithPooling
dataclass
¶
Bases: BaseModelOutputWithPooling
Base class for outputs of the LUKE model.
| PARAMETER | DESCRIPTION |
|---|---|
last_hidden_state
|
Sequence of hidden-states at the output of the last layer of the model.
TYPE:
|
entity_last_hidden_state
|
Sequence of entity hidden-states at the output of the last layer of the model.
TYPE:
|
pooler_output
|
Last layer hidden-state of the first token of the sequence (classification token) further processed by a Linear layer and a Tanh activation function.
TYPE:
|
hidden_states
|
Tuple of
TYPE:
|
entity_hidden_states
|
Tuple of
TYPE:
|
attentions
|
Tuple of
TYPE:
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.EntityClassificationOutput
dataclass
¶
Bases: ModelOutput
Outputs of entity classification models.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
Classification scores (before SoftMax).
TYPE:
|
hidden_states
|
Tuple of
TYPE:
|
entity_hidden_states
|
Tuple of
TYPE:
|
attentions
|
Tuple of
TYPE:
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.EntityPairClassificationOutput
dataclass
¶
Bases: ModelOutput
Outputs of entity pair classification models.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
Classification scores (before SoftMax).
TYPE:
|
hidden_states
|
Tuple of
TYPE:
|
entity_hidden_states
|
Tuple of
TYPE:
|
attentions
|
Tuple of
TYPE:
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.EntitySpanClassificationOutput
dataclass
¶
Bases: ModelOutput
Outputs of entity span classification models.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
Classification scores (before SoftMax).
TYPE:
|
hidden_states
|
Tuple of
TYPE:
|
entity_hidden_states
|
Tuple of
TYPE:
|
attentions
|
Tuple of
TYPE:
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeEmbeddings
¶
Bases: Module
Same as BertEmbeddings with a tiny tweak for positional embeddings indexing.
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeEmbeddings.create_position_ids_from_inputs_embeds(inputs_embeds)
¶
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
| PARAMETER | DESCRIPTION |
|---|---|
inputs_embeds
|
mindspore.Tensor
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntityClassification
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntityClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size,) or (batch_size, num_labels), optional):
Labels for computing the classification loss. If the shape is (batch_size,), the cross entropy loss is
used for the single-label classification. In this case, labels should contain the indices that should be in
[0, ..., config.num_labels - 1]. If the shape is (batch_size, num_labels), the binary cross entropy
loss is used for the multi-label classification. In this case, labels should only contain [0, 1], where 0
and 1 indicate false and true, respectively.
Returns:
Examples:
>>> from transformers import AutoTokenizer, LukeForEntityClassification
>>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-open-entity")
>>> model = LukeForEntityClassification.from_pretrained("studio-ousia/luke-large-finetuned-open-entity")
>>> text = "Beyoncé lives in Los Angeles."
>>> entity_spans = [(0, 7)] # character-based entity span corresponding to "Beyoncé"
>>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="ms")
>>> outputs = model(**inputs)
>>> logits = outputs.logits
>>> predicted_class_idx = logits.argmax(-1).item()
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
Predicted class: person
Source code in mindnlp\transformers\models\luke\modeling_luke.py
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntityPairClassification
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntityPairClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size,) or (batch_size, num_labels), optional):
Labels for computing the classification loss. If the shape is (batch_size,), the cross entropy loss is
used for the single-label classification. In this case, labels should contain the indices that should be in
[0, ..., config.num_labels - 1]. If the shape is (batch_size, num_labels), the binary cross entropy
loss is used for the multi-label classification. In this case, labels should only contain [0, 1], where 0
and 1 indicate false and true, respectively.
Returns:
Examples:
>>> from transformers import AutoTokenizer, LukeForEntityPairClassification
>>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-tacred")
>>> model = LukeForEntityPairClassification.from_pretrained("studio-ousia/luke-large-finetuned-tacred")
>>> text = "Beyoncé lives in Los Angeles."
>>> entity_spans = [
... (0, 7),
... (17, 28),
... ] # character-based entity spans corresponding to "Beyoncé" and "Los Angeles"
>>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="ms")
>>> outputs = model(**inputs)
>>> logits = outputs.logits
>>> predicted_class_idx = logits.argmax(-1).item()
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
Predicted class: per:cities_of_residence
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntitySpanClassification
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForEntitySpanClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, entity_start_positions=None, entity_end_positions=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
entity_start_positions (mindspore.Tensor):
The start positions of entities in the word token sequence.
entity_end_positions (mindspore.Tensor):
The end positions of entities in the word token sequence.
labels (mindspore.Tensor of shape (batch_size, entity_length) or (batch_size, entity_length, num_labels), optional):
Labels for computing the classification loss. If the shape is (batch_size, entity_length), the cross
entropy loss is used for the single-label classification. In this case, labels should contain the indices
that should be in [0, ..., config.num_labels - 1]. If the shape is (batch_size, entity_length,
num_labels), the binary cross entropy loss is used for the multi-label classification. In this case,
labels should only contain [0, 1], where 0 and 1 indicate false and true, respectively.
Returns:
Examples:
>>> from transformers import AutoTokenizer, LukeForEntitySpanClassification
>>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-conll-2003")
>>> model = LukeForEntitySpanClassification.from_pretrained("studio-ousia/luke-large-finetuned-conll-2003")
>>> text = "Beyoncé lives in Los Angeles"
# List all possible entity spans in the text
>>> word_start_positions = [0, 8, 14, 17, 21] # character-based start positions of word tokens
>>> word_end_positions = [7, 13, 16, 20, 28] # character-based end positions of word tokens
>>> entity_spans = []
>>> for i, start_pos in enumerate(word_start_positions):
... for end_pos in word_end_positions[i:]:
... entity_spans.append((start_pos, end_pos))
>>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="ms")
>>> outputs = model(**inputs)
>>> logits = outputs.logits
>>> predicted_class_indices = logits.argmax(-1).squeeze().tolist()
>>> for span, predicted_class_idx in zip(entity_spans, predicted_class_indices):
... if predicted_class_idx != 0:
... print(text[span[0] : span[1]], model.config.id2label[predicted_class_idx])
Beyoncé PER
Los Angeles LOC
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForMaskedLM
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForMaskedLM.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, labels=None, entity_labels=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size, sequence_length), optional):
Labels for computing the masked language modeling loss. Indices should be in [-100, 0, ...,
config.vocab_size] (see input_ids docstring) Tokens with indices set to -100 are ignored (masked), the
loss is only computed for the tokens with labels in [0, ..., config.vocab_size]
entity_labels (mindspore.Tensor of shape (batch_size, entity_length), optional):
Labels for computing the masked language modeling loss. Indices should be in [-100, 0, ...,
config.vocab_size] (see input_ids docstring) Tokens with indices set to -100 are ignored (masked), the
loss is only computed for the tokens with labels in [0, ..., config.vocab_size]
Returns:
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForMultipleChoice
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForMultipleChoice.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForQuestionAnswering
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForQuestionAnswering.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, start_positions=None, end_positions=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForSequenceClassification
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForSequenceClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForTokenClassification
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 | |
mindnlp.transformers.models.luke.modeling_luke.LukeForTokenClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
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\luke\modeling_luke.py
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 | |
mindnlp.transformers.models.luke.modeling_luke.LukeLMHead
¶
Bases: Module
Roberta Head for masked language modeling.
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeMaskedLMOutput
dataclass
¶
Bases: ModelOutput
Base class for model's outputs, with potential hidden states and attentions.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
The sum of masked language modeling (MLM) loss and entity prediction loss.
TYPE:
|
mlm_loss
|
Masked language modeling (MLM) loss.
TYPE:
|
mep_loss
|
Masked entity prediction (MEP) loss.
TYPE:
|
logits
|
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
TYPE:
|
entity_logits
|
Prediction scores of the entity prediction head (scores for each entity vocabulary token before SoftMax).
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeModel
¶
Bases: LukePreTrainedModel
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 1025 1026 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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeModel.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, entity_ids=None, entity_attention_mask=None, entity_token_type_ids=None, entity_position_ids=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from transformers import AutoTokenizer, LukeModel
>>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-base")
>>> model = LukeModel.from_pretrained("studio-ousia/luke-base")
# Compute the contextualized entity representation corresponding to the entity mention "Beyoncé"
>>> text = "Beyoncé lives in Los Angeles."
>>> entity_spans = [(0, 7)] # character-based entity span corresponding to "Beyoncé"
>>> encoding = tokenizer(text, entity_spans=entity_spans, add_prefix_space=True, return_tensors="ms")
>>> outputs = model(**encoding)
>>> word_last_hidden_state = outputs.last_hidden_state
>>> entity_last_hidden_state = outputs.entity_last_hidden_state
# Input Wikipedia entities to obtain enriched contextualized representations of word tokens
>>> text = "Beyoncé lives in Los Angeles."
>>> entities = [
... "Beyoncé",
... "Los Angeles",
... ] # Wikipedia entity titles corresponding to the entity mentions "Beyoncé" and "Los Angeles"
>>> entity_spans = [
... (0, 7),
... (17, 28),
... ] # character-based entity spans corresponding to "Beyoncé" and "Los Angeles"
>>> encoding = tokenizer(
... text, entities=entities, entity_spans=entity_spans, add_prefix_space=True, return_tensors="ms"
... )
>>> outputs = model(**encoding)
>>> word_last_hidden_state = outputs.last_hidden_state
>>> entity_last_hidden_state = outputs.entity_last_hidden_state
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 1025 1026 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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeModel.get_extended_attention_mask(word_attention_mask, entity_attention_mask)
¶
Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
| PARAMETER | DESCRIPTION |
|---|---|
word_attention_mask
|
Attention mask for word tokens with ones indicating tokens to attend to, zeros for tokens to ignore.
TYPE:
|
entity_attention_mask
|
Attention mask for entity tokens with ones indicating tokens to attend to, zeros for tokens to ignore.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeMultipleChoiceModelOutput
dataclass
¶
Bases: ModelOutput
Outputs of multiple choice models.
| 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:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukePreTrainedModel
¶
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeQuestionAnsweringModelOutput
dataclass
¶
Bases: ModelOutput
Outputs of question answering models.
| 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:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeSequenceClassifierOutput
dataclass
¶
Bases: ModelOutput
Outputs of sentence classification models.
| 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:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.LukeTokenClassifierOutput
dataclass
¶
Bases: ModelOutput
Base class for outputs of token classification models.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Classification loss.
TYPE:
|
logits
|
Classification scores (before SoftMax).
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
TYPE:
|
entity_hidden_states
|
Tuple of
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\luke\modeling_luke.py
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 | |
mindnlp.transformers.models.luke.modeling_luke.create_position_ids_from_input_ids(input_ids, padding_idx)
¶
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's utils.make_positions.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
mindspore.Tensor x:
|
Source code in mindnlp\transformers\models\luke\modeling_luke.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
mindnlp.transformers.models.luke.configuration_luke
¶
LUKE configuration
mindnlp.transformers.models.luke.configuration_luke.LukeConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [LukeModel]. It is used to instantiate a LUKE
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 LUKE
studio-ousia/luke-base 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 LUKE model. Defines the number of different tokens that can be represented by the
TYPE:
|
entity_vocab_size
|
Entity vocabulary size of the LUKE model. Defines the number of different entities that can be represented
by the
TYPE:
|
hidden_size
|
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
entity_emb_size
|
The number of dimensions of the entity embedding.
TYPE:
|
num_hidden_layers
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size
|
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act
|
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob
|
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob
|
The dropout ratio for the attention probabilities.
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:
|
type_vocab_size
|
The vocabulary size of the
TYPE:
|
initializer_range
|
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps
|
The epsilon used by the layer normalization layers.
TYPE:
|
use_entity_aware_attention
|
Whether or not the model should use the entity-aware self-attention mechanism proposed in LUKE: Deep Contextualized Entity Representations with Entity-aware Self-attention (Yamada et al.).
TYPE:
|
classifier_dropout
|
The dropout ratio for the classification head.
TYPE:
|
pad_token_id
|
Padding token id.
TYPE:
|
bos_token_id
|
Beginning of stream token id.
TYPE:
|
eos_token_id
|
End of stream token id.
TYPE:
|
>>> from transformers import LukeConfig, LukeModel
>>> # Initializing a LUKE configuration
>>> configuration = LukeConfig()
>>> # Initializing a model from the configuration
>>> model = LukeModel(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\luke\configuration_luke.py
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 | |
mindnlp.transformers.models.luke.configuration_luke.LukeConfig.__init__(vocab_size=50267, entity_vocab_size=500000, hidden_size=768, entity_emb_size=256, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, hidden_act='gelu', hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position_embeddings=512, type_vocab_size=2, initializer_range=0.02, layer_norm_eps=1e-12, use_entity_aware_attention=True, classifier_dropout=None, pad_token_id=1, bos_token_id=0, eos_token_id=2, **kwargs)
¶
Constructs LukeConfig.
Source code in mindnlp\transformers\models\luke\configuration_luke.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 | |
mindnlp.transformers.models.luke.tokenization_luke
¶
Tokenization classes for LUKE.
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer
¶
Bases: PreTrainedTokenizer
Constructs a LUKE tokenizer, derived from the GPT-2 tokenizer, using byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import LukeTokenizer
...
>>> tokenizer = LukeTokenizer.from_pretrained("studio-ousia/luke-base")
>>> tokenizer("Hello world")["input_ids"]
[0, 31414, 232, 2]
>>> tokenizer(" Hello world")["input_ids"]
[0, 20920, 232, 2]
You can get around that behavior by passing add_prefix_space=True when instantiating this tokenizer or when you
call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True, this tokenizer will add a space before each word (even the first one).
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods. It also creates entity sequences, namely
entity_ids, entity_attention_mask, entity_token_type_ids, and entity_position_ids to be used by the LUKE
model.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
merges_file
|
Path to the merges file.
TYPE:
|
entity_vocab_file
|
Path to the entity vocabulary file.
TYPE:
|
task
|
Task for which you want to prepare sequences. One of
TYPE:
|
max_entity_length
|
The maximum length of
TYPE:
|
max_mention_length
|
The maximum number of tokens inside an entity span.
TYPE:
|
entity_token_1
|
The special token used to represent an entity span in a word token sequence. This token is only used when
TYPE:
|
entity_token_2
|
The special token used to represent an entity span in a word token sequence. This token is only used when
TYPE:
|
errors
|
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
TYPE:
|
bos_token
|
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token. When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the
TYPE:
|
eos_token
|
The end of sequence token. When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the
TYPE:
|
sep_token
|
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for sequence classification or for a text and a question for question answering. It is also used as the last token of a sequence built with special tokens.
TYPE:
|
cls_token
|
The classifier token which is used when doing sequence classification (classification of the whole sequence instead of per-token classification). It is the first token of the sequence when built with special tokens.
TYPE:
|
unk_token
|
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
mask_token
|
The token used for masking values. This is the token used when training this model with masked language modeling. This is the token which the model will try to predict.
TYPE:
|
add_prefix_space
|
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (LUKE tokenizer detect beginning of words by the preceding space).
TYPE:
|
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 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 1025 1026 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 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 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 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 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.vocab_size
property
¶
Returns the size of the vocabulary.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the LukeTokenizer class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of items in the encoder, representing the size of the vocabulary. |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.__call__(text, text_pair=None, entity_spans=None, entity_spans_pair=None, entities=None, entities_pair=None, add_special_tokens=True, padding=False, truncation=None, max_length=None, max_entity_length=None, stride=0, is_split_into_words=False, pad_to_multiple_of=None, return_tensors=None, return_token_type_ids=None, return_attention_mask=None, return_overflowing_tokens=False, return_special_tokens_mask=False, return_offsets_mapping=False, return_length=False, verbose=True, **kwargs)
¶
Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of sequences, depending on the task you want to prepare them for.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The sequence or batch of sequences to be encoded. Each sequence must be a string. Note that this tokenizer does not support tokenization based on pretokenized strings.
TYPE:
|
text_pair
|
The sequence or batch of sequences to be encoded. Each sequence must be a string. Note that this tokenizer does not support tokenization based on pretokenized strings.
TYPE:
|
entity_spans
|
The sequence or batch of sequences of entity spans to be encoded. Each sequence consists of tuples each
with two integers denoting character-based start and end positions of entities. If you specify
TYPE:
|
entity_spans_pair
|
The sequence or batch of sequences of entity spans to be encoded. Each sequence consists of tuples each
with two integers denoting character-based start and end positions of entities. If you specify the
TYPE:
|
entities
|
The sequence or batch of sequences of entities to be encoded. Each sequence consists of strings
representing entities, i.e., special entities (e.g., [MASK]) or entity titles of Wikipedia (e.g., Los
Angeles). This argument is ignored if you specify the
TYPE:
|
entities_pair
|
The sequence or batch of sequences of entities to be encoded. Each sequence consists of strings
representing entities, i.e., special entities (e.g., [MASK]) or entity titles of Wikipedia (e.g., Los
Angeles). This argument is ignored if you specify the
TYPE:
|
max_entity_length
|
The maximum length of
TYPE:
|
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.__init__(vocab_file, merges_file, entity_vocab_file, task=None, max_entity_length=32, max_mention_length=30, entity_token_1='<ent>', entity_token_2='<ent2>', entity_unk_token='[UNK]', entity_pad_token='[PAD]', entity_mask_token='[MASK]', entity_mask2_token='[MASK2]', errors='replace', bos_token='<s>', eos_token='</s>', sep_token='</s>', cls_token='<s>', unk_token='<unk>', pad_token='<pad>', mask_token='<mask>', add_prefix_space=False, **kwargs)
¶
Initialize the LukeTokenizer class.
This method initializes an instance of the LukeTokenizer class. It takes the following parameters:
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
vocab_file
|
The path to the vocabulary file.
TYPE:
|
merges_file
|
The path to the merges file.
TYPE:
|
entity_vocab_file
|
The path to the entity vocabulary file.
TYPE:
|
task
|
The task for which the tokenizer is used. Defaults to None.
TYPE:
|
max_entity_length
|
The maximum length of the entity. Defaults to 32.
TYPE:
|
max_mention_length
|
The maximum length of the mention. Defaults to 30.
TYPE:
|
entity_token_1
|
The first entity token. Defaults to '
TYPE:
|
entity_token_2
|
The second entity token. Defaults to '
TYPE:
|
entity_unk_token
|
The unknown entity token. Defaults to '[UNK]'.
TYPE:
|
entity_pad_token
|
The padding entity token. Defaults to '[PAD]'.
TYPE:
|
entity_mask_token
|
The masked entity token. Defaults to '[MASK]'.
TYPE:
|
entity_mask2_token
|
The second masked entity token. Defaults to '[MASK2]'.
TYPE:
|
errors
|
The error handling strategy. Defaults to 'replace'.
TYPE:
|
bos_token
|
The beginning of sentence token. Defaults to '
TYPE:
|
eos_token
|
The end of sentence token. Defaults to ''.
TYPE:
|
sep_token
|
The separator token. Defaults to ''.
TYPE:
|
cls_token
|
The classification token. Defaults to '
TYPE:
|
unk_token
|
The unknown token. Defaults to '
TYPE:
|
pad_token
|
The padding token. Defaults to '
TYPE:
|
mask_token
|
The masked token. Defaults to '
TYPE:
|
add_prefix_space
|
Whether to add space before the token. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the specified entity special token is not found in the entity vocabulary file. |
ValueError
|
If the task is not supported. Select task from ['entity_classification', 'entity_pair_classification', 'entity_span_classification'] only. |
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.bpe(token)
¶
This method 'bpe' in the class 'LukeTokenizer' performs Byte Pair Encoding (BPE) on the input token.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the LukeTokenizer class.
TYPE:
|
token
|
The input token to be processed using Byte Pair Encoding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The processed token after applying Byte Pair Encoding. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input token is empty. |
TypeError
|
If the input token is not a string. |
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A LUKE sequence has the following format:
- single sequence:
<s> X </s> - pair of sequences:
<s> A </s></s> B </s>
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
558 559 560 561 562 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.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. LUKE 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\luke\tokenization_luke.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.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\luke\tokenization_luke.py
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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.get_vocab()
¶
Retrieves the vocabulary dictionary for the 'LukeTokenizer' class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the 'LukeTokenizer' class.
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary containing the vocabulary of the tokenizer. The keys are the tokens and the values are their corresponding IDs. |
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.pad(encoded_inputs, padding=True, max_length=None, max_entity_length=None, pad_to_multiple_of=None, return_attention_mask=None, return_tensors=None, verbose=True)
¶
Pad a single encoded input or a batch of encoded inputs up to predefined length or to the max sequence length
in the batch. Padding side (left/right) padding token ids are defined at the tokenizer level (with
self.padding_side, self.pad_token_id and self.pad_token_type_id) .. note:: If the encoded_inputs passed
are dictionary of numpy arrays, PyTorch tensors or TensorFlow tensors, the result will use the same type unless
you provide a different tensor type with return_tensors. In the case of PyTorch tensors, you will lose the
specific device of your tensors however.
| PARAMETER | DESCRIPTION |
|---|---|
encoded_inputs
|
Tokenized inputs. Can represent one input ([
TYPE:
|
padding
|
Select a strategy to pad the returned sequences (according to the model's padding side and padding index) among:
TYPE:
|
max_length
|
Maximum length of the returned list and optionally padding length (see above).
TYPE:
|
max_entity_length
|
The maximum length of the entity sequence.
TYPE:
|
pad_to_multiple_of
|
If set will pad the sequence to a multiple of the provided value. This is especially useful to enable
the use of Tensor Cores on NVIDIA hardware with compute capability
TYPE:
|
return_attention_mask
|
Whether to return the attention mask. If left to the default, will return the attention mask according
to the specific tokenizer's default, defined by the
TYPE:
|
return_tensors
|
If set, will return tensors instead of list of python integers. Acceptable values are:
TYPE:
|
verbose
|
Whether or not to print more information and warnings.
TYPE:
|
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.prepare_for_model(ids, pair_ids=None, entity_ids=None, pair_entity_ids=None, entity_token_spans=None, pair_entity_token_spans=None, add_special_tokens=True, padding=False, truncation=None, max_length=None, max_entity_length=None, stride=0, pad_to_multiple_of=None, return_tensors=None, return_token_type_ids=None, return_attention_mask=None, return_overflowing_tokens=False, return_special_tokens_mask=False, return_offsets_mapping=False, return_length=False, verbose=True, prepend_batch_axis=False, **kwargs)
¶
Prepares a sequence of input id, entity id and entity span, or a pair of sequences of inputs ids, entity ids,
entity spans so that it can be used by the model. It adds special tokens, truncates sequences if overflowing
while taking into account the special tokens and manages a moving window (with user defined stride) for
overflowing tokens. Please Note, for pair_ids different than None and truncation_strategy = longest_first
or True, it is not possible to return overflowing tokens. Such a combination of arguments will raise an
error.
| PARAMETER | DESCRIPTION |
|---|---|
ids
|
Tokenized input ids of the first sequence.
TYPE:
|
pair_ids
|
Tokenized input ids of the second sequence.
TYPE:
|
entity_ids
|
Entity ids of the first sequence.
TYPE:
|
pair_entity_ids
|
Entity ids of the second sequence.
TYPE:
|
entity_token_spans
|
Entity spans of the first sequence.
TYPE:
|
pair_entity_token_spans
|
Entity spans of the second sequence.
TYPE:
|
max_entity_length
|
The maximum length of the entity sequence.
TYPE:
|
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
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 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.prepare_for_tokenization(text, is_split_into_words=False, **kwargs)
¶
Prepares the input text for tokenization by adding a prefix space if necessary.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the LukeTokenizer class.
TYPE:
|
text
|
The input text to be tokenized.
TYPE:
|
is_split_into_words
|
A flag indicating if the input text is already split into words. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method modifies the input text in-place. |
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
mindnlp.transformers.models.luke.tokenization_luke.LukeTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to specified directory with an optional filename prefix.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
Instance of LukeTokenizer class.
|
save_directory
|
The directory path where the vocabulary files will be saved.
TYPE:
|
filename_prefix
|
An optional prefix to be added to the filename. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing paths to the saved vocabulary files - vocab_file, merge_file, and entity_vocab_file. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the specified save_directory does not exist. |
IOError
|
If there is an issue with reading or writing the vocabulary files. |
ValueError
|
If the provided filename_prefix is not a string. |
Exception
|
Any other unexpected error that may occur during the execution of the method. |
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
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 | |
mindnlp.transformers.models.luke.tokenization_luke.bytes_to_unicode()
cached
¶
Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control characters the bpe code barfs on.
The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
mindnlp.transformers.models.luke.tokenization_luke.get_pairs(word)
¶
Return set of symbol pairs in a word.
Word is represented as tuple of symbols (symbols being variable-length strings).
Source code in mindnlp\transformers\models\luke\tokenization_luke.py
178 179 180 181 182 183 184 185 186 187 188 189 | |