Transformers documentation

SLANeXt

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

このモデルは2026年3月21日にHugging Face Transformersに貢献されました。

SLANeXt

概要

SLANeXt_wired と SLANeXt_wireless は、文書や自然なシーンにおける表構造の正確な認識に焦点を当てた、表構造認識専用の軽量モデルシリーズの一部です。SLANeXt シリーズモデルの詳細については、公式ドキュメントを参照してください。

モデルアーキテクチャ

SLANeXt シリーズは、Baidu PaddlePaddle Vision チームが独自に開発した次世代の表構造認識モデルです。SLANeXt は表構造認識に特化しており、有線表と無線表それぞれに専用の重みを学習しています。あらゆる種類の表に対する認識能力が大幅に向上し、特に有線表において顕著な改善が見られます。

使用方法

単一入力推論

以下の例では、AutoModelを使用してPP-OCRV5_Mobile_Detでテキストを検出する方法を示しています。

AutoModel
import requests
from PIL import Image

from transformers import AutoImageProcessor, AutoModelForTableRecognition


model_path="PaddlePaddle/SLANeXt_wired_safetensors"
model = AutoModelForTableRecognition.from_pretrained(model_path, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_path)

image = Image.open(requests.get("https://huggingface.co/datasets/hf-internal-testing/transformers-synthetic-assets/resolve/main/images/paddle_table_recognition.jpg", stream=True).raw)
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
outputs = model(**inputs)

results = image_processor.post_process_table_recognition(outputs)

print(result['structure'])
print(result['structure_score'])

SLANeXtConfig

class transformers.SLANeXtConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonevision_config: dict | transformers.models.slanext.configuration_slanext.SLANeXtVisionConfig | None = Nonepost_conv_in_channels: int = 256post_conv_out_channels: int = 512out_channels: int = 50hidden_size: int = 512max_text_length: int = 500 )

パラメータ

  • vision_config (dict または SLANeXtVisionConfig、optional) — ビジョンエンコーダーの設定です。None の場合、デフォルトの SLANeXtVisionConfig が使用されます。
  • post_conv_in_channels (int、任意、デフォルトは 256) — エンコーダー後の畳み込み層の入力チャネル数です。
  • post_conv_out_channels (int、任意、デフォルト値は 512) — エンコーダー後の畳み込み層の出力チャネル数。
  • out_channels (int, 任意、デフォルト値は 50) — テーブル構造トークン予測ヘッドの語彙サイズ、すなわちモデルが予測できる個別の構造トークンの数です。
  • hidden_size (int、任意、デフォルトは 512) — アテンション GRU セルおよび構造/位置予測ヘッドにおける隠れ状態の次元数。
  • max_text_length (int、任意、デフォルト値は 500) — 構造および位置デコーダーにおける自己回帰デコーディングの最大ステップ数(トークン数)。

これは SlanextModel の設定を保存するための設定クラスです。指定された引数に基づいて Slanext モデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、PaddlePaddle/SLANeXt_wired_safetensors と同様の設定が得られます。

設定オブジェクトはPreTrainedConfigを継承し、モデルの出力を制御するために使用できます。詳細については、PreTrainedConfigのドキュメントを参照してください。

SLANeXtVisionConfig

class transformers.SLANeXtVisionConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonehidden_size: int = 768output_channels: int = 256num_hidden_layers: int = 12num_attention_heads: int = 12num_channels: int = 3image_size: int = 512patch_size: int | list[int] | tuple[int, int] = 16hidden_act: str = 'gelu'layer_norm_eps: float = 1e-06attention_dropout: float | int = 0.0initializer_range: float = 1e-10qkv_bias: bool = Trueuse_abs_pos: bool = Trueuse_rel_pos: bool = Truewindow_size: int = 14global_attn_indexes: list[int] | tuple[int, ...] = (2, 5, 8, 11)mlp_dim: int = 3072 )

