pipelines

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAverageAggregation added in v0.3.4

func WithAverageAggregation() backends.PipelineOption[*TokenClassificationPipeline]

WithAverageAggregation sets the aggregation strategy for the token labels to average It reproduces simple aggregation from the huggingface implementation.

func WithBatchSize added in v0.5.0

func WithBatchSize(size int) backends.PipelineOption[*CrossEncoderPipeline]

func WithBoxesOutput added in v0.6.0

func WithBoxesOutput(name string) backends.PipelineOption[*ObjectDetectionPipeline]

Options.

func WithClassification added in v0.6.2

func WithClassification() backends.PipelineOption[*TabularPipeline]

func WithDetectionIouThreshold added in v0.6.0

func WithDetectionIouThreshold(th float32) backends.PipelineOption[*ObjectDetectionPipeline]

func WithDetectionScoreThreshold added in v0.6.0

func WithDetectionScoreThreshold(th float32) backends.PipelineOption[*ObjectDetectionPipeline]

func WithDetectionTopK added in v0.6.0

func WithDetectionTopK(k int) backends.PipelineOption[*ObjectDetectionPipeline]

func WithFirstAggregation added in v0.3.4

func WithFirstAggregation() backends.PipelineOption[*TokenClassificationPipeline]

WithFirstAggregation sets the aggregation strategy for the token labels to first It reproduces first aggregation from the huggingface implementation.

func WithFixedPadding added in v0.5.1

func WithFixedPadding(fixedPaddingLength int) backends.PipelineOption[*TextClassificationPipeline]

func WithHypothesisTemplate added in v0.1.4

func WithHypothesisTemplate(hypothesisTemplate string) backends.PipelineOption[*ZeroShotClassificationPipeline]

WithHypothesisTemplate can be used to set the hypothesis template for classification.

func WithIDLabelMap added in v0.6.2

func WithIDLabelMap(labels map[int]string) backends.PipelineOption[*TabularPipeline]

func WithIgnoreLabels

func WithIgnoreLabels(ignoreLabels []string) backends.PipelineOption[*TokenClassificationPipeline]

func WithImageMode added in v0.6.0

WithImageMode enables image feature extraction mode for vision encoders (e.g., CLIP visual encoder). When enabled, the pipeline accepts images instead of text and skips tokenization.

func WithLabels added in v0.1.4

WithLabels can be used to set the labels to classify the examples.

func WithMaxAggregation added in v0.3.4

WithMaxAggregation sets the aggregation strategy for the token labels to Max It reproduces max aggregation from the huggingface implementation.

func WithMaxLength added in v0.6.0

func WithMaxLength(maxLength int) backends.PipelineOption[*TextGenerationPipeline]

WithMaxLength allows the user to define the maximum generated tokens.

func WithMultiLabel added in v0.0.9

func WithMultilabel added in v0.1.4

func WithMultilabel(multilabel bool) backends.PipelineOption[*ZeroShotClassificationPipeline]

WithMultilabel can be used to set whether the pipeline is multilabel.

func WithNCHWFormat added in v0.5.7

func WithNCHWFormat[T imagePipeline]() backends.PipelineOption[T]

func WithNHWCFormat added in v0.5.7

func WithNHWCFormat[T imagePipeline]() backends.PipelineOption[T]

func WithNormalization added in v0.1.1

WithNormalization applies normalization to the mean pooled output of the feature pipeline.

func WithNormalizationSteps added in v0.5.0

func WithNormalizationSteps[T imagePipeline](steps ...imageutil.NormalizationStep) backends.PipelineOption[T]

func WithOutputName added in v0.1.4

func WithOutputName(outputName string) backends.PipelineOption[*FeatureExtractionPipeline]

WithOutputName if there are multiple outputs from the underlying model, which output should be returned. If not passed, the first output from the feature pipeline is returned.

func WithPreprocessSteps added in v0.5.0

