Improve memory recall in Korean at every speech level
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+60
-23
@@ -290,8 +290,8 @@ def self_answer(text, lang="en"):
|
||||
if _state.get("holding"):
|
||||
parts.append(f"I'm holding {_state['holding']}." if not ko else f"손에 {_j(_held_ko(_state['holding']), '을', '를')} 들고 있어요.")
|
||||
elif _state.get("gripper"):
|
||||
parts.append({"open": ("My hand is open and empty.", "손은 펴져 있고 비어 있어요."),
|
||||
"closed": ("My hand is closed, with nothing in it.", "손은 닫혀 있고 비어 있어요.")}[_state["gripper"]][ko])
|
||||
parts.append({"open": ("My hand is open and empty.", "손은 펴져 있고, 아무것도 안 들고 있어요."),
|
||||
"closed": ("My hand is closed, with nothing in it.", "손은 닫혀 있고, 아무것도 안 들고 있어요.")}[_state["gripper"]][ko])
|
||||
return " ".join(parts) or None
|
||||
|
||||
|
||||
@@ -360,6 +360,17 @@ def _object(text):
|
||||
return None
|
||||
|
||||
|
||||
def _colour(text, name):
|
||||
"""The colour said with the thing ("a green apple", "초록 사과"), else None ("orange" the fruit is no colour)."""
|
||||
from assistant import seeing
|
||||
t = text.lower()
|
||||
for w in sorted(seeing.COLOURS, key=len, reverse=True):
|
||||
if w == name or w == "하늘" or not re.search(rf"(?<![a-z가-힣]){w}(?![a-z])", t):
|
||||
continue
|
||||
return seeing.COLOURS[w]
|
||||
return None
|
||||
|
||||
|
||||
def _thing_words(e, lang):
|
||||
from assistant import seeing
|
||||
if lang == "ko":
|
||||
@@ -394,7 +405,14 @@ def seen_answer(text, lang="en", now=None, days="ask"):
|
||||
(f" {when(other['t'], 'ko', now)}에 본 적은 있어요." if other else "")
|
||||
return f"I haven't seen {'anyone' if name == 'person' else 'one'} {span_en}." + \
|
||||
(f" I saw one {when(other['t'], 'en', now)}." if other else "")
|
||||
e = hits[-1]
|
||||
colour = _colour(text, name)
|
||||
if colour and not any(e.get("colour") == colour for e in hits): # "a green apple?" when only a red one was seen
|
||||
e = hits[-1]
|
||||
if lang == "ko":
|
||||
return f"{span_ko} {seeing._j(seeing.COLOUR_KO.get(colour, colour) + ' ' + word_ko, '은', '는')} 못 봤어요. " \
|
||||
f"{when(e['t'], 'ko', now)}{_where(e, 'ko')} {seeing._j(_thing_words(e, 'ko'), '은', '는')} 봤어요."
|
||||
return f"I haven't seen {seeing._a(name, colour)} {span_en}. I saw {_thing_words(e, 'en')} {when(e['t'], 'en', now)}{_where(e, 'en')}."
|
||||
e = next((e for e in reversed(hits) if e.get("colour") == colour), hits[-1])
|
||||
if lang == "ko":
|
||||
return f"네, {when(e['t'], 'ko', now)}{_where(e, 'ko')} {seeing._j(_thing_words(e, 'ko'), '을', '를')} 봤어요."
|
||||
return f"Yes, I saw {_thing_words(e, 'en')} {when(e['t'], 'en', now)}{_where(e, 'en')}."
|
||||
@@ -435,13 +453,15 @@ SUMMARY_PROMPT = """Here is a conversation between a visitor and Lumi, a robot.
|
||||
"summary": "<2-3 short sentences: what was asked and answered, in English>",
|
||||
"facts": ["<each name, place, number or plan the visitor gave, in English>"],
|
||||
"commands": ["<each command for Lumi agreed in the talk, e.g. go to p3 and wave>"],
|
||||
"title_ko": "<the title in Korean>", "summary_ko": "<the summary in polite Korean (-요)>"}
|
||||
"title_ko": "<the title in Korean>", "summary_ko": "<the summary in polite Korean (-요)>",
|
||||
"facts_ko": ["<each fact in polite Korean (-요)>"]}
|
||||
Only what is in the conversation; nothing else."""
|
||||
SUMMARY_SCHEMA = {"type": "object", "properties": {"title": {"type": "string"}, "summary": {"type": "string"},
|
||||
"facts": {"type": "array", "items": {"type": "string"}},
|
||||
"commands": {"type": "array", "items": {"type": "string"}},
|
||||
"title_ko": {"type": "string"}, "summary_ko": {"type": "string"}},
|
||||
"required": ["title", "summary", "facts", "commands", "title_ko", "summary_ko"]}
|
||||
"title_ko": {"type": "string"}, "summary_ko": {"type": "string"},
|
||||
"facts_ko": {"type": "array", "items": {"type": "string"}}},
|
||||
"required": ["title", "summary", "facts", "commands", "title_ko", "summary_ko", "facts_ko"]}
|
||||
|
||||
|
||||
def _transcript(history):
|
||||
@@ -463,7 +483,8 @@ def summarise(history, chat=None):
|
||||
return {"title": str(out.get("title", "")).strip()[:60], "summary": str(out.get("summary", "")).strip()[:600],
|
||||
"facts": [str(f)[:160] for f in out.get("facts", [])][:10],
|
||||
"commands": [str(f)[:160] for f in out.get("commands", [])][:5],
|
||||
"title_ko": str(out.get("title_ko", "")).strip()[:60], "summary_ko": str(out.get("summary_ko", "")).strip()[:600]}
|
||||
"title_ko": str(out.get("title_ko", "")).strip()[:60], "summary_ko": str(out.get("summary_ko", "")).strip()[:600],
|
||||
"facts_ko": [str(f)[:160] for f in out.get("facts_ko", [])][:10]}
|
||||
|
||||
|
||||
def keep_talk(history, person=None, t=None, chat=None, embed=None, name=None):
|
||||
@@ -517,14 +538,15 @@ RECALL_Q = re.compile( # a question about an earlier talk; "I remember when ..
|
||||
r"\bwe (?:talked|spoke|chatted|discussed|were talking)\b|\bour (?:talk|chat|conversation)\b|"
|
||||
r"\b(?:what|which) did (?:we|i) (?:talk|speak|chat|say|tell|ask)\b|\bwhat did you (?:tell|say to) me about\b|"
|
||||
r"\bwhat (?:did )?we (?:talk|talked|discuss|discussed|chat|chatted)\b|\bdid (?:we|i) (?:talk|speak|chat|tell you|ask you|mention)\b|"
|
||||
r"\bearlier (?:i|we) (?:said|told|asked|talked)\b|\bremember\W*$|\bremind me\b|\bwe had (?:a|our|that) (?:talk|chat|conversation)\b|"
|
||||
r"\bearlier (?:i|we) (?:said|told|asked|talked)\b|\bremember(?: (?:that|this|it))?\W*$|\bring a bell\b|\bremind me\b|\bwe had (?:a|our|that) (?:talk|chat|conversation)\b|"
|
||||
r"\bdid we have (?:a|any) (?:talk|chat|conversation)\b|\bdid i (?:tell|give) you\b|\bwhat (?:we|you) (?:said|told me|talked about)\b|"
|
||||
r"(?:말해|알려|얘기해|이야기해) ?(?:줬|주었|드렸)(?:던|었|지|잖|죠)|(?:했던|나눴던|한) (?:얘기|이야기|대화)|"
|
||||
r"(?:얘기|이야기|대화)\s*(?:\S+\s+)?(?:했잖|했었|했던|나눴)|무슨\s*(?:topic|주제)(?:였|이었)|"
|
||||
r"기억\s*(?:이\s*)?(?:나|해|하|날)|생각\s*(?:이\s*)?나|"
|
||||
r"(?:얘기|이야기|대화|말)(?:를|을)?\s*(?:했던|했었|나눴|나누었|나누셨|하셨|한 거|했지|했잖|했는|했죠|했어|했노|했나|했니|했냐|했더라|했습니까|했을까)",
|
||||
r"(?:얘기|이야기|대화|말)(?:를|을)?\s*(?:했던|했었|나눴|나누었|나누셨|하셨|한 거|했지|했잖|했는|했죠|했어|했노|했나|했니|했냐|했더라|했습니까|했을까)|"
|
||||
r"\b(?:remember|recall)\s*(?:해|하|나|돼|되)|\b(?:talk|chat|conversation)\s*(?:했던|했었|한 거|나눴)", # Konglish: "remember 해?"
|
||||
re.I)
|
||||
NOT_RECALL = re.compile(r"\bremember (?:to|that you|my|me)\b|\bremember me\?$|\b(?:i|we) (?:don'?t |do not )?remember\b|"
|
||||
NOT_RECALL = re.compile(r"\bremember (?:to|that you|my|me)\b(?! (?:asking|telling|saying|talking|ask|tell|say|talk))|\bremember me\?$|\b(?:i|we) (?:don'?t |do not )?remember\b|"
|
||||
r"\b(?:can|could|will|would) you remember\b(?! (?:what|when|our|that we|we))|기억력|기억해\s*(?:줘|주세요|둬|놔)", re.I)
|
||||
GENERIC = re.compile(r"\b(?:what|which) did (?:we|i) (?:talk|speak|chat|say)(?: about)?\W*(?:today|yesterday|earlier|last time|before)?\W*$|"
|
||||
r"무슨 ?(?:얘기|이야기|대화|말)|뭐(?:라고)? ?(?:얘기|이야기|말)", re.I)
|
||||
@@ -547,7 +569,7 @@ CANT_REMEMBER = {"en": "I can't remember that.", "ko": "그건 기억이 안 나
|
||||
OFFER_WAIT_S = 60 # s a "do you mean ...?" waits for yes / no
|
||||
|
||||
|
||||
DETAIL = re.compile(r"\bremind me\b|\bwhat you (?:told|said)\b|\bmain point\b|\bthe point\b|\bconclusion\b|\bwhat was (?:it|that)(?: again)?\b|결론|요점|포인트|point|\bwhat (?:did|was it) you (?:say|tell|said|told)|\bwhat was (?:it|that|the \w+)\b|"
|
||||
DETAIL = re.compile(r"\bremind me\b|\b(?:your|the) answer\b|\bwhat was your (?:point|answer)\b|\bwhat you (?:told|said)\b|\bmain point\b|\bthe point\b|\bconclusion\b|\bwhat was (?:it|that)(?: again)?\b|결론|요점|포인트|point|\bwhat (?:did|was it) you (?:say|tell|said|told)|\bwhat was (?:it|that|the \w+)\b|"
|
||||
r"\btell me (?:more|again|what)\b|\bwhat did you (?:say|tell me)\b|\bwhat (?:you|we) said\b|\bthe details?\b|"
|
||||
r"무슨 (?:얘기|이야기|말)(?:였|이었)|뭐라고 (?:했|하셨|말했)|다시 (?:말해|알려)|자세히|뭐였", re.I)
|
||||
|
||||
@@ -587,9 +609,12 @@ def _told(s, lang, detail=False, turn=-99):
|
||||
talk has no Korean summary (the LLM then says it from the talk in its prompt)."""
|
||||
_recall.update(talk=s, offered=[], left=[], turn=turn)
|
||||
facts = " ".join(f if f.endswith(".") else f + "." for f in s.get("facts", [])[:3])
|
||||
if lang == "ko":
|
||||
ko = (s.get("facts_ko") or s.get("summary_ko")) if detail else s.get("summary_ko")
|
||||
return f"{'' if detail else '네, 기억나요. '}{' '.join(ko) if isinstance(ko, list) else ko}" if ko else None
|
||||
if lang == "ko": # a detail is the facts (the summary only names the topic)
|
||||
facts_ko = " ".join(f if f.endswith(".") else f + "." for f in s.get("facts_ko", [])[:3])
|
||||
if detail:
|
||||
return facts_ko or (None if s.get("facts") else s.get("summary_ko")) or None
|
||||
ko = s.get("summary_ko")
|
||||
return f"네, 기억나요. {ko}" + (f" {facts_ko}" if facts_ko and facts_ko not in ko else "") if ko else None
|
||||
if detail:
|
||||
return f"I told you that {facts[:1].lower() + facts[1:]}" if facts else f"We talked about this: {s['summary']}"
|
||||
return f"Yes, I remember. {s['summary']}" + (f" {facts}" if facts and facts not in s["summary"] else "")
|
||||
@@ -601,10 +626,14 @@ that this it its was were is are had have has yesterday today tonight earlier mo
|
||||
day days two right again what which so and oh going back to in on at of with still can could would will any something thing
|
||||
things then there when where how much go ahead just okay ok well there's what's we've i've you've anything that's again,
|
||||
tell, remember, now yes yeah no topic topics subject subjects um uh hmm oh wait right pls bro hey talk? chatted?
|
||||
by way anyway also too stuff""".split())
|
||||
_STOP_KO = re.compile(r"^(?:기억|얘기|이야기|대화|말|했|한|하|어제|오늘|아까|그저께|그제|이틀|우리|저|제가|내가|나랑|저랑|저와|나와|"
|
||||
r"루미|그때|그거|그것|뭐|무슨|나눴|나누|거|것|요|혹시|있잖|맞|좀|다시|알려|아침|오전|오후|저녁|지난|전에|"
|
||||
r"그래서|결론|요점|그러니까|줄|주|줘|알|있|없|해|할|뭔|어떤|무엇|어디|언제|이었|였|이에|예요|입니|이야|주제|remember|recall|talk|yesterday|today)")
|
||||
by way anyway also too stuff answer point main back asking asked ask didn't don't ring bell""".split())
|
||||
_STOP_KO = re.compile(r"^(?:기억|얘기|이야기|대화|말씀|말했|말한|했|어제|오늘|아까|그저께|그제|이틀|우리|제가|내가|나랑|저랑|저와|나와|"
|
||||
r"루미|그때|그거|그것|무슨|나눴|나누|혹시|있잖|맞|좀|다시|알려|아침|오전|오후|저녁|지난|전에|"
|
||||
r"그래서|결론|요점|그러니까|어떤|무엇|어디|언제|이었|였|이에|예요|입니|이야|주제|remember|recall|talk|yesterday|today|"
|
||||
r"(?:그리고|그럼|그러면|그런데|근데|잠깐|궁금한|궁금해|참|저기|음|어|아|자|얘|야|위해서|위해|대해|대해서|관해|관해서|대한|관한)$|"
|
||||
# one-syllable stems only alone or with a verb ending ("한 거", "해 줘"; not "한글", "해변", "주말")
|
||||
r"(?:말|한|하|거|것|요|주|줘|줄|알|있|없|해|할|뭔|뭐|저)(?:[요어아지죠고던는신셨세시자게니냐나까서면기여였잖든다며라래려줘봐야해했할줄][가-힣]?)?$|"
|
||||
r"(?:가|이|은|는|을|를|도|에|의|로|으로|에서)$)") # a particle left alone ("point가")
|
||||
_KO_TAIL = re.compile(r"(?:에\s*대해서?|에\s*관해서?|이랑|랑|하고|얘기|이야기|은|는|을|를|도|에|의|요)+$")
|
||||
|
||||
|
||||
@@ -618,6 +647,8 @@ def topic(text):
|
||||
so a filler ("Class, listen: ...", "Jason, look") is not taken for a topic."""
|
||||
m = FOCUS.search(text)
|
||||
part = next((g for g in m.groups() if g), text) if m else text
|
||||
if m and m.group(3): # "시청자분들 위해서 어제 한글 얘기": what follows the time word
|
||||
part = re.split(r"(?:어제|오늘|아까|그저께|그제|이틀 ?전|지난번|저번에|우리|오늘 ?아침)\s*", part)[-1] or part
|
||||
return (_words(part) if m else "") or _words(text)
|
||||
|
||||
|
||||
@@ -637,10 +668,15 @@ def _words(text):
|
||||
return " ".join(out)
|
||||
|
||||
|
||||
NAMES_KO = {"cutshion": "쿳션 컷션 커션", "jaka": "자카", "lumi": "루미", "hangul": "한글", "chuseok": "추석", "kimchi": "김치",
|
||||
"seoul": "서울", "busan": "부산", "jeju": "제주", "everest": "에베레스트"} # names a title may keep in English
|
||||
|
||||
|
||||
def _hits(words, s):
|
||||
"""The share of the topic words found in a talk's own words (English and Korean title, summary, facts); a
|
||||
one-syllable Korean word only alone or with a particle ("달" is not in "달해요")."""
|
||||
text = " ".join([s["title"], s["summary"], s.get("title_ko", ""), s.get("summary_ko", "")] + s.get("facts", [])).lower()
|
||||
text += "".join(f" {ko}" for en, ko in NAMES_KO.items() if en in text) # "쿳션 얘기" for the talk "Cutshion"
|
||||
n = 0
|
||||
for w in words:
|
||||
if w.isascii():
|
||||
@@ -648,7 +684,7 @@ def _hits(words, s):
|
||||
elif len(w) > 1:
|
||||
n += w in text
|
||||
else:
|
||||
n += bool(re.search(rf"(?<![가-힣]){w}(?:[은는이가을를도의]|에서|에)?(?![가-힣])", text))
|
||||
n += bool(re.search(rf"(?<![가-힣]){w}(?:들)?(?:[은는이가을를도의]|에서|에)?(?![가-힣])", text))
|
||||
return n / len(words) if words else 0.0
|
||||
|
||||
|
||||
@@ -691,7 +727,7 @@ def recall(text, lang="en", now=None, embed=None, history=()):
|
||||
other_q = HAND_Q.search(text) or SEEN_Q.search(text) or PLACE_Q.search(text) or LIFT_Q.search(text)
|
||||
if _recall["offered"] and now - _recall["at"] < OFFER_WAIT_S and not other_q:
|
||||
yes = brain.confirm_answer(text)
|
||||
if yes == "yes" or yes == "correction" and re.match(r"\W*(?:yes|yeah|yep|right|exactly|네|응|맞아|그래)\b", text, re.I):
|
||||
if yes == "yes" or yes == "correction" and re.match(r"\W*(?:yes|yeah|yep|right|exactly|네|예|응|맞아|맞습니다|맞아요|그래|그렇|그거)", text, re.I):
|
||||
return _told(_recall["offered"][-1], lang, turn=len(past))
|
||||
if yes in ("no", "cancel") or yes == "correction" and re.match(r"\W*(?:no|nope|not that|아니|아뇨)\b", text, re.I):
|
||||
if yes == "cancel":
|
||||
@@ -709,7 +745,7 @@ def recall(text, lang="en", now=None, embed=None, history=()):
|
||||
_recall["turn"] = len(past)
|
||||
return out
|
||||
recent = _recall.get("talk") and len(past) - _recall.get("turn", -99) <= RECENT_TURNS
|
||||
if recent and DETAIL.search(text) and (not about or PRONOUN.search(text) or _hits(about.split(), _recall["talk"]) >= 0.5):
|
||||
if recent and DETAIL.search(text) and (not about or _hits(about.split(), _recall["talk"]) >= 0.5): # not "back to chess: what was that?"
|
||||
return _told(_recall["talk"], lang, detail=True, turn=len(past)) # "remind me what you said", "결론이 뭐였어요?"
|
||||
if NAME_Q.search(text):
|
||||
return name_answer(lang)
|
||||
@@ -717,7 +753,7 @@ def recall(text, lang="en", now=None, embed=None, history=()):
|
||||
return None
|
||||
days = _asked_days(text)
|
||||
words = [w for w in about.split() if len(w) > 2 or len(w) > 1 and not w.isascii()]
|
||||
if words and days in (None, {0}) and any(w in f"{q} {a}".lower() for q, a in past for w in words):
|
||||
if words and days in (None, {0}) and any(w in f"{q} {a}".lower() for q, a in past if not RECALL_Q.search(q) for w in words):
|
||||
return None # a topic of this talk ("아까 배터리에 대해 뭐라고 하셨죠?"): the LLM has it
|
||||
if days == "too old":
|
||||
return ONLY_TWO_DAYS[lang]
|
||||
@@ -819,7 +855,8 @@ def _clean(text):
|
||||
return re.sub(r"(?<![\w'])(?:ur|u|pls|plz|da|dat|wat|r)(?![\w'])", lambda m: CHAT_EN[m.group(0).lower()], text, flags=re.I)
|
||||
|
||||
|
||||
SEEN_MORE = re.compile(r"\W*(?:(?:and|what about|how about|or|then|so|also|그럼|그러면|그리고|아니면|또|혹시)\W+)*(?:the |an? |any )?"
|
||||
SEEN_MORE = re.compile(r"\W*(?:(?:and|what about|how about|or|then|so|also|um|uh|oh|okay|ok|well|lumi|그럼|그러면|그리고|아니면|또|혹시|"
|
||||
r"음|어|아|자|잠깐|저기|근데|그런데|루미야?)\W+)*(?:the |an? |any )?"
|
||||
r"(?:[\w가-힣]+\s+)?([\w가-힣]+?)(?:은요|는요|이요|은|는|도|이나|나)?(?: either| too| then)?\W*", re.I)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user