---
title: "Python"
description: "252 posts about Python, summarised, each linking to the original."
---

# Python
> 252 posts about Python, summarised, each linking to the original.

## Articles

### [Gradio 3.0 is Out!](https://yomu.fyi/post/gradio-3-0-is-out.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Abubakar Abid
- Published: May 16, 2022
- Type: Announcement

Gradio 3.0 introduces a ground-up redesign of the Gradio library to improve machine learning demo development and browser performance. The frontend has been rebuilt using modern technologies such as Svelte, resulting in smaller payloads, faster page load times, and cleaner visual designs suitable for embedding in blog posts. Component updates include revamping the Dataframe component to support CSV drag-and-drop, introducing new UI elements like Gallery, and adding the TabbedInterface class to group demos under distinct tabs. Developers also gain access to Gradio Blocks, a low-level Python API enabling custom layouts, multi-step interfaces, dynamic component property modifications, and complex data flows. A competition called the Gradio Blocks Party has been organized through the end of May to encourage community adoption.


### [Accelerated Inference with Optimum and Transformers Pipelines](https://yomu.fyi/post/accelerated-inference-with-optimum-and-transformers-pipelines.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Philipp Schmid
- Published: May 10, 2022
- Type: Announcement

Transformer-based models are moving into production for large-scale workloads, but default implementations remain slow and resource-intensive compared to traditional machine learning algorithms. Hugging Face Optimum addresses this issue by integrating performance optimization tools and accelerated runtimes like ONNX Runtime directly into standard Transformers pipelines. Developers replace standard model classes with Optimum equivalents to convert models to ONNX, run graph optimizations such as operator fusion, and apply quantization. In an evaluation on an AWS EC2 m5.xlarge CPU instance, optimizing and quantizing a RoBERTa question-answering model cut average latency from 117.61 ms to 64.94 ms while retaining 99.61 percent accuracy. Known limitations include a 2GB remote model size limit, lack of seq2seq support, omitted past key values in causal language models, and no local caching for optimized ONNX models.


### [Welcome fastai to the Hugging Face Hub](https://yomu.fyi/post/welcome-fastai-to-the-hugging-face-hub.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Omar Espejel
- Published: May 6, 2022
- Type: Tutorial

Hugging Face Hub has integrated with the fastai deep learning library, allowing practitioners to upload and download models directly through the huggingface\_hub Python client. Fastai Learner objects, which bundle model architectures, data loaders, and loss functions, can be published to a designated repository namespace using push\_to\_hub\_fastai. Uploaded models automatically receive Git-based version control, Git LFS support for large files, and generated model cards. Practitioners can retrieve and instantiate published models locally for inference or transfer learning via from\_pretrained\_fastai. The integration also supports Blurr, an ecosystem library that combines fastai with Hugging Face Transformers for sequence classification and related text modeling tasks.


### [Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel](https://yomu.fyi/post/accelerate-large-model-training-using-pytorch-fully-sharded-data-paral.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Sourab Mangrulkar, Sylvain Gugger
- Published: May 2, 2022
- Type: Benchmark

Increasing parameter counts in modern machine learning models make loading and training them prohibitive on standard hardware. While Distributed Data Parallel replicates the entire model across GPUs, PyTorch Fully Sharded Data Parallel shards optimizer states, gradients, and parameters across data-parallel workers. Benchmarks on causal language modeling using GPT-2 Large and XL across Titan RTX GPUs demonstrate that FSDP increases allowable batch sizes and prevents out-of-memory errors encountered in standard DDP. Integrating FSDP through Hugging Face Accelerate enables these capabilities alongside CPU offloading to run models exceeding GPU memory limits. However, Accelerate requires preparing models before creating optimizers when using multiple models and notes that mixed precision support with FSDP currently has transformer compatibility issues.


### [Opinion Classification with Kili and HuggingFace AutoTrain](https://yomu.fyi/post/opinion-classification-with-kili-and-huggingface-autotrain.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Alper
- Published: Apr 28, 2022
- Type: Tutorial

Understanding mobile application user feedback often requires expensive and labor-intensive manual analysis. To streamline this process, an active learning pipeline was constructed using Kili for data annotation alongside HuggingFace AutoTrain and standard transformers for text classification. The workflow utilized approximately 40,000 Medium reviews collected from the Google Play Store, classifying content into categories such as Subscription, Content, Interface, and User Experience. Hyperparameter searches with Ray backend were compared against AutoTrain, which automated training within 30 minutes. Subsequent sentiment analysis of the categorized reviews revealed that while overall sentiment remained positive, subscription and interface categories contained predominantly negative feedback, especially in application version 4.5.