func WithPreprocessSteps[T imagePipeline](steps ...imageutil.PreprocessStep) backends.PipelineOption[T]

WithPreprocessSteps is a unified option to add image preprocessing steps to any pipeline that supports them (e.g., FeatureExtractionPipeline in image mode and ImageClassificationPipeline). This avoids conflicting option names.

func WithRegression added in v0.6.2

func WithRegression() backends.PipelineOption[*TabularPipeline]

func WithScoreThreshold added in v0.5.0

func WithScoreThreshold(threshold float32) backends.PipelineOption[*CrossEncoderPipeline]

func WithScoresOutput added in v0.6.0

func WithScoresOutput(name string) backends.PipelineOption[*ObjectDetectionPipeline]

func WithSeed added in v0.6.3

func WithSigmoid added in v0.0.9

func WithSimpleAggregation

func WithSimpleAggregation() backends.PipelineOption[*TokenClassificationPipeline]

WithSimpleAggregation sets the aggregation strategy for the token labels to simple It reproduces simple aggregation from the huggingface implementation.

func WithSingleLabel added in v0.0.9

func WithSoftmax added in v0.0.9

func WithSortResults added in v0.5.0

func WithSortResults(sort bool) backends.PipelineOption[*CrossEncoderPipeline]

func WithSplitWords added in v0.5.9

WithSplitWords enables word-level alignment like Hugging Face's is_split_into_words.

func WithStopSequences added in v0.6.3

func WithStopSequences(stopSequences []string) backends.PipelineOption[*TextGenerationPipeline]

WithStopSequences allows the user to define stop sequences that will end the generation when encountered. If the model produces any of the provided strings in the output, generation for that sequence will stop and the stop string will be excluded.

func WithStreaming added in v0.6.0

WithStreaming allows the user to receive generated tokens as a stream instead of waiting for the entire response.

func WithSystemPrompt added in v0.6.2

func WithSystemPrompt(systemPrompt string) backends.PipelineOption[*TextGenerationPipeline]

WithSystemPrompt allows the user to define a system prompt that will be prepended to every input.

func WithTabularSigmoid added in v0.6.2

func WithTabularSigmoid() backends.PipelineOption[*TabularPipeline]

func WithTabularSoftmax added in v0.6.2

func WithTabularSoftmax() backends.PipelineOption[*TabularPipeline]

func WithTemperature added in v0.6.3

func WithTemperature(temperature float64) backends.PipelineOption[*TextGenerationPipeline]

func WithTopK added in v0.5.0

WithTopK sets the number of top classifications to return.

func WithTopP added in v0.6.3

func WithoutAggregation

WithoutAggregation returns the token labels.

Types

type ClassificationOutput

type ClassificationOutput struct {
	Label string
	Score float32
}

type CrossEncoderOutput added in v0.5.0

type CrossEncoderOutput struct {
	Results []CrossEncoderResult
}

func (*CrossEncoderOutput) GetOutput added in v0.5.0

func (t *CrossEncoderOutput) GetOutput() []any

type CrossEncoderPipeline added in v0.5.0

type CrossEncoderPipeline struct {
	*backends.BasePipeline
	// contains filtered or unexported fields
}

func NewCrossEncoderPipeline added in v0.5.0

func NewCrossEncoderPipeline(config backends.PipelineConfig[*CrossEncoderPipeline], s *options.Options, model *backends.Model) (*CrossEncoderPipeline, error)

func (*CrossEncoderPipeline) Forward added in v0.5.0

func (p *CrossEncoderPipeline) Forward(batch *backends.PipelineBatch) error

func (*CrossEncoderPipeline) GetMetadata added in v0.5.0

func (*CrossEncoderPipeline) GetModel added in v0.5.0

func (p *CrossEncoderPipeline) GetModel() *backends.Model

func (*CrossEncoderPipeline) GetStatistics added in v0.5.9

