mLUKE

## [](#overview)Overview

The mLUKE model was proposed in [mLUKE: The Power of Entity Representations in Multilingual Pretrained Language Models](https://arxiv.org/abs/2110.08151) by Ryokan Ri, Ikuya Yamada, and Yoshimasa Tsuruoka. It’s a multilingual extension of the [LUKE model](https://arxiv.org/abs/2010.01057) trained on the basis of XLM-RoBERTa.

It is based on XLM-RoBERTa and adds entity embeddings, which helps improve performance on various downstream tasks involving reasoning about entities such as named entity recognition, extractive question answering, relation classification, cloze-style knowledge completion.

The abstract from the paper is the following:

_Recent studies have shown that multilingual pretrained language models can be effectively improved with cross-lingual alignment information from Wikipedia entities. However, existing methods only exploit entity information in pretraining and do not explicitly use entities in downstream tasks. In this study, we explore the effectiveness of leveraging entity representations for downstream cross-lingual tasks. We train a multilingual language model with 24 languages with entity representations and show the model consistently outperforms word-based pretrained models in various cross-lingual transfer tasks. We also analyze the model and the key insight is that incorporating entity representations into the input allows us to extract more language-agnostic features. We also evaluate the model with a multilingual cloze prompt task with the mLAMA dataset. We show that entity-based prompt elicits correct factual knowledge more likely than using only word representations._

One can directly plug in the weights of mLUKE into a LUKE model, like so:

```
from transformers import LukeModel

model = LukeModel.from_pretrained("studio-ousia/mluke-base")```

Note that mLUKE has its own tokenizer, [MLukeTokenizer](/docs/transformers/v4.30.0/en/model_doc/mluke#transformers.MLukeTokenizer). You can initialize it as follows:

```
from transformers import MLukeTokenizer

tokenizer = MLukeTokenizer.from_pretrained("studio-ousia/mluke-base")```

As mLUKE’s architecture is equivalent to that of LUKE, one can refer to [LUKE’s documentation page](luke) for all tips, code examples and notebooks.

This model was contributed by [ryo0634](https://huggingface.co/ryo0634). The original code can be found [here](https://github.com/studio-ousia/luke).

## [](#transformers.MLukeTokenizer)MLukeTokenizer

### class transformers.MLukeTokenizer

[](#transformers.MLukeTokenizer)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/mluke/tokenization_mluke.py#L147)

( vocab\_fileentity\_vocab\_filebos\_token = '
'eos\_token = '
'sep\_token = '
'cls\_token = '
'unk\_token = '<unk>'pad\_token = '<pad>'mask\_token = '<mask>'task = Nonemax\_entity\_length = 32max\_mention\_length = 30entity\_token\_1 = '<ent>'entity\_token\_2 = '<ent2>'entity\_unk\_token = '\[UNK\]'entity\_pad\_token = '\[PAD\]'entity\_mask\_token = '\[MASK\]'entity\_mask2\_token = '\[MASK2\]'sp\_model\_kwargs: typing.Union\[typing.Dict\[str, typing.Any\], NoneType\] = None\*\*kwargs )

Adapted from [XLMRobertaTokenizer](/docs/transformers/v4.30.0/en/model_doc/xlm-roberta#transformers.XLMRobertaTokenizer) and [LukeTokenizer](/docs/transformers/v4.30.0/en/model_doc/luke#transformers.LukeTokenizer). Based on [SentencePiece](https://github.com/google/sentencepiece).

This tokenizer inherits from [PreTrainedTokenizer](/docs/transformers/v4.30.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer) which contains most of the main methods. Users should refer to this superclass for more information regarding those methods.

#### \_\_call\_\_

[](#transformers.MLukeTokenizer.__call__)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/mluke/tokenization_mluke.py#L364)

( text: typing.Union\[str, typing.List\[str\]\]text\_pair: typing.Union\[str, typing.List\[str\], NoneType\] = Noneentity\_spans: typing.Union\[typing.List\[typing.Tuple\[int, int\]\], typing.List\[typing.List\[typing.Tuple\[int, int\]\]\], NoneType\] = Noneentity\_spans\_pair: typing.Union\[typing.List\[typing.Tuple\[int, int\]\], typing.List\[typing.List\[typing.Tuple\[int, int\]\]\], NoneType\] = Noneentities: typing.Union\[typing.List\[str\], typing.List\[typing.List\[str\]\], NoneType\] = Noneentities\_pair: typing.Union\[typing.List\[str\], typing.List\[typing.List\[str\]\], NoneType\] = Noneadd\_special\_tokens: bool = Truepadding: typing.Union\[bool, str, transformers.utils.generic.PaddingStrategy\] = Falsetruncation: typing.Union\[bool, str, transformers.tokenization\_utils\_base.TruncationStrategy\] = Nonemax\_length: typing.Optional\[int\] = Nonemax\_entity\_length: typing.Optional\[int\] = Nonestride: int = 0is\_split\_into\_words: typing.Optional\[bool\] = Falsepad\_to\_multiple\_of: typing.Optional\[int\] = Nonereturn\_tensors: typing.Union\[str, transformers.utils.generic.TensorType, NoneType\] = Nonereturn\_token\_type\_ids: typing.Optional\[bool\] = Nonereturn\_attention\_mask: typing.Optional\[bool\] = Nonereturn\_overflowing\_tokens: bool = Falsereturn\_special\_tokens\_mask: bool = Falsereturn\_offsets\_mapping: bool = Falsereturn\_length: bool = Falseverbose: bool = True\*\*kwargs ) → [BatchEncoding](/docs/transformers/v4.30.0/en/main_classes/tokenizer#transformers.BatchEncoding)

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.

#### save\_vocabulary

[](#transformers.MLukeTokenizer.save_vocabulary)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/mluke/tokenization_mluke.py#L1488)

( save\_directory: strfilename\_prefix: typing.Optional\[str\] = None )