Sentiment Analysis on Encrypted Data with Homomorphic Encryption
Sentiment classification can run on encrypted text by computing a transformer (RoBERTa) hidden representation on the client, then running a quantized XGBoost classifier under fully homomorphic encryption with Concrete-ML. On the Twitter airline sentiment dataset the transformer-embedding + XGBoost model reaches 85% accuracy (above the transformer alone at 80%), and FHE predictions match clear-text probabilities exactly. Compilation takes about 9 seconds and FHE inference about 4.4 seconds per example on a 16-core CPU. Deployment uses Concrete-ML's FHEModelDev API to export client/server artifacts, demonstrated in a Hugging Face Space with a Gradio client and a FastAPI server.
Related posts
- Running Privacy-Preserving Inferences on Hugging Face Endpoints
Hugging Face mediumAdeptZama's Concrete ML models, compiled for Fully Homomorphic Encryption (FHE), can be deployed as Hugging Face Inference Endpoints using custom inference handlers. Clients quantize and encrypt inputs locally, upload FHE evaluation keys in chunks (about 70 MB), and receive encrypted predictions that only they can decrypt. The handler exposes save_key, append_key and inference methods. Keys live in endpoint RAM, so they are lost on restart and not shared across replicas, and machines top out at 8 vCPUs. Measured latencies range from 0.4 s for logistic regression to 24 s for a CNN on MNIST.
- Towards Encrypted Large Language Models with FHE
Hugging Face hardMasterA single attention head of GPT2's first multi-head attention layer can run on encrypted data using TFHE via Zama's Concrete-Python and Concrete-ML, with the rest of the model executing in plaintext on the client. Weights and activations are post-training quantized to integers, nonlinearities become Programmable Bootstrapping table lookups, and the Hugging Face transformers forward pass is overridden with a quantized SingleHeadAttention module. Four-bit quantization keeps about 96% of original top-k accuracy on roughly 80 sentences, and the compiled circuit needs 8-bit width. A 6-token sequence costs 11,622 PBS operations, which takes minutes on CPU; the authors expect future FHE ASICs to bring that under 100 ms.
- Data-Centric Machine Learning: Building Shopify Inbox’s Message Classification Model
Shopify Engineering mediumAdeptShopify Inbox's message classifier improved from ~70% to ~90% accuracy, and from ~35% to ~80% high-confidence coverage, by investing in better training data rather than model tweaks. The v1 prototype used Universal Sentence Encoder embeddings with UMAP/HDBSCAN clustering and semi-supervised labeling on 40,000 examples. For v2, the team fine-tuned DistilBERT on 20,000 human-labeled messages. Those labels came from a 45-topic taxonomy built with support advisors and domain experts, refined through inter-annotator agreement exercises, and scrubbed of personal information with Presidio and Faker. Model predictions were then used to surface underrepresented topics for further annotation.
- Federated Learning using Hugging Face and Flower
Hugging Face mediumAdeptFederated fine-tuning of a pre-trained distilBERT model for IMDB sentiment classification uses Flower to coordinate multiple clients and a server, so raw data never leaves the clients. The walkthrough covers loading and tokenizing IMDB with Hugging Face datasets, standard PyTorch train/test loops, a Flower NumPyClient that exchanges model state_dict parameters, and a server running the FedAvg strategy with weighted metric aggregation over three rounds. A Colab notebook variant uses Flower's simulation mode (start_simulation) instead of separate client processes.
- Getting Started with Sentiment Analysis on Twitter
Hugging Face mediumAdeptTwitter sentiment analysis can be done with an off-the-shelf model instead of manual labeling, and two routes are shown: code and no-code. Developers can pull tweets with Tweepy and classify them through the Hugging Face Inference API using cardiffnlp/twitter-roberta-base-sentiment-latest, then chart the results with pandas, Matplotlib and WordCloud. A sample run on 1,000 tweets mentioning Notion came out 50% positive and 8.2% negative. Non-coders can build a Zapier workflow that triggers on Twitter mentions, calls the Inference API and writes the results to Google Sheets.