func (*CrossEncoderPipeline) IsGenerative added in v0.6.0

func (p *CrossEncoderPipeline) IsGenerative() bool

INTERFACE IMPLEMENTATIONS.

func (*CrossEncoderPipeline) Postprocess added in v0.5.0

func (p *CrossEncoderPipeline) Postprocess(batch *backends.PipelineBatch, documents []string) (*CrossEncoderOutput, error)

func (*CrossEncoderPipeline) Preprocess added in v0.5.0

func (p *CrossEncoderPipeline) Preprocess(batch *backends.PipelineBatch, inputs []string) error

func (*CrossEncoderPipeline) Run added in v0.5.0

func (*CrossEncoderPipeline) RunPipeline added in v0.5.0

func (p *CrossEncoderPipeline) RunPipeline(query string, documents []string) (*CrossEncoderOutput, error)

func (*CrossEncoderPipeline) Validate added in v0.5.0

func (p *CrossEncoderPipeline) Validate() error

type CrossEncoderResult added in v0.5.0

type CrossEncoderResult struct {
	Document string
	Score    float32
	Index    int
}

type CrossEncoderStatistics added in v0.5.9

type CrossEncoderStatistics struct {
	TotalQueries     uint64
	TotalDocuments   uint64
	AverageLatency   time.Duration
	AverageBatchSize float64
	FilteredResults  uint64
}

type Detection added in v0.6.0

type Detection struct {
	Label string
	Class int
	Box   [4]float32 // [xmin, ymin, xmax, ymax] in pixels
	Score float32
}

type Entity added in v0.0.5

type Entity struct {
	Entity    string
	Word      string
	Scores    []float32
	TokenID   []uint32
	Index     int
	Start     uint
	End       uint
	Score     float32
	IsSubword bool
}

type FeatureExtractionOutput

type FeatureExtractionOutput struct {
	Embeddings [][]float32
}

func (*FeatureExtractionOutput) GetOutput added in v0.0.5

func (t *FeatureExtractionOutput) GetOutput() []any

type FeatureExtractionPipeline

type FeatureExtractionPipeline struct {
	*backends.BasePipeline
	OutputName string

	Output backends.InputOutputInfo

	OutputIndex   int // Record the index of the output selected, defaults to first (0)
	Normalization bool
	// contains filtered or unexported fields
}

FeatureExtractionPipeline A feature extraction pipeline is a go version of https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/feature_extraction.py It supports both text and image inputs for embedding extraction.

func NewFeatureExtractionPipeline

func NewFeatureExtractionPipeline(config backends.PipelineConfig[*FeatureExtractionPipeline], s *options.Options, model *backends.Model) (*FeatureExtractionPipeline, error)

NewFeatureExtractionPipeline init a feature extraction pipeline.

func (*FeatureExtractionPipeline) Forward added in v0.1.4

Forward performs the forward inference of the feature extraction pipeline.

func (*FeatureExtractionPipeline) GetMetadata added in v0.1.4

GetMetadata returns metadata information about the pipeline, in particular: OutputInfo: names and dimensions of the output layer.

func (*FeatureExtractionPipeline) GetModel added in v0.3.0

func (p *FeatureExtractionPipeline) GetModel() *backends.Model

func (*FeatureExtractionPipeline) GetStatistics added in v0.5.9

GetStatistics returns the runtime statistics for the pipeline.

func (*FeatureExtractionPipeline) IsGenerative added in v0.6.0

func (p *FeatureExtractionPipeline) IsGenerative() bool

func (*FeatureExtractionPipeline) Postprocess

Postprocess parses the first output from the network similar to the transformers' implementation.

func (*FeatureExtractionPipeline) Preprocess added in v0.1.4

func (p *FeatureExtractionPipeline) Preprocess(batch *backends.PipelineBatch, inputs []string) error

Preprocess tokenizes the input strings.

