Fine-Tuning vs. Frozen Embeddings: Choosing an Efficient LLM Classification Approach
Fine-Tuning vs. Frozen Embeddings: When to Adapt the LLM or the Classifier
By Iván Palomares Carrascosa · October 27, 2026 · Language Models
The key choice in adapting a language model for a domain is how much of the model to change. Fine-tuning with LoRA can adjust the model itself; a classifier trained on frozen embeddings leaves its weights untouched. That difference affects compute, training time, and potentially accuracy. The right choice depends on what the task needs—and what your hardware and budget can support.
This article compares the two approaches in a practical classification exercise. It covers frozen embeddings as a lightweight option, QLoRA fine-tuning with Hugging Face and PEFT, and the resulting training time and accuracy on a real dataset. The comparison is useful, though its small sample means the results should be read as a focused demonstration rather than a definitive ranking.

Two ways to adapt a model
Fine-tuning is the familiar route: update model parameters using examples from the target domain. LoRA, or Low-Rank Adaptation, makes those updates more efficient. The alternative is to keep the language model fixed, extract its embeddings, and train a smaller downstream classifier—in this case, a scikit-learn head.
Here's the practical distinction: one method spends compute changing the model’s representation; the other asks whether that representation is already good enough for the classification task. If you're choosing an approach for a constrained application, the second option deserves a serious look. A simpler training step may be sufficient, but the fragment doesn’t establish which method wins on accuracy or time.
Comparison setup
The example uses the AG News dataset from Hugging Face, which groups news articles into four categories. It loads Qwen/Qwen2.5-1.5B; the code also points out that meta-llama/Meta-Llama-3-8B can be substituted. To keep the run short, it selects 800 shuffled training examples and 200 shuffled test examples, using seed 42. That scale makes the exercise manageable, but limits how far its results can be generalized.
For a Google Colab run, the instructions call for a T4 GPU. The listed install command is:
!pip install -q -U bitsandbytes peft accelerate evaluateIn another Python environment, the article also calls for scikit-learn, transformers, and datasets. The setup imports PyTorch, NumPy, timing utilities, Hugging Face dataset loading, and Transformer classes for tokenization, sequence classification, and quantization configuration. It then loads the model and tokenizer with a classification head suited to the dataset’s four labels.
The walkthrough assumes basic familiarity with LLMs, fine-tuning, and Hugging Face’s transformers. The central question is straightforward: when does adapting the model pay for its added training cost, and when can a frozen representation do the job?
Preparing the model
The setup keeps the base model in 4-bit form and adds a four-class sequence classification head. That reduces the model’s memory footprint, though the code doesn’t say which model or hardware the run uses. It also assigns the end-of-sequence token as padding, a practical fix for decoder-only models that may not define a separate padding token.
print("2. Configuring Tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
tokenizer.pad_token = tokenizer.eos_token # Necessary for decoder-only models
print("3. Loading Base Model in 4-bit...")
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4"
)
# Loading the model with a classification head
model = AutoModelForSequenceClassification.from_pretrained(
MODEL_ID,
num_labels=4,
quantization_config=bnb_config,
device_map="auto"
)
model.config.pad_token_id = tokenizer.pad_token_idStrategy A: Frozen embeddings and scikit-learn
The alternative to fine-tuning is to hold the language model’s weights fixed and use it as a feature extractor. Text passes through the model, and its hidden-state vectors become input features for a separate, lightweight classifier. That’s a useful baseline when changing the LLM itself would add too much cost or complexity.
There’s a small but meaningful difference between the description and the implementation: the prose refers to taking the final token’s embedding, while the function below averages the hidden states for all non-padding tokens. It processes texts in batches of eight, truncates inputs at 128 tokens, and returns the pooled vectors as NumPy float32 arrays.
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
def extract_embeddings(texts, batch_size=8):
model.eval()
embeddings = []
for i in range(0, len(texts), batch_size):
batch = texts[i:i+batch_size]
inputs = tokenizer(batch, return_tensors="pt", padding=True, truncation=True, max_length=128).to(model.device)
with torch.no_grad():
# output_hidden_states=True forces the model to return the raw vectors
outputs = model(**inputs, output_hidden_states=True)
last_hidden_state = outputs.hidden_states[-1]
# Mean pooling: averaging the vectors across the sequence length, ignoring padding tokens
mask = inputs["attention_mask"].unsqueeze(-1).float()
sum_embeds = torch.sum(last_hidden_state * mask, dim=1)
mean_pooled = sum_embeds / torch.clamp(mask.sum(dim=1), min=1e-9)
embeddings.append(mean_pooled.cpu().numpy().astype(np.float32))
return np.concatenate(embeddings, axis=0)Mean pooling masks out padding before averaging, so short inputs aren’t diluted by padded positions. The imports point toward a Random Forest classifier and accuracy scoring, although this fragment doesn’t show the classifier being trained or evaluated.
The embedding function processes texts in batches, tokenizes each batch with padding and truncation at 128 tokens, then runs the model without gradient tracking. It averages the final hidden-state vectors across each sequence, using the attention mask to exclude padding, and collects the results as `float32` NumPy arrays. Finally, it concatenates the batches into one embedding matrix. The next step is to apply that function to the dataset’s existing training and test splits. Those frozen embeddings become the inputs for training and evaluating a random forest classifier.