The standard way to train a sentiment model on IMDB reviews is to gather every nasty comment and glowing recommendation into one massive dataset. That works, but it also means someone, somewhere, has access to all of it. A new tutorial from the Flower federated learning framework shows how to build the same model while keeping each client’s data completely local, using Hugging Face’s Transformers for the model and Flower to orchestrate the training.

The setup is disarmingly simple. You load the IMDB dataset through Hugging Face’s datasets library, tokenize it with DistilBERT, and wrap it in PyTorch dataloaders. The tutorial pares the dataset down to 100 training samples and 100 test samples — a deliberate choice to keep compute time manageable for a demo, not a production benchmark. The actual training loop is vanilla PyTorch, complete with AdamW at a 5e-5 learning rate. Nothing exotic there.

Where it gets interesting is the IMDBClient class. It inherits from Flower’s NumPyClient and implements the two methods that matter: get_parameters, which ships model weights to the server, and the corresponding update method that applies aggregated weights locally. Each client trains on its own slice of data, then sends only the parameters back. The server aggregates them using a predefined strategy and redistributes the result.

Flower has been pushing hard to make federated learning approachable for mainstream ML practitioners, and this integration with Hugging Face is a logical next step. The notebook even offers a simulation mode, so you can test the whole federated workflow inside a single Colab instance before you spin up a real multi-machine setup. That lowers the barrier considerably — federated learning has historically been the domain of people willing to manage infrastructure, not people who just want to train a sentiment classifier. For anyone in healthcare, finance, or any field where raw data can’t leave the device, this is the clearest path yet to a production-grade model that respects that constraint.