func (*FeatureExtractionPipeline) PreprocessImages added in v0.6.0

func (p *FeatureExtractionPipeline) PreprocessImages(batch *backends.PipelineBatch, inputs []image.Image) error

PreprocessImages converts images to input tensors for vision models.

func (*FeatureExtractionPipeline) Run

Run the pipeline on a batch of strings.

func (*FeatureExtractionPipeline) RunPipeline added in v0.0.6

func (p *FeatureExtractionPipeline) RunPipeline(inputs []string) (*FeatureExtractionOutput, error)

RunPipeline is like Run, but returns the concrete feature extraction output type rather than the interface.

func (*FeatureExtractionPipeline) RunWithImagePaths added in v0.6.0

func (p *FeatureExtractionPipeline) RunWithImagePaths(paths []string) (*FeatureExtractionOutput, error)

RunWithImagePaths loads images from file paths and runs the pipeline. Convenience method that combines image loading with RunWithImages.

func (*FeatureExtractionPipeline) RunWithImages added in v0.6.0

func (p *FeatureExtractionPipeline) RunWithImages(images []image.Image) (*FeatureExtractionOutput, error)

RunWithImages runs the pipeline on a batch of images (for vision models). Use this method when ImageMode is enabled.

func (*FeatureExtractionPipeline) Validate added in v0.0.5

func (p *FeatureExtractionPipeline) Validate() error

Validate checks that the pipeline is valid.

type ImageClassificationOutput added in v0.5.0

type ImageClassificationOutput struct {
	Predictions [][]ImageClassificationResult // batch of results
}

func (*ImageClassificationOutput) GetOutput added in v0.5.0

func (o *ImageClassificationOutput) GetOutput() []any

type ImageClassificationPipeline added in v0.5.0

type ImageClassificationPipeline struct {
	*backends.BasePipeline
	IDLabelMap map[int]string

	Output backends.InputOutputInfo

	TopK int
	// contains filtered or unexported fields
}

ImageClassificationPipeline is a go version of https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/image_classification.py It takes images (as file paths or image.Image) and returns top-k class predictions.

func NewImageClassificationPipeline added in v0.5.0

func NewImageClassificationPipeline(config backends.PipelineConfig[*ImageClassificationPipeline], s *options.Options, model *backends.Model) (*ImageClassificationPipeline, error)

NewImageClassificationPipeline initializes an image classification pipeline.

func (*ImageClassificationPipeline) Forward added in v0.5.0

Forward runs inference.

func (*ImageClassificationPipeline) GetMetadata added in v0.5.0

func (*ImageClassificationPipeline) GetModel added in v0.5.0

func (*ImageClassificationPipeline) GetStatistics added in v0.5.9

func (*ImageClassificationPipeline) IsGenerative added in v0.6.0

func (p *ImageClassificationPipeline) IsGenerative() bool

func (*ImageClassificationPipeline) Postprocess added in v0.5.0

Postprocess parses logits and returns top-k predictions for each image.

func (*ImageClassificationPipeline) Preprocess added in v0.5.0

func (p *ImageClassificationPipeline) Preprocess(batch *backends.PipelineBatch, inputs []image.Image) error

Preprocess decodes images from file paths or image.Image and creates input tensors. Preprocess loads images from file paths and creates input tensors.

func (*ImageClassificationPipeline) Run added in v0.5.0

Run runs the pipeline on a batch of image file paths.

func (*ImageClassificationPipeline) RunPipeline added in v0.5.0

RunPipeline returns the concrete output type.

func (*ImageClassificationPipeline) RunWithImages added in v0.5.0

func (*ImageClassificationPipeline) Validate added in v0.5.0

func (p *ImageClassificationPipeline) Validate() error

type ImageClassificationResult added in v0.5.0

type ImageClassificationResult struct {
	Label      string
	Score      float32
	ClassIndex int
}

type ObjectDetectionOutput added in v0.6.0

type ObjectDetectionOutput struct {
	Detections [][]Detection
}

func (*ObjectDetectionOutput) GetOutput added in v0.6.0

func (o *ObjectDetectionOutput) GetOutput() []any

type ObjectDetectionPipeline added in v0.6.0

type ObjectDetectionPipeline struct {
	*backends.BasePipeline
	IDLabelMap map[int]string

	BoxesOutput  string
	ScoresOutput string

	TopK           int
	ScoreThreshold float32
	IouThreshold   float32
	// contains filtered or unexported fields
}

ObjectDetectionPipeline implements a Hugging Face-like object detection pipeline. It supports models that output bounding boxes and class scores.

func NewObjectDetectionPipeline added in v0.6.0

func NewObjectDetectionPipeline(config backends.PipelineConfig[*ObjectDetectionPipeline], s *options.Options, model *backends.Model) (*ObjectDetectionPipeline, error)

NewObjectDetectionPipeline initializes an object detection pipeline.

func (*ObjectDetectionPipeline) Forward added in v0.6.0

Forward inference.

func (*ObjectDetectionPipeline) GetMetadata added in v0.6.0

func (*ObjectDetectionPipeline) GetModel added in v0.6.0

func (p *ObjectDetectionPipeline) GetModel() *backends.Model

func (*ObjectDetectionPipeline) GetStatistics added in v0.6.0

func (*ObjectDetectionPipeline) GetStats added in v0.6.0

func (p *ObjectDetectionPipeline) GetStats() []string

func (*ObjectDetectionPipeline) IsGenerative added in v0.6.0

func (p *ObjectDetectionPipeline) IsGenerative() bool

Interface implementations.

func (*ObjectDetectionPipeline) Postprocess added in v0.6.0

Postprocess parses boxes/scores, applies thresholds and NMS.

func (*ObjectDetectionPipeline) Preprocess added in v0.6.0

func (p *ObjectDetectionPipeline) Preprocess(batch *backends.PipelineBatch, inputs []image.Image) error

Preprocess images into tensors.

func (*ObjectDetectionPipeline) Run added in v0.6.0

Run with file paths.

func (*ObjectDetectionPipeline) RunPipeline added in v0.6.0

func (p *ObjectDetectionPipeline) RunPipeline(inputs []string) (*ObjectDetectionOutput, error)

func (*ObjectDetectionPipeline) RunWithImages added in v0.6.0

func (p *ObjectDetectionPipeline) RunWithImages(inputs []image.Image) (*ObjectDetectionOutput, error)

func (*ObjectDetectionPipeline) Validate added in v0.6.0

func (p *ObjectDetectionPipeline) Validate() error

type TabularClassificationOutput added in v0.6.2

type TabularClassificationOutput struct {
	PredictedClass string
	Probabilities  []ClassificationOutput
}

type TabularOutput added in v0.6.2

type TabularOutput struct {
	ClassificationResults []TabularClassificationOutput
	RegressionResults     []float32
}

TabularOutput returns per-input results. - For classification: []TabularClassificationOutput - For regression: float32 for each input.

func (*TabularOutput) GetOutput added in v0.6.2

func (o *TabularOutput) GetOutput() []any

type TabularPipeline added in v0.6.2

type TabularPipeline struct {
	*backends.BasePipeline
	AggregationFunctionName string         // for classification: SOFTMAX or SIGMOID
	ProblemType             string         // "classification" or "regression"
	IDLabelMap              map[int]string // optional mapping from class IDs to labels
}

TabularPipeline supports classic ML models (e.g., decision trees, random forests) exported to ONNX that take numeric feature vectors and output either class logits or regression values.

func NewTabularPipeline added in v0.6.2

func NewTabularPipeline(config backends.PipelineConfig[*TabularPipeline], s *options.Options, model *backends.Model) (*TabularPipeline, error)

NewTabularPipeline initializes the pipeline.

