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:
- Adding
usestatements forExtractiveQuestionAnsweringInput,ExtractiveQuestionAnsweringInterface,ExtractiveQuestionAnsweringItem, andExtractiveQuestionAnsweringOutput - Adding
ExtractiveQuestionAnsweringInterfaceto theimplementslist inHuggingfaceProvider - Adding
'extractive_question_answering'to$supportedTypeswith filter'question-answering' - Adding
'extractive_question_answering'togetSupportedOperationTypes() - Implementing the
extractiveQuestionAnswering()method, following the same pattern astextClassification()
Tested models
deepset/roberta-base-squad2— general-purpose extractive QA trained on SQuAD 2.0distilbert/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_answeringoperation type to AI Core
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork ai_provider_huggingface-3584375
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
Comment #2
ahmad khader commentedComment #4
ahmad khader commentedComment #5
arianraeesi commented