Transformers.js documentation
transformers
Get started
Tutorials
Building a Vanilla JS ApplicationBuilding a React ApplicationBuilding a Next.js ApplicationBuilding a Browser ExtensionBuilding an Electron ApplicationServer-side Inference in Node.jsBuilding a Next.js AI Chatbot with Vercel AI SDK
Developer Guides
Running models on WebGPUUsing quantized models (dtypes)Accessing Private/Gated ModelsServer-side Audio Processing
Integrations
API Reference
You are viewing main version, which requires installation from source. If you'd like
regular npm install, checkout the latest stable version (v3.8.1).
transformers
Public API of @huggingface/transformers. Everything re-exported from
this file is considered stable — other imports are internal and may change.
Start here
pipeline()— the one-call entry point for every task.- Environment —
envfields andLogLevelenum.
Model loading
- Pipelines — task-specific pipeline classes (
TextGenerationPipeline, etc.). - Models —
AutoModel*classes (one per task). - Tokenizers —
AutoTokenizer, chat templates,Message. - Processors —
AutoProcessor,AutoImageProcessor,AutoFeatureExtractor. - Configs —
AutoConfig/PretrainedConfig.
Generation
- Generation config — sampling and beam-search parameters.
- Generation parameters — full shape of
generate()arguments. - Logits processors — modify next-token probabilities.
- Stopping criteria — control when generation halts.
- Streamers — receive tokens as they’re produced.
Data types and I/O
- Tensors —
Tensor, shape ops, math, I/O. - Images —
RawImage,load_image(). - Audio —
RawAudio,load_audio(). - Video —
RawVideo,RawVideoFrame,load_video()(experimental).
Utilities
- Hub options — shared
from_pretrained()option shapes. - Maths —
softmax,cos_sim, typed-array helpers. - Model registry — inspect or clear the model cache.
- Random — seedable MT19937 PRNG matching Python’s
random.
Type Definitions
DeviceType
Type: keyof typeof DEVICE_TYPES
DataType
Type: keyof typeof DATA_TYPES