fix(meeting): keep polish from inventing markers or dropping qualifiers
The local model follows the polish instructions only most of the time: in repeated runs it added a [00:00] or [화자 1] marker that was never in the audio, and it turned "사실 거의 근간" into "사실 근간". Both change what the meeting record says, so they are now enforced in code instead of hoped for in the prompt: markers absent from the original chunk are stripped, and meaning qualifiers the speaker said are restored from that chunk. The instructions themselves were re-measured on the model: a fixed removal list, an explicit qualifier example and a marker ban keep the filler cleanup without touching ordinary words, and the same wording is used by the app, the tests and the probe. Unknown-word repair still depends on the model.
This commit is contained in:
parent
bcd0cf4f23
commit
3aa68f466c
8 changed files with 167 additions and 5 deletions
|
|
@ -442,6 +442,64 @@ export function correctLearnedTerms(
|
|||
return { text: out + trimmed.slice(cursor), corrections }
|
||||
}
|
||||
|
||||
const TIMESTAMP_MARKER_LINE = /^\s*\[\d{1,3}:\d{2}\]\s*/u
|
||||
const TIMESTAMP_MARKER_ANY = /\[\d{1,3}:\d{2}\]/u
|
||||
const SPEAKER_MARKER = /\[(?:화자\s*\d+|SPEAKER[\s_-]?\d+)\]/giu
|
||||
|
||||
/**
|
||||
* 모델이 원문에 없던 화자 표기·타임스탬프를 붙였으면 지운다.
|
||||
*
|
||||
* 교열은 형식을 만들지 않는다. 회의 전사에서 시각은 STT 세그먼트가 찍은 값이어야 하고,
|
||||
* 화자 라벨은 화자 구분(diarization)만 붙인다. 모델이 만들어 낸 `[00:00]`·`[화자 1]` 은
|
||||
* 문서·채팅·동기화에 그대로 저장되어 사용자가 출처를 오해한다.
|
||||
*/
|
||||
export function stripInventedMarkers(input: string, output: string): string {
|
||||
if (!output) return output
|
||||
const hasTimestamp = TIMESTAMP_MARKER_ANY.test(input)
|
||||
const allowedSpeakers = new Set(
|
||||
(input.match(SPEAKER_MARKER) ?? []).map((label) => label.replace(/\s+/gu, ' ').toLowerCase()),
|
||||
)
|
||||
const lines = output.split('\n').map((line) => {
|
||||
let next = hasTimestamp ? line : line.replace(TIMESTAMP_MARKER_LINE, '')
|
||||
next = next.replace(SPEAKER_MARKER, (label) =>
|
||||
allowedSpeakers.has(label.replace(/\s+/gu, ' ').toLowerCase()) ? label : '',
|
||||
)
|
||||
return next.replace(/^\s+/u, '').replace(/[ \t]{2,}/gu, ' ')
|
||||
})
|
||||
return lines.join('\n').trim()
|
||||
}
|
||||
/**
|
||||
* 교열이 실수로 지우면 안 되는 의미 한정 부사 목록.
|
||||
*
|
||||
* 8B 로컬 모델은 같은 지시에도 3회 중 1~2회 "거의"를 필러처럼 지웠다(실측). 프롬프트로 100%를
|
||||
* 보장할 수 없으므로, 사용자가 실제로 말한 한정 부사는 코드가 되돌려 놓는다.
|
||||
*/
|
||||
const PROTECTED_QUALIFIERS: readonly string[] = [
|
||||
'거의', '대부분', '아직', '대략', '최소', '최대', '반드시', '전혀',
|
||||
'별로', '특히', '주로', '일부', '전체', '매번', '자주', '약',
|
||||
]
|
||||
|
||||
/**
|
||||
* 모델이 지운 의미 한정 부사를 원문 근거로 되돌린다.
|
||||
*
|
||||
* 원문에서 그 부사 뒤에 오는 어절을 출력에서 찾아 앞에 다시 붙인다(그 어절이 없으면 건드리지 않는다).
|
||||
* 새 단어를 만드는 것이 아니라 사용자가 말한 단어를 복원하는 것만 한다.
|
||||
*/
|
||||
export function restoreProtectedQualifiers(input: string, output: string): string {
|
||||
if (!input || !output) return output
|
||||
let result = output
|
||||
for (const qualifier of PROTECTED_QUALIFIERS) {
|
||||
if (!input.includes(qualifier) || result.includes(qualifier)) continue
|
||||
const match = new RegExp(`${qualifier}\\s+(\\p{L}[\\p{L}\\p{N}]*)`, 'u').exec(input)
|
||||
if (!match) continue
|
||||
const anchor = match[1]
|
||||
const index = result.indexOf(anchor)
|
||||
if (index < 0) continue
|
||||
result = `${result.slice(0, index)}${qualifier} ${result.slice(index)}`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM 교열 프롬프트에 넣는 참고 블록. 정보가 없으면 빈 문자열.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue