Problem/Motivation

The AI core module has possibility to add a new extractive_question_answering operation type (see #3584371: Add Extractive Question Answering operation type). The Hugging Face provider already has the low-level API client method HuggingfaceApi::questionAnswering() but the provider plugin (HuggingfaceProvider) does not implement ExtractiveQuestionAnsweringInterface, so the operation type is not available to users.

Extractive question answering is a well-established Hugging Face pipeline (question-answering) with popular models like deepset/roberta-base-squad2 and distilbert/distilbert-base-cased-distilled-squad, both of which have active free inference endpoints. The API client method is ready — it just needs to be wired to the provider plugin.

Proposed resolution

Wire up the existing HuggingfaceApi::questionAnswering() client method to the provider plugin by:

  1. Adding use statements for ExtractiveQuestionAnsweringInput, ExtractiveQuestionAnsweringInterface, ExtractiveQuestionAnsweringItem, and ExtractiveQuestionAnsweringOutput
  2. Adding ExtractiveQuestionAnsweringInterface to the implements list in HuggingfaceProvider
  3. Adding 'extractive_question_answering' to $supportedTypes with filter 'question-answering'
  4. Adding 'extractive_question_answering' to getSupportedOperationTypes()
  5. Implementing the extractiveQuestionAnswering() method, following the same pattern as textClassification()

Tested models

  • deepset/roberta-base-squad2 — general-purpose extractive QA trained on SQuAD 2.0
  • distilbert/distilbert-base-cased-distilled-squad — lightweight extractive QA trained on SQuAD

Example API response

The Hugging Face Inference API for question-answering returns:

{
  "answer": "Paris",
  "score": 0.9825,
  "start": 25,
  "end": 30
}

This maps directly to ExtractiveQuestionAnsweringItem(answer, score, start, end).

Depends on

  • AI core issue: Add Extractive Question Answering operation type — adds the extractive_question_answering operation type to AI Core

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ahmad khader created an issue. See original summary.

ahmad khader’s picture

Issue summary: View changes

ahmad khader’s picture

Assigned: ahmad khader » Unassigned
arianraeesi’s picture