DEV Community

shashank ms
shashank ms

Posted on

Introduction to Transfer Learning in LLM

We are going to build a support ticket intent classifier using in-context transfer learning. By embedding labeled examples directly into the prompt, we can adapt a general LLM to a specialized classification task without fine-tuning or infrastructure overhead. This approach is ideal for teams that need to ship fast, and Oxlo.ai's flat per-request pricing means long few-shot prompts cost the same as short ones, so you are not penalized for giving the model more context.

What you'll need

  • Python 3.10+
  • An Oxlo.ai API key from https://portal.oxlo.ai
  • The OpenAI SDK installed with pip install openai

1. Configure the Oxlo.ai client

First, instantiate the OpenAI SDK and point it at Oxlo.ai. I use llama-3.3-70b because it follows few-shot instruction reliably.

from openai import OpenAI
import json

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

MODEL = "llama-3.3-70b"

2. Define the categories and examples

Transfer learning here means giving the model a set of input-output pairs so it learns the mapping from raw text to intent. I picked three common support categories and wrote ten short examples.

CATEGORIES = ["Billing", "Technical Issue", "Account Access"]

FEW_SHOT_EXAMPLES = [
    {"text": "I was charged twice for my subscription this month.", "label": "Billing"},
    {"text": "The API returns a 500 error when I post to /v1/chat.", "label": "Technical Issue"},
    {"text": "I forgot my password and the reset email never arrives.", "label": "Account Access"},
    {"text": "Can I get a refund for the Pro plan I bought yesterday?", "label": "Billing"},
    {"text": "WebSocket connections drop after 30 seconds.", "label": "Technical Issue"},
    {"text": "My account is locked after too many login attempts.", "label": "Account Access"},
    {"text": "Why is my invoice showing the wrong company name?", "label": "Billing"},
    {"text": "The Python SDK throws a timeout on large requests.", "label": "Technical Issue"},
    {"text": "I need to change the email associated with my account.", "label": "Account Access"},
    {"text": "Is there a way to download all past invoices at once?", "label": "Billing"},
]

3. Build the system prompt

The system prompt is where the transfer happens. It contains the task definition, the categories, and all ten examples. Because Oxlo.ai does not charge by the token, you can include as many examples as the model's context window allows without worrying about ballooning costs.

SYSTEM_PROMPT = """You are a support ticket classifier. Classify each user message into exactly one of these categories: Billing, Technical Issue, Account Access.

Follow the format of the examples below exactly.

Examples:
Text: I was charged twice for my subscription this month.
Category: Billing

Text: The API returns a 500 error when I post to /v1/chat.
Category: Technical Issue

Text: I forgot my password and the reset email never arrives.
Category: Account Access

Text: Can I get a refund for the Pro plan I bought yesterday?
Category: Billing

Text: WebSocket connections drop after 30 seconds.
Category: Technical Issue

Text: My account is locked after too many login attempts.
Category: Account Access

Text: Why is my invoice showing the wrong company name?
Category: Billing

Text: The Python SDK throws a timeout on large requests.
Category: Technical Issue

Text: I need to change the email associated with my account.
Category: Account Access

Text: Is there a way to download all past invoices at once?
Category: Billing

Respond with a JSON object in this exact format:
{"category": "", "confidence": ""}

Do not include any text outside the JSON object."""

4. Create the classifier function

We call the Oxlo.ai chat completions endpoint with JSON mode enabled. I keep the temperature low so the model sticks to the learned pattern.

def classify_ticket(text: str) -> dict:
    response = client.chat.completions.create(
        model=MODEL,
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": f"Text: {text}"},
        ],
        response_format={"type": "json_object"},
        temperature=0.1,
    )
    raw = response.choices[0].message.content
    return json.loads(raw)

5. Run a batch of unseen tickets

These tickets were not in the example set, so the model must generalize from the transferred knowledge.

if __name__ == "__main__":
    test_tickets = [
        "My credit card was declined but I still got charged.",
        "How do I enable two-factor authentication?",
        "The dashboard loads forever and never shows data.",
    ]

    for ticket in test_tickets:
        result = classify_ticket(ticket)
        print(f"Ticket: {ticket}")
        print(f"Result: {result}")
        print()

Run it

Save the script as classify.py, replace YOUR_OXLO_API_KEY, and run python classify.py. You should see output similar to this:

Ticket: My credit card was declined but I still got charged.
Result: {'category': 'Billing', 'confidence': 'high'}

Ticket: How do I enable two-factor authentication?
Result: {'category': 'Account Access', 'confidence': 'medium'}

Ticket: The dashboard loads forever and never shows data.
Result: {'category': 'Technical Issue', 'confidence': 'high'}

Wrap-up

You now have a working few-shot classifier that runs entirely on Oxlo.ai. To make it production-ready, collect a validation set of 50 labeled tickets and measure precision per category. If you need to handle more categories or longer documents, swap in qwen-3-32b or kimi-k2.6 for larger context windows, still at the same flat per-request cost.

Top comments (0)