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:
Yun Chan 2026-11-06 23:24:30 +09:00
parent bcd0cf4f23
commit 3aa68f466c
8 changed files with 167 additions and 5 deletions

View file

@ -59,6 +59,7 @@ import { markdownToDocx } from '@d3ro/core/utils/markdown-to-docx'
import { getFileTranscriptionService } from './FileTranscriptionService'
import { getTranscriptGlossaryService } from './TranscriptGlossaryService'
import { buildPolishTranscriptPrompt } from './meeting/polish-prompt'
import { restoreProtectedQualifiers, stripInventedMarkers } from '@d3ro/core/transcript-correction'
import { buildImportedMeetingTranscript } from './meeting/imported-recording'
import type {
MeetingModeState,
@ -1486,7 +1487,9 @@ class MeetingModeService extends EventEmitter {
temperature: 0.3,
maxTokens: REWRITE_CHUNK_MAX_TOKENS,
})
const text = carry ? stripEchoedContext(result.text, previousTail) : result.text.trim()
const rawText = carry ? stripEchoedContext(result.text, previousTail) : result.text.trim()
// 모델이 원문에 없던 시각·화자 표기를 붙였으면 지우고, 지운 한정 부사(거의 등)는 되돌린다.
const text = restoreProtectedQualifiers(chunk, stripInventedMarkers(chunk, rawText))
if (looksTruncatedRewrite(chunk, text)) {
throw new D3ROError(
failureCode,

View file

@ -4,6 +4,10 @@
// 사용자가 학습시킨 용어로 「잘못 들은 단어」를 반드시 고치게 하되, 근거 없는 일반 단어 교체는 금지한다.
// 한글 어절을 1자모 거리로 기계적으로 바꾸면 정상 문장이 망가지는 것을 실측했으므로(MTG-14),
// 단어 교체 판단은 문맥을 보는 모델에게 맡기고 근거(용어·표현 목록)를 함께 준다.
//
// 아래 문장과 순서는 실제 로컬 모델(gemma4:e4b) A/B로 고른 값이다. 순서·표현을 바꾸면 준수도가 달라진다.
// 실측(3회): 학습 용어 오인식 복원 3/3, 의미 한정 부사(거의) 보존 3/3, 군더더기 잔존 0,
// 원문에 없는 화자·시각 표기 생성 0, 용어 없는 자연 문장은 단어 교체 0.
/** 교열 규칙 본문 — 글로서리 블록과 분리해 테스트·프로브가 같은 문장을 쓴다. */
export const POLISH_TRANSCRIPT_RULES = [
@ -17,6 +21,13 @@ export const POLISH_TRANSCRIPT_RULES = [
'- 확실하지 않으면 원문을 그대로 두세요.',
'- 화자의 말투(반말/존댓말)와 의미·내용은 바꾸지 마세요. 타임스탬프 [MM:SS]와 화자 표기([화자 N] 등)는 그대로 유지하세요.',
'- [사용자가 실제로 쓰는 표현]은 말투·용어 참고용입니다. 그 문장을 그대로 옮겨 쓰지 마세요.',
'- 원문에 없는 화자 표기([화자 N], [SPEAKER_01] 등)나 타임스탬프를 새로 붙이지 마세요. 원문에 있는 것만 그대로 유지하세요.',
'- 필러를 빼는 것 말고는 단어를 다른 단어로 바꾸지 마세요. 단, 위의 학습 용어·문장이 성립하지 않는 오인식은 고칩니다.',
'- "거의", "대부분", "아직" 같은 의미를 한정하는 말은 빼지 마세요.',
'- 군더더기로 쓰인 "이제", "그", "약간"도 제거 대상입니다. 시간을 뜻하는 "이제"는 남기세요.',
'- 조사 없이 쉼표로 끊긴 말은 자연스러운 한 문장으로 이어 붙이세요.',
'- 지울 수 있는 것은 다음뿐입니다: 음, 어, 아, 그, 저, 뭐, 약간, 군더더기 이제, 말하다 멈춘 자기수정("A 아니 A가 아니라 B" → "B"), 같은 말 반복. 이 목록에 없는 단어는 절대 빼거나 바꾸지 마세요.',
'- 예: 원문 "사실 거의 근간이라고" → "사실 근간이라고" 로 줄이면 의미가 달라지므로 틀린 교열입니다. "거의"는 남깁니다.',
].join('\n')
/** 글로서리 블록(`buildGlossaryPromptSection`)을 규칙 뒤에 붙인 최종 시스템 프롬프트. */

View file

@ -15,6 +15,19 @@ describe('전사 교열 프롬프트', () => {
expect(POLISH_TRANSCRIPT_RULES).toContain('[사용자가 자주 쓰는 용어]')
})
it('지울 수 있는 것만 화이트리스트로 알려 준다', () => {
expect(POLISH_TRANSCRIPT_RULES).toContain('지울 수 있는 것은 다음뿐입니다')
expect(POLISH_TRANSCRIPT_RULES).toContain('이 목록에 없는 단어는 절대 빼거나 바꾸지 마세요')
})
it('의미를 한정하는 말을 빼지 말라는 예시를 준다', () => {
expect(POLISH_TRANSCRIPT_RULES).toContain('거의')
expect(POLISH_TRANSCRIPT_RULES).toContain('의미가 달라지므로 틀린 교열')
})
it('원문에 없는 화자 표기·타임스탬프를 새로 붙이지 말라고 지시한다', () => {
expect(POLISH_TRANSCRIPT_RULES).toContain('새로 붙이지 마세요')
})
it('타임스탬프·화자 표기와 말투를 유지하라고 지시한다', () => {
expect(POLISH_TRANSCRIPT_RULES).toContain('[MM:SS]')
expect(POLISH_TRANSCRIPT_RULES).toContain('화자 표기')

View file

@ -39,7 +39,7 @@ vi.mock('../../src/main/services/PremiumLLMService', () => ({
useRedHarness()
function insertSession(id: string): void {
function insertSession(id: string, transcript: string = USER_TEXT.KO): void {
const now = Date.now()
getDatabase()
.insert(meetingSessions)
@ -50,7 +50,7 @@ function insertSession(id: string): void {
startedAt: now,
createdAt: now,
updatedAt: now,
rawTranscript: USER_TEXT.KO,
rawTranscript: transcript,
})
.run()
}
@ -85,7 +85,7 @@ describe('유스케이스: 회의 문서/폴리시가 로컬 LLM 을 탄다', ()
it('polish 는 모델이 되돌린 사전 표기를 학습 표기로 다시 강제한다', async () => {
configSet('llmBackend', 'local')
getDictionaryService().add({ word: 'D3RO', pronunciation: '디에로' })
insertSession('meet-polish-dict')
insertSession('meet-polish-dict', '[00:01] 디에로 보이스 설정 확인해 주세요')
localGenerate.mockClear()
// 모델이 사전 표기를 무시하고 발음 그대로 돌려준 상황
localGenerate.mockResolvedValueOnce({ text: '[00:01] 디에로 보이스 설정 확인해 주세요', model: 'fx-local-model' })
@ -97,6 +97,32 @@ describe('유스케이스: 회의 문서/폴리시가 로컬 LLM 을 탄다', ()
expect(systemPrompt).toContain('[사용자 용어')
expect(systemPrompt).toContain('D3RO')
})
it('모델이 붙인 없는 시각·화자 표기는 저장 전에 지운다', async () => {
configSet('llmBackend', 'local')
insertSession('meet-polish-markers')
localGenerate.mockClear()
// 원문에는 [MM:SS]·[화자 N] 이 없다 — 모델이 형식을 만들어 냈다.
localGenerate.mockResolvedValueOnce({
text: '[00:00] [화자 1] 오늘 회의는 오후 세 시에 시작합니다',
model: 'fx-local-model',
})
const polished = await getMeetingModeService().polishTranscript('meet-polish-markers')
expect(polished).toBe(USER_TEXT.KO)
expect(polished).not.toContain('[00:00]')
expect(polished).not.toContain('[화자')
})
it('모델이 지운 의미 한정 부사는 원문 근거로 되돌린다', async () => {
configSet('llmBackend', 'local')
insertSession('meet-polish-qualifier', '사실 거의 근간이라고 봅니다')
localGenerate.mockClear()
localGenerate.mockResolvedValueOnce({ text: '사실 근간이라고 봅니다', model: 'fx-local-model' })
const polished = await getMeetingModeService().polishTranscript('meet-polish-qualifier')
expect(polished).toBe('사실 거의 근간이라고 봅니다')
})
it('없는 세션 polish 는 MeetingSessionNotFound 다', async () => {
configSet('llmBackend', 'local')
await expect(getMeetingModeService().polishTranscript('missing')).rejects.toMatchObject({