> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# What Changes With Predictive Models

> Explains differences between generative and predictive models, deploying a DistilBERT sentiment classifier with KServe, and how request and response shapes and manifests differ

Welcome to this module on serving predictive models with KServe. In the previous lesson we deployed a generative language model (Qwen) and invoked it with chat-style prompts. In this lesson we'll contrast that workflow with predictive (classification) models: what changes in the request/response shape, what stays the same in your deployment manifest, and why distilled models like DistilBERT are a great fit for production classification tasks.

This guide covers:

* The conceptual difference between generative and predictive models
* Why request and response payloads differ
* How KServe keeps the InferenceService manifest stable across model types
* A brief introduction to model distillation and the DistilBERT sentiment classifier we'll deploy

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/presentation-agenda-predictive-generative-models.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=dd61fe03561c11940783e9a903d5510b" alt="The image shows a presentation agenda with three points: differentiating predictive models from generative models, explaining model type impacts on request/response formats, and describing KServe InferenceService manifest stability." width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/presentation-agenda-predictive-generative-models.jpg" />
</Frame>

## Generative vs Predictive — core concept

A generative model composes new content token-by-token. Example: you ask "Tell me about Kubernetes" and the model generates an explanatory paragraph. Its output space is effectively open-ended.

A predictive model, by contrast, maps inputs to a predefined set of labels. It answers questions like "Which bucket does this input belong to?" or "Which label best describes this input?" The output is a discrete set (e.g., {spam, not_spam}) or a probability distribution over those labels.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/generative-vs-predictive-models-diagram.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=44df6e3cdb0994e83366a5f57cab4638" alt="The image illustrates the core difference between generative and predictive models, showing input from a client going into a predictive model to determine which category it belongs to, resulting in output from a fixed set of answers." width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/generative-vs-predictive-models-diagram.jpg" />
</Frame>

Common predictive examples:

* Spam filtering: label an email `spam` or `not_spam`.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/spam-filtering-predictive-model-diagram.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=4a8002c9439ba24c03e17a23d9f695bc" alt="The image illustrates a spam filtering process using a predictive model, showing email as input and classifying the output as either &#x22;Spam&#x22; or &#x22;Not spam.&#x22;" width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/spam-filtering-predictive-model-diagram.jpg" />
</Frame>

* Image classification: detect whether a photo contains a cat (`cat` / `no_cat`).
* Sentiment analysis: classify text as `positive` or `negative`.

