Problem/Motivation
The AI core module is adding a new text_classification operation type in #3456768 (MR !1400). The Hugging Face provider already has the low-level API client method HuggingfaceApi::textClassification() but the provider plugin (HuggingfaceProvider) does not implement TextClassificationInterface, so the operation type is not available to users.
The Hugging Face project page already lists Text Classification as a feature, and the Inference API supports it via the text-classification pipeline.
Steps to reproduce
- Install the AI core module with the text classification patch from #3456768
- Install and enable
ai_provider_huggingface - Visit
/admin/config/ai/providers/huggingface— there is no "Add Text Classification Model" button - The Text Classification Explorer at
/admin/config/ai/explorers/text_classification_generator
Proposed resolution
Wire up the existing HuggingfaceApi::textClassification() client method to the provider plugin by:
Depends on
- #3456768: Interface suggestion for text classification operator type — adds the
text_classificationoperation type to AI core
Issue fork ai_provider_huggingface-3583809
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 #3
ahmad khader commentedComment #4
ahmad khader commentedSteps to test
/admin/config/ai/providers/huggingface— there is now "Add Text Classification Model" buttonnlptown/bert-base-multilingual-uncased-sentiment— sentiment analysis (1-5 stars) ordistilbert-base-uncased-finetuned-sst-2-english— positive/negative sentiment/admin/config/ai/explorers/text_classification_generatorAdditional fix needed in HuggingfaceApi
The existing
HuggingfaceApi::textClassification()method always sends'parameters' => []in the request payload. The Hugging Face Inference API interprets an empty PHP array as a JSON list[], which causes a400 Bad Requesterror:{"error":"'list' object has no attribute 'setdefault'"}The fix is to omit the
parameterskey when the array is empty, or cast it to(object)so it serializes as{}.Comment #5
ahmad khader commentedComment #6
ahmad khader commentedComment #7
arianraeesi commented