Skip to content

Score sentences by likelihood and connect sentences within a note - #4

Merged
otnc merged 2 commits into
mainfrom
improve/sentence-likelihood-and-note-coherence
Oct 1, 2026
Merged

otnc merged 2 commits into
mainfrom
improve/sentence-likelihood-and-note-coherence

Conversation

@otnc

@otnc otnc commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Summary

Two follow-ups from #1, building on #2's Markov chain smoothing work.

  • Likelihood-aware scoring: generateSentence previously scored candidate sentences only by closeness to the target length. pick() now also returns the log probability of the token it chose; these are summed over the walk and folded into the score as a length-normalized average, so among several sampled attempts the one the model finds more probable is preferred, not just the one closest to the target length. This is best-of-N reranking by model likelihood applied to the existing multi-attempt loop (Li & Bertsekas, 2024, rollout algorithms for n-gram sequence generation).
  • Cross-sentence coherence: generateNote used to generate every sentence after the first independently (seed: undefined), with no connection to the sentence(s) before it, even though reply generation already seeds from a noun in the other person's note to stay on topic. It now seeds sentence N+1 from a noun in sentence N the same way, so a multi-sentence note reads as one topic. Falls back to an unseeded sentence when no suitable noun is found.

Neither change adds a new rejection rule, so the range of generatable sentences is not narrowed.

Test plan

  • npm run typecheck, npm run lint, npm run format:check, npm test all pass at every commit on this branch
  • Manually generated several multi-sentence notes (HI_MAX_SENTENCES=3) and confirmed a noun from the first sentence reappears in the next sentence, where previously sentences were unrelated

Closes #1

otnc added 2 commits October 1, 2026 14:38
Previously, generateSentence scored candidates only by how close
their length was to the target. Now pick() also returns the log
probability of the token it chose, these are summed over the walk,
and the score adds the per-token average log probability (normalized
by sentence length so it does not just penalize longer sentences).

This is best-of-N reranking by model likelihood, applied to the
existing multi-attempt generation loop rather than changing what can
be generated: Li & Bertsekas (2024) frame this as a rollout policy
over an n-gram's distribution.
generateNote used to generate every sentence after the first with no
connection to what came before it, even though reply generation
already seeds from a noun in the other person's note to stay on
topic. Expose the token list alongside the generated text
(generateSentenceWithTokens), and use the same noun-picking logic to
seed sentence N+1 from a noun in sentence N, so multi-sentence notes
read as one topic instead of unrelated sentences stitched together.

Falls back to an unseeded sentence when no suitable noun is found, so
this only adds a better default and does not remove any existing
generation path.
@otnc
otnc merged commit 546b4ae into main Oct 1, 2026
3 checks passed
@otnc
otnc deleted the improve/sentence-likelihood-and-note-coherence branch October 1, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

もう少し文章が自然にならないか、精度を上げられないかを検証

1 participant