### [Getting Started with Transformers on Habana Gaudi](https://yomu.fyi/post/getting-started-with-transformers-on-habana-gaudi.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Julien Simon
- Published: Apr 26, 2022
- Type: Tutorial

Habana Labs and Hugging Face partnered to accelerate Transformer model training using Habana Gaudi accelerators, which offer up to 40% better price performance than recent GPU-based Amazon EC2 instances. Setting up the environment requires launching an Amazon EC2 dl1.24xlarge instance using the Habana Deep Learning Base AMI on Ubuntu 20.04. Inside an interactive PyTorch Docker container configured for Habana runtimes, users install the Optimum Habana package from source along with necessary dependencies. Fine-tuning the bert-large-uncased-whole-word-masking model on the GLUE MRPC task completes in 2 minutes and 12 seconds with an F1 score of 0.9181. Utilizing EC2 Spot Instances reduces the hourly compute cost by 70%, from $13.11 down to $3.93.


### [Supercharged Customer Service with Machine Learning](https://yomu.fyi/post/supercharged-customer-service-with-machine-learning.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Patrick von Platen
- Published: Apr 25, 2022
- Type: Tutorial

Customer support teams often receive high volumes of messages that cannot all be answered manually. To prioritize urgent inquiries, support workflows can be modeled as a text classification task to identify the most unsatisfied customers. Using the Hugging Face ecosystem, an NLP pipeline is established by selecting the Amazon reviews multi dataset and fine-tuning a DeBERTa model for sentiment classification across five granular categories. Evaluation on test data shows that the model identifies roughly 95% of unsatisfied messages with an 11.7% false-positive rate on satisfied messages, potentially reducing human triage workload by 83%. For production deployment, performance can be optimized through hardware acceleration, lower precision arithmetic, open-source libraries like Optimum and ONNX Runtime, and inference servers.


### [CO2 Emissions and the 🤗 Hub: Leading the Charge](https://yomu.fyi/post/co2-emissions-and-the-hub-leading-the-charge.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Sasha Luccioni, Zachary Mueller, Nate Raw
- Published: Apr 22, 2022
- Type: Tutorial

Training and deploying machine learning models produces greenhouse gas emissions determined by infrastructure runtime, hardware type, and energy grid carbon intensity. Hugging Face introduced mechanisms to measure, report, and filter models based on their carbon footprint to improve ecological transparency. Using the huggingface\_hub library, practitioners can query HfApi.list\_models with an emissions\_thresholds parameter to filter models by maximum or minimum carbon emissions measured in grams. In addition, installing the codecarbon package enables the Transformers Trainer to automatically attach CodeCarbonCallback and log training emissions to an emissions.csv file. Users can then publish these measured values directly into model card metadata under co2\_eq\_emissions for public tracking.


### [Machine Learning Experts - Lewis Tunstall](https://yomu.fyi/post/machine-learning-experts-lewis-tunstall.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Britney Muller
- Published: Apr 13, 2022
- Type: Explainer

In this interview with Britney Muller, Hugging Face machine learning engineer Lewis Tunstall discusses his background, his book Natural Language Processing with Transformers, and tooling optimizations for deploying transformer models. Tunstall notes that large model parameter sizes often lead to high latency, making off-the-shelf transformers impractical for responsive applications like chatbots. To resolve this issue, he developed single-line export tooling within the transformers library to convert models into the ONNX format. This conversion enables engineers to run PyTorch models in TensorFlow or on specialized hardware, achieving faster latency and higher throughput. Tunstall also recounts co-authoring the O'Reilly book with Leandro von Werra and Thom Wolf, collaborating on the Hugging Face Course, and training a GPT-2 model named code parrot on Python code.


