Auto Classes
多くの場合、from_pretrained()メソッドに与えられた事前学習済みモデルの名前やパスから、使用したいアーキテクチャを推測することができます。自動クラスはこの仕事をあなたに代わって行うためにここにありますので、事前学習済みの重み/設定/語彙への名前/パスを与えると自動的に関連するモデルを取得できます。
AutoConfig、AutoModel、AutoTokenizerのいずれかをインスタンス化すると、関連するアーキテクチャのクラスが直接作成されます。例えば、
model = AutoModel.from_pretrained("google-bert/bert-base-cased")これはBertModelのインスタンスであるモデルを作成します。
各タスクごと、そして各バックエンド(PyTorch、TensorFlow、またはFlax)ごとにAutoModelのクラスが存在します。
自動クラスの拡張
Section titled “自動クラスの拡張”それぞれの自動クラスには、カスタムクラスで拡張するためのメソッドがあります。例えば、NewModelというモデルのカスタムクラスを定義した場合、NewModelConfigを確保しておけばこのようにして自動クラスに追加することができます:
from transformers import AutoConfig, AutoModel
AutoConfig.register("new-model", NewModelConfig)AutoModel.register(NewModelConfig, NewModel)その後、通常どおりauto classesを使用することができるようになります!
あなたのNewModelConfigがPreTrainedConfigのサブクラスである場合、そのmodel_type属性がコンフィグを登録するときに使用するキー(ここでは"new-model")と同じに設定されていることを確認してください。
同様に、あなたのNewModelがPreTrainedModelのサブクラスである場合、そのconfig_class属性がモデルを登録する際に使用するクラス(ここではNewModelConfig)と同じに設定されていることを確認してください。
AutoConfig
Section titled “AutoConfig”[[autodoc]] AutoConfig
AutoTokenizer
Section titled “AutoTokenizer”[[autodoc]] AutoTokenizer
AutoFeatureExtractor
Section titled “AutoFeatureExtractor”[[autodoc]] AutoFeatureExtractor
AutoImageProcessor
Section titled “AutoImageProcessor”[[autodoc]] AutoImageProcessor
AutoProcessor
Section titled “AutoProcessor”[[autodoc]] AutoProcessor
Generic model classes
Section titled “Generic model classes”以下の自動クラスは、特定のヘッドを持たないベースモデルクラスをインスタンス化するために利用可能です。
AutoModel
Section titled “AutoModel”[[autodoc]] AutoModel
Generic pretraining classes
Section titled “Generic pretraining classes”以下の自動クラスは、事前学習ヘッドを持つモデルをインスタンス化するために利用可能です。
AutoModelForPreTraining
Section titled “AutoModelForPreTraining”[[autodoc]] AutoModelForPreTraining
Natural Language Processing
Section titled “Natural Language Processing”以下の自動クラスは、次の自然言語処理タスクに利用可能です。
AutoModelForCausalLM
Section titled “AutoModelForCausalLM”[[autodoc]] AutoModelForCausalLM
AutoModelForMaskedLM
Section titled “AutoModelForMaskedLM”[[autodoc]] AutoModelForMaskedLM
AutoModelForMaskGeneration
Section titled “AutoModelForMaskGeneration”[[autodoc]] AutoModelForMaskGeneration
AutoModelForSeq2SeqLM
Section titled “AutoModelForSeq2SeqLM”[[autodoc]] AutoModelForSeq2SeqLM
AutoModelForSequenceClassification
Section titled “AutoModelForSequenceClassification”[[autodoc]] AutoModelForSequenceClassification
AutoModelForMultipleChoice
Section titled “AutoModelForMultipleChoice”[[autodoc]] AutoModelForMultipleChoice
AutoModelForNextSentencePrediction
Section titled “AutoModelForNextSentencePrediction”[[autodoc]] AutoModelForNextSentencePrediction
AutoModelForTokenClassification
Section titled “AutoModelForTokenClassification”[[autodoc]] AutoModelForTokenClassification
AutoModelForQuestionAnswering
Section titled “AutoModelForQuestionAnswering”[[autodoc]] AutoModelForQuestionAnswering
AutoModelForTextEncoding
Section titled “AutoModelForTextEncoding”[[autodoc]] AutoModelForTextEncoding
Computer vision
Section titled “Computer vision”以下の自動クラスは、次のコンピュータービジョンタスクに利用可能です。
AutoModelForDepthEstimation
Section titled “AutoModelForDepthEstimation”[[autodoc]] AutoModelForDepthEstimation
AutoModelForImageClassification
Section titled “AutoModelForImageClassification”[[autodoc]] AutoModelForImageClassification
AutoModelForVideoClassification
Section titled “AutoModelForVideoClassification”[[autodoc]] AutoModelForVideoClassification
AutoModelForMaskedImageModeling
Section titled “AutoModelForMaskedImageModeling”[[autodoc]] AutoModelForMaskedImageModeling
AutoModelForObjectDetection
Section titled “AutoModelForObjectDetection”[[autodoc]] AutoModelForObjectDetection
AutoModelForImageSegmentation
Section titled “AutoModelForImageSegmentation”[[autodoc]] AutoModelForImageSegmentation
AutoModelForImageToImage
Section titled “AutoModelForImageToImage”[[autodoc]] AutoModelForImageToImage
AutoModelForSemanticSegmentation
Section titled “AutoModelForSemanticSegmentation”[[autodoc]] AutoModelForSemanticSegmentation
AutoModelForInstanceSegmentation
Section titled “AutoModelForInstanceSegmentation”[[autodoc]] AutoModelForInstanceSegmentation
AutoModelForUniversalSegmentation
Section titled “AutoModelForUniversalSegmentation”[[autodoc]] AutoModelForUniversalSegmentation
AutoModelForZeroShotImageClassification
Section titled “AutoModelForZeroShotImageClassification”[[autodoc]] AutoModelForZeroShotImageClassification
AutoModelForZeroShotObjectDetection
Section titled “AutoModelForZeroShotObjectDetection”[[autodoc]] AutoModelForZeroShotObjectDetection
以下の自動クラスは、次の音声タスクに利用可能です。
AutoModelForAudioClassification
Section titled “AutoModelForAudioClassification”[[autodoc]] AutoModelForAudioClassification
AutoModelForAudioFrameClassification
Section titled “AutoModelForAudioFrameClassification”[[autodoc]] AutoModelForAudioFrameClassification
AutoModelForCTC
Section titled “AutoModelForCTC”[[autodoc]] AutoModelForCTC
AutoModelForSpeechSeq2Seq
Section titled “AutoModelForSpeechSeq2Seq”[[autodoc]] AutoModelForSpeechSeq2Seq
AutoModelForAudioXVector
Section titled “AutoModelForAudioXVector”[[autodoc]] AutoModelForAudioXVector
AutoModelForTextToSpectrogram
Section titled “AutoModelForTextToSpectrogram”[[autodoc]] AutoModelForTextToSpectrogram
AutoModelForTextToWaveform
Section titled “AutoModelForTextToWaveform”[[autodoc]] AutoModelForTextToWaveform
Multimodal
Section titled “Multimodal”以下の自動クラスは、次のマルチモーダルタスクに利用可能です。
AutoModelForTableQuestionAnswering
Section titled “AutoModelForTableQuestionAnswering”[[autodoc]] AutoModelForTableQuestionAnswering
AutoModelForDocumentQuestionAnswering
Section titled “AutoModelForDocumentQuestionAnswering”[[autodoc]] AutoModelForDocumentQuestionAnswering
AutoModelForVisualQuestionAnswering
Section titled “AutoModelForVisualQuestionAnswering”[[autodoc]] AutoModelForVisualQuestionAnswering
AutoModelForVision2Seq
Section titled “AutoModelForVision2Seq”[[autodoc]] AutoModelForVision2Seq
AutoModelForImageTextToText
Section titled “AutoModelForImageTextToText”[[autodoc]] AutoModelForImageTextToText
Time Series
Section titled “Time Series”AutoModelForTimeSeriesPrediction
Section titled “AutoModelForTimeSeriesPrediction”[[autodoc]] AutoModelForTimeSeriesPrediction