Files
kadirnar e21711a049 Refactor computer vision and NLP pipelines to simplify model selection and enhance functionality
- 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.
2026-02-08 18:26:10 +00:00

33 lines
1020 B
Python

from transformers import pipeline as hf_pipeline
import json
aggregation_strategy_list = [
"simple",
"first",
"average",
"max",
"none",
]
class TokenClassificationPipeline:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"default": "", "multiline": True}),
"model_name": ("STRING", {"default": "dslim/bert-base-NER"}),
"aggregation_strategy": (aggregation_strategy_list, {"default": "simple"}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("entities_json",)
FUNCTION = "run_token_classification"
CATEGORY = "Transformers/NLP/TokenClassification"
def run_token_classification(self, text, model_name, aggregation_strategy):
pipe = hf_pipeline("token-classification", model=model_name, aggregation_strategy=aggregation_strategy, trust_remote_code=True)
result = pipe(text)
return (json.dumps(result, indent=2, default=str),)