Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of a GPU chip with multiple data streams flowing into a transformer model, representing batch inference
Python

Python Transformers GPU and Batch Inference

python transformers gpu and batch inference: Learn how to run Hugging Face Transformers models on GPU with batched inputs to improve throughput and reduce inference la...

transformersgpubatch inferencehuggingface
Illustration of a Python transformers model being saved to a local directory and reloaded, with weight files and configuration represented as labeled blocks.
Python

Save and Load Local Models with Python Transformers

Use save_pretrained and from_pretrained in Python to save and reload fine-tuned Hugging Face models from a local directory, including what gets written and common failure modes.

transformerssave_pretrainedfrom_pretrainedHugging Face
Diagram showing text input being tokenized and passed through a transformer model to produce embedding vectors.
Python

Python Transformers Embeddings and Feature Extraction

python transformers embeddings and feature extraction: Learn how to extract embeddings and feature vectors from text using Python Transformers, covering tokenization,...

embeddingsfeature extractiontransformersHugging Face
Illustration of Python Transformers handling text summarization, translation, and question answering tasks with distinct icons and a clean technical background.
Python

Python Transformers for Summarization, Translation, and QA

python transformers summarization translation and question answering: Learn to use Python Transformers for summarization, translation, and question answering with prac...

transformershuggingfacenlpsummarization
A diagram showing how padding tokens are added to shorter sequences and how the attention mask marks them as zero so the model ignores them.
Python

Python Transformers: Padding, Truncation, and Attention Masks

Understand how Hugging Face tokenizers use padding, truncation, and attention masks to shape batches for transformer models, with practical examples and common edge cases.

transformerstokenizerattention-maskspadding
Illustration of AutoTokenizer and AutoModel automatically selecting the correct model architecture from a checkpoint name.
Python

Using AutoTokenizer and AutoModel in Hugging Face Transformers

Learn how AutoTokenizer and AutoModel simplify loading pretrained models and tokenizers in the Hugging Face transformers library, including task-specific variants and tokenizer behavior.

Hugging FaceAutoTokenizerAutoModelPretrained Models
A diagram showing text flowing into a transformer pipeline node that splits into a sentiment classification branch and a text generation branch.
Python

Python Transformers Pipeline for Sentiment and Generation

python transformers pipeline text classification sentiment and generation: Use the Transformers pipeline API for sentiment analysis and text generation in Python: mode...

transformerspipeline APIsentiment analysistext generation
A side-by-side visual comparison of PyTorch and TensorFlow code structures, highlighting their different API approaches.
Python

PyTorch vs TensorFlow: Which One Fits Your Project

Compare PyTorch and TensorFlow from a developer's perspective: API design, training loops, debugging, deployment, and decision criteria for your project.

PyTorchTensorFlowDeep LearningKeras
A GPU chip with a memory gauge showing reduced usage after applying PyTorch optimizations.
Python

Python PyTorch GPU Memory Optimization

python pytorch gpu memory optimization: Learn practical techniques to reduce GPU memory usage in PyTorch: mixed precision, gradient accumulation, checkpointing, and pr...

PyTorchGPU memorymixed precisiongradient accumulation
Illustration showing FP32 and FP16 data paths converging through a scaling node inside a neural network training loop.
Python

PyTorch Mixed Precision Training with torch.cuda.amp

Use PyTorch's autocast and GradScaler for mixed precision training on CUDA GPUs: reduce memory use, accelerate Tensor Core GPUs, and avoid gradient underflow.

PyTorchMixed PrecisionAMPGPU Training