Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

FreeAgent Engineering 10 min read How-to mediumAdept

Fine-tuning a DistilBERT classifier with numerical and text inputs

A DistilBERT text classifier can take a numeric feature directly by concatenating the scaled value to the 768-dimensional [CLS] embedding before a custom classification head. Price and description are trained end to end as one network instead of serialising the number into the text with a [SEP] token. Using the Kaggle wine reviews dataset (description plus price, three rating classes), the walkthrough subclasses DistilBertForSequenceClassification and TextClassificationPipeline so the setup stays compatible with Hugging Face Trainer and pipelines. One epoch of training reaches 85% test accuracy against a 59% majority baseline, and the approach is then compared with a text-only model that appends the price as a string.

Assumes: PyTorch nn.Module basicsHugging Face transformersfine-tuning BERT classifiersscikit-learn preprocessing

Related posts

  • Federated Learning using Hugging Face and Flower

    Hugging Face mediumAdept

    Federated 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.

  • The Partnership: Amazon SageMaker and Hugging Face

    Hugging Face mediumAdept

    Hugging Face and AWS partner, making AWS Hugging Face's preferred cloud and introducing Hugging Face Deep Learning Containers plus a HuggingFace Estimator in the SageMaker Python SDK for training Transformers models. An end-to-end walkthrough fine-tunes DistilBERT on IMDB binary sentiment classification: setting up a SageMaker session and IAM role, writing a Trainer-based train.py that reads SageMaker environment variables, tokenizing and uploading datasets to S3, and launching a training job with estimator.fit(). The containers also support SageMaker's data-parallel and model-parallel distributed training libraries through a distribution parameter, along with automatic hyperparameter tuning.

  • Supercharged Customer Service with Machine Learning

    Hugging Face mediumAdept

    A walkthrough of building a classifier that flags very unsatisfied customer messages by framing the problem as 5-class sentiment text classification. Covers choosing a dataset on the Hugging Face Hub, settling on English Amazon Reviews Multi (1-5 star labels, 200k training examples) over GLUE, Amazon polarity, Tweet eval and Yelp, and choosing a pretrained model by checking GLUE/SuperGLUE leaderboards, landing on microsoft/deberta-v3-base. It then shows code to load and tokenize the data with Datasets and Transformers and fine-tune the model, pushing checkpoints to the Hub.

  • Training Machine Learning Models with ClickHouse

    ClickHouse mediumAdept

    ClickHouse can serve as both the transformation engine and offline store in a virtual feature store, using the open-source Featureform as an orchestration layer. Exploration and feature engineering run as SQL at the data source, with no need to move data into frameworks like Spark, and results persist via INSERT INTO SELECT or views. A hands-on walkthrough deploys Featureform with ClickHouse in Docker, registers a Kaggle credit card fraud dataset, and defines versioned features. Those features are then used to train Logistic Regression and Decision Tree classifiers.

  • Convert Transformers to ONNX with Hugging Face Optimum

    Hugging Face mediumAdept

    Hugging Face Transformers models can be exported to ONNX in three ways, shown here on a DistilBERT text-classification checkpoint. The low-level torch.onnx.export requires manually specifying input/output names and dynamic axes. transformers.onnx derives these from per-architecture config objects. Optimum's ORTModelForXxx classes convert in one call with from_transformers=True and return a model usable directly in pipelines. Once a model is in ONNX it can go on to ONNX Runtime acceleration, static quantization (~3x latency gains claimed) or TensorRT conversion.

The quest for software engineering knowledge.

Look:
Layout: