Repository navigation
fix(backend): reject pronouns/fillers as auto-detected speaker names (#5223) - #7807
Conversation
…5223) detect_speaker_from_text's introduction regexes ("I am X", "I'm X", ...) capture whatever capitalized word follows, so run-on transcripts like "I'm It was great" / "I'm You know..." / "I'm Them and..." produced phantom speaker contacts named "It", "You", "Them" — exactly the junk reported in #5223/#5250. Deleting them didn't help: the next conversation recreated them. Add a stopword guard: a captured name that is a pronoun, demonstrative, question word, or common filler is rejected and pattern matching continues. Real introductions ("I am John", "I'm Will", "Soy Carlos") are unaffected. Applies to both creation paths (realtime /v4/listen and offline sync) since both go through detect_speaker_from_text. Adds parametrized regression tests for the reported phantom names.
Greptile SummaryThis PR adds a
Confidence Score: 4/5Safe to merge — the change is narrowly scoped to one guard condition and both creation paths benefit automatically since they share detect_speaker_from_text. The logic is correct, the lookup is efficient, and the regression tests directly cover the reported phantom-name transcripts. The only non-trivial concern is that a handful of stopwords (notably 'her') coincide with legitimate given names in non-English languages, which could produce silent false negatives for a small set of users — but this is a very niche edge case and does not affect the main fix. No files require special attention; speaker_identification.py is the primary change and its logic is straightforward. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["detect_speaker_from_text(text)"] --> B["Iterate patterns_to_check"]
B --> C{"re.search(pattern, text)"}
C -- "No match" --> B
C -- "Match" --> D["name = match.groups()[-1]"]
D --> E{"name AND len >= 2?"}
E -- "No" --> B
E -- "Yes" --> F{"name.lower() in STOPWORDS?"}
F -- "Yes - pronoun/filler" --> B
F -- "No - real name" --> G["return name.capitalize()"]
B -- "Exhausted" --> H["return None"]
Reviews (1): Last reviewed commit: "fix(backend): reject pronouns/fillers as..." | Re-trigger Greptile |
| 'her', | ||
| 'his', | ||
| 'hers', |
There was a problem hiding this comment.
'her' (and 'him') block real given names cross-language
'her' is a common Vietnamese given name (e.g. "Tôi là Her") and 'him' appears in some cultures as well. Because detect_speaker_from_text applies all patterns without language filtering, a Vietnamese speaker whose name is "Her" would match the Vietnamese pattern and then have that name silently dropped by the stopword guard. The tradeoff is reasonable for the English use-case, but worth noting for future expansion of the stopword list — words that are pronouns in one language may be names in another.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Is there a plan to make detect_speaker_from_text language-aware so that the stopword set can be scoped to the detected language?
| def test_real_name_after_stopword_guard(self): | ||
| """Genuine introductions still detect after the stopword guard.""" | ||
| assert detect_speaker_from_text("I am John") == "John" | ||
| assert detect_speaker_from_text("My name is Alice") == "Alice" |
There was a problem hiding this comment.
Positive guard test duplicates existing
POSITIVE_CASES entries without parametrization
test_real_name_after_stopword_guard hardcodes "John" and "Alice", both of which already appear in POSITIVE_CASES and are exercised by test_positive_detection. The intent — confirming real names survive the stopword check — is good, but near-miss stopword names (e.g. a name starting with "He", "So", or "Will") would be more valuable additions to POSITIVE_CASES rather than a separate non-parametrized method.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Bug
#5223 / #5250: phantom speaker contacts named "It", "You", "Them" keep being created and reappear after deletion.
The toggle half of those reports ("Auto Create Speakers off but still creating") was already fixed end-to-end on main by 041f6b2 (June 1). This PR fixes the remaining half: even with the toggle ON (the default), junk pronoun contacts are still created for everyone.
Root cause
detect_speaker_from_text(backend/utils/speaker_identification.py) matches introduction patterns like\b(I am|I'm|...)\s+([A-Z][a-zA-Z]*)\band returns whatever capitalized word follows. Run-on / smart-cased transcripts trigger it constantly:(Reproduced against the real patterns — these exact phrases yield exactly the reported phantom names.) The realtime /v4/listen path then calls
create_personwith that name; the next conversation recreates any contact the user deleted.Fix
Add
SPEAKER_NAME_STOPWORDS(pronouns, demonstratives, question words, common fillers) and reject a captured name when it's a stopword, continuing to the next pattern. Real introductions are unaffected ("I am John", "I'm Will", "Soy Carlos", "Je m'appelle Sophie" all still detect — verified).Covers both creation/assignment paths (realtime
transcribe.pyand offlinesync.py) since both go throughdetect_speaker_from_text.Tests
None)tests/unit/test_speaker_id_pipeline.pyis already intest.sh(runs in CI)🤖 automated by hourly watchdog; opened for review, not merged.
Fixes #5223
Fixes #5250
🤖 Generated with Claude Code