func (*TabularPipeline) Forward added in v0.6.2

func (p *TabularPipeline) Forward(batch *backends.PipelineBatch) error

func (*TabularPipeline) GetMetadata added in v0.6.2

func (p *TabularPipeline) GetMetadata() backends.PipelineMetadata

func (*TabularPipeline) GetModel added in v0.6.2

func (p *TabularPipeline) GetModel() *backends.Model

func (*TabularPipeline) GetStatistics added in v0.6.2

func (p *TabularPipeline) GetStatistics() backends.PipelineStatistics

func (*TabularPipeline) IsGenerative added in v0.6.2

func (p *TabularPipeline) IsGenerative() bool

func (*TabularPipeline) Postprocess added in v0.6.2

func (p *TabularPipeline) Postprocess(batch *backends.PipelineBatch) (*TabularOutput, error)

func (*TabularPipeline) Preprocess added in v0.6.2

func (p *TabularPipeline) Preprocess(batch *backends.PipelineBatch, inputs [][]float32) error

Preprocess parses inputs strings into [][]float32 and builds tensors.

func (*TabularPipeline) Run added in v0.6.2

Run executes the pipeline over inputs.

func (*TabularPipeline) RunPipeline added in v0.6.2

func (p *TabularPipeline) RunPipeline(inputs [][]float32) (*TabularOutput, error)

func (*TabularPipeline) Validate added in v0.6.2

func (p *TabularPipeline) Validate() error

type TextClassificationOutput

type TextClassificationOutput struct {
	ClassificationOutputs [][]ClassificationOutput
}

func (*TextClassificationOutput) GetOutput added in v0.0.5

func (t *TextClassificationOutput) GetOutput() []any

type TextClassificationPipeline

type TextClassificationPipeline struct {
	*backends.BasePipeline
	AggregationFunctionName string
	ProblemType             string
	FixedPaddingLength      int
}

func NewTextClassificationPipeline

func NewTextClassificationPipeline(config backends.PipelineConfig[*TextClassificationPipeline], s *options.Options, model *backends.Model) (*TextClassificationPipeline, error)

NewTextClassificationPipeline initializes a new text classification pipeline.

func (*TextClassificationPipeline) Forward

func (*TextClassificationPipeline) GetMetadata added in v0.1.4

GetMetadata returns metadata information about the pipeline, in particular: OutputInfo: names and dimensions of the output layer used for text classification.

func (*TextClassificationPipeline) GetModel added in v0.3.0

func (p *TextClassificationPipeline) GetModel() *backends.Model

func (*TextClassificationPipeline) GetStatistics added in v0.5.9

GetStatistics returns the runtime statistics for the pipeline.

func (*TextClassificationPipeline) IsGenerative added in v0.6.0

func (p *TextClassificationPipeline) IsGenerative() bool

func (*TextClassificationPipeline) Postprocess

func (*TextClassificationPipeline) Preprocess added in v0.1.4

func (p *TextClassificationPipeline) Preprocess(batch *backends.PipelineBatch, inputs []string) error

Preprocess tokenizes the input strings.

func (*TextClassificationPipeline) Run

Run the pipeline on a string batch.

func (*TextClassificationPipeline) RunPipeline added in v0.0.6

func (p *TextClassificationPipeline) RunPipeline(inputs []string) (*TextClassificationOutput, error)

func (*TextClassificationPipeline) Validate added in v0.0.5

func (p *TextClassificationPipeline) Validate() error

Validate checks that the pipeline is valid.

type TextGenerationOutput added in v0.5.0

type TextGenerationOutput struct {
	TokenStream chan backends.SequenceDelta
	ErrorStream chan error
	Responses   []string
}

func (*TextGenerationOutput) GetOutput added in v0.5.0

func (t *TextGenerationOutput) GetOutput() []any

type TextGenerationPipeline added in v0.5.0

