Transformers.js documentation
processors
processors
Processors are used to prepare inputs (e.g., text, image or audio) for a model.
Example: Using a WhisperProcessor to prepare an audio input for a model.
import { AutoProcessor, read_audio } from '@huggingface/transformers';
const processor = await AutoProcessor.from_pretrained('openai/whisper-tiny.en');
const audio = await read_audio('https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac', 16000);
const { input_features } = await processor(audio);
// Tensor {
// data: Float32Array(240000) [0.4752984642982483, 0.5597258806228638, 0.56434166431427, ...],
// dims: [1, 80, 3000],
// type: 'float32',
// size: 240000,
// }- processors
- static
- .Processor
new Processor(config, components, chat_template)- instance
.image_processorβImageProcessor|undefined.tokenizerβPreTrainedTokenizer|undefined.feature_extractorβFeatureExtractor|undefined.apply_chat_template(messages, options)βReturnType.<PreTrainedTokenizer>.batch_decode(...args)βReturnType.<PreTrainedTokenizer>.decode(...args)βReturnType.<PreTrainedTokenizer>._call(input, ...args)βPromise.<any>
- static
.from_pretrained(pretrained_model_name_or_path, options)βPromise.<Processor>
- .Processor
- inner
~PreTrainedTokenizer:Object
- static
processors.Processor
Represents a Processor that extracts features from an input.
Kind: static class of processors
- .Processor
new Processor(config, components, chat_template)- instance
.image_processorβImageProcessor|undefined.tokenizerβPreTrainedTokenizer|undefined.feature_extractorβFeatureExtractor|undefined.apply_chat_template(messages, options)βReturnType.<PreTrainedTokenizer>.batch_decode(...args)βReturnType.<PreTrainedTokenizer>.decode(...args)βReturnType.<PreTrainedTokenizer>._call(input, ...args)βPromise.<any>
- static
.from_pretrained(pretrained_model_name_or_path, options)βPromise.<Processor>
new Processor(config, components, chat_template)
Creates a new Processor with the given components
| Param | Type |
|---|---|
| config | Object |
| components | Record.<string, Object> |
| chat_template | string |
processor.image_processor β ImageProcessor | undefined
Kind: instance property of Processor
Returns: ImageProcessor | undefined - The image processor of the processor, if it exists.
processor.tokenizer β PreTrainedTokenizer | undefined
Kind: instance property of Processor
Returns: PreTrainedTokenizer | undefined - The tokenizer of the processor, if it exists.
processor.feature_extractor β FeatureExtractor | undefined
Kind: instance property of Processor
Returns: FeatureExtractor | undefined - The feature extractor of the processor, if it exists.
processor.apply_chat_template(messages, options) β ReturnType. < PreTrainedTokenizer >
Kind: instance method of Processor
| Param | Type |
|---|---|
| messages | Parameters |
| options | Parameters |
processor.batch_decode(...args) β ReturnType. < PreTrainedTokenizer >
Kind: instance method of Processor
| Param | Type |
|---|---|
| ...args | Parameters.<PreTrainedTokenizer> |
processor.decode(...args) β ReturnType. < PreTrainedTokenizer >
Kind: instance method of Processor
| Param | Type |
|---|---|
| ...args | Parameters.<PreTrainedTokenizer> |
processor._call(input, ...args) β Promise. < any >
Calls the feature_extractor function with the given input.
Kind: instance method of Processor
Returns: Promise.<any> - A Promise that resolves with the extracted features.
| Param | Type | Description |
|---|---|---|
| input | any | The input to extract features from. |
| ...args | any | Additional arguments. |
Processor.from_pretrained(pretrained_model_name_or_path, options) β Promise. < Processor >
Instantiate one of the processor classes of the library from a pretrained model.
The processor class to instantiate is selected based on the image_processor_type (or feature_extractor_type; legacy)
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path if possible)
Kind: static method of Processor
Returns: Promise.<Processor> - A new instance of the Processor class.
| Param | Type | Description |
|---|---|---|
| pretrained_model_name_or_path | string | The name or path of the pretrained model. Can be either:
|
| options | PretrainedProcessorOptions | Additional options for loading the processor. |
processors~PreTrainedTokenizer : Object
Additional processor-specific properties.
Kind: inner typedef of processors
Update on GitHub