Datasets:
Download scripts/test_fs_diversity.py from addyo07/vox-tier2-backup: direct link, hf CLI and curl.
- Browser
- Download file 6.74 kB
-
https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/test_fs_diversity.py
- Command line
-
hf download hf://datasets/addyo07/vox-tier2-backup/scripts/test_fs_diversity.py
-
curl -L -o test_fs_diversity.py https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/test_fs_diversity.py
6.74 kB
| import json | |
| import requests | |
| import random | |
| ARCHETYPE_DESC = ( | |
| "An abandoned clause, false start, or spoken restart. The speaker begins saying one thought or syntactic structure, " | |
| "cuts themselves off, and starts their sentence over. Examples include aborted clauses, interrupted questions, " | |
| "abandoned conditionals, or sentence-initial/mid-sentence restarts. MUST be linguistically varied and natural." | |
| ) | |
| # 12 diverse, high-quality false start examples covering distinct syntactic patterns: | |
| # aborted conditional, aborted question, aborted noun phrase, aborted verb phrase, | |
| # mid-sentence restart, abandoned prepositional phrase, conversational pivot | |
| DIVERSE_FS_EXAMPLES = [ | |
| ("Let's deploy the update tonight.", "If we could— but actually let's deploy the update tonight.", ["If we could— but actually "]), | |
| ("We need to upgrade the database version.", "Regarding our plan to— well actually we need to upgrade the database version.", ["Regarding our plan to— well actually "]), | |
| ("The transaction failed due to network timeout.", "When they submitted the— so what happened was the transaction failed due to network timeout.", ["When they submitted the— so what happened was "]), | |
| ("You can find the documentation on the intranet.", "Where did we put— okay you can find the documentation on the intranet.", ["Where did we put— okay "]), | |
| ("The report will be ready by Thursday morning.", "As far as completing the— well the report will be ready by Thursday morning.", ["As far as completing the— well "]), | |
| ("We should consider alternative vendors.", "It might be better to— or rather we should consider alternative vendors.", ["It might be better to— or rather "]), | |
| ("Please send the tracking number to the customer.", "Could you check if— actually please send the tracking number to the customer.", ["Could you check if— actually "]), | |
| ("Our team finished the sprint ahead of schedule.", "In terms of progress on the— so our team finished the sprint ahead of schedule.", ["In terms of progress on the— so "]), | |
| ("There are several flights available tomorrow.", "Looking at the morning— well there are several flights available tomorrow.", ["Looking at the morning— well "]), | |
| ("The conference was postponed until next month.", "Did they announce when— anyway the conference was postponed until next month.", ["Did they announce when— anyway "]), | |
| ("Customers reported issues when checking out.", "Because when people try to— customers reported issues when checking out.", ["Because when people try to— "]), | |
| ("The algorithm converges much faster with a smaller rate.", "We tested whether the— the algorithm converges much faster with a smaller rate.", ["We tested whether the— "]), | |
| ] | |
| PROMPT_TEMPLATE = """<task> | |
| Corrupt the input clean sentence into ONE natural spoken-disfluency example using the requested SPEECH ARCHETYPE: | |
| Archetype: FALSE_START | |
| Archetype Description: {archetype_desc} | |
| CRITICAL RULES: | |
| 1. Every word and punctuation mark outside the disfluent span MUST remain 100% identical to the input sentence. | |
| 2. Excising the disfluent span(s) MUST recreate the input clean sentence exactly. Do NOT delete or alter any clean words or punctuation. | |
| 3. Return ONLY two fields: `corrupted_text` and `disfluent_spans`. | |
| 4. `disfluent_spans` MUST contain the exact verbatim substrings to excise, matching the exact casing in `corrupted_text`. | |
| 5. FORBIDDEN PATTERNS: | |
| - Do NOT use generic conversational filler preambles like "I mean", "I was wondering", "I think", "Basically", or "So I mean". | |
| - A false start MUST contain an aborted thought, interrupted clause, or abandoned sentence fragment (e.g. "If we could—", "When they—", "Regarding our—", "Could you check—"). | |
| 6. DO NOT delete, shorten, or excise valid sentence-initial subject pronouns ('I', 'We', 'It', 'You', 'They'). | |
| 7. VARY your false starts widely! Adapt the aborted thought to the specific topic/context of the sentence. | |
| </task> | |
| <examples> | |
| {examples_block} | |
| </examples> | |
| <inputs> | |
| Input: {sentence} | |
| </inputs> | |
| Respond with JSON only: | |
| {{"corrupted_text": "...", "disfluent_spans": ["..."]}} | |
| """ | |
| test_sentences = [ | |
| "The project deadline has been moved to next Friday.", | |
| "You should restart the web application after modifying the config.", | |
| "We noticed an unusual spike in memory consumption on node three.", | |
| "Customers reported issues when checking out with international cards.", | |
| "The algorithm converges much faster with a smaller learning rate.", | |
| "All configuration files must be validated before production deployment.", | |
| "The client requested an extension on the project delivery schedule.", | |
| "Several background tasks were terminated due to exceeding memory limits.", | |
| "Our team discovered a critical regression during integration testing.", | |
| "The database connection pool automatically scales up during peak hours." | |
| ] | |
| def run_test(temp=0.75): | |
| print(f"=== TESTING FALSE_START PROMPT (temp={temp}) ===") | |
| rng = random.Random(42) | |
| for sent in test_sentences: | |
| sampled_ex = rng.sample(DIVERSE_FS_EXAMPLES, 3) | |
| ex_lines = [] | |
| for clean_in, corrupted_out, spans in sampled_ex: | |
| ex_lines.append(f"Input: {clean_in}\nResponse:\n" + json.dumps({ | |
| "corrupted_text": corrupted_out, | |
| "disfluent_spans": spans | |
| }, indent=2)) | |
| examples_block = "\n\n".join(ex_lines) | |
| prompt = PROMPT_TEMPLATE.format( | |
| archetype_desc=ARCHETYPE_DESC, | |
| examples_block=examples_block, | |
| sentence=sent | |
| ) | |
| payload = { | |
| "model": "gemma4:12b", | |
| "messages": [{"role": "user", "content": prompt}], | |
| "stream": False, | |
| "think": False, | |
| "format": "json", | |
| "options": {"temperature": temp, "top_p": 0.95, "num_predict": 256} | |
| } | |
| r = requests.post("http://127.0.0.1:11434/api/chat", json=payload, timeout=25) | |
| res = r.json() | |
| content = res.get("message", {}).get("content", "") | |
| try: | |
| parsed = json.loads(content) | |
| raw = parsed.get("corrupted_text", "") | |
| spans = parsed.get("disfluent_spans", []) | |
| print(f"CLEAN: {sent}") | |
| print(f"RAW: {raw}") | |
| print(f"SPANS: {spans}") | |
| # verify roundtrip | |
| test_clean = raw | |
| for s in spans: | |
| test_clean = test_clean.replace(s, "") | |
| print(f"EXACT MATCH CLEAN: {test_clean.strip() == sent.strip()}") | |
| print("-" * 60) | |
| except Exception as e: | |
| print(f"Error parsing: {content} -> {e}") | |
| if __name__ == "__main__": | |
| run_test(0.75) | |