Tune paragraph prompts for multilingual noise

This commit is contained in:
Adolfo Reyna
2026-03-17 11:51:53 -04:00
parent 7da02a9697
commit 7451d164b7
5 changed files with 304 additions and 42 deletions
+36 -14
View File
@@ -31,11 +31,15 @@ Produce the most faithful readable English update.
Decision rules:
1. NEW SOURCE TEXT is the primary evidence and should dominate the output.
2. Use PREVIOUS SOURCE TEXT and PREVIOUS REFINED CONTEXT only when they clearly help resolve or continue the new material.
3. If the new material starts a fresh thought, output only the new material.
4. Remove exact or near-exact repetition unless the repetition is clearly intentional rhetoric.
5. Do not add explanations, disclaimers, or meta commentary.
6. Prefer conservative wording over guessed meaning.
7. Return only the revised transcript text."""
3. The final answer must be English only.
4. Never copy non-English words into the output unless they are proper names.
5. If a non-English fragment appears as an isolated clause, trailing fragment, or side comment without a clear English anchor, drop it.
6. Only translate a non-English fragment when it is clearly central to the same idea and its meaning is reasonably obvious from context.
7. If the new material starts a fresh thought, output only the new material.
8. Remove exact or near-exact repetition unless the repetition is clearly intentional rhetoric.
9. Do not add explanations, disclaimers, or meta commentary.
10. Prefer conservative wording over guessed meaning.
11. Return only the revised transcript text."""
prompt = f"""Edit this transcript update.
@@ -137,7 +141,10 @@ def run_llm_prompt_test(args):
raise RuntimeError(f"OpenAI API error {response.status_code}: {detail}")
return response.json()["choices"][0]["message"]["content"].strip()
def call_ollama(model, prompt, temperature, system=None):
def call_ollama(model, prompt, temperature, system=None, extra_options=None):
options = {"temperature": temperature}
if extra_options:
options.update(extra_options)
response = requests.post(
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
json={
@@ -145,7 +152,7 @@ def run_llm_prompt_test(args):
"prompt": prompt,
"system": system or "",
"stream": False,
"options": {"temperature": temperature},
"options": options,
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
},
timeout=getattr(args, "post_correct_llm_timeout", 8.0),
@@ -153,7 +160,7 @@ def run_llm_prompt_test(args):
response.raise_for_status()
return response.json().get("response", "").strip()
def send_test_request(mode, messages, prompt, temperature, metadata, model=None):
def send_test_request(mode, messages, prompt, temperature, metadata, model=None, extra_options=None):
request_model = model or args.post_correct_model
is_openai = request_model.startswith("gpt-")
entry = {
@@ -162,6 +169,7 @@ def run_llm_prompt_test(args):
"provider": "openai" if is_openai else "ollama",
"model": request_model,
"temperature": temperature,
"options": extra_options or {},
"messages": messages,
"metadata": metadata,
}
@@ -185,7 +193,7 @@ def run_llm_prompt_test(args):
system = message.get("content", "")
break
try:
response_text = call_ollama(request_model, prompt, temperature, system=system)
response_text = call_ollama(request_model, prompt, temperature, system=system, extra_options=extra_options)
entry["response"] = {"status": "ok", "content": response_text}
return response_text
except Exception as exc:
@@ -352,7 +360,10 @@ def run_llm_processor(in_queue, out_queue, args):
raise RuntimeError(f"OpenAI API error {response.status_code}: {detail}")
return response.json()["choices"][0]["message"]["content"].strip()
def call_ollama(prompt, temperature, system=None):
def call_ollama(prompt, temperature, system=None, extra_options=None):
options = {"temperature": temperature}
if extra_options:
options.update(extra_options)
response = requests.post(
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
json={
@@ -360,7 +371,7 @@ def run_llm_processor(in_queue, out_queue, args):
"prompt": prompt,
"system": system or "",
"stream": False,
"options": {"temperature": temperature},
"options": options,
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
},
timeout=getattr(args, "post_correct_llm_timeout", 8.0),
@@ -368,13 +379,14 @@ def run_llm_processor(in_queue, out_queue, args):
response.raise_for_status()
return response.json().get("response", "").strip()
def call_llm(messages, prompt, temperature, warn_key):
def call_llm(messages, prompt, temperature, warn_key, extra_options=None):
entry = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"mode": "paragraph" if warn_key == "paragraph_warned" else "line",
"provider": "openai" if is_openai else "ollama",
"model": args.post_correct_model,
"temperature": temperature,
"options": extra_options or {},
"messages": messages,
}
started_at = time.time()
@@ -391,7 +403,7 @@ def run_llm_processor(in_queue, out_queue, args):
if message.get("role") == "system":
system = message.get("content", "")
break
response_text = call_ollama(prompt, temperature, system=system)
response_text = call_ollama(prompt, temperature, system=system, extra_options=extra_options)
entry["response"] = {"status": "ok", "content": response_text}
return response_text
except Exception as exc:
@@ -412,7 +424,17 @@ def run_llm_processor(in_queue, out_queue, args):
def call_llm_rolling_refine(new_segments_str, context, previous_source_text):
messages, prompt = build_paragraph_messages(context, previous_source_text, new_segments_str)
return call_llm(messages, prompt, 0.1, "paragraph_warned")
paragraph_options = {
"top_p": getattr(args, "llm_paragraph_top_p", 0.8),
"repeat_penalty": getattr(args, "llm_paragraph_repeat_penalty", 1.0),
}
return call_llm(
messages,
prompt,
getattr(args, "llm_paragraph_temperature", 0.2),
"paragraph_warned",
extra_options=paragraph_options,
)
def post_correct_line(text):
if not getattr(args, "post_correct", False):