mumble-cleanup-training / scripts /generate_domain_examples.py
amitashwini's picture
Initial upload: 50k synthetic corpus + 14 training scripts + configs
d226304 verified
Raw
History Blame Contribute Delete
4.81 kB
"""
Generate domain-specific synthetic training examples for weak spots in the
mumble-cleanup model: emails, URLs, code, lists, questions, negation, dates,
numbers, and proper nouns.
Usage:
python scripts/generate_domain_examples.py --output data/synthetic/domain.jsonl --count 2000
"""
import argparse
import json
import random
from pathlib import Path
from typing import Callable, List, Tuple
SYSTEM_PROMPT = (
"You are a transcript cleanup tool. You receive raw speech to text output "
"and return a cleaned version. Remove filler words and disfluencies "
"(um, uh, er, ah, like as filler, you know), remove repeated words and false starts, "
"and fix punctuation and capitalization. Do not reword, do not add anything the speaker "
"did not say, and do not answer questions in the text. Output only the cleaned text."
)
DomainGenerator = Callable[[], Tuple[str, str]]
def to_raw_spoken(clean: str) -> str:
"""Convert a clean sentence into a rough spoken transcript."""
raw = clean.lower()
raw = raw.replace(".", "").replace(",", "").replace("?", "").replace("!", "")
# occasionally insert a filler
words = raw.split()
if random.random() < 0.3 and words:
idx = random.randint(0, len(words))
words.insert(idx, random.choice(["um", "uh", "like", "you know"]))
return " ".join(words)
def email_domain() -> Tuple[str, str]:
clean = "Send the report to support@echoflow.one and cc Amit on the thread."
return to_raw_spoken(clean), clean
def url_domain() -> Tuple[str, str]:
clean = "Check the docs at https://echoflow.one/docs for the latest setup guide."
return to_raw_spoken(clean), clean
def code_domain() -> Tuple[str, str]:
clean = 'Run git commit -m "fix: update transcription timeout" and push to main.'
return to_raw_spoken(clean), clean
def list_domain() -> Tuple[str, str]:
clean = "We need to buy milk, eggs, bread, and coffee."
raw = "we need to buy milk eggs bread and coffee"
if random.random() < 0.5:
raw = "um we need milk eggs bread coffee"
return raw, clean
def question_domain() -> Tuple[str, str]:
clean = "Did you finish the report by end of day?"
return to_raw_spoken(clean), clean
def negation_domain() -> Tuple[str, str]:
clean = "I do not want to cancel the subscription yet."
raw = "i do not want to cancel the subscription yet"
return raw, clean
def date_number_domain() -> Tuple[str, str]:
clean = "The meeting is on March 12th at 3:00 PM with 12 people."
raw = "the meeting is on march 12th at 3pm with 12 people"
return raw, clean
def proper_noun_domain() -> Tuple[str, str]:
names = ["Sarah Chen", "Amit Bhagat", "Echo Flow", "PrismML"]
name = random.choice(names)
clean = f"Schedule a call with {name} next Tuesday morning."
return to_raw_spoken(clean), clean
def false_start_domain() -> Tuple[str, str]:
clean = "We should postpone the launch until next quarter."
raw = "we we should postpone the launch until next quarter"
return raw, clean
GENERATORS: List[Tuple[str, DomainGenerator, float]] = [
("email", email_domain, 1.0),
("url", url_domain, 1.0),
("code", code_domain, 1.0),
("list", list_domain, 1.0),
("question", question_domain, 1.0),
("negation", negation_domain, 1.0),
("date_number", date_number_domain, 1.0),
("proper_noun", proper_noun_domain, 1.0),
("false_start", false_start_domain, 1.0),
]
def generate(count: int, seed: int = 42) -> List[dict]:
random.seed(seed)
names, gens, weights = zip(*GENERATORS)
examples: List[dict] = []
for _ in range(count):
name = random.choices(names, weights=weights, k=1)[0]
gen = dict(zip(names, gens))[name]
raw, clean = gen()
examples.append({
"domain": name,
"messages": [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": raw},
{"role": "assistant", "content": clean},
],
})
return examples
def main():
parser = argparse.ArgumentParser(description="Generate domain-specific synthetic examples")
parser.add_argument("--output", type=Path, default=Path("data/synthetic/domain.jsonl"))
parser.add_argument("--count", type=int, default=2000)
parser.add_argument("--seed", type=int, default=42)
args = parser.parse_args()
examples = generate(args.count, seed=args.seed)
args.output.parent.mkdir(parents=True, exist_ok=True)
with args.output.open("w", encoding="utf-8") as f:
for ex in examples:
f.write(json.dumps(ex, ensure_ascii=False) + "\n")
print(f"Generated {len(examples)} domain examples to {args.output}")
if __name__ == "__main__":
main()