Transformersのpipelineモジュールに関する質問 [D]

Reddit r/MachineLearning / 2026/5/3

💬 オピニオン

要点

  • 著者は、DistilBERTベースのQAモデルを使い、Transformersの`pipeline("question-answering")`でテキストから「answer/cause」スパンを抽出しようとしている。
  • しかし、`question-answering`タスクがpipelineで認識されず、代わりに複数の別タスクが利用可能として表示されるという問題に直面している。
  • 画像を含む「document-question-answering」ではなく、テキストのみで動く質問応答の方法を探している。
  • `question-answering`の代替として利用できる別のpipelineタスクや、同じ目的を果たすモジュールがあるかを質問している。
from transformers import pipeline , DistilBertTokenizer , DistilBertModel model = DistilBertModel . from_pretrained ('distilbert-base-cased-distilled-squad') # すでに質問応答で学習済みのモデルを読み込む extractor = pipeline ("question-answering") def get_emotion_cause (text, emotion): question = f"この文章が {emotion} の症状を伝える理由は何ですか?" # モデルはテキストから 'cause(原因)' のスパンを抽出する result = extractor(question = question, context = text) return result ['answer'] # 例: text = "私はとても不安です。明日が期末試験で、勉強していないからです。" print ( get_emotion_cause (text, "anxiety")) 

最近、事前の学習データなしで質問応答を行える「ready-to-go(すぐ使える)」モデルを調べていて、その場で質問応答を実行できるように事前学習されたこのパイプラインに出会いました。私はそのドキュメントを調べ、指示に従ってコードを書いたのですが、上記のようなコードになりました。しかし、パイプラインは「question-answering」機能からは遠ざかってしまったようです。

そして次のような機能の一覧が表示されます。"Unknown task question-answering, available tasks are ['any-to-any', 'audio-classification', 'automatic-speech-recognition', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-feature-extraction', 'image-segmentation', 'image-text-to-text', 'keypoint-matching', 'mask-generation', 'ner', 'object-detection', 'sentiment-analysis', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'token-classification', 'video-classification', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection']

どのように対応すればよいか教えてください。利用可能な別の「question-answering」機能を使うのでしょうか? または、同じ仕事ができる他のモジュールをおすすめしてもらえますか。

P.s. ドキュメント質問応答(document-question-answering)には画像が必要で、私はテキストのみを扱っています。

submitted by /u/Mountain_Turnip_6403
[link] [comments]