The classifier we’ll deploy in this lesson performs sentiment analysis: it reads a sentence and predicts positive or negative sentiment. This is a canonical predictive task and useful to illustrate the differences from generative workflows.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/predictive-model-flowchart-client-input.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=de2f91855e26fc1c2950438565fc79db" alt="The image displays a flowchart of a predictive model, where a client input (&#x22;This course has been great!&#x22;) is processed to produce either a positive or negative output. It illustrates how the model predicts outcomes based on given inputs." width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/predictive-model-flowchart-client-input.jpg" />
</Frame>

## Distillation — why DistilBERT?

Distillation trains a smaller "student" model to mimic a larger "teacher". The result is a compact model that approximates the teacher's behavior while using far less memory, CPU, and storage. Distilled models trade a small amount of accuracy for much lower inference cost — ideal for production classifiers.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/distillation-machine-learning-models-illustration.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=8312f21ba7da62848ce862ebd050db49" alt="The image explains distillation in machine learning, illustrating how a smaller model is trained to mimic a larger one, with visual representations of a large model, distillation process, and distilled model." width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/distillation-machine-learning-models-illustration.jpg" />
</Frame>

The model we’ll use is:

* Name: `distilbert-base-uncased-finetuned-sst-2-english`
  * DistilBERT: lighter, faster variant of BERT
  * `uncased`: ignores case differences
  * `finetuned SST-2 English`: trained on the Stanford Sentiment Treebank (SST-2) for sentiment classification

When you send a sentence to this model it returns a label (positive/negative) and a confidence score. We pull the model directly from Hugging Face via an hf URI — no external object storage is required. The Hugging Face model URI is:
`hf://distilbert-base-uncased-finetuned-sst-2-english`

## KServe InferenceService — what stays the same

One of KServe's strengths is that the InferenceService manifest and predictor spec look the same whether you deploy a large generative model or a compact classifier. Only a few fields change: most notably the InferenceService `metadata.name` and the `storageUri` (model identifier). Resource requests/limits typically shrink for distilled classifiers.

Example InferenceService manifest (Hugging Face model):

```yaml theme={null}
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
  name: sentiment-classifier
  namespace: kserve-inference
spec:
  predictor:
    model:
      modelFormat:
        name: huggingface
      storageUri: "hf://distilbert-base-uncased-finetuned-sst-2-english"
      resources:
        requests:
          cpu: "500m"
          memory: "1Gi"
        limits:
          cpu: "1"
          memory: "2Gi"
```

Only a few manifest details differ compared to a generative model deployment:

* `metadata.name` — a descriptive name for the InferenceService
* `storageUri` — model identifier (e.g., the Hugging Face URI)
* `resources` — classifiers typically require smaller requests/limits than large generative LLMs

This consistency means you can reuse the same deployment workflow and tooling across generative and predictive models.

## Request / Response shape — what changes

The primary runtime difference is the inference payload. Generative models accept chat-style prompts (a list of messages, system and user roles) and produce open-ended text. Classifiers accept a single input (text or data tensor) and return a label or a probability distribution over labels.

Common payload examples (these are typical shapes — exact format depends on your predictor and KServe runtime configuration):

* Simple instances-style request:

```json theme={null}
{
  "instances": [
    "This course has been great!"
  ]
}
```

* Typical classifier response (probabilities for labels in fixed order `[negative, positive]`):

```json theme={null}
{
  "predictions": [
    [0.02, 0.98]
  ]
}
```

* Alternatively, some Hugging Face-style APIs return labeled results:

```json theme={null}
[
  {
    "label": "POSITIVE",
    "score": 0.9873
  }
]
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/FGVrgw9JPQBH4CfE/images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/qwen-vs-classifier-request-formats.jpg?fit=max&auto=format&n=FGVrgw9JPQBH4CfE&q=85&s=6f72b7b4795c08888663480e9816d67f" alt="The image compares &#x22;Qwen&#x22; and &#x22;Classifier&#x22; request formats, highlighting that Qwen uses chat-style prompts, accepts system and user messages, and generates text responses, whereas the Classifier takes plain text input and returns labels or categories without needing a conversation format." width="1920" height="1080" data-path="images/KServe-Fundamentals-Serving-ML-Models-on-Kubernetes/Serving-a-Predictive-Model/What-Changes-With-Predictive-Models/qwen-vs-classifier-request-formats.jpg" />
</Frame>

Note: the exact JSON keys (`instances` vs `inputs` vs a Hugging Face-specific shape) can differ by predictor and the chosen protocol (V1/V2). KServe docs and your runtime configuration specify the exact expected format.

<Callout icon="lightbulb" color="#1CB2FE">
  Key takeaway: predictive models select from a predefined set of labels (e.g., positive/negative). KServe uses the same InferenceService manifest and runtime for both generative and predictive models; only the inference payload shape changes.
</Callout>

## Quick comparison: generative vs predictive

| Aspect          |               Generative Model | Predictive (Classifier)              |
| --------------- | -----------------------------: | ------------------------------------ |
| Output          |                 Free-form text | Fixed set of labels or probabilities |
| Input           |   Chat-style messages, prompts | Single text or tensor input          |
| Typical use     | Content generation, completion | Classification, detection, ranking   |
| Resource cost   |   Often very high (large LLMs) | Typically lower (distilled models)   |
| KServe manifest |      Same API & predictor spec | Same API & predictor spec            |

## Summary

* Predictive models map inputs to predefined labels rather than generating free-form content.
* DistilBERT (fine-tuned on SST-2) is a compact, production-friendly sentiment classifier.
* KServe keeps the InferenceService manifest and runtime consistent across different model types; only the model URI and resource sizing change.
* The main difference is the runtime payload format: generative models accept prompts/messages, while classifiers expect a single input and return labels or probability distributions.

Next: we'll deploy the sentiment classifier and demonstrate the exact request/response payloads for your KServe setup.

References:

* KServe documentation: [https://kserve.github.io](https://kserve.github.io)
* Hugging Face models: [https://huggingface.co](https://huggingface.co)
* Stanford Sentiment Treebank (SST-2): [https://nlp.stanford.edu/sentiment/](https://nlp.stanford.edu/sentiment/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/kserve-fundamentals-serving-ml-models-on-kubernetes/module/d3f12b82-312d-4aee-a0bc-f5b313a63fd2/lesson/fa8f5ef0-41de-4835-854a-0971e79c2dae" />
</CardGroup>