### [The Magic of Merlin: Shopify's New Machine Learning Platform](https://yomu.fyi/post/the-magic-of-merlin-shopify-s-new-machine-learning-platform.md)
- Company: [Shopify](https://yomu.fyi/company/shopify.md)
- Author: 2023-10-18
- Published: Apr 6, 2022
- Type: Explainer

Shopify’s machine learning platform team redesigned its infrastructure to accommodate varied use cases, dependencies, data types, integrations, and production requirements. Merlin uses an open-source stack in which on-demand Merlin Workspaces run as short-lived Ray clusters on Kubernetes, while projects isolate code and dependencies in Docker-based environments. Its first iteration focuses on training and batch inference, with users moving from local or Jupyter-based prototypes to automated production workflows through the Merlin API, Airflow, or Oozie. Shopify validated the platform by migrating its product categorization workflows, using Ray Train for distributed TensorFlow training and Ray ActorPool for batch inference; planned extensions include online inference, model lifecycle management, and machine learning monitoring.


### [~Don't~ Repeat Yourself](https://yomu.fyi/post/don-t-repeat-yourself.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Patrick von Platen
- Published: Apr 5, 2022
- Type: Explainer

Hugging Face's Transformers library intentionally departs from the traditional "Don't repeat yourself" (DRY) software design principle by adopting a single model file policy. This architecture places all code required for a model's forward pass into a dedicated file, avoiding centralized shared modules for components like attention mechanisms. Because machine learning research evolves rapidly and published model architectures remain static, isolating code protects individual models from breaking changes and lowers contribution barriers for the open-source community. To maintain consistency without manually syncing duplicated code across successor models, the library uses automated tooling driven by Copied from comments. While this approach complicates unified API enforcement and component-wide research integration, Transformers validates API consistency by running approximately 20,000 automated tests daily.


### [Introducing Decision Transformers on Hugging Face 🤗](https://yomu.fyi/post/introducing-decision-transformers-on-hugging-face.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Edward Beeching, Thomas Simonini
- Published: Mar 28, 2022
- Type: Announcement

Hugging Face has integrated the Decision Transformer architecture into its transformers library and Hub, expanding support for offline reinforcement learning. Unlike standard reinforcement learning methods that maximize returns by learning value functions or policies through active environment interaction, Decision Transformers model trajectories as conditional sequence problems. The model feeds past states, actions, and target returns-to-go over a context window into a GPT-2 autoregressive backbone to generate future actions. Evaluating pre-trained continuous control checkpoints requires standardizing observations with training set statistics and iteratively updating the target return based on received rewards. This sequence modeling paradigm enables practitioners to adjust agent behaviors and skill levels directly by specifying different target returns at runtime.


### [Faster Pull Request Merges](https://yomu.fyi/post/faster-pull-request-merges.md)
- Company: [Ramp](https://yomu.fyi/company/ramp.md)
- Author: Neal Wu & Young Kim
- Published: Mar 22, 2022
- Type: Problem & solution

Ramp’s growing Python pytest suite took over 12 minutes, while pull requests could wait up to one to two hours between merge queueing and production. Previously, Kodiak kept pull requests in a merge queue, requiring each PR to be up-to-date with master and rerun the full suite after every merge. Removing that requirement exposed a failure mode: parallel branches could introduce Alembic migrations with multiple heads, making the database migration history invalid. Ramp instead added migrations/migration-hash.txt, a hash of migration filenames that creates merge conflicts between migration-changing PRs while leaving other PRs free to merge; the deploy pipeline still runs tests on master before deployment. This reduced average merge time from more than an hour to 12 minutes.


### [Fine-Tune a Semantic Segmentation Model with a Custom Dataset](https://yomu.fyi/post/fine-tune-a-semantic-segmentation-model-with-a-custom-dataset.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Tobias Cornille, Niels Rogge
- Published: Mar 17, 2022
- Type: Tutorial

Fine-tuning a semantic segmentation model requires domain-appropriate training data and an efficient pipeline. Existing autonomous driving datasets feature roadway imagery captured by cars, creating a distribution mismatch for sidewalk-based delivery robots. To resolve this discrepancy, a dedicated dataset of sidewalk imagery is loaded from the Hugging Face Hub, split into training and test sets, and augmented on-the-fly using SegformerImageProcessor and torchvision. The smallest SegFormer architecture, B0, is fine-tuned using Hugging Face's Trainer API with mean Intersection over Union evaluation metrics. The final pipeline pushes the fine-tuned model to the Hub and executes inference by upsampling output logits to original image dimensions.


### [Accelerate BERT inference with Hugging Face Transformers and AWS Inferentia](https://yomu.fyi/post/accelerate-bert-inference-with-hugging-face-transformers-and-aws-infer.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Philipp Schmid
- Published: Mar 16, 2022
- Type: Tutorial

Production deployments of BERT and Transformer architectures often face cost and latency challenges because these models are significantly larger and more computationally intensive than traditional algorithms. To optimize text classification workloads, developers can compile vanilla PyTorch models for AWS Inferentia using the AWS Neuron SDK and its tracing utilities. Because the Neuron SDK requires static tensor dimensions, the model is traced with fixed input lengths and packaged alongside a custom inference script configuring one Neuron Core per worker. Deploying the resulting artifacts to an Amazon SageMaker ml.inf1.xlarge endpoint yields an average latency of 5 to 6 milliseconds for a sequence length of 128 across 10,000 synchronous evaluation requests.


### [Image search with 🤗 datasets](https://yomu.fyi/post/image-search-with-datasets.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Daniel van Strien
- Published: Mar 16, 2022
- Type: Tutorial

Hugging Face datasets expanded its capabilities by introducing an Image feature type, enabling image processing and integration with vector indexing tools. The library was applied to a sample of historical book embellishments extracted via OCR from the British Library. Images were loaded using the ImageFolder loader, enriched with filename metadata, and pushed to the Hugging Face Hub. A FAISS index and CLIP embeddings were used to retrieve images matching natural language queries, such as categories, specific objects, and boolean operators. While the retrieval system demonstrated reasonable semantic search results across various prompts, full public deployment was avoided due to CLIP model card restrictions and potential bias in the historical dataset.


### [Guiding Text Generation with Constrained Beam Search in 🤗 Transformers](https://yomu.fyi/post/guiding-text-generation-with-constrained-beam-search-in-transformers.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Chan Woo Kim
- Published: Mar 11, 2022
- Type: Explainer

Constrained beam search introduces direct control over generated text in Hugging Face Transformers. Standard beam search operates token-by-token without knowing the optimal step to force specific words or phrases, making it difficult to enforce mandatory vocabulary or choose between alternative expressions. To resolve this, the generate interface accepts constraints through arguments such as force\_words\_ids and a list of Constraint subclasses like PhrasalConstraint. This mechanism enables disjunctive constraints, where generation must include at least one phrase from a provided set, alongside strictly required sequences. Consequently, practitioners can inject prior knowledge or formatting requirements directly at generation time rather than filtering candidate outputs afterward.


### [Shopify's Playbook for Scaling Machine Learning](https://yomu.fyi/post/shopify-s-playbook-for-scaling-machine-learning.md)
- Company: [Shopify](https://yomu.fyi/company/shopify.md)
- Author: 2023-10-18
- Published: Feb 11, 2022
- Type: Explainer

Shopify describes how its machine-learning practice grew from a first order-fraud product into a portfolio used across products such as Shopify Capital, product categorization, and Help Center search. The playbook starts with choosing a user-important problem, validating trustworthy and accessible data, tracing downstream dependencies, understanding existing solutions, and optimizing for product outcomes rather than model scores alone. To productionize models, Shopify recommends well-defined training, verification, and testing pipelines, deployment decisions based on volume and user commitment, and platform practices that encode validated standards without abstracting too early. Its fraud pipeline builds models in Python, serializes them with PMML for deployment in Ruby-based production systems, and uses Apache Airflow to schedule operations. The account concludes that scaling is a full-stack problem requiring data scientists and data engineers to align on one roadmap and goal.


### [Fine-Tune ViT for Image Classification with 🤗 Transformers](https://yomu.fyi/post/fine-tune-vit-for-image-classification-with-transformers.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Nate Raw
- Published: Feb 11, 2022
- Type: Tutorial

Vision Transformer models bring transformer architectures to computer vision by splitting images into grids of sub-image patches and projecting them into token sequences. To classify healthy and diseased leaves using the beans dataset, the Hugging Face datasets and transformers libraries enable streamlined data ingestion and model fine-tuning. Preprocessing relies on ViTImageProcessor paired with lazy on-the-fly dataset transforms to dynamically generate normalized pixel tensors. Training leverages ViTForImageClassification with the Trainer API, requiring remove\_unused\_columns set to False so raw image data is preserved for batch collation. Over four training epochs, fine-tuning the google/vit-base-patch16-224-in21k checkpoint achieves an evaluation accuracy of 98.5% alongside an evaluation loss of 0.0637.


### [Getting Started with Sentiment Analysis using Python](https://yomu.fyi/post/getting-started-with-sentiment-analysis-using-python.md)
- Company: [Hugging Face](https://yomu.fyi/company/hugging-face.md)
- Author: Federico Pascual
- Published: Feb 2, 2022
- Type: Tutorial

Modern natural language processing tools allow developers to perform sentiment analysis without deep machine learning expertise. Sentiment analysis categorizes text polarity into positive, negative, or neutral labels to extract insights from large volumes of social posts, reviews, and support tickets. Using the Hugging Face Transformers library and the Hub, practitioners can quickly run pre-trained transformer pipelines or target specific multilingual and emotion-detection models with minimal Python code. For custom requirements, developers can fine-tune models like DistilBERT using the IMDB dataset via the Trainer API or train models automatically with AutoNLP. Applying these workflows to social media data enables automated sentiment distribution analysis and visualization using pandas, matplotlib, and word clouds.


[Newer posts](https://yomu.fyi/topic/python/page/9.md) · [Older posts](https://yomu.fyi/topic/python/page/11.md)
