File size: 18,578 Bytes
e69482a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | """
Dataset Builder v3 โ Football Prediction Extractor
- Always outputs JSON array (even single tip)
- 70% single-tip / 30% multi-tip (2-4 events)
- Noise: random emojis, typos, missing fields, varied separators
- Varied date formats, bookmakers, times, headers
- Pure stdlib โ no pip installs needed
"""
import csv
import json
import random
from pathlib import Path
from collections import defaultdict
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# CONFIG
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TEAMS_CSV = "teams_tier1_tier2.csv"
OUTPUT_TRAIN = "train_dataset.jsonl"
OUTPUT_VAL = "val_dataset.jsonl"
EXAMPLES_COUNT = 300
VAL_SPLIT = 0.1
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SYSTEM PROMPT โ always array
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SYSTEM_PROMPT = (
"You are a football data extraction assistant. "
"Extract structured data from the message and return ONLY a valid JSON array. "
"Each object in the array must have exactly these keys: "
"league, team_1, team_2, prediction, date, odds. "
"If a field is missing, use null. No extra text, no markdown."
)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# VOCABULARY
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
PREDICTIONS = [
"Over 1.5", "Over 2.5", "Over 3.5",
"Under 2.5", "Under 3.5",
"1X", "X2", "12",
"Home Win", "Away Win", "Draw",
"Both Teams to Score",
"Home Win or Draw",
"Away Win or Draw",
"GG", "NG",
]
DATE_FORMATS = [
lambda d, m, y: f"{d:02d}/{m:02d}/{y}",
lambda d, m, y: f"{d:02d}-{m:02d}-{y}",
lambda d, m, y: f"{d:02d}.{m:02d}.{y}",
lambda d, m, y: f"{['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][m-1]} {d}, {y}",
lambda d, m, y: f"{d} {['January','February','March','April','May','June','July','August','September','October','November','December'][m-1]} {y}",
]
TIMES = ["13:00", "15:00", "16:00", "17:00", "18:00", "19:00", "19:45", "20:00", "20:45", "21:00", "21:45"]
BOOKS = ["BETANO", "Bet365", "William Hill", "Unibet", "1xBet", "Betway", "Bwin", "Pinnacle"]
HEADERS = ["Prediction of the Day", "Football Tip", "Best Bet Today", "Daily Pick", "Top Prediction", "Sure Tip", "VIP Prediction"]
SEPARATORS = [" - ", " vs ", " v ", " โ ", " VS ", " x "]
EXTRA_EMOJIS = ["๐ฅ","๐ฅ","๐ฏ","๐","๐ฐ","๐
","โก๏ธ","๐","๐","โจ","๐","๐","๐ค","๐จ","โ
","โ๏ธ","๐","๐","๐","๐"]
MULTI_HEADERS = [
"โฝ๏ธ ๐๐ซ๐๐๐ข๐๐ญ๐ข๐จ๐ง๐ฌ ๐จ๐ ๐ญ๐ก๐ ๐๐๐ฒ โฝ๏ธ",
"๐ฅ TODAY'S FOOTBALL TIPS ๐ฅ",
"๐ฐ Daily Predictions ๐ฐ",
"โก๏ธ Best Bets Today โก๏ธ",
"๐ Football Tips",
"๐ฏ Today's Picks",
]
MULTI_FOOTERS = [
"For more predictions visit www.eaglepredict.com",
"Follow us for daily tips! ๐",
"Good luck everyone! ๐",
"Join our VIP channel for more! ๐",
"Win big today! ๐ค",
"", # no footer sometimes
]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SINGLE TIP TEMPLATES
# placeholders: {league} {team_1} {team_2} {prediction}
# {date} {odds} {time} {header} {book} {sep}
# templates 7 and 8 intentionally omit odds/date
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SINGLE_TEMPLATES = [
# 1 structured Telegram bold style
"โฝ๏ธ {header} โฝ๏ธ\n๐๐๐ญ๐: {date}\n๐๐๐๐ ๐ฎ๐: {league}\n๐๐๐ญ๐๐ก: {team_1}{sep}{team_2}\n๐๐ข๐๐ค ๐จ๐๐: {time} WAT\nโ
{prediction}\nโ
Odds @{odds} on {book}",
# 2 plain structured
"โฝ๏ธ {header} โฝ๏ธ\nDate: {date}\nLeague: {league}\nMatch: {team_1}{sep}{team_2}\nKick off: {time} WAT\nโ
{prediction}\nโ
Odds @{odds} on {book}",
# 3 emoji compact
"๐ {league}\n{team_1}{sep}{team_2}\n๐
{date} | โฐ {time}\n๐ฏ Tip: {prediction}\n๐ฐ Odds: {odds}",
# 4 casual noisy
"wow predictions present\nINCREDIBLE MATCH BETWEEN {team_1}{sep}{team_2}\nTime: {time}\nwe forecast {prediction}\nOdds {odds}",
# 5 one-liner
"{team_1}{sep}{team_2} | {league} | {date} | {prediction} @ {odds}",
# 6 verbose channel
"๐ฅ Today's football tip ๐ฅ\nCompetition: {league}\nGame: {team_1}{sep}{team_2}\nDate: {date}, KO {time}\nOur pick: {prediction}\nBest odds: {odds} ({book})\nGood luck! โฝ",
# 7 minimal no emojis
"Match: {team_1}{sep}{team_2}\nLeague: {league}\nDate: {date}\nPrediction: {prediction}\nOdds: {odds}",
# 8 different field order
"๐ {date} | {time}\nโฝ {league}: {team_1}{sep}{team_2}\nโ๏ธ {prediction} | @{odds}",
# 9 ALL CAPS noisy
"MATCH: {team_1}{sep}{team_2}\nLEAGUE: {league}\nDATE: {date}\nPICK: {prediction}\nODDS: {odds}",
# 10 missing odds intentionally
"โฝ๏ธ {header}\n{league}\n{team_1}{sep}{team_2}\n{date}\nPrediction: {prediction}",
# 11 missing date intentionally
"๐๏ธ {league}\n{team_1}{sep}{team_2}\nTip: {prediction}\nOdds: {odds} on {book}",
# 12 missing league intentionally
"{team_1}{sep}{team_2}\n๐
{date}\nโ
{prediction} @ {odds}",
# 13 telegram minimal
"๐ {league}\n{team_1}{sep}{team_2} โ {date}\n{prediction} | {odds}",
# 14 with extra commentary noise
"Today I really like this match ๐\n{team_1}{sep}{team_2} ({league})\nDate: {date}\nMy pick: {prediction}\nOdds: {odds} on {book}",
]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# MULTI-TIP BLOCK TEMPLATES (per tip)
# extra placeholder: {n} = tip number
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
MULTI_BLOCK_TEMPLATES = [
# Telegram numbered bold
"โฝ๏ธ ๐๐ผ๐ผ๐๐ฏ๐ฎ๐น๐น ๐ง๐ถ๐ฝ {n} โฝ๏ธ\n๐๐๐ญ๐: {date}\n๐๐๐๐ ๐ฎ๐: {league}\n๐๐๐ญ๐๐ก: {team_1}{sep}{team_2}\n๐๐ข๐๐ค ๐จ๐๐: {time} WAT\nโ
{prediction}\nโ
Odds @{odds} on {book}",
# plain numbered
"Tip {n}:\nLeague: {league}\nMatch: {team_1}{sep}{team_2}\nDate: {date} | KO: {time}\nPrediction: {prediction} @ {odds}",
# compact numbered
"#{n} {league} | {team_1}{sep}{team_2} | {date}\nโ {prediction} @ {odds}",
# emoji numbered
"๐ฏ Pick #{n}\n{team_1}{sep}{team_2} ({league})\n๐
{date} โฐ {time}\nโ
{prediction} | odds: {odds}",
# minimal numbered
"{n}. {team_1}{sep}{team_2} โ {league} โ {prediction} @ {odds} ({date})",
]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# LOAD TEAMS FROM CSV
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def load_teams(csv_path: str) -> dict:
leagues = defaultdict(list)
path = Path(csv_path)
if not path.exists():
raise FileNotFoundError(f"CSV not found: {csv_path}")
with open(path, encoding="utf-8") as f:
sample = f.read(2048)
f.seek(0)
delimiter = "\t" if "\t" in sample else ","
reader = csv.DictReader(f, delimiter=delimiter)
for row in reader:
row = {k.strip(): v.strip() for k, v in row.items()}
country = row.get("Country", "")
league = row.get("League", "")
team = row.get("Team", "")
if country and league and team:
leagues[(country, league)].append(team)
total = sum(len(v) for v in leagues.values())
print(f"[โ] Loaded {total} teams across {len(leagues)} leagues")
return leagues
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# RANDOM HELPERS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def random_date() -> str:
month = random.randint(8, 12) if random.random() < 0.5 else random.randint(1, 5)
year = 2025 if month >= 8 else 2026
day = random.randint(1, 28)
return random.choice(DATE_FORMATS)(day, month, year)
def random_odds() -> float:
return round(random.uniform(1.05, 3.50), 2)
def random_fixture(leagues: dict) -> dict | None:
key = random.choice(list(leagues.keys()))
teams = leagues[key]
if len(teams) < 2:
return None
_, league = key
team_1, team_2 = random.sample(teams, 2)
return {
"league": league,
"team_1": team_1,
"team_2": team_2,
"prediction": random.choice(PREDICTIONS),
"date": random_date(),
"odds": random_odds(),
}
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# NOISE FUNCTIONS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def inject_emojis(text: str) -> str:
"""40% chance: sprinkle 1-3 random emojis into random lines."""
if random.random() < 0.40:
emojis = random.sample(EXTRA_EMOJIS, k=random.randint(1, 3))
lines = text.split("\n")
for e in emojis:
idx = random.randint(0, len(lines) - 1)
lines[idx] = (e + " " + lines[idx]) if random.random() < 0.5 else (lines[idx] + " " + e)
return "\n".join(lines)
return text
def inject_typos(text: str) -> str:
"""15% chance: swap two adjacent chars in a random word."""
if random.random() < 0.15:
words = text.split(" ")
idx = random.randint(0, len(words) - 1)
w = words[idx]
if len(w) > 3 and w.isalpha():
i = random.randint(0, len(w) - 2)
w = w[:i] + w[i+1] + w[i] + w[i+2:]
words[idx] = w
return " ".join(words)
return text
def inject_extra_lines(text: str) -> str:
"""20% chance: add irrelevant noise lines."""
noise_lines = [
"For more predictions visit www.eaglepredict.com",
"Join our VIP channel ๐",
"Yesterday result: WIN โ
",
"Record this week: 8W 2L",
"All tips are for 18+ only",
"Use responsible gambling ๐",
]
if random.random() < 0.20:
line = random.choice(noise_lines)
if random.random() < 0.5:
return line + "\n" + text
else:
return text + "\n" + line
return text
def maybe_null_field(fixture: dict, has_odds: bool, has_date: bool, has_league: bool) -> dict:
"""
Randomly null out one field (20% chance).
Respects whether template already omits it.
"""
f = dict(fixture)
if not has_odds:
f["odds"] = None
if not has_date:
f["date"] = None
if not has_league:
f["league"] = None
# extra random null on top
if random.random() < 0.20:
field = random.choice(["odds", "date", "league"])
f[field] = None
return f
def apply_noise(text: str) -> str:
text = inject_emojis(text)
text = inject_typos(text)
text = inject_extra_lines(text)
return text
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# EXAMPLE GENERATORS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def make_single_example(leagues: dict) -> dict | None:
fixture = random_fixture(leagues)
if not fixture:
return None
template = random.choice(SINGLE_TEMPLATES)
has_odds = "{odds}" in template
has_date = "{date}" in template
has_league= "{league}" in template
sep = random.choice(SEPARATORS)
input_text = template.format(
sep = sep,
league = fixture["league"],
team_1 = fixture["team_1"],
team_2 = fixture["team_2"],
prediction = fixture["prediction"],
date = fixture["date"],
odds = fixture["odds"],
time = random.choice(TIMES),
header = random.choice(HEADERS),
book = random.choice(BOOKS),
)
input_text = apply_noise(input_text)
output_json = maybe_null_field(fixture, has_odds, has_date, has_league)
return {
"input": input_text,
"output": [output_json], # always array
}
def make_multi_example(leagues: dict) -> dict | None:
n_tips = random.randint(2, 4)
fixtures = [random_fixture(leagues) for _ in range(n_tips * 2)]
fixtures = [f for f in fixtures if f][:n_tips]
if len(fixtures) < 2:
return None
block_template = random.choice(MULTI_BLOCK_TEMPLATES)
sep = random.choice(SEPARATORS)
blocks = []
for i, f in enumerate(fixtures, 1):
has_odds = "{odds}" in block_template
has_date = "{date}" in block_template
has_league= "{league}" in block_template
block = block_template.format(
n = i,
sep = sep,
league = f["league"],
team_1 = f["team_1"],
team_2 = f["team_2"],
prediction = f["prediction"],
date = f["date"],
odds = f["odds"],
time = random.choice(TIMES),
book = random.choice(BOOKS),
)
blocks.append((block, f, has_odds, has_date, has_league))
header = random.choice(MULTI_HEADERS)
footer = random.choice(MULTI_FOOTERS)
parts = [header] + [b[0] for b in blocks] + ([footer] if footer else [])
input_text = "\n".join(parts)
input_text = apply_noise(input_text)
output = [
maybe_null_field(f, has_odds, has_date, has_league)
for _, f, has_odds, has_date, has_league in blocks
]
return {"input": input_text, "output": output}
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# FORMAT AS TRAINING EXAMPLE
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def make_training_example(ex: dict) -> dict:
return {
"messages": [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": ex["input"].strip()},
{"role": "assistant", "content": json.dumps(ex["output"], ensure_ascii=False)},
]
}
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# MAIN
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def build_dataset():
leagues = load_teams(TEAMS_CSV)
examples = []
n_single = int(EXAMPLES_COUNT * 0.70)
n_multi = EXAMPLES_COUNT - n_single
print(f"[1/2] Generating {n_single} single-tip + {n_multi} multi-tip examples...")
# single tip
attempts = 0
while len([e for e in examples if len(json.loads(e["messages"][2]["content"])) == 1]) < n_single:
attempts += 1
if attempts > n_single * 5:
break
ex = make_single_example(leagues)
if ex:
examples.append(make_training_example(ex))
# multi tip
attempts = 0
while len([e for e in examples if len(json.loads(e["messages"][2]["content"])) > 1]) < n_multi:
attempts += 1
if attempts > n_multi * 5:
break
ex = make_multi_example(leagues)
if ex:
examples.append(make_training_example(ex))
print(f" โ {len(examples)} total examples generated")
# โโ Write files โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
print("[2/2] Writing dataset files...")
random.shuffle(examples)
split = int(len(examples) * (1 - VAL_SPLIT))
train, val = examples[:split], examples[split:]
for path, data in [(OUTPUT_TRAIN, train), (OUTPUT_VAL, val)]:
with open(path, "w", encoding="utf-8") as f:
for ex in data:
f.write(json.dumps(ex, ensure_ascii=False) + "\n")
# โโ Stats โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
all_ex = train + val
single = sum(1 for e in all_ex if len(json.loads(e["messages"][2]["content"])) == 1)
multi = len(all_ex) - single
nulls = sum(
1 for e in all_ex
for obj in json.loads(e["messages"][2]["content"])
if any(v is None for v in obj.values())
)
print(f"\nโ
Done!")
print(f" {OUTPUT_TRAIN} โ {len(train)} examples")
print(f" {OUTPUT_VAL} โ {len(val)} examples")
print(f" Single-tip โ {single}")
print(f" Multi-tip โ {multi}")
print(f" With null fieldsโ {nulls}")
# โโ Previews โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
print("\nโโ Single-tip sample โโโโโโโโโโโโโโโโโโโโโโโ")
s = next(e for e in examples if len(json.loads(e["messages"][2]["content"])) == 1)
for msg in s["messages"]:
print(f"[{msg['role']}]\n{msg['content'][:200]}\n")
print("โโ Multi-tip sample โโโโโโโโโโโโโโโโโโโโโโโโ")
m = next(e for e in examples if len(json.loads(e["messages"][2]["content"])) > 1)
for msg in m["messages"]:
print(f"[{msg['role']}]\n{msg['content'][:300]}\n")
if __name__ == "__main__":
build_dataset()
|