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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
from datetime import date, timedelta
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
random.seed(155)
|
| 8 |
+
|
| 9 |
+
OUT_DIR = Path("data/synthetic_customer_support")
|
| 10 |
+
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 11 |
+
|
| 12 |
+
START_DATE = date(2025, 1, 1)
|
| 13 |
+
|
| 14 |
+
PRODUCTS = [
|
| 15 |
+
"AI Assistant SaaS",
|
| 16 |
+
"ERP Cloud Suite",
|
| 17 |
+
"Private AI Desktop",
|
| 18 |
+
"CRM Automation",
|
| 19 |
+
"Analytics Dashboard",
|
| 20 |
+
"eCommerce Growth Pack",
|
| 21 |
+
"HR Recruiter AI",
|
| 22 |
+
"Document Intelligence API"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
CATEGORIES = [
|
| 26 |
+
"Billing",
|
| 27 |
+
"Login Issue",
|
| 28 |
+
"Feature Request",
|
| 29 |
+
"Bug Report",
|
| 30 |
+
"Account Setup",
|
| 31 |
+
"Integration",
|
| 32 |
+
"Performance",
|
| 33 |
+
"Data Import",
|
| 34 |
+
"Subscription",
|
| 35 |
+
"General Question"
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
PRIORITIES = ["Low", "Medium", "High", "Urgent"]
|
| 39 |
+
STATUSES = ["Open", "Pending", "Resolved", "Closed"]
|
| 40 |
+
CHANNELS = ["Email", "Chat", "Phone", "Web Form", "In-App"]
|
| 41 |
+
SENTIMENTS = ["Positive", "Neutral", "Negative", "Frustrated"]
|
| 42 |
+
PLANS = ["Free", "Starter", "Professional", "Business", "Enterprise"]
|
| 43 |
+
|
| 44 |
+
AGENTS = [
|
| 45 |
+
"Support Agent A",
|
| 46 |
+
"Support Agent B",
|
| 47 |
+
"Support Agent C",
|
| 48 |
+
"Support Agent D",
|
| 49 |
+
"Support Agent E"
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
KB_TOPICS = [
|
| 53 |
+
"How to reset password",
|
| 54 |
+
"How to update billing method",
|
| 55 |
+
"How to import CSV data",
|
| 56 |
+
"How to connect API key",
|
| 57 |
+
"How to export reports",
|
| 58 |
+
"How to invite team members",
|
| 59 |
+
"How to troubleshoot slow dashboard",
|
| 60 |
+
"How to upgrade subscription",
|
| 61 |
+
"How to configure integrations",
|
| 62 |
+
"How to use AI assistant"
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
def random_date():
|
| 66 |
+
return START_DATE + timedelta(days=random.randint(0, 364))
|
| 67 |
+
|
| 68 |
+
def write_csv(path, rows):
|
| 69 |
+
with path.open("w", encoding="utf-8", newline="") as f:
|
| 70 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0].keys()))
|
| 71 |
+
writer.writeheader()
|
| 72 |
+
writer.writerows(rows)
|
| 73 |
+
|
| 74 |
+
def write_jsonl(path, rows):
|
| 75 |
+
with path.open("w", encoding="utf-8") as f:
|
| 76 |
+
for row in rows:
|
| 77 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 78 |
+
|
| 79 |
+
kb_rows = []
|
| 80 |
+
for i, topic in enumerate(KB_TOPICS, start=1):
|
| 81 |
+
kb_rows.append({
|
| 82 |
+
"article_id": f"KB-{i:05d}",
|
| 83 |
+
"title": topic,
|
| 84 |
+
"category": random.choice(CATEGORIES),
|
| 85 |
+
"product": random.choice(PRODUCTS),
|
| 86 |
+
"summary": f"Synthetic help article explaining: {topic}.",
|
| 87 |
+
"recommended_action": random.choice([
|
| 88 |
+
"Follow step-by-step guide",
|
| 89 |
+
"Check account settings",
|
| 90 |
+
"Contact support if issue continues",
|
| 91 |
+
"Review integration configuration",
|
| 92 |
+
"Retry after clearing cache"
|
| 93 |
+
]),
|
| 94 |
+
"is_synthetic": True,
|
| 95 |
+
"source": "Synthetic Realigns customer support dataset",
|
| 96 |
+
"license": "Synthetic data generated for public developer use"
|
| 97 |
+
})
|
| 98 |
+
|
| 99 |
+
tickets = []
|
| 100 |
+
interactions = []
|
| 101 |
+
|
| 102 |
+
for i in range(1, 2001):
|
| 103 |
+
ticket_id = f"TICKET-{i:07d}"
|
| 104 |
+
created_date = random_date()
|
| 105 |
+
priority = random.choice(PRIORITIES)
|
| 106 |
+
status = random.choice(STATUSES)
|
| 107 |
+
category = random.choice(CATEGORIES)
|
| 108 |
+
|
| 109 |
+
first_response_hours = {
|
| 110 |
+
"Low": random.uniform(6, 48),
|
| 111 |
+
"Medium": random.uniform(2, 24),
|
| 112 |
+
"High": random.uniform(0.5, 8),
|
| 113 |
+
"Urgent": random.uniform(0.1, 2),
|
| 114 |
+
}[priority]
|
| 115 |
+
|
| 116 |
+
resolution_hours = first_response_hours + random.uniform(2, 120)
|
| 117 |
+
if status in ["Open", "Pending"]:
|
| 118 |
+
resolution_hours = None
|
| 119 |
+
|
| 120 |
+
tickets.append({
|
| 121 |
+
"ticket_id": ticket_id,
|
| 122 |
+
"created_date": created_date.isoformat(),
|
| 123 |
+
"customer_plan": random.choice(PLANS),
|
| 124 |
+
"product": random.choice(PRODUCTS),
|
| 125 |
+
"category": category,
|
| 126 |
+
"priority": priority,
|
| 127 |
+
"status": status,
|
| 128 |
+
"channel": random.choice(CHANNELS),
|
| 129 |
+
"assigned_agent": random.choice(AGENTS),
|
| 130 |
+
"sentiment": random.choice(SENTIMENTS),
|
| 131 |
+
"first_response_hours": round(first_response_hours, 2),
|
| 132 |
+
"resolution_hours": round(resolution_hours, 2) if resolution_hours is not None else None,
|
| 133 |
+
"sla_breached": bool(resolution_hours and resolution_hours > random.choice([24, 48, 72])),
|
| 134 |
+
"related_kb_article_id": random.choice(kb_rows)["article_id"],
|
| 135 |
+
"is_synthetic": True,
|
| 136 |
+
"privacy_note": "No real customers, emails, phone numbers, account IDs, or private support messages are included.",
|
| 137 |
+
"source": "Synthetic Realigns customer support dataset",
|
| 138 |
+
"license": "Synthetic data generated for public developer use"
|
| 139 |
+
})
|
| 140 |
+
|
| 141 |
+
for j in range(random.randint(1, 6)):
|
| 142 |
+
interaction_date = created_date + timedelta(days=random.randint(0, 20))
|
| 143 |
+
interactions.append({
|
| 144 |
+
"interaction_id": f"INT-{len(interactions) + 1:08d}",
|
| 145 |
+
"ticket_id": ticket_id,
|
| 146 |
+
"interaction_date": interaction_date.isoformat(),
|
| 147 |
+
"sender_type": random.choice(["Customer", "Support Agent", "System"]),
|
| 148 |
+
"channel": random.choice(CHANNELS),
|
| 149 |
+
"message_type": random.choice(["Question", "Reply", "Status Update", "Troubleshooting Step", "Resolution Note"]),
|
| 150 |
+
"message_summary": random.choice([
|
| 151 |
+
"Customer reported an issue and requested help.",
|
| 152 |
+
"Agent provided troubleshooting instructions.",
|
| 153 |
+
"System updated ticket status.",
|
| 154 |
+
"Customer confirmed issue still exists.",
|
| 155 |
+
"Agent shared knowledge base guidance.",
|
| 156 |
+
"Ticket was resolved after follow-up."
|
| 157 |
+
]),
|
| 158 |
+
"is_synthetic": True,
|
| 159 |
+
"source": "Synthetic Realigns customer support dataset",
|
| 160 |
+
"license": "Synthetic data generated for public developer use"
|
| 161 |
+
})
|
| 162 |
+
|
| 163 |
+
write_csv(OUT_DIR / "synthetic_support_tickets.csv", tickets)
|
| 164 |
+
write_jsonl(OUT_DIR / "synthetic_support_tickets.jsonl", tickets)
|
| 165 |
+
|
| 166 |
+
write_csv(OUT_DIR / "synthetic_support_interactions.csv", interactions)
|
| 167 |
+
write_jsonl(OUT_DIR / "synthetic_support_interactions.jsonl", interactions)
|
| 168 |
+
|
| 169 |
+
write_csv(OUT_DIR / "synthetic_support_knowledge_base.csv", kb_rows)
|
| 170 |
+
write_jsonl(OUT_DIR / "synthetic_support_knowledge_base.jsonl", kb_rows)
|
| 171 |
+
|
| 172 |
+
metadata = {
|
| 173 |
+
"dataset": "Synthetic Customer Support Tickets Dataset",
|
| 174 |
+
"prepared_by": "Realigns Inc.",
|
| 175 |
+
"records": {
|
| 176 |
+
"support_tickets": len(tickets),
|
| 177 |
+
"support_interactions": len(interactions),
|
| 178 |
+
"knowledge_base_articles": len(kb_rows)
|
| 179 |
+
},
|
| 180 |
+
"year": 2025,
|
| 181 |
+
"privacy": "No real customers, emails, phone numbers, account IDs, support messages, or private customer service records are included.",
|
| 182 |
+
"intended_use": [
|
| 183 |
+
"AI customer support assistant testing",
|
| 184 |
+
"helpdesk dashboard development",
|
| 185 |
+
"ticket classification",
|
| 186 |
+
"SLA analytics",
|
| 187 |
+
"sentiment and priority analysis",
|
| 188 |
+
"RAG support workflows"
|
| 189 |
+
],
|
| 190 |
+
"license": "Synthetic data generated for public developer use"
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
(OUT_DIR / "metadata.json").write_text(json.dumps(metadata, indent=2), encoding="utf-8")
|
| 194 |
+
|
| 195 |
+
print("Done. Synthetic Customer Support dataset created.")
|
| 196 |
+
print(json.dumps(metadata, indent=2))
|