---
title: "Fine-tuning a DistilBERT classifier with numerical and text inputs"
description: "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."
url: "https://swe.quest/articles/fine-tuning-a-distilbert-classifier-with-numerical-and-text-inputs-c6c37c6fa2b0960a"
canonical: "https://engineering.freeagent.com/2026/04/10/fine-tuning-a-distilbert-classifier-with-numerical-and-text-inputs/"
source: "FreeAgent Engineering"
published: "2026-04-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["model-training","machine-learning","python"]
---

# Fine-tuning a DistilBERT classifier with numerical and text inputs

A post on [FreeAgent Engineering](https://swe.quest/sources/freeagent.md), published 2026-04-10, 10 min read, How-to. Original: [https://engineering.freeagent.com/2026/04/10/fine-tuning-a-distilbert-classifier-with-numerical-and-text-inputs/](https://engineering.freeagent.com/2026/04/10/fine-tuning-a-distilbert-classifier-with-numerical-and-text-inputs/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch nn.Module basics
- Hugging Face transformers
- fine-tuning BERT classifiers ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- scikit-learn preprocessing

## Keywords

DistilBERT, Hugging Face Transformers, PyTorch, scikit-learn, Kaggle wine reviews

## Related posts

- [Federated Learning using Hugging Face and Flower](https://swe.quest/articles/federated-learning-using-hugging-face-and-flower-51b18eb47f6bd9fe.md): Hugging Face · 2023-03-27 · Medium · 5 min read · Model training, Machine learning, Python, Privacy
  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 Partnership: Amazon SageMaker and Hugging Face](https://swe.quest/articles/the-partnership-amazon-sagemaker-and-hugging-face-bdc6f1a55662e5fc.md): Hugging Face · 2021-03-23 · Medium · 14 min read · Model training, ML platforms, Cloud platforms, Python
  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.
- [Supercharged Customer Service with Machine Learning](https://swe.quest/articles/supercharged-customer-service-with-machine-learning-40f2ea8336a86ea0.md): Hugging Face · 2022-04-25 · Medium · 22 min read · Model training, Machine learning, Python
  A walkthrough of building a classifier that flags very unsatisfied customer messages by framing the problem as 5-class sentiment text classification.
- [Training Machine Learning Models with ClickHouse](https://swe.quest/articles/training-machine-learning-models-with-clickhouse-fff12f2958d1827c.md): ClickHouse · 2024-04-03 · Medium · 25 min read · ML platforms, Analytics & OLAP, Machine learning, Python
  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.
- [Convert Transformers to ONNX with Hugging Face Optimum](https://swe.quest/articles/convert-transformers-to-onnx-with-hugging-face-optimum-86f6804aa2e19f43.md): Hugging Face · 2022-06-22 · Medium · 5 min read · Inference & serving, Machine learning, Python
  Hugging Face Transformers models can be exported to ONNX in three ways, shown here on a DistilBERT text-classification checkpoint.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
