Views
No views yet
1generation_config = {
2 "max_new_tokens": 128,
3 "temperature": 0.7,
4 "do_sample": True,
5 "top_p": 0.9,
6 "top_k": 50,
7}pip install unsloth transformers peft torch1from peft import PeftModel
2from transformers import AutoModelForCausalLM, AutoTokenizer
3import torch
4
5# Load base model
6base_model = AutoModelForCausalLM.from_pretrained(
7 "microsoft/Phi-4-Mini",
8 device_map="auto",
9 torch_dtype=torch.float16,
10 trust_remote_code=True,
11)
12
13# Load tokenizer
14tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-Mini", trust_remote_code=True)
15
16# Load LoRA adapter
17model = PeftModel.from_pretrained(base_model, "Lakshan2003/Phi-4-mini-instruct-customerservice")
18
19# Merge adapter (optional, for deployment)
20model = model.merge_and_unload()
21model.eval()1# Prompt template (adjust for Phi format)
2prompt_template = """<|system|>
3{instruction}<|end|>
4<|user|>
5Conversation History:
6{history}
7
8Client Question:
9{client_question}<|end|>
10<|assistant|>
11"""
12
13# Example conversation
14instruction = "You are a professional call-center customer service agent working at Optimal Financial Partners. Review the conversation history and any provided context (if available). Make sure your response is consistent with the conversation history (names, issues, and actions already taken). If no history is given, treat the client’s message as the start of the conversation. Continue the dialogue as the agent by giving a clear, helpful, and professional response. Responses should sound natural and human-like, like a real phone call, and usually be few short sentences. Provide more detail when the client’s request clearly requires it."
15history = "Kathrine has contacted Almira from Optimal Financial Partners regarding unexpected charges on her statement and her rights as a consumer. Almira confirmed that as a customer, Kathrine has the right to dispute any unauthorized or incorrect charges. Almira offered to investigate any charges Kathrine believes are incorrect. No specific charges, amounts, or account identifiers have been mentioned, and no verification steps have been completed or are pending at this time. The conversation is currently focused on explaining consumer rights and the process for disputing charges."
16client_question = "That's great to know. What if I'm not satisfied with the outcome of the investigation?"
17
18# Format input
19input_text = prompt_template.format(
20 instruction=instruction,
21 history=history,
22 client_question=client_question
23)
24
25# Tokenize
26inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512).to(model.device)
27
28# Generate
29with torch.no_grad():
30 outputs = model.generate(
31 **inputs,
32 max_new_tokens=128,
33 temperature=0.7,
34 do_sample=True,
35 top_p=0.9,
36 top_k=50,
37 pad_token_id=tokenizer.eos_token_id,
38 eos_token_id=tokenizer.eos_token_id,
39 )
40
41# Decode response
42input_length = inputs.input_ids.shape[1]
43response = tokenizer.decode(outputs[0][input_length:], skip_special_tokens=True).strip()
44print(response)1@article{cooray2026small,
2 title={Can Small Language Models Handle Context-Summarized Multi-Turn Customer-Service QA? A Synthetic Data-Driven Comparative Evaluation},
3 author={Cooray, Lakshan and Sumanathilaka, Deshan and Raju, Pattigadapa Venkatesh},
4 journal={arXiv preprint arXiv:2602.00665},
5 year={2026}
6}