# -*- coding: utf-8 -*- """Baut aus echten deutschen Gespraechstranskripten einen Kalibrier-Datensatz fuer die rkllm-Quantisierung. Laeuft AUF DEM BOARD (python3 + mysql client). Format laut rkllm-toolkit 1.3.0: [{"input": "...", "target": "..."}, ...] """ import json, subprocess, random SQL = ( "select id, transcript from recordings " "where transcript is not null and char_length(transcript) > 2000 " "and deleted_at is null order by id desc limit 24;" ) out = subprocess.run( ['mysql', '-ucallrec', '-pcallrec123', 'callrec', '-N', '-B', '-e', SQL], capture_output=True) rows = out.stdout.decode('utf-8', 'replace').splitlines() random.seed(29) samples = [] for row in rows: parts = row.split('\t', 1) if len(parts) != 2: continue rid, text = parts # mysql -B escapt Zeilenumbrueche als \n text = text.replace('\\n', '\n').replace('\\t', '\t') text = ' '.join(text.split()) if len(text) < 2000: continue # drei Ausschnitte je Aufnahme: Anfang, Mitte, zufaellig starts = [0, max(0, len(text) // 2 - 600)] if len(text) > 6000: starts.append(random.randint(1000, len(text) - 2000)) for st in starts: chunk = text[st:st + 1400].strip() if len(chunk) > 800: samples.append({"input": chunk, "target": ""}) random.shuffle(samples) samples = samples[:64] with open('/tmp/calib-de.json', 'w', encoding='utf-8') as f: json.dump(samples, f, ensure_ascii=False, indent=1) print('Samples: %d' % len(samples)) print('Zeichen gesamt: %d' % sum(len(s['input']) for s in samples)) print('Durchschnitt: %d' % (sum(len(s['input']) for s in samples) // max(1, len(samples))))