fix(meeting): stop learned vocabulary from rewriting ordinary Korean
The first cut replaced any Hangul word within one jamo of a learned term. Measured against the real local corpus (three stored meeting transcripts) it changed 286 of 3,005 words: 하면 became 라면, 이제 became 이게, 매일 became 메일. Most of what the app learns from typing is ordinary grammar, so distance alone cannot separate a misheard word from a correct one. Deterministic correction now covers only dictionary pronunciations and the Latin identifiers the user types, preserving their casing. Korean terms still bias recognition through the prompt hint and guide the polish prompt. Re-measured on the same transcripts: 0 of 3,005 words changed. Hangul-layout typing artifacts (dkssudgktpdy) are dropped from the hint.
This commit is contained in:
parent
a21de78303
commit
72e9b7c18b
7 changed files with 116 additions and 101 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -13,6 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Plugin system for custom pipelines
|
||||
|
||||
|
||||
## [1.16.3] - 2026-11-05
|
||||
|
||||
> Supersedes 1.16.2, which could rewrite ordinary Korean words in transcripts.
|
||||
|
||||
### Fixed
|
||||
- Stop the learned-vocabulary pass from rewriting ordinary Korean. Measured against real meeting transcripts it changed 286 of 3,005 words (`하면`→`라면`, `이제`→`이게`, `매일`→`메일`, `정보`→`정도`). Deterministic correction is now limited to your dictionary's pronunciations and the Latin identifiers you type; Korean terms reach recognition through the prompt hint and the polish prompt instead. Re-measured: 0 of 3,005 words changed.
|
||||
- Drop Hangul-layout typing artifacts (for example `dkssudgktpdy`) from the recognition hint so they no longer bias transcription, and keep the original casing of learned identifiers (`VSCode`).
|
||||
|
||||
### Changed
|
||||
- Korean terms are no longer auto-replaced word by word. They are used as a recognition hint and as reference for the local model, which decides with sentence context.
|
||||
|
||||
## [1.16.2] - 2026-11-05
|
||||
|
||||
> Published from an annotated tag. Installer and update metadata are served by the
|
||||
|
|
|
|||
|
|
@ -24,13 +24,22 @@ function learnPhrase(text: string, times: number): void {
|
|||
}
|
||||
|
||||
describe('학습한 어휘가 전사 교정에 쓰인다', () => {
|
||||
it('키보드로 배운 어절과 한 글자 다른 전사 어절을 되돌린다', () => {
|
||||
it('키보드로 배운 식별자와 한 글자 다른 전사 어절을 되돌린다', () => {
|
||||
learnPhrase('VSCode 설정 열기', 5)
|
||||
|
||||
const result = getTranscriptGlossaryService().correct('VSCod 설정 열기')
|
||||
|
||||
expect(result.text).toBe('VSCode 설정 열기')
|
||||
expect(result.corrections).toEqual([{ from: 'VSCod', to: 'VSCode', source: 'learned' }])
|
||||
})
|
||||
|
||||
it('한글 문장은 학습 어휘로 바꾸지 않는다', () => {
|
||||
learnPhrase('회의록 정리해줘', 5)
|
||||
|
||||
const result = getTranscriptGlossaryService().correct('회이록 정리해줘')
|
||||
|
||||
expect(result.text).toBe('회의록 정리해줘')
|
||||
expect(result.corrections).toEqual([{ from: '회이록', to: '회의록', source: 'learned' }])
|
||||
expect(result.text).toBe('회이록 정리해줘')
|
||||
expect(result.corrections).toEqual([])
|
||||
})
|
||||
|
||||
it('사용자 사전의 발음 표기를 정본 표기로 바꾼다', () => {
|
||||
|
|
@ -53,11 +62,11 @@ describe('학습한 어휘가 전사 교정에 쓰인다', () => {
|
|||
})
|
||||
|
||||
it('한 번만 쓴 어절은 학습 어휘로 쓰지 않는다', () => {
|
||||
learnPhrase('회의록 정리해줘', 1)
|
||||
learnPhrase('VSCode 설정 열기', 1)
|
||||
|
||||
const result = getTranscriptGlossaryService().correct('회이록 정리해줘')
|
||||
const result = getTranscriptGlossaryService().correct('VSCod 설정 열기')
|
||||
|
||||
expect(result.text).toBe('회이록 정리해줘')
|
||||
expect(result.text).toBe('VSCod 설정 열기')
|
||||
})
|
||||
|
||||
it('사전에 단어를 추가하면 캐시를 기다리지 않고 바로 반영된다', () => {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ Status quick-reference: `[x]` done+verified · `[~]` partial/unverified · `[ ]`
|
|||
| MTG-11 | Meeting AI chat over transcript | [x] | [ ] | [ ] | [x] | Desktop `MeetingChatPanel` + `MEETING_CHAT` |
|
||||
| MTG-12 | Content reporting for generated docs | [-] | [ ] | [x] | [x] | `content-report` Edge + generation receipts |
|
||||
| MTG-13 | Existing audio/video import into a meeting | [x] | [ ] | [~] | [x] | **2026-11-01:** Desktop `meetingMode:importRecording` reuses `FileTranscriptionService` without duplicate history, saves canonical timestamped transcript + normalized WAV, then opens existing minutes generation. Mobile `MeetingsScreen` creates the workspace then routes `meetingId` + `importRequest` to the existing durable Record meeting pipeline. **2026-11-02:** installed Windows 1.16.0 passed the actual Electron picker→timestamped transcript→local summary/action-item journey, so desktop is `[x]`. Fold6 `.3` import entry/editor rendered, but authenticated device file-to-minutes E2E remains (`GAP-MTG-03`). [Evidence](../evidence/2026-11-02-verification.md). |
|
||||
| MTG-14 | Learning-informed transcript correction (user dictionary + typed vocabulary) | [~] | [ ] | [ ] | [ ] | **2026-11-05 (root cause + rebuild of the transcript-correction seam):** the learned corpus was only wired to input suggestions. Meeting/live captions ran STT with a hardcoded `다음은 한국어 대화입니다.` prompt (no dictionary, no learned terms), the refine prompt had no glossary, the refine result updated only `CaptionService`'s own copy (meetings and the renderer kept the raw line), and the persisted `rawTranscript` was a plain join of raw segments. Now: core SSOT `@d3ro/core/transcript-correction` (glossary build, dictionary-variant replacement, 1-jamo learned-term correction with a unique-best rule that never touches words the user actually wrote, LLM reference block) + desktop `TranscriptGlossaryService` (dictionary + `personal_phrases`, 15 s cache invalidated on dictionary writes, fail-closed) are wired into `CaptionService` (hint on every recognition, deterministic correction per final line, glossary-aware refine, `segment-updated` event), `MeetingRecordingSession`/`MeetingModeService` (refined lines reach the meeting transcript and renderer via `meetingMode:segmentUpdated`; auto-polish gets the glossary block), `FileTranscriptionService` (per-chunk hint + correction) and `VoiceModeService` (learned-term pass). Tests: core `transcript-correction.test.ts` (16), desktop `transcript-glossary.test.ts` (9); real-app meeting verification still open (`GAP-MTG-04`). |
|
||||
| MTG-14 | Learning-informed transcript correction (user dictionary + typed vocabulary) | [~] | [ ] | [ ] | [ ] | **2026-11-05 (root cause + rebuild of the transcript-correction seam):** the learned corpus was only wired to input suggestions. Meeting/live captions ran STT with a hardcoded `다음은 한국어 대화입니다.` prompt (no dictionary, no learned terms), the refine prompt had no glossary, the refine result updated only `CaptionService`'s own copy (meetings and the renderer kept the raw line), and the persisted `rawTranscript` was a plain join of raw segments. Now: core SSOT `@d3ro/core/transcript-correction` (glossary build, dictionary-variant replacement, learned-identifier correction with a unique-best rule, LLM reference block) + desktop `TranscriptGlossaryService` (dictionary + `personal_phrases`, 15 s cache invalidated on dictionary writes, fail-closed) are wired into `CaptionService` (hint on every recognition, deterministic correction per final line, glossary-aware refine, `segment-updated` event), `MeetingRecordingSession`/`MeetingModeService` (refined lines reach the meeting transcript and renderer via `meetingMode:segmentUpdated`; auto-polish gets the glossary block), `FileTranscriptionService` (per-chunk hint + correction) and `VoiceModeService` (learned-term pass). **2026-11-05 (v1.16.3 correction policy):** the first cut also rewrote ordinary Hangul words by 1-jamo distance. Measured against the real local corpus (users/_local/d3ro.db, 3 stored meeting transcripts) it changed **286 of 3,005 words** (하면 to 라면, 이제 to 이게, 매일 to 메일, 정보 to 정도). Deterministic correction is now limited to dictionary pronunciations and typed Latin identifiers (canonical casing preserved); Korean terms reach recognition through the STT hint and the polish prompt only. Re-measured on the same corpus: **0 of 3,005**. Real-engine check (sidecar large-v3-turbo, Korean TTS fixture containing the user term): baseline 하람로그에 to hinted transcript haramlog에, and a dictionary pronunciation entry still maps 디에로 to D3RO. Hangul-layout typing artifacts (dkssudgktpdy) are dropped from the hint. Tests: core transcript-correction.test.ts (16), desktop transcript-glossary.test.ts (10); live meeting with real jargon still open (GAP-MTG-04). |
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ Legend: `[ ]` open · `[~]` in progress · `[!]` blocked externally · `[x]` res
|
|||
| GAP-MTG-01 | Meetings | Audio seek ↔ transcript timestamp sync missing. | `apps/mobile-rn/src/features/meetings/meetings-service.ts`, `MeetingDetailScreen.tsx`, `apps/web/src/components/meetings/{meeting-audio-player,live-transcript-list}.tsx`, `apps/mobile-rn/__tests__/meetings.test.ts` | `[x]` 2026-10-30: 모바일(`MeetingDetailScreen.tsx`)과 웹(`meeting-audio-player.tsx` ↔ `live-transcript-list.tsx`) 및 데스크톱(`TranscriptTab.tsx` / `EditableSegment.tsx`)에 `[MM:SS]` 구간 타임스탬프 파싱·오디오 시크 이동 및 재생 위치별 활성 전사 세그먼트 하이라이트를 구현했다 (`__tests__/meetings.test.ts` 통과). |
|
||||
| GAP-MTG-02 | Meetings | Speaker diarization only partially done on desktop; absent web/mobile. | `docs/phases/phase-15.5-speaker-diarization.md`, SSOT H-014 | Finish desktop pyannote path; expose speaker labels cross-surface. |
|
||||
| GAP-MTG-03 | Meetings | Existing recordings could become plain transcription history, but not a meeting with linked audio and minutes. | desktop `MeetingModeService`, `meeting/imported-recording.ts`, `meeting-mode-handlers.ts`; mobile `MeetingsScreen` → `RecordScreen`; MTG-13 | `[~]` 2026-11-02: installed Windows 1.16.0 passed native picker→timestamped transcript→local summary/action item with a real WAV (`2026-11-02-verification.md`). Desktop GUI gate is complete; authenticated Android picker→upload→transcript→minutes on Fold6 remains. |
|
||||
| GAP-MTG-04 | Meetings | Learned typing vocabulary never reached meeting transcription: STT used a hardcoded Korean hint, refine had no glossary, refined lines stopped inside `CaptionService`, and the stored transcript was raw segments. | `packages/core/src/transcript-correction.ts`, `apps/desktop/src/main/services/TranscriptGlossaryService.ts`, `CaptionService.ts`, `meeting/MeetingRecordingSession.ts`, `MeetingModeService.ts`, `FileTranscriptionService.ts`, `VoiceModeService.ts`; MTG-14 | `[~]` 2026-11-05: one glossary SSOT wired into caption, meeting, file transcription and dictation; refined lines now propagate to the meeting transcript and renderer (`meetingMode:segmentUpdated`). Evidence: `packages/core/__tests__/transcript-correction.test.ts` 16/16, `apps/desktop/tests/main/services/transcript-glossary.test.ts` 9/9, desktop offline suite, workspace typecheck, touched-file ESLint and `test:hygiene` green. **Remaining:** run a real meeting with the user's actual learned vocabulary and confirm no over-correction of ordinary Korean words, plus a packaged-install check of the new IPC event. |
|
||||
| GAP-MTG-04 | Meetings | Learned typing vocabulary never reached meeting transcription: STT used a hardcoded Korean hint, refine had no glossary, refined lines stopped inside `CaptionService`, and the stored transcript was raw segments. | `packages/core/src/transcript-correction.ts`, `apps/desktop/src/main/services/TranscriptGlossaryService.ts`, `CaptionService.ts`, `meeting/MeetingRecordingSession.ts`, `MeetingModeService.ts`, `FileTranscriptionService.ts`, `VoiceModeService.ts`; MTG-14 | `[~]` 2026-11-05: one glossary SSOT wired into caption, meeting, file transcription and dictation; refined lines now propagate to the meeting transcript and renderer (`meetingMode:segmentUpdated`). **Direct measurement against the real local database** (`users/_local/d3ro.db`: 1,952 learned phrases / 2,522 typing samples / 3 meeting transcripts) exposed that the first cut also rewrote ordinary Korean (286 of 3,005 words: 하면→라면, 이제→이게, 매일→메일, 정보→정도), and v1.16.3 restricts deterministic correction to dictionary pronunciations plus typed Latin identifiers — re-measured **0 of 3,005**. Real-engine check with the local sidecar (`large-v3-turbo`): a Korean TTS fixture containing the user term transcribes as 하람로그에 with no hint and haramlog에 with the learned hint; a dictionary pronunciation entry maps 디에로 → D3RO. Hangul-layout artifacts (dkssudgktpdy) are excluded from the hint. Evidence: `packages/core/__tests__/transcript-correction.test.ts` 16/16, `apps/desktop/tests/main/services/transcript-glossary.test.ts` 10/10, core 589/589, desktop offline suite, workspace typecheck, touched-file ESLint, `test:hygiene`. **Remaining:** a live meeting with real names/jargon by voice, and a packaged-install check of the new IPC event. |
|
||||
| GAP-INFRA-01 | Build | `apps/mobile-rn` is outside npm workspaces, so root `typecheck`/`test`/`lint` skip it. `typecheck:mobile`/`lint:mobile`/`test:mobile`/`verify:all` root scripts added 2026-09-13 (`package.json`), but membership/CI integration is still open. | `package.json`, `.forgejo/workflows/ci.yml`, `.gitlab-ci.yml` | `[x]` 2026-10-30: React Native Metro/Gradle 네이티브 오토링킹 격리를 위해 `apps/mobile-rn`은 독립 `node_modules`로 유지하고, 루트 `verify:all` 및 `.forgejo/workflows/ci.yml`·`.gitlab-ci.yml`의 `mobile-quality` 잡이 모바일 `lint`·`typecheck`·`test:ci`를 필수 게이트로 실행하도록 정본화했다. **2026-11-04:** root `test:mobile`도 watch-capable 기본 Jest가 아니라 mobile `test:ci`(`jest --runInBand`)를 호출하도록 고정했다. |
|
||||
| GAP-MOB-01 | Legacy | `apps/mobile` Expo skeleton duplicated auth/data code and got version-sync edits. | SSOT G-002 | `[x]` 2026-09-13: deleted `apps/mobile`, removed from `sync-version.mjs` and `package-lock.json`; `version:check` GREEN. |
|
||||
| GAP-INFRA-02 | CI | GitLab admin NAS deploy job is disabled; admin deploy is manual/GHCR. | `.gitlab-ci.yml`, `docs/deployment/nas-deploy-runbook.md` | `[x]` 2026-10-30: 임시 CI DinD 데몬만 바꾸던 구 잡 대신 `docker-compose.nas.yml` 기반의 정본 배포·헬스체크·롤백 절차를 `docs/deployment/nas-deploy-runbook.md`로 문서화하고 `.gitlab-ci.yml` 및 `02-infrastructure.md`에 연결했다. |
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
- 해결: 새 SSOT `packages/core/src/transcript-correction.ts`(글로서리·사전 변형 치환·1자모 학습 어절 교정·LLM 참고 블록) + `TranscriptGlossaryService`(사전+개인 문구 15초 캐시, 사전 변경 시 즉시 무효화, 실패 시 빈 어휘) 를 `CaptionService`(매 인식 힌트·확정 줄 교정·교열 프롬프트·`segment-updated`), `MeetingRecordingSession`/`MeetingModeService`(`meetingMode:segmentUpdated`로 회의 세션·화면 갱신, auto-polish에 용어 블록), `FileTranscriptionService`(조각별 힌트·교정), `VoiceModeService`(학습 어절 패스)에 배선.
|
||||
- 교정 안전 규칙: 사용자가 실제로 쓴 어절은 절대 변경하지 않고, 후보가 동률이면 고치지 않으며, 조사는 그대로 두고 어절만 바꾼다.
|
||||
- 검증: core `transcript-correction.test.ts` 16, 데스크톱 `transcript-glossary.test.ts` 9, 데스크톱 offline 전체(2788)에서 드러난 회귀 2건을 수정해 재통과, workspace typecheck·변경 파일 ESLint·`test:hygiene` GREEN. 실회의 실측은 `GAP-MTG-04`로 남김.
|
||||
- **1.16.2 배포 직후 실사용 DB로 직접 검증해 결함 발견 → 1.16.3으로 수정:** `users/_local/d3ro.db`(개인 문구 1,952·이핑 표본 2,522·회의 전사 3건)에 결정적 교정을 돌리니 실제 전사 3,005어절 중 **286개가 잘못 바뀌었다**(하면→라면, 이제→이게, 매일→메일, 정보→정도, 일단→일반). 학습 어휘 대부분이 일반 명사·부사·어미라 1자모 거리로는 오인식과 정상 단어를 구분할 수 없다. 수정: 결정적 교정은 **사전 발음 변형 + 사용자가 친 라틴 식별자**만(대소문자 보존), 한글 용어는 STT 힌트·LLM 교열 참고로만. 같은 코퍼스 재측정 **0/3,005**. 실제 사이드카(`large-v3-turbo`)로 한국어 TTS 픽스처 검증: 힌트 없음 `하람로그에` → 힌트 있음 `haramlog에`, 사전 발음 등록 시 `디에로`→`D3RO`. 한영 자판 오타 산물(`dkssudgktpdy`)은 힌트에서 제외. 교훈: **"학습 데이터를 쓴다"는 기능은 실사용 코퍼스로 오탐을 먼저 재고 나서 켠다.**
|
||||
|
||||
## v1.9.0 — 전사 구간·프리셋 프롬프트 동기화 (2026-09-27)
|
||||
|
||||
|
|
|
|||
|
|
@ -90,33 +90,45 @@ describe('replaceDictionaryTerms', () => {
|
|||
|
||||
describe('correctLearnedTerms', () => {
|
||||
const glossary = buildTranscriptGlossary({
|
||||
phrases: phrases(['회의록 정리해줘', 6], ['전사 교정', 4]),
|
||||
phrases: phrases(['VSCode 설정 열기', 6], ['D3RO Voice 녹음', 4]),
|
||||
})
|
||||
|
||||
it('1자모 차이 나는 전사 어절을 학습 어절로 되돌린다', () => {
|
||||
const result = correctLearnedTerms('회이록 정리해줘', glossary)
|
||||
it('학습한 식별자와 한 글자 다른 전사 어절을 되돌린다', () => {
|
||||
const result = correctLearnedTerms('VSCod 설정 열기', glossary)
|
||||
|
||||
expect(result.text).toBe('회의록 정리해줘')
|
||||
expect(result.corrections).toEqual([{ from: '회이록', to: '회의록', source: 'learned' }])
|
||||
expect(result.text).toBe('VSCode 설정 열기')
|
||||
expect(result.corrections).toEqual([{ from: 'VSCod', to: 'VSCode', source: 'learned' }])
|
||||
})
|
||||
|
||||
it('조사는 붙인 채로 어절만 고친다', () => {
|
||||
expect(correctLearnedTerms('회이록은 좋다', glossary).text).toBe('회의록은 좋다')
|
||||
})
|
||||
it('이미 맞게 적힌 식별자는 건드리지 않는다', () => {
|
||||
const result = correctLearnedTerms('VSCode 설정 열기', glossary)
|
||||
|
||||
it('사용자가 실제로 쓴 어절은 건드리지 않는다', () => {
|
||||
const result = correctLearnedTerms('회의록 정리해줘', glossary)
|
||||
|
||||
expect(result.text).toBe('회의록 정리해줘')
|
||||
expect(result.text).toBe('VSCode 설정 열기')
|
||||
expect(result.corrections).toEqual([])
|
||||
})
|
||||
|
||||
it('한글 어절은 1자모만 달라도 고치지 않는다', () => {
|
||||
// 실사용 코퍼스 측정: 한글까지 고치면 정상 문장이 대량으로 망가졌다(하면→라면, 이제→이게 …).
|
||||
const korean = buildTranscriptGlossary({
|
||||
phrases: phrases(['회의록 정리해줘', 6], ['라면 먹고 싶다', 5]),
|
||||
})
|
||||
|
||||
expect(correctLearnedTerms('회이록 정리해줘', korean).text).toBe('회이록 정리해줘')
|
||||
expect(correctLearnedTerms('하면 좋겠다', korean).text).toBe('하면 좋겠다')
|
||||
})
|
||||
|
||||
it('후보가 둘 이상이면(동률) 고치지 않는다', () => {
|
||||
const tied = buildTranscriptGlossary({
|
||||
phrases: phrases(['정리해', 4], ['정리히', 4]),
|
||||
phrases: phrases(['vscode 사용', 4], ['vscodf 사용', 4]),
|
||||
})
|
||||
|
||||
expect(correctLearnedTerms('정리하', tied).text).toBe('정리하')
|
||||
expect(correctLearnedTerms('vscodd', tied).text).toBe('vscodd')
|
||||
})
|
||||
|
||||
it('너무 짧은 식별자·한 글자 어절은 대상이 아니다', () => {
|
||||
const shortTerms = buildTranscriptGlossary({ phrases: phrases(['api 서버', 9]) })
|
||||
|
||||
expect(correctLearnedTerms('ap 서버', shortTerms).text).toBe('ap 서버')
|
||||
})
|
||||
|
||||
it('어휘가 없으면 원문을 그대로 돌려준다', () => {
|
||||
|
|
@ -124,15 +136,6 @@ describe('correctLearnedTerms', () => {
|
|||
|
||||
expect(result).toEqual({ text: '아무 말이나 적는다', corrections: [] })
|
||||
})
|
||||
|
||||
it('사전 정본 표기가 학습 어절보다 우선한다', () => {
|
||||
const withDictionary = buildTranscriptGlossary({
|
||||
dictionary: [{ word: '회의록', pronunciation: null }],
|
||||
phrases: phrases(['회의녹 정리', 9]),
|
||||
})
|
||||
|
||||
expect(correctLearnedTerms('회이록 정리', withDictionary).text).toBe('회의록 정리')
|
||||
})
|
||||
})
|
||||
|
||||
describe('LLM 교열 참고 블록', () => {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
//
|
||||
// 순수 함수만 둔다. DB·Electron 을 모르므로 데스크톱 서비스가 소스를 주입한다.
|
||||
|
||||
import { decomposeHangul, editDistance, tokenizeWords } from './typo-correction'
|
||||
import { editDistance, latinToHangul, tokenizeWords } from './typo-correction'
|
||||
|
||||
/** 사용자 사전 한 항목 */
|
||||
export interface GlossaryDictionaryEntry {
|
||||
|
|
@ -59,15 +59,7 @@ const STOP_WORDS: ReadonlySet<string> = new Set([
|
|||
'이렇게', '그렇게', '저렇게', '여기', '거기', '저기',
|
||||
])
|
||||
|
||||
/** 토큰에서 떼어 낼 수 있는 조사 (긴 것부터) */
|
||||
const JOSA_SUFFIXES: readonly string[] = [
|
||||
'이라는', '이라고', '이라도', '에서는', '에게는', '에서도', '으로는', '으로써',
|
||||
'에서는', '부터', '까지', '에게', '한테', '에서', '으로', '라고', '라는',
|
||||
'이나', '라도', '이랑', '하고', '이고', '이든', '처럼', '보다', '만큼',
|
||||
'에는', '에도', '께서', '이란', '이라',
|
||||
'은', '는', '이', '가', '을', '를', '에', '의', '로', '도', '와', '과', '만', '들',
|
||||
]
|
||||
|
||||
/** 학습 어휘를 STT 힌트·LLM 교열·식별자 교정에 쓰기 위한 묶음. */
|
||||
export interface TranscriptGlossary {
|
||||
/** 사전 정본 단어 (원표기) */
|
||||
terms: readonly string[]
|
||||
|
|
@ -75,6 +67,8 @@ export interface TranscriptGlossary {
|
|||
dictionary: readonly { word: string; variants: readonly string[] }[]
|
||||
/** 소문자 어절 → 빈도 (교정 후보) */
|
||||
vocabulary: ReadonlyMap<string, number>
|
||||
/** 소문자 어절 → 처음 본 표기 (VSCode 같은 대소문자 보존) */
|
||||
canonical: ReadonlyMap<string, string>
|
||||
/** 사용자가 실제로 쓰는 표현 (문체 참고) */
|
||||
examples: readonly string[]
|
||||
/** STT initial_prompt 힌트 (없으면 빈 문자열) */
|
||||
|
|
@ -96,6 +90,7 @@ const EMPTY_GLOSSARY: TranscriptGlossary = {
|
|||
terms: [],
|
||||
dictionary: [],
|
||||
vocabulary: new Map<string, number>(),
|
||||
canonical: new Map<string, string>(),
|
||||
examples: [],
|
||||
promptHint: '',
|
||||
}
|
||||
|
|
@ -144,6 +139,7 @@ export function buildTranscriptGlossary(input: {
|
|||
const dictionary: Array<{ word: string; variants: readonly string[] }> = []
|
||||
const terms: string[] = []
|
||||
const vocabulary = new Map<string, number>()
|
||||
const canonical = new Map<string, string>()
|
||||
const seen = new Set<string>()
|
||||
|
||||
for (const entry of (input.dictionary ?? []).slice(0, limits.dictionaryEntries)) {
|
||||
|
|
@ -156,10 +152,13 @@ export function buildTranscriptGlossary(input: {
|
|||
terms.push(word)
|
||||
// 사전 정본은 어떤 학습 어절보다 우선 후보가 되도록 큰 가중치를 준다.
|
||||
bump(vocabulary, key, 1000)
|
||||
canonical.set(key, word)
|
||||
}
|
||||
|
||||
const examples: string[] = []
|
||||
const phraseTokens = new Map<string, number>()
|
||||
/** 같은 뜻의 한글 표기가 코퍼스에 있는 영문 토큰(한영 자판 오타 산물) — 힌트·교정에서 뺀다. */
|
||||
const hangulObserved = new Set<string>()
|
||||
for (const phrase of (input.phrases ?? []).slice(0, limits.phrases)) {
|
||||
const text = phrase.text?.replace(/\s+/gu, ' ').trim()
|
||||
if (!text) continue
|
||||
|
|
@ -175,7 +174,21 @@ export function buildTranscriptGlossary(input: {
|
|||
for (const token of tokenizeWords(text)) {
|
||||
const word = token.text
|
||||
if (!isLearnableToken(word)) continue
|
||||
bump(phraseTokens, word.toLowerCase(), weight)
|
||||
if (/^[가-힣]+$/u.test(word)) hangulObserved.add(word)
|
||||
const key = word.toLowerCase()
|
||||
bump(phraseTokens, key, weight)
|
||||
if (!canonical.has(key)) canonical.set(key, word)
|
||||
}
|
||||
}
|
||||
|
||||
// 한영 자판 오타 산물( 같은)은 같은 뜻의 한글 표기가 코퍼스에 있으므로 뺀다.
|
||||
// 그대로 두면 STT 힌트가 의미 없는 라틴 문자열로 편향되고, 식별자 교정 후보로도 쓰인다.
|
||||
for (const word of [...phraseTokens.keys()]) {
|
||||
if (!/^[a-z]+$/u.test(word)) continue
|
||||
const converted = latinToHangul(word)
|
||||
if (converted.complete && hangulObserved.has(converted.text)) {
|
||||
phraseTokens.delete(word)
|
||||
canonical.delete(word)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,9 +224,9 @@ export function buildTranscriptGlossary(input: {
|
|||
const promptHint = joined ? `용어: ${joined}.` : ''
|
||||
|
||||
if (vocabulary.size === 0 && terms.length === 0 && examples.length === 0) {
|
||||
return { ...EMPTY_GLOSSARY, vocabulary: new Map() }
|
||||
return { ...EMPTY_GLOSSARY, vocabulary: new Map(), canonical: new Map() }
|
||||
}
|
||||
return { terms, dictionary, vocabulary, examples, promptHint }
|
||||
return { terms, dictionary, vocabulary, canonical, examples, promptHint }
|
||||
}
|
||||
|
||||
/** 글로서리에 아무 정보도 없으면 true */
|
||||
|
|
@ -287,8 +300,8 @@ export function replaceDictionaryTerms(
|
|||
interface VocabularyCandidate {
|
||||
word: string
|
||||
count: number
|
||||
jamo: readonly string[]
|
||||
script: 'hangul' | 'latin'
|
||||
lower: string
|
||||
chars: readonly string[]
|
||||
}
|
||||
|
||||
interface VocabularyIndex {
|
||||
|
|
@ -303,11 +316,16 @@ interface VocabularyIndex {
|
|||
*/
|
||||
const vocabularyIndexCache = new WeakMap<TranscriptGlossary, VocabularyIndex>()
|
||||
|
||||
function scriptOf(value: string): 'hangul' | 'latin' | null {
|
||||
if (/^[가-힣]+$/u.test(value)) return 'hangul'
|
||||
if (/^[A-Za-z]+$/u.test(value)) return 'latin'
|
||||
return null
|
||||
}
|
||||
/**
|
||||
* 결정적 교정 대상은 ASCII 식별자(제품명·약어·코드)뿐이다.
|
||||
*
|
||||
* 한글 어절을 「학습 어휘와 1자모 다르면 교체」로 고치는 방식은 실사용 DB 코퍼스로 측정했을 때
|
||||
* 정상 문장을 대량으로 망쳤다(회의 전사 3,005어절 중 286개 변경: 하면→라면, 이제→이게, 매일→메일,
|
||||
* 정보→정도, 일단→일반 …). 사용자가 실제로 쓰는 어휘에는 일반 명사·부사·어미가 대부분이라
|
||||
* 1자모 거리만으로는 「오인식」과 「정상 단어」를 구분할 수 없다. 한글 용어는 STT 힌트와 LLM 교열에만
|
||||
* 쓰고, 결정적으로는 고치지 않는다(정밀도 우선).
|
||||
*/
|
||||
const IDENTIFIER_TOKEN = /^[A-Za-z][A-Za-z0-9]{3,}$/u
|
||||
|
||||
function buildVocabularyIndex(glossary: TranscriptGlossary): VocabularyIndex {
|
||||
const cached = vocabularyIndexCache.get(glossary)
|
||||
|
|
@ -321,40 +339,37 @@ function buildVocabularyIndexUncached(glossary: TranscriptGlossary): VocabularyI
|
|||
const byLength = new Map<number, VocabularyCandidate[]>()
|
||||
const known = new Set<string>()
|
||||
for (const [word, count] of glossary.vocabulary) {
|
||||
const script = scriptOf(word)
|
||||
if (!script) continue
|
||||
if (!IDENTIFIER_TOKEN.test(word)) continue
|
||||
known.add(word)
|
||||
const candidate: VocabularyCandidate = {
|
||||
word,
|
||||
word: glossary.canonical.get(word) ?? word,
|
||||
count,
|
||||
jamo: decomposeHangul(word),
|
||||
script,
|
||||
lower: word.toLowerCase(),
|
||||
chars: Array.from(word.toLowerCase()),
|
||||
}
|
||||
const bucket = byLength.get(candidate.jamo.length)
|
||||
const bucket = byLength.get(candidate.chars.length)
|
||||
if (bucket) bucket.push(candidate)
|
||||
else byLength.set(candidate.jamo.length, [candidate])
|
||||
else byLength.set(candidate.chars.length, [candidate])
|
||||
}
|
||||
return { byLength, known }
|
||||
}
|
||||
|
||||
/**
|
||||
* 학습 어절에서 1자모 차이 나는 유일한 후보를 찾는다.
|
||||
* 학습 어휘에서 1글자 차이 나는 유일한 후보를 찾는다.
|
||||
* 동률이면(어느 쪽이 맞는지 알 수 없으면) 고치지 않는다.
|
||||
*/
|
||||
function bestCandidate(token: string, index: VocabularyIndex): VocabularyCandidate | null {
|
||||
const script = scriptOf(token)
|
||||
if (!script) return null
|
||||
const jamo = decomposeHangul(token)
|
||||
const lower = token.toLowerCase()
|
||||
const chars = Array.from(lower)
|
||||
let best: VocabularyCandidate | null = null
|
||||
let bestCount = 0
|
||||
let ties = 0
|
||||
for (const length of [jamo.length - 1, jamo.length, jamo.length + 1]) {
|
||||
for (const length of [chars.length - 1, chars.length, chars.length + 1]) {
|
||||
const bucket = index.byLength.get(length)
|
||||
if (!bucket) continue
|
||||
for (const candidate of bucket) {
|
||||
if (candidate.script !== script) continue
|
||||
if (candidate.jamo.length === jamo.length && candidate.word === token.toLowerCase()) continue
|
||||
if (editDistance(jamo, candidate.jamo) > 1) continue
|
||||
if (candidate.lower === lower) continue
|
||||
if (editDistance(chars, candidate.chars) > 1) continue
|
||||
if (candidate.count > bestCount) {
|
||||
best = candidate
|
||||
bestCount = candidate.count
|
||||
|
|
@ -367,27 +382,9 @@ function bestCandidate(token: string, index: VocabularyIndex): VocabularyCandida
|
|||
return ties === 0 ? best : null
|
||||
}
|
||||
|
||||
interface TokenAttempt {
|
||||
/** 비교할 어절 (조사를 떼어 낸 형태일 수 있다) */
|
||||
text: string
|
||||
}
|
||||
|
||||
function tokenAttempts(token: string): TokenAttempt[] {
|
||||
const attempts: TokenAttempt[] = [{ text: token }]
|
||||
for (const josa of JOSA_SUFFIXES) {
|
||||
if (token.length - josa.length < 2) continue
|
||||
if (!token.endsWith(josa)) continue
|
||||
const stem = token.slice(0, token.length - josa.length)
|
||||
if (!/^[가-힣A-Za-z0-9]+$/u.test(stem)) continue
|
||||
attempts.push({ text: stem })
|
||||
break
|
||||
}
|
||||
return attempts
|
||||
}
|
||||
|
||||
/**
|
||||
* 학습 어휘로 어절을 되돌린다. 띄어쓰기·문장부호·조사는 그대로 두고 어절만 바꾼다.
|
||||
* 사용자가 실제로 쓴 어절(어휘에 있음)은 절대 건드리지 않는다.
|
||||
* 학습 어휘로 ASCII 식별자 어절을 되돌린다 (예: `vscod` → `VSCode`).
|
||||
* 한글 어절·띄어쓰기·문장부호는 건드리지 않는다.
|
||||
*/
|
||||
export function correctLearnedTerms(
|
||||
text: string,
|
||||
|
|
@ -397,26 +394,20 @@ export function correctLearnedTerms(
|
|||
if (!trimmed || glossary.vocabulary.size === 0) return { text: trimmed, corrections: [] }
|
||||
|
||||
const index = buildVocabularyIndex(glossary)
|
||||
if (index.byLength.size === 0) return { text: trimmed, corrections: [] }
|
||||
|
||||
const corrections: TranscriptCorrectionEntry[] = []
|
||||
let out = ''
|
||||
let cursor = 0
|
||||
|
||||
for (const token of tokenizeWords(trimmed)) {
|
||||
let replaced: { value: string; prefixLength: number } | null = null
|
||||
for (const attempt of tokenAttempts(token.text)) {
|
||||
if (index.known.has(attempt.text.toLowerCase())) continue
|
||||
if (attempt.text.length < 2) continue
|
||||
const candidate = bestCandidate(attempt.text, index)
|
||||
if (!candidate) continue
|
||||
replaced = { value: candidate.word, prefixLength: attempt.text.length }
|
||||
break
|
||||
}
|
||||
if (!replaced) continue
|
||||
const original = token.text.slice(0, replaced.prefixLength)
|
||||
if (original === replaced.value) continue
|
||||
corrections.push({ from: original, to: replaced.value, source: 'learned' })
|
||||
out += trimmed.slice(cursor, token.start) + replaced.value
|
||||
cursor = token.start + replaced.prefixLength
|
||||
if (!IDENTIFIER_TOKEN.test(token.text)) continue
|
||||
if (index.known.has(token.text.toLowerCase())) continue
|
||||
const candidate = bestCandidate(token.text, index)
|
||||
if (!candidate) continue
|
||||
corrections.push({ from: token.text, to: candidate.word, source: 'learned' })
|
||||
out += trimmed.slice(cursor, token.start) + candidate.word
|
||||
cursor = token.end
|
||||
}
|
||||
|
||||
if (corrections.length === 0) return { text: trimmed, corrections: [] }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue