Transformers 文档

布局XLM

LayoutXLM

概述

LayoutXLM 是由 Yiheng Xu, Tengchao Lv, Lei Cui, Guoxin Wang, Yijuan Lu, Dinei Florencio, Cha Zhang, Furu Wei 在 LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding 中提出的。它是 LayoutLMv2 模型 的多语言扩展,训练于 53 种语言。

论文的摘要如下:

最近,结合文本、布局和图像的多模态预训练在视觉丰富的文档理解任务中取得了SOTA性能,这展示了跨不同模态联合学习的巨大潜力。在本文中,我们提出了LayoutXLM,一个用于多语言文档理解的多模态预训练模型,旨在为视觉丰富的文档理解消除语言障碍。为了准确评估LayoutXLM,我们还引入了一个名为XFUN的多语言表单理解基准数据集,该数据集包含7种语言(中文、日语、西班牙语、法语、意大利语、德语、葡萄牙语)的表单理解样本,并且每种语言的关键值对都经过手动标注。实验结果表明,LayoutXLM模型在XFUN数据集上显著优于现有的SOTA跨语言预训练模型。

该模型由nielsr贡献。原始代码可以在这里找到。

使用技巧和示例

可以直接将LayoutXLM的权重插入到LayoutLMv2模型中,如下所示:

from transformers import LayoutLMv2Model

model = LayoutLMv2Model.from_pretrained("microsoft/layoutxlm-base")

请注意,LayoutXLM 有自己的分词器,基于 LayoutXLMTokenizer/LayoutXLMTokenizerFast。您可以按如下方式初始化它:

from transformers import LayoutXLMTokenizer

tokenizer = LayoutXLMTokenizer.from_pretrained("microsoft/layoutxlm-base")

与LayoutLMv2类似,您可以使用LayoutXLMProcessor(内部依次应用 LayoutLMv2ImageProcessorLayoutXLMTokenizer/LayoutXLMTokenizerFast)来为模型准备所有数据。

由于LayoutXLM的架构与LayoutLMv2相同,可以参考LayoutLMv2的文档页面获取所有提示、代码示例和笔记本。

LayoutXLMTokenizer

transformers.LayoutXLMTokenizer

< >

( vocab_file bos_token = '' eos_token = '' sep_token = '' cls_token = '' unk_token = '' pad_token = '' mask_token = '' cls_token_box = [0, 0, 0, 0] sep_token_box = [1000, 1000, 1000, 1000] pad_token_box = [0, 0, 0, 0] pad_token_label = -100 only_label_first_subword = True sp_model_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None **kwargs )

参数

  • vocab_file (str) — 词汇表文件的路径。
  • bos_token (str, optional, defaults to "<s>") — The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

    在使用特殊标记构建序列时,这不是用于序列开头的标记。使用的标记是cls_token

  • eos_token (str, optional, defaults to "</s>") — The end of sequence token.

    在使用特殊标记构建序列时,这不是用于序列结束的标记。 使用的标记是sep_token

  • sep_token (str, 可选, 默认为 "") — 分隔符标记,用于从多个序列构建序列时,例如用于序列分类的两个序列或用于问答的文本和问题。它也用作使用特殊标记构建的序列的最后一个标记。
  • cls_token (str, 可选, 默认为 "") — 用于序列分类的分类器标记(对整个序列进行分类而不是对每个标记进行分类)。当使用特殊标记构建时,它是序列的第一个标记。
  • unk_token (str, 可选, 默认为 "") — 未知标记。不在词汇表中的标记无法转换为ID,而是设置为这个标记。
  • pad_token (str, optional, defaults to "") — 用于填充的标记,例如在对不同长度的序列进行批处理时使用。
  • mask_token (str, 可选, 默认为 "") — 用于屏蔽值的标记。这是在训练此模型时用于屏蔽语言建模的标记。这是模型将尝试预测的标记。
  • cls_token_box (List[int], optional, defaults to [0, 0, 0, 0]) — 用于特殊 [CLS] 标记的边界框。
  • sep_token_box (List[int], 可选, 默认为 [1000, 1000, 1000, 1000]) — 用于特殊 [SEP] 令牌的边界框。
  • pad_token_box (List[int], 可选, 默认为 [0, 0, 0, 0]) — 用于特殊 [PAD] 令牌的边界框。
  • pad_token_label (int, optional, defaults to -100) — 用于填充标签的标签。默认为-100,这是PyTorch的CrossEntropyLoss的ignore_index
  • only_label_first_subword (bool, 可选, 默认为 True) — 是否仅标记第一个子词,在提供单词标签的情况下。
  • sp_model_kwargs (dict, optional) — Will be passed to the SentencePieceProcessor.__init__() method. The Python wrapper for SentencePiece can be used, among other things, to set:
    • enable_sampling: 启用子词正则化。

    • nbest_size: 用于unigram的采样参数。对于BPE-Dropout无效。

      • nbest_size = {0,1}: No sampling is performed.
      • nbest_size > 1: samples from the nbest_size results.
      • nbest_size < 0: assuming that nbest_size is infinite and samples from the all hypothesis (lattice) using forward-filtering-and-backward-sampling algorithm.
    • alpha: 用于单字采样的平滑参数,以及BPE-dropout的合并操作丢弃概率。

  • sp_model (SentencePieceProcessor) — 用于每次转换(字符串、标记和ID)的SentencePiece处理器。

改编自 RobertaTokenizerXLNetTokenizer。基于 SentencePiece

此分词器继承自PreTrainedTokenizer,其中包含了大部分主要方法。用户应参考此超类以获取有关这些方法的更多信息。

__call__

< >

( text: typing.Union[str, typing.List[str], typing.List[typing.List[str]]] text_pair: typing.Union[typing.List[str], typing.List[typing.List[str]], NoneType] = None boxes: typing.Union[typing.List[typing.List[int]], typing.List[typing.List[typing.List[int]]]] = None word_labels: typing.Union[typing.List[int], typing.List[typing.List[int]], NoneType] = None add_special_tokens: bool = True padding: typing.Union[bool, str, transformers.utils.generic.PaddingStrategy] = False truncation: typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = None max_length: typing.Optional[int] = None stride: int = 0 pad_to_multiple_of: typing.Optional[int] = None padding_side: typing.Optional[bool] = None return_tensors: typing.Union[str, transformers.utils.generic.TensorType, NoneType] = None return_token_type_ids: typing.Optional[bool] = None return_attention_mask: typing.Optional[bool] = None return_overflowing_tokens: bool = False return_special_tokens_mask: bool = False return_offsets_mapping: bool = False return_length: bool = False verbose: bool = True **kwargs ) BatchEncoding

参数

  • text (str, List[str], List[List[str]]) — 要编码的序列或序列批次。每个序列可以是一个字符串、一个字符串列表 (单个示例的单词或一批示例的问题)或一个字符串列表的列表(一批 单词)。
  • text_pair (List[str], List[List[str]]) — 要编码的序列或序列批次。每个序列应该是一个字符串列表 (预分词的字符串)。
  • boxes (List[List[int]], List[List[List[int]]]) — 单词级别的边界框。每个边界框应归一化到0-1000的范围内。
  • word_labels (List[int], List[List[int]], optional) — 单词级别的整数标签(用于诸如FUNSD、CORD等标记分类任务)。
  • add_special_tokens (bool, optional, defaults to True) — 是否使用与模型相关的特殊标记对序列进行编码。
  • padding (bool, str or PaddingStrategy, optional, defaults to False) — Activates and controls padding. Accepts the following values:
    • True or 'longest': Pad to the longest sequence in the batch (or no padding if only a single sequence if provided).
    • 'max_length': Pad to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided.
    • False or 'do_not_pad' (default): No padding (i.e., can output a batch with sequences of different lengths).
  • truncation (bool, str or TruncationStrategy, optional, defaults to False) — Activates and controls truncation. Accepts the following values:
    • True or 'longest_first': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will truncate token by token, removing a token from the longest sequence in the pair if a pair of sequences (or a batch of pairs) is provided.
    • 'only_first': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will only truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
    • 'only_second': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will only truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
    • False or 'do_not_truncate' (default): No truncation (i.e., can output batch with sequence lengths greater than the model maximum admissible input size).
  • max_length (int, optional) — Controls the maximum length to use by one of the truncation/padding parameters.

    如果未设置或设置为None,则在需要截断/填充参数时,将使用预定义的模型最大长度。如果模型没有特定的最大输入长度(如XLNet),则截断/填充到最大长度的功能将被停用。

  • stride (int, 可选, 默认为 0) — 如果设置为一个数字并与 max_length 一起使用,当 return_overflowing_tokens=True 时返回的溢出标记将包含一些来自截断序列末尾的标记, 以提供截断序列和溢出序列之间的一些重叠。此参数的值定义了重叠标记的数量。
  • pad_to_multiple_of (int, 可选) — 如果设置,将序列填充到提供的值的倍数。这对于在计算能力>= 7.5(Volta)的NVIDIA硬件上启用Tensor Cores特别有用。
  • return_tensors (str or TensorType, 可选) — 如果设置,将返回张量而不是Python整数列表。可接受的值有:
    • 'tf': 返回 TensorFlow tf.constant 对象。
    • 'pt': 返回 PyTorch torch.Tensor 对象。
    • 'np': 返回 Numpy np.ndarray 对象。
  • return_token_type_ids (bool, optional) — Whether to return token type IDs. If left to the default, will return the token type IDs according to the specific tokenizer’s default, defined by the return_outputs attribute.

    什么是token type IDs?

  • return_attention_mask (bool, optional) — 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 return_outputs attribute.

    什么是注意力掩码?

  • return_overflowing_tokens (bool, 可选, 默认为 False) — 是否返回溢出的令牌序列。如果提供了一对输入ID序列(或一批对)并且使用了truncation_strategy = longest_firstTrue,则会引发错误而不是返回溢出的令牌。
  • return_special_tokens_mask (bool, optional, defaults to False) — 是否返回特殊令牌掩码信息。
  • return_offsets_mapping (bool, optional, defaults to False) — Whether or not to return (char_start, char_end) for each token.

    这仅在继承自PreTrainedTokenizerFast的快速分词器上可用,如果使用Python的分词器,此方法将引发NotImplementedError

  • return_length (bool, optional, defaults to False) — 是否返回编码输入的长度。
  • verbose (bool, optional, defaults to True) — 是否打印更多信息和警告。
  • **kwargs — 传递给 self.tokenize() 方法

返回

BatchEncoding

一个 BatchEncoding 包含以下字段:

  • input_ids — 要输入模型的标记ID列表。

    什么是输入ID?

  • bbox — 要输入模型的边界框列表。

  • token_type_ids — 要输入模型的标记类型ID列表(当 return_token_type_ids=True 或 如果 “token_type_ids”self.model_input_names 中时)。

    什么是标记类型ID?

  • attention_mask — 指定模型应关注哪些标记的索引列表(当 return_attention_mask=True 或如果 “attention_mask”self.model_input_names 中时)。

    什么是注意力掩码?

  • labels — 要输入模型的标签列表。(当指定了 word_labels 时)。

  • overflowing_tokens — 溢出标记序列列表(当指定了 max_length 并且 return_overflowing_tokens=True 时)。

  • num_truncated_tokens — 被截断的标记数量(当指定了 max_length 并且 return_overflowing_tokens=True 时)。

  • special_tokens_mask — 0和1的列表,1表示添加的特殊标记,0表示 常规序列标记(当 add_special_tokens=True 并且 return_special_tokens_mask=True 时)。

  • length — 输入的长度(当 return_length=True 时)。

主要方法,用于将一个或多个序列或一个或多个序列对进行分词,并为模型准备,这些序列带有单词级别的归一化边界框和可选的标签。

build_inputs_with_special_tokens

< >

( token_ids_0: typing.List[int] token_ids_1: typing.Optional[typing.List[int]] = None ) List[int]

参数

  • token_ids_0 (List[int]) — 特殊令牌将被添加到的ID列表。
  • token_ids_1 (List[int], optional) — 可选的第二个序列对的ID列表。

返回

List[int]

带有适当特殊标记的输入ID列表。

通过连接和添加特殊标记,从序列或序列对构建序列分类任务的模型输入。一个XLM-RoBERTa序列具有以下格式:

  • 单一序列: X
  • 序列对: A B

get_special_tokens_mask

< >

( token_ids_0: typing.List[int] token_ids_1: typing.Optional[typing.List[int]] = None already_has_special_tokens: bool = False ) List[int]

参数

  • token_ids_0 (List[int]) — ID列表.
  • token_ids_1 (List[int], optional) — 可选的第二个序列对的ID列表。
  • already_has_special_tokens (bool, optional, defaults to False) — 令牌列表是否已经用模型的特殊令牌格式化。

返回

List[int]

一个整数列表,范围在[0, 1]:1表示特殊标记,0表示序列标记。

从没有添加特殊标记的标记列表中检索序列ID。当使用标记器的prepare_for_model方法添加特殊标记时,会调用此方法。

create_token_type_ids_from_sequences

< >

( token_ids_0: typing.List[int] token_ids_1: typing.Optional[typing.List[int]] = None ) List[int]

参数

  • token_ids_0 (List[int]) — ID列表.
  • token_ids_1 (List[int], optional) — 可选的第二个序列对的ID列表。

返回

List[int]

零的列表。

从传递给序列对分类任务的两个序列中创建一个掩码。XLM-RoBERTa不使用标记类型ID,因此返回一个零列表。

保存词汇表

< >

( 保存目录: str 文件名前缀: typing.Optional[str] = None )

LayoutXLMTokenizerFast

transformers.LayoutXLMTokenizerFast

< >

( vocab_file = None tokenizer_file = None bos_token = '' eos_token = '' sep_token = '' cls_token = '' unk_token = '' pad_token = '' mask_token = '' cls_token_box = [0, 0, 0, 0] sep_token_box = [1000, 1000, 1000, 1000] pad_token_box = [0, 0, 0, 0] pad_token_label = -100 only_label_first_subword = True **kwargs )

参数

  • vocab_file (str) — 词汇表文件的路径。
  • bos_token (str, optional, defaults to "<s>") — The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

    在使用特殊标记构建序列时,这不是用于序列开头的标记。使用的标记是cls_token

  • eos_token (str, optional, defaults to "</s>") — The end of sequence token.

    在使用特殊标记构建序列时,这不是用于序列结束的标记。 使用的标记是sep_token

  • sep_token (str, 可选, 默认为 "") — 分隔符标记,用于从多个序列构建序列时,例如用于序列分类的两个序列或用于问答的文本和问题。它也用作使用特殊标记构建的序列的最后一个标记。
  • cls_token (str, 可选, 默认为 "") — 用于序列分类的分类器标记(对整个序列进行分类而不是对每个标记进行分类)。当使用特殊标记构建时,它是序列的第一个标记。
  • unk_token (str, 可选, 默认为 "") — 未知标记。不在词汇表中的标记无法转换为ID,而是设置为这个标记。
  • pad_token (str, optional, defaults to "") — 用于填充的标记,例如在对不同长度的序列进行批处理时使用。
  • mask_token (str, 可选, 默认为 "") — 用于屏蔽值的标记。这是在训练此模型时使用的标记,用于屏蔽语言建模。这是模型将尝试预测的标记。
  • cls_token_box (List[int], optional, 默认为 [0, 0, 0, 0]) — 用于特殊 [CLS] 令牌的边界框。
  • sep_token_box (List[int], 可选, 默认为 [1000, 1000, 1000, 1000]) — 用于特殊 [SEP] 令牌的边界框。
  • pad_token_box (List[int], optional, defaults to [0, 0, 0, 0]) — 用于特殊 [PAD] 令牌的边界框。
  • pad_token_label (int, 可选, 默认为 -100) — 用于填充标签的标签。默认为 -100,这是 PyTorch 的 CrossEntropyLoss 的 ignore_index.
  • only_label_first_subword (bool, optional, defaults to True) — 是否仅标记第一个子词,在提供单词标签的情况下。
  • additional_special_tokens (List[str], optional, defaults to ["NOTUSED", "NOTUSED"]) — 分词器使用的额外特殊标记。

构建一个“快速”的LayoutXLM分词器(基于HuggingFace的tokenizers库)。改编自 RobertaTokenizerXLNetTokenizer。基于 BPE

这个分词器继承自PreTrainedTokenizerFast,其中包含了大部分主要方法。用户应参考这个超类以获取有关这些方法的更多信息。

__call__

< >

( text: typing.Union[str, typing.List[str], typing.List[typing.List[str]]] text_pair: typing.Union[typing.List[str], typing.List[typing.List[str]], NoneType] = None boxes: typing.Union[typing.List[typing.List[int]], typing.List[typing.List[typing.List[int]]]] = None word_labels: typing.Union[typing.List[int], typing.List[typing.List[int]], NoneType] = None add_special_tokens: bool = True padding: typing.Union[bool, str, transformers.utils.generic.PaddingStrategy] = False truncation: typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = None max_length: typing.Optional[int] = None stride: int = 0 pad_to_multiple_of: typing.Optional[int] = None padding_side: typing.Optional[bool] = None return_tensors: typing.Union[str, transformers.utils.generic.TensorType, NoneType] = None return_token_type_ids: typing.Optional[bool] = None return_attention_mask: typing.Optional[bool] = None return_overflowing_tokens: bool = False return_special_tokens_mask: bool = False return_offsets_mapping: bool = False return_length: bool = False verbose: bool = True **kwargs ) BatchEncoding

参数

  • text (str, List[str], List[List[str]]) — 要编码的序列或序列批次。每个序列可以是一个字符串、一个字符串列表 (单个示例的单词或一批示例的问题)或一个字符串列表的列表(一批 单词)。
  • text_pair (List[str], List[List[str]]) — 要编码的序列或序列批次。每个序列应该是一个字符串列表 (预分词的字符串)。
  • boxes (List[List[int]], List[List[List[int]]]) — 单词级别的边界框。每个边界框应归一化到0-1000的范围内。
  • word_labels (List[int], List[List[int]], optional) — 单词级别的整数标签(用于如FUNSD、CORD等标记分类任务)。
  • add_special_tokens (bool, optional, defaults to True) — 是否使用与模型相关的特殊标记对序列进行编码。
  • padding (bool, str or PaddingStrategy, optional, defaults to False) — Activates and controls padding. Accepts the following values:
    • True or 'longest': Pad to the longest sequence in the batch (or no padding if only a single sequence if provided).
    • 'max_length': Pad to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided.
    • False or 'do_not_pad' (default): No padding (i.e., can output a batch with sequences of different lengths).
  • truncation (bool, str or TruncationStrategy, optional, defaults to False) — Activates and controls truncation. Accepts the following values:
    • True or 'longest_first': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will truncate token by token, removing a token from the longest sequence in the pair if a pair of sequences (or a batch of pairs) is provided.
    • 'only_first': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will only truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
    • 'only_second': Truncate to a maximum length specified with the argument max_length or to the maximum acceptable input length for the model if that argument is not provided. This will only truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
    • False or 'do_not_truncate' (default): No truncation (i.e., can output batch with sequence lengths greater than the model maximum admissible input size).
  • max_length (int, optional) — Controls the maximum length to use by one of the truncation/padding parameters.

    如果未设置或设置为None,则在需要截断/填充参数时,将使用预定义的模型最大长度。如果模型没有特定的最大输入长度(如XLNet),则截断/填充到最大长度的功能将被停用。

  • stride (int, 可选, 默认为 0) — 如果与 max_length 一起设置为一个数字,当 return_overflowing_tokens=True 时返回的溢出标记将包含来自截断序列末尾的一些标记,以提供截断序列和溢出序列之间的一些重叠。此参数的值定义了重叠标记的数量。
  • pad_to_multiple_of (int, 可选) — 如果设置,将序列填充到提供的值的倍数。这对于在计算能力>= 7.5(Volta)的NVIDIA硬件上启用Tensor Cores特别有用。
  • return_tensors (strTensorType, 可选) — 如果设置,将返回张量而不是Python整数列表。可接受的值有:
    • 'tf': 返回 TensorFlow tf.constant 对象。
    • 'pt': 返回 PyTorch torch.Tensor 对象。
    • 'np': 返回 Numpy np.ndarray 对象。
  • return_token_type_ids (bool, optional) — Whether to return token type IDs. If left to the default, will return the token type IDs according to the specific tokenizer’s default, defined by the return_outputs attribute.

    什么是token type IDs?

  • return_attention_mask (bool, optional) — 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 return_outputs attribute.

    什么是注意力掩码?

  • return_overflowing_tokens (bool, optional, defaults to False) — 是否返回溢出的token序列。如果提供了一对输入id序列(或一批对)并且truncation_strategy = longest_firstTrue,则会引发错误而不是返回溢出的token。
  • return_special_tokens_mask (bool, optional, defaults to False) — 是否返回特殊令牌掩码信息。
  • return_offsets_mapping (bool, optional, defaults to False) — Whether or not to return (char_start, char_end) for each token.

    这仅在继承自PreTrainedTokenizerFast的快速分词器上可用,如果使用Python的分词器,此方法将引发NotImplementedError

  • return_length (bool, 可选, 默认为 False) — 是否返回编码输入的长度.
  • verbose (bool, optional, defaults to True) — 是否打印更多信息和警告。
  • **kwargs — 传递给 self.tokenize() 方法

返回

BatchEncoding

一个 BatchEncoding 包含以下字段:

  • input_ids — 要输入模型的标记ID列表。

    什么是输入ID?

  • bbox — 要输入模型的边界框列表。

  • token_type_ids — 要输入模型的标记类型ID列表(当 return_token_type_ids=True 或 如果 “token_type_ids”self.model_input_names 中时)。

    什么是标记类型ID?

  • attention_mask — 指定模型应关注哪些标记的索引列表(当 return_attention_mask=True 或如果 “attention_mask”self.model_input_names 中时)。

    什么是注意力掩码?

  • labels — 要输入模型的标签列表。(当指定了 word_labels 时)。

  • overflowing_tokens — 溢出标记序列列表(当指定了 max_length 并且 return_overflowing_tokens=True 时)。

  • num_truncated_tokens — 被截断的标记数量(当指定了 max_length 并且 return_overflowing_tokens=True 时)。

  • special_tokens_mask — 0和1的列表,1表示添加的特殊标记,0表示 常规序列标记(当 add_special_tokens=True 并且 return_special_tokens_mask=True 时)。

  • length — 输入的长度(当 return_length=True 时)。

主要方法,用于将一个或多个序列或一个或多个序列对进行分词,并为模型准备,这些序列带有单词级别的归一化边界框和可选的标签。

LayoutXLMProcessor

transformers.LayoutXLMProcessor

< >

( image_processor = 无 tokenizer = 无 **kwargs )

参数

构建一个LayoutXLM处理器,它将LayoutXLM图像处理器和LayoutXLM分词器组合成一个单一的处理器。

LayoutXLMProcessor 提供了准备模型数据所需的所有功能。

它首先使用LayoutLMv2ImageProcessor将文档图像调整为固定大小,并可以选择应用OCR来获取单词和归一化的边界框。然后将这些提供给LayoutXLMTokenizerLayoutXLMTokenizerFast,它们将单词和边界框转换为标记级别的input_idsattention_masktoken_type_idsbbox。可以选择提供整数word_labels,这些将被转换为标记级别的labels,用于标记分类任务(如FUNSD、CORD)。

__call__

< >

( images text: typing.Union[str, typing.List[str], typing.List[typing.List[str]]] = None text_pair: typing.Union[typing.List[str], typing.List[typing.List[str]], NoneType] = None boxes: typing.Union[typing.List[typing.List[int]], typing.List[typing.List[typing.List[int]]]] = None word_labels: typing.Union[typing.List[int], typing.List[typing.List[int]], NoneType] = None add_special_tokens: bool = True padding: typing.Union[bool, str, transformers.utils.generic.PaddingStrategy] = False truncation: typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = None max_length: typing.Optional[int] = None stride: int = 0 pad_to_multiple_of: typing.Optional[int] = None return_token_type_ids: typing.Optional[bool] = None return_attention_mask: typing.Optional[bool] = None return_overflowing_tokens: bool = False return_special_tokens_mask: bool = False return_offsets_mapping: bool = False return_length: bool = False verbose: bool = True return_tensors: typing.Union[str, transformers.utils.generic.TensorType, NoneType] = None **kwargs )

此方法首先将images参数转发给~LayoutLMv2ImagePrpcessor.__call__。如果LayoutLMv2ImagePrpcessor初始化时apply_ocr设置为True,它会将获得的单词和边界框与附加参数一起传递给call()并返回输出,以及调整大小后的images。如果LayoutLMv2ImagePrpcessor初始化时apply_ocr设置为False,它会将用户指定的单词(text/text_pair)和boxes与附加参数一起传递给[__call__()](/docs/transformers/v4.47.1/en/model_doc/layoutxlm#transformers.LayoutXLMTokenizer.__call__)并返回输出,以及调整大小后的images

请参考上述两个方法的文档字符串以获取更多信息。

< > Update on GitHub