パラメータ

  • hidden_size (int、任意、デフォルトは 768) — 隠れ表現の次元数。
  • output_channels (int、任意、デフォルトは 256) — Patch Encoder の出力チャネルの次元数。
  • num_hidden_layers (int、任意、デフォルトは 12) — Transformer デコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは12) — Transformerデコーダーの各アテンション層におけるアテンションヘッドの数。
  • num_channels (int、任意、デフォルトは3) — 入力チャネル数。
  • image_size (int、任意、デフォルトは 512) — 各画像のサイズ(解像度)。
  • patch_size (Union[int, list[int], tuple[int, int]]、任意、デフォルトは16) — 各パッチのサイズ(解像度)です。
  • hidden_act (str、任意、デフォルトは gelu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • layer_norm_eps (float、任意、デフォルトは 1e-06) — レイヤーノーマル層で使用する epsilon です。
  • attention_dropout (Union[float, int]、任意、デフォルトは 0.0) — アテンション確率のドロップアウト率です。
  • initializer_range (float、任意、デフォルトは 1e-10) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。
  • qkv_bias (bool、省略可、デフォルトは True) — クエリ、キー、バリューにバイアスを追加するかどうか。
  • use_abs_pos (bool、任意、デフォルトは True) — 絶対位置埋め込みを使用するかどうか。
  • use_rel_pos (bool、任意、デフォルトはTrue) — 相対位置埋め込みを使用するかどうかを指定します。
  • window_size (int, 任意、デフォルト値は 14)— 相対位置のウィンドウサイズです。
  • global_attn_indexes (list[int]、任意、デフォルトは [2, 5, 8, 11]) — グローバルアテンションレイヤーのインデックスです。
  • mlp_dim (int、任意、デフォルト値は 3072) — Transformer エンコーダーにおける MLP レイヤーの次元数。

これは SlanextModel の設定を保存するための設定クラスです。指定された引数に基づいて Slanext モデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、PaddlePaddle/SLANeXt_wired_safetensors と同様の設定が得られます。

設定オブジェクトはPreTrainedConfigを継承し、モデルの出力を制御するために使用できます。詳細については、PreTrainedConfigのドキュメントを参照してください。

SLANeXtForTableRecognition

クラス transformers.SLANeXtForTableRecognition

< >

( config: SLANeXtConfig )

パラメータ

  • config (SLANeXtConfig) — モデルのパラメータをすべて含むモデル設定クラスです。設定ファイルで初期化しても、モデルに関連する重みは読み込まれず、設定のみが読み込まれます。モデルの重みをロードするには、from_pretrained() メソッドを参照してください。

認識タスク用のSLANeXt Table Recognitionモデル。SLANeXtPreTrainedModelをラップし、Transformersの認識APIと互換性のある出力を返します。

このモデルは PreTrainedModel を継承しています。すべてのモデルに実装されている汎用的なメソッド(ダウンロードや保存、入力埋め込みのリサイズ、ヘッドのプルーニングなど)については、スーパークラスのドキュメントを参照してください。

このモデルは、PyTorchのtorch.nn.Moduleのサブクラスでもあります。 通常のPyTorch Moduleとして使用し、一般的な使用方法や動作に関する詳細については、PyTorchのドキュメントを参照してください。

forward

< >

( pixel_values: FloatTensor**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → SLANeXtForTableRecognitionOutput or tuple(torch.FloatTensor)

パラメータ

  • pixel_values (torch.FloatTensor、shape (batch_size, num_channels, image_size, image_size)) — 入力画像に対応するテンソルです。ピクセル値はSLANeXtImageProcessorを使用して取得できます。詳細はSLANeXtImageProcessor.call()を参照してください(processor_classは画像の処理にSLANeXtImageProcessorを使用します)。

戻り値

SLANeXtForTableRecognitionOutput または tuple(torch.FloatTensor)

SLANeXtForTableRecognitionOutput、またはtorch.FloatTensorのタプル(return_dict=Falseが渡された場合、またはconfig.return_dict=Falseの場合)。設定(SLANeXtConfig)と入力に応じて、さまざまな要素で構成されます。

SLANeXtForTableRecognitionのforwardメソッドは、__call__特殊メソッドをオーバーライドします。

この関数内でフォワードパスの手順を定義する必要がありますが、その後、この関数ではなくModuleインスタンスを呼び出すべきです。前者は前処理と後処理の実行を適切に処理するのに対し、後者はそれらを黙って無視するためです。

  • last_hidden_state (torch.FloatTensor、shape (batch_size, sequence_length, hidden_size)) — モデルの最終層の出力における隠れ状態のシーケンス。

  • hidden_states (tuple(torch.FloatTensor)、optional、output_hidden_states=True が渡された場合または config.output_hidden_states=True の場合に返されます)— torch.FloatTensor のタプル(埋め込み層を持つモデルの場合、埋め込みの出力が 1 つ、各層の出力がそれぞれ 1 つずつ)で、形状は (batch_size, sequence_length, hidden_size) です。

    各層の出力におけるモデルのHidden-states、および任意の初期埋め込み出力。

  • attentions (tuple(torch.FloatTensor)、optional、output_attentions=True が渡された場合または config.output_attentions=True の場合に返されます)— torch.FloatTensor のタプル(各レイヤーごとに1つ)、形状は (batch_size, num_heads, sequence_length, sequence_length)。

    アテンションのsoftmax後のアテンション重み。自己アテンションヘッド内で加重平均を計算するために使用されます。

  • head_hidden_states (tuple(torch.FloatTensor)、optional、output_hidden_states=True が渡された場合、または config.output_hidden_states=True の場合に返されます)— 各予測ステップにおける SLANeXtSLAHead の隠れ状態。早期終了に依存して、最大 self.config.max_text_length 個の状態まで変化します。

  • head_attentions (tuple(torch.FloatTensor)、optional、output_attentions=True が渡された場合または config.output_attentions=True の場合に返されます) — 各予測ステップにおける SLANeXtSLAHead のアテンション。早期終了に応じて、最大 self.config.max_text_length 個のアテンションまで変化します。

SLANeXtBackbone

class transformers.SLANeXtBackbone

< >

( config: dict | None = None**kwargs )

SLANeXtSLAHead

class transformers.SLANeXtSLAHead

< >

( config: dict | None = None**kwargs )

SLANeXtImageProcessor

class transformers.SLANeXtImageProcessor

< >

( **kwargs: *<class 'transformers.processing_utils.ImagesKwargs'> )

パラメータ

  • do_convert_rgb (bool、kwargs、optional、デフォルトは True) — 画像を RGB に変換するかどうか。
  • do_resize (bool、kwargs、任意、デフォルトはTrue) — 画像をリサイズするかどうか。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs、デフォルトは {'height' -- 512, 'width': 512}): モデルへの最大入力サイズを指定します。
  • default_to_square (bool、kwargs、任意、デフォルトは True) — size が int の場合、リサイズ時に正方形の画像をデフォルトとするかどうかを指定します。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — center_crop を適用した後の出力画像のサイズ。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs, デフォルトは 2) — 画像のリサイズ時に使用するリサンプリングフィルタです。PILImageResampling の列挙型のいずれかを使用できます。do_resize が True に設定されている場合のみ、効果が現れます。
  • do_rescale (bool、kwargs、任意、デフォルトはTrue) — 画像をリスケールするかどうかを指定します。
  • rescale_factor (float、kwargs、任意、デフォルト値は 0.00392156862745098) — do_rescale が True に設定されている場合、画像をリスケールするための係数です。
  • do_normalize (bool、kwargs、optional、デフォルトはTrue) — 画像を正規化するかどうかを指定します。
  • image_mean (Union[float, list[float], tuple[float, ...]]、kwargs、optional、デフォルト値は [0.485, 0.456, 0.406]) — 正規化に使用する画像の平均値。do_normalize が True に設定されている場合のみ有効です。
  • image_std (Union[float, list[float], tuple[float, ...]]、kwargs、optional、デフォルト値は [0.229, 0.224, 0.225]) — 正規化に使用する画像の標準偏差。do_normalize が True に設定されている場合のみ有効です。
  • do_pad (bool、kwargs、optional、デフォルトは True) — 画像をパディングするかどうか。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。具体的なパディング戦略はモデルによって異なります。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs, defaults to {'height' -- 512, 'width': 512}): The size in {"height": int, "width" int} to pad the images to. Must be larger than any image size provided for preprocessing. If pad_size is not provided, images will be padded to the largest height and width in the batch. Applied only when do_pad=True.
  • do_center_crop (bool, kwargs, optional) — 画像を中央クロップするかどうかを指定します。
  • data_format (Union[str, ~image_utils.ChannelDimension]、kwargs、任意) — サポートされているのは ChannelDimension.FIRST のみです。slow processors との互換性のために追加されました。
  • input_data_format (Union[str, ~image_utils.ChannelDimension], kwargs, 省略可) — 入力画像のチャネル次元の形式です。設定されていない場合、入力画像からチャネル次元の形式が推測されます。次のいずれかになります:
    • "channels_first" または ChannelDimension.FIRST: (num_channels, height, width) 形式の画像。
    • "channels_last" または ChannelDimension.LAST: (高さ, 幅, チャネル数) 形式の画像。
    • "none" または ChannelDimension.NONE: (height, width) 形式の画像。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 'pt' に設定されている場合はスタックされたテンソルを返し、それ以外の場合はテンソルのリストを返します。
  • disable_grouping (bool、kwargs、任意) — サイズごとに画像をグループ化してバッチ処理するのではなく、個別に処理するためにグループ化を無効にするかどうか。None の場合、画像が CPU にある場合は True、それ以外の場合は False に設定されます。この選択は、https://github.com/huggingface/transformers/pull/38157 に詳しく記載されている経験則に基づいています。
  • image_seq_length (int、kwargs、任意) — 入力内の各画像に使用される画像トークンの数です。 後方互換性のために追加されましたが、将来のモデルではプロセッサの属性として設定されるべきです。

SLANeXtImageProcessor 画像プロセッサを構築します。

init_decoder

< >

( )

構造認識用のデコーダー語彙を初期化します。

HTMLテーブル構造トークン(例: <thead>、<tr>、<td>、colspan/ rowspan属性)を整数インデックスにマッピングする文字列辞書を構築します。辞書には、特殊な"sos"(シーケンス開始)トークンと"eos"(シーケンス終了)トークンが含まれます。適用可能な場合、単独の<td>トークンの代わりに、マージされた<td></td>トークンが使用されます。

post_process_table_recognition

< >

( outputs ) → dict

パラメータ

  • outputs (SLANeXtForTableRecognitionOutput) — SLANeXt モデルからの生出力です。last_hidden_state フィールドには、各デコーディングステップにおける構造語彙に対する予測確率分布が含まれており、その形状は (batch_size, max_text_length, num_classes) です。

戻り値

dict

以下の内容を含む辞書:

  • structure (list[str]): <html>、<body>、<table> タグでラップされた、トークンのリストとして表された予測された HTML テーブルの構造。
  • structure_score (float): 予測されたすべてのトークンにわたる平均信頼度スコア。

生のモデル出力を後処理し、予測されたテーブル構造をHTMLトークン列にデコードします。

モデルが構造語彙に対して予測した確率分布を、テーブル構造を表すHTMLトークンのシーケンスに変換します。デコードされたトークンは<html>、<body>、<table>タグでラップされ、完全なHTMLテーブル構造を形成します。

Update on GitHub