type TextGenerationPipeline struct {
	*backends.BasePipeline
	SystemPrompt  string
	MaxLength     int
	Streaming     bool
	Temperature   *float64
	TopP          *float64
	Seed          *int
	StopSequences []string
}

func NewTextGenerationPipeline added in v0.5.0

func NewTextGenerationPipeline(config backends.PipelineConfig[*TextGenerationPipeline], s *options.Options, model *backends.Model) (*TextGenerationPipeline, error)

NewTextGenerationPipeline initializes a new text generation pipeline.

func (*TextGenerationPipeline) Forward added in v0.5.0

Forward initiates the generation loop.

func (*TextGenerationPipeline) GetMetadata added in v0.5.0

func (*TextGenerationPipeline) GetModel added in v0.5.0

func (p *TextGenerationPipeline) GetModel() *backends.Model

func (*TextGenerationPipeline) GetStatistics added in v0.5.9

GetStatistics returns the runtime statistics for the pipeline.

func (*TextGenerationPipeline) IsGenerative added in v0.6.0

func (p *TextGenerationPipeline) IsGenerative() bool

func (*TextGenerationPipeline) Preprocess added in v0.5.0

func (p *TextGenerationPipeline) Preprocess(batch *backends.PipelineBatch, inputs any) error

func (*TextGenerationPipeline) Run added in v0.5.0

func (*TextGenerationPipeline) RunMessages added in v0.6.0

func (p *TextGenerationPipeline) RunMessages(ctx context.Context, inputs [][]backends.Message) (*TextGenerationOutput, error)

RunMessages processes a batch of message inputs. If multimodal, the images should be added to the messages.

func (*TextGenerationPipeline) RunPipeline added in v0.5.0

func (p *TextGenerationPipeline) RunPipeline(ctx context.Context, inputs []string) (*TextGenerationOutput, error)

RunPipeline processes a batch of string inputs.

func (*TextGenerationPipeline) Validate added in v0.5.0

func (p *TextGenerationPipeline) Validate() error

type TokenClassificationOutput

type TokenClassificationOutput struct {
	Entities [][]Entity
}

func (*TokenClassificationOutput) GetOutput added in v0.0.5

func (t *TokenClassificationOutput) GetOutput() []any

type TokenClassificationPipeline

type TokenClassificationPipeline struct {
	*backends.BasePipeline
	IDLabelMap          map[int]string
	AggregationStrategy string
	IgnoreLabels        []string
	SplitWords          bool
}

TokenClassificationPipeline is a go version of huggingface tokenClassificationPipeline. https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/token_classification.py

func NewTokenClassificationPipeline

func NewTokenClassificationPipeline(config backends.PipelineConfig[*TokenClassificationPipeline], s *options.Options, model *backends.Model) (*TokenClassificationPipeline, error)

NewTokenClassificationPipeline Initializes a feature extraction pipeline.

func (*TokenClassificationPipeline) Aggregate

func (p *TokenClassificationPipeline) Aggregate(input backends.TokenizedInput, preEntities []Entity) ([]Entity, error)

func (*TokenClassificationPipeline) Forward added in v0.1.4

Forward performs the forward inference of the pipeline.

func (*TokenClassificationPipeline) GatherPreEntities

func (p *TokenClassificationPipeline) GatherPreEntities(input backends.TokenizedInput, output [][]float32) []Entity

GatherPreEntities from batch of logits to list of pre-aggregated outputs.

func (*TokenClassificationPipeline) GetMetadata added in v0.1.4

GetMetadata returns metadata information about the pipeline, in particular: OutputInfo: names and dimensions of the output layer used for token classification.

func (*TokenClassificationPipeline) GetModel added in v0.3.0

func (*TokenClassificationPipeline) GetStatistics added in v0.5.9

GetStatistics returns the runtime statistics for the pipeline.

func (*TokenClassificationPipeline) GroupEntities

