The Hugging Face transformers library provides model implementations, preprocessing utilities, training integrations, and convenient loading APIs for pretrained models. A compatible model repository is a versioned collection of model artifacts and configuration files that lets the library reconstruct the model and its inputs.
Repository Contents #
A typical repository contains a model configuration such as config.json, weights in a supported format such as model.safetensors, and preprocessing artifacts. Text models commonly include tokenizer files; vision, audio, and multimodal models may include image, feature-extractor, processor, or generation configuration files.
The configuration identifies the architecture and hyperparameters. The weight files hold learned parameters. Preprocessing files are just as important: using a different tokenizer vocabulary, normalization rule, or image size can make valid weights produce incorrect results.
Use safetensors when possible for downloaded weight files because its format does not execute Python code during deserialization. Treat pickled PyTorch artifacts from untrusted sources as unsafe.
Loading a Repository #
The Auto classes inspect repository metadata and select an appropriate implementation:
from transformers import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("organization/model-name")
model = AutoModel.from_pretrained("organization/model-name")Task-specific variants such as AutoModelForSequenceClassification should be used when the repository exposes a matching head. Pin a revision or commit hash in reproducible applications so a moving repository branch does not silently change a deployment.
Pipelines and Lower-Level APIs #
pipeline() is a useful high-level interface for exploration and simple applications. Lower-level APIs provide more control over tokenization, batching, devices, generation settings, and post-processing:
inputs = tokenizer("A short example", return_tensors="pt")
outputs = model(**inputs)The appropriate level is a design choice, not a quality judgment. Pipelines remove boilerplate; direct model calls are preferable when an application needs explicit control or custom behavior.
Publishing Models #
Before publishing, include enough metadata for another user to reproduce inference: architecture configuration, weights, required tokenizer or processor files, license, intended task, limitations, and an example. Do not require arbitrary remote code unless it is necessary; users who enable remote code should review and pin it because it executes in their Python environment.
Comments
Read or comment on GitHub (sign-in required to comment)