Model Description
This is a fine-tuned T5-large model for IT help desk ticket categorization and summarization. The model takes ticket titles and descriptions as input and outputs structured predictions for:
- System Category: The type of system or technology involved (e.g., "Computer", "Network", "Software")
- Topic Summary: A concise summary of the issue or topic
The model uses special tokens to structure its output:
<|sys|>...system category...</|sys|>for system classification<|top|>...topic summary...</|top|>for topic summarization
Usage
Input Format
The model expects input in the following format: <|title|>{ticket_title}</|title|><|desc|>{ticket_description}</|desc|>
Output Parsing
The model outputs structured text that needs to be parsed using the provided OutputParser class to extract the system category and topic summary.
Example
# Example prediction
title = "Windows Stuck"
description = "I cannot start my computer because Windows keeps getting stuck on a blue screen."
prediction = predict_ticket_summary(model, title, description)
system, topic = OutputParser.parse_prediction(prediction)
print(f"System: {system}")
print(f"Topic: {topic}")
Requirements
To use this model, you'll need to install the following dependencies:
pip install torch transformers sentencepiece
The requirements are based on:
torch- Used for the PyTorch model and tensor operationstransformers- For the T5 model and tokenizer classessentencepiece- Required by the T5 tokenizer for text tokenizationThe requirements are based on:torch- Used for the PyTorch model and tensor operationstransformers- For the T5 model and tokenizer classessentencepiece- Required by the T5
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
import re
model_path = "KameronB/sitcc-t5-large-v4"
# Load the model
model = T5ForConditionalGeneration.from_pretrained(model_path, use_safetensors=True)
# Load the tokenizer (if applicable)
tokenizer = T5Tokenizer.from_pretrained(model_path)
model.half()
def create_model_input(short_description:str, description:str, max_chars = 1024) -> str:
# Convert the newlines to sentences
lines = description.split("\n")
for line in lines:
if line[-1] in [".", "!", "?"]:
line += " "
else:
line += ". "
description = "".join(lines)
# constrain the description to the specified length
total_chars = 0
sentences = []
for s in sent_tokenize(description):
total_chars += len(s)
if total_chars < max_chars:
sentences.append(s)
else:
break
description = " ".join(sentences)
return "<|title|>" + short_description + "</|title|><|desc|>" + description + "</|desc|>"
def predict_ticket_summary(model:T5ForConditionalGeneration, title, description, max_length=128):
"""
Generate system and topic predictions for a ticket using quantized model
"""
# Format input text as used during training
input_text = create_model_input(title, description, max_length)
# Clear any previous tokenizer state and create fresh inputs
tokenizer.pad_token = tokenizer.eos_token # Ensure pad token is set
# Tokenize input with explicit parameters to avoid caching issues
inputs = tokenizer(
input_text,
return_tensors="pt",
max_length=512,
truncation=True,
padding=True,
add_special_tokens=False # Explicitly add special tokens
)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=max_length,
do_sample=False,
)
# Decode prediction
prediction = tokenizer.decode(outputs[0], skip_special_tokens=False)
return prediction
class OutputParser:
SYS_TOKEN = "<|sys|>"
SYS_END_TOKEN = "</|sys|>"
TOP_TOKEN = "<|top|>"
TOP_END_TOKEN = "</|top|>"
LINE_RE = re.compile(r"(</\|(?:sys|top)\|>|<\|(?:sys|top)\|>|(?:<(?!/?\|(?:sys|top)\|>)|[^<])+)")
@classmethod
def parse_prediction(cls, prediction: str) -> tuple[str, str]:
# remove other special tokens
prediction = prediction.replace("<pad>", "").replace("</s>", "").strip()
mode = None
sys_content, top_content = [], []
for m in cls.LINE_RE.finditer(prediction):
token = m.group(0).strip()
if mode == None:
if token == cls.SYS_TOKEN or token == cls.SYS_END_TOKEN:
mode = cls.SYS_TOKEN
continue
elif token == cls.TOP_TOKEN or token == cls.TOP_END_TOKEN:
mode = cls.TOP_TOKEN
continue
else:
mode = cls.SYS_TOKEN
sys_content.append(token)
continue
elif mode == cls.SYS_TOKEN:
if token == cls.SYS_END_TOKEN or token == cls.SYS_TOKEN:
mode = cls.SYS_END_TOKEN
continue
elif token == cls.TOP_TOKEN:
mode = cls.TOP_TOKEN
continue
else:
sys_content.append(token)
elif mode == cls.SYS_END_TOKEN:
if token == cls.TOP_TOKEN or token == cls.TOP_END_TOKEN:
mode = cls.TOP_TOKEN
continue
else:
continue
elif mode == cls.TOP_TOKEN:
if token == cls.TOP_TOKEN:
continue
elif token == cls.TOP_END_TOKEN:
break
else:
top_content.append(token)
return " ".join(sys_content).strip(), " ".join(top_content).strip()
OutputParser.parse_prediction(predict_ticket_summary(model, "Windows Stuck", "I cannot start my computer because Windows keeps getting stuck on a blue screen."))
- Downloads last month
- 9
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support