func (p *TokenClassificationPipeline) GroupEntities(entities []Entity) ([]Entity, error)

GroupEntities group together adjacent tokens with the same entity predicted.

func (*TokenClassificationPipeline) IsGenerative added in v0.6.0

func (p *TokenClassificationPipeline) IsGenerative() bool

func (*TokenClassificationPipeline) Postprocess

Postprocess function for a token classification pipeline.

func (*TokenClassificationPipeline) Preprocess added in v0.1.4

func (p *TokenClassificationPipeline) Preprocess(batch *backends.PipelineBatch, inputs []string) error

Preprocess tokenizes the input strings.

func (*TokenClassificationPipeline) PreprocessWords added in v0.5.9

func (p *TokenClassificationPipeline) PreprocessWords(batch *backends.PipelineBatch, inputs [][]string) error

PreprocessWords tokenizes pre-split words and maps tokens to word IDs via offsets.

func (*TokenClassificationPipeline) Run

Run the pipeline on a string batch.

func (*TokenClassificationPipeline) RunPipeline added in v0.0.6

RunPipeline is like Run but returns the concrete type rather than the interface.

func (*TokenClassificationPipeline) RunWords added in v0.5.9

RunWords runs the pipeline for pre-split word inputs. Each input is a slice of words representing a pretokenized sentence. This is particularly useful when the user wants to control tokenization because of special tokens, hashtags, or other domain-specific tokenization needs.

func (*TokenClassificationPipeline) Validate added in v0.0.5

func (p *TokenClassificationPipeline) Validate() error

Validate checks that the pipeline is valid.

type ZeroShotClassificationOutput added in v0.1.4

type ZeroShotClassificationOutput struct {
	Sequence     string
	SortedValues []struct {
		Key   string
		Value float64
	}
}

type ZeroShotClassificationPipeline added in v0.1.4

type ZeroShotClassificationPipeline struct {
	*backends.BasePipeline
	HypothesisTemplate string
	Sequences          []string
	Labels             []string
	EntailmentID       int
	Multilabel         bool
}

func NewZeroShotClassificationPipeline added in v0.1.4

NewZeroShotClassificationPipeline create new Zero Shot Classification Pipeline.

func (*ZeroShotClassificationPipeline) Forward added in v0.1.4

func (*ZeroShotClassificationPipeline) GetMetadata added in v0.1.4

func (*ZeroShotClassificationPipeline) GetModel added in v0.3.0

func (*ZeroShotClassificationPipeline) GetStatistics added in v0.5.9

GetStatistics returns the runtime statistics for the pipeline.

func (*ZeroShotClassificationPipeline) IsGenerative added in v0.6.0

func (p *ZeroShotClassificationPipeline) IsGenerative() bool

func (*ZeroShotClassificationPipeline) Postprocess added in v0.1.4

func (p *ZeroShotClassificationPipeline) Postprocess(outputTensors [][][]float32, labels []string, sequences []string) (*ZeroShotOutput, error)

func (*ZeroShotClassificationPipeline) Preprocess added in v0.1.4

func (p *ZeroShotClassificationPipeline) Preprocess(batch *backends.PipelineBatch, inputs []string) error

func (*ZeroShotClassificationPipeline) Run added in v0.1.4

func (*ZeroShotClassificationPipeline) RunPipeline added in v0.1.4

func (p *ZeroShotClassificationPipeline) RunPipeline(inputs []string) (*ZeroShotOutput, error)

func (*ZeroShotClassificationPipeline) Validate added in v0.1.4

func (p *ZeroShotClassificationPipeline) Validate() error

type ZeroShotOutput added in v0.1.4

type ZeroShotOutput struct {
	ClassificationOutputs []ZeroShotClassificationOutput
}

func (*ZeroShotOutput) GetOutput added in v0.1.4

func (t *ZeroShotOutput) GetOutput() []any

GetOutput converts raw output to readable output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL