Views
No views yet
masabhuq/stl_phone_summarizerpip install unsloth torch1from unsloth import FastLanguageModel
2from unsloth.chat_templates import get_chat_template
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 "masabhuq/stl_phone_summarizer",
6 max_seq_length=2048,
7 dtype=None, # Auto-detect (bfloat16 if supported)
8 load_in_4bit=True, # 4-bit quantization for memory efficiency
9)
10FastLanguageModel.for_inference(model)1tokenizer = get_chat_template(
2 tokenizer,
3 chat_template="llama-3.2",
4 map_eos_token=True,
5)1system_prompt = (
2 "You are an expert at summarizing phone specifications into short, appealing key descriptions for an e-commerce site. "
3 "Always output in exactly this format:\n"
4 "Display: [concise display summary]\n"
5 "Processor: [processor name]\n"
6 "Camera: [camera highlights]\n"
7 "Battery: [battery capacity and charging]\n"
8 "Others: [comma-separated unique features]. "
9 "Focus on desirable aspects like high refresh rates, zoom capabilities, fast charging, and unique features such as water resistance or special sensors. "
10 "Do not include complicated keyboards that don't make sense on their own. "
11 "Do not include words that are too technical to understand for someone who is not highly tech savvy. "
12 "Output should be within 280 characters. Don't include anything like IPDC or IP64 or any such features in the result. Words starting with IP are not to be considered display feature."
13)
14
15specs = "Build: Glass front (Gorilla Glass 5), silicone polymer back (eco leather), plastic frame\nWeight: 178 g ..."
16
17prompt = [
18 {"role": "system", "content": system_prompt},
19 {"role": "user", "content": specs}
20]
21
22formatted_prompt = tokenizer.apply_chat_template(
23 prompt,
24 tokenize=False,
25 add_generation_prompt=True,
26)1import torch
2
3inputs = tokenizer(formatted_prompt, return_tensors="pt").to("cuda")
4outputs = model.generate(
5 **inputs,
6 max_new_tokens=256,
7 do_sample=True,
8 temperature=0.7,
9 top_p=0.9,
10)1generated_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
2# Extract the last paragraph and clean up
3paragraphs = generated_text.strip().split("\n\n")
4last_paragraph = paragraphs[-1]
5clean_last_paragraph = last_paragraph.split("<|eot_id|>")[0].strip()
6print(clean_last_paragraph)1model.cpu()
2torch.cuda.empty_cache()model.cpu()).model.cpu() and torch.cuda.empty_cache() to free GPU memory after inference, especially on low-VRAM GPUs.temperature and top_p for more or less creative outputs, and max_new_tokens for longer or shorter summaries.unsloth/Llama-3.2-3B-Instruct-bnb-4bitr=16, targeting modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"].specs) paired with concise summaries (output) in the format shown above.trl.SFTTrainer, train_on_responses_only to focus on assistant responses, and Llama-3.2 chat template for single-turn interactions.specs_list.json) containing pairs of detailed phone specifications and their corresponding summaries. Each entry includes:specs: Detailed technical specs (e.g., display size, chipset, camera details).output: A concise summary in the format:
Display: [summary]
Processor: [name]
Camera: [highlights]
Battery: [capacity and charging]
Others: [features]LICENSE file in the repository for details.1@misc{stl_phone_summarizer,
2 author = {masabhuq},
3 title = {STL Phone Summarizer: A Fine-Tuned Llama-3.2 Model for Phone Specification Summaries},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/masabhuq/stl_phone_summarizer}}
7}1model.cpu()
2torch.cuda.empty_cache()