- Updated model selection in image-to-image, mask generation, object detection, video classification, zero-shot image classification, zero-shot object detection, document question answering, feature extraction, image-to-text, image-text-to-text, visual question answering, conversational, fill mask, question answering, sentence similarity, table question answering, zero-shot classification, text classification, text generation, and token classification pipelines to use a default string instead of a model list. - Removed unused keypoint detection, summarization, text2text generation, and translation pipelines. - Added utility nodes for type conversion: IntToString, StringToInt, FloatToString, and StringToFloat. - Updated all pipeline calls to include trust_remote_code=True for enhanced security. - Improved requirements by adding timm and opencv-python for better functionality.
23 lines
784 B
Python
23 lines
784 B
Python
from transformers import pipeline as hf_pipeline
|
|
|
|
class TextClassificationPipeline:
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"text": ("STRING", {"default": "", "multiline": True}),
|
|
"model_name": ("STRING", {"default": "distilbert-base-uncased-finetuned-sst-2-english"}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING", "FLOAT",)
|
|
RETURN_NAMES = ("label", "score",)
|
|
FUNCTION = "run_classification"
|
|
CATEGORY = "Transformers/NLP/TextClassification"
|
|
|
|
def run_classification(self, text, model_name):
|
|
pipe = hf_pipeline("text-classification", model=model_name, trust_remote_code=True)
|
|
result = pipe(text)
|
|
top = result[0]
|
|
return (top["label"], top["score"],)
|