Israelbliz/User-Modeling-Agent
0
1"""Nigerian style layer — bonus marks via cultural contextualization.2 3The challenge brief awards extra credit for systems that *behave and sound4like Nigerians*. We treat this as a toggleable rendering layer, not as a5core dependency, for two reasons:6 7 1. Eval datasets are English Amazon reviews. Rendering everything in8 Nigerian register would hurt our ROUGE / BERTScore against the9 ground truth.10 2. Keeping it as a flag means we can showcase the capability without11 sacrificing benchmark scores. Best of both rubric worlds.12 13Two functions:14 15 naija_style_review(text) → rewrites a generated review in Nigerian16 English register, preserving sentiment,17 rating intent, and key entities.18 19 naija_persona_examples() → returns hand-crafted Nigerian personas the20 judges can demo Task B against. These show21 the system handling local taste profiles22 (afrobeats, jollof, Nollywood, etc.) even23 when the underlying catalog is Amazon-global.24 25Design note: the style layer renders output in rich, expressive Nigerian26Pidgin — confident and fluent across the whole text, the way a Nigerian27genuinely talks when giving a strong opinion. Sentiment, rating intent and28factual content are always preserved; only the register changes.29"""30from __future__ import annotations31 32from core.llm import LLMClient33 34NAIJA_STYLE_SYSTEM = """You are a stylist who rewrites text in rich, expressive Nigerian Pidgin English — the way a Nigerian would genuinely talk when sharing strong opinions. Rules:35 36- Keep the sentiment, rating intent, and all factual content unchanged. A positive review stays positive; a 2-star pan stays a pan; named items, authors, and plot facts stay accurate.37- Write FULLY in Nigerian Pidgin register — not standard English with a sprinkle. Lean into it confidently across the whole text.38- Use natural Pidgin grammar and vocabulary throughout. Examples of the texture wanted:39 · "This book sweet me die, I no fit drop am at all."40 · "Abeg, the storyline just dey drag, e tire me well well."41 · "Na correct work be this — the writer sabi wetin e dey do."42 · "I no go lie, the ending shock me, I no see am coming."43 · "The characters dey alive, you go feel like say you sabi them."44 · "E no make sense, I vex small as I read am finish."45 · "This one na better book, e make sense gan-gan."46- Common markers to use freely: "abeg", "sha", "na", "dey", "wetin", "e be like say", "no be small thing", "gan-gan", "well well", "I no go lie", "comot", "sabi", "vex", "sweet me", "make sense".47- Keep it authentic, not caricature — write like a real Nigerian sharing a genuine opinion, not a parody. It should read as natural Pidgin, fluent and confident.48- Do NOT add cultural references that weren't in the original (no jollof, Lagos traffic, etc. unless the source mentioned them).49- Length should stay roughly the same.50- Return ONLY the rewritten text. No preamble, no explanation."""51 52 53def naija_style_review(text: str, llm: LLMClient | None = None) -> str:54 """Rewrite an English review in Nigerian English register.55 56 Idempotent on already-Naija text in practice (the model leaves natural57 phrasings alone).58 """59 llm = llm or LLMClient()60 return llm.complete(61 prompt=f"Rewrite this review in Nigerian English register:\n\n{text}",62 system=NAIJA_STYLE_SYSTEM,63 model="bulk",64 ).strip()65 66 67# ──────────────────────────────────────────────────────────────────────────────68# Demo personas — used in the Streamlit UI to showcase cold-start handling69# ──────────────────────────────────────────────────────────────────────────────70 71NAIJA_DEMO_PERSONAS: list[dict] = [72 {73 "name": "Tunde — Lagos software engineer",74 "description": (75 "A 28-year-old software engineer in Lagos who reads mostly non-fiction "76 "(business biographies, productivity, AI/tech), watches African and "77 "international thrillers, and complains when books are padded or movies "78 "are too slow. Prefers concise, practical writing. Gives 5 stars only "79 "when something genuinely changed his thinking; defaults to 4. "80 "Frequently mentions 'value for time' and 'execution'."81 ),82 "stated_preferences": ["business biographies", "AI and tech books",83 "fast-paced thrillers", "Nollywood crime dramas",84 "concise practical writing"],85 "deal_breakers": ["padded chapters", "slow pacing", "academic jargon"],86 },87 {88 "name": "Ngozi — Abuja public health doctor",89 "description": (90 "A 35-year-old doctor in Abuja who reads literary fiction and African "91 "memoirs, watches character-driven dramas (West African and global), "92 "and dislikes anything that handles women's lives shallowly. Writes "93 "thoughtful, longer-than-average reviews. Rates with a tough 3.5 average. "94 "Often references 'emotional truth' and 'craft'."95 ),96 "stated_preferences": ["literary fiction", "African memoirs",97 "character-driven dramas", "Adichie-adjacent voice"],98 "deal_breakers": ["shallow female characters", "trauma porn",99 "lazy plotting"],100 },101 {102 "name": "Bayo — Ibadan undergraduate",103 "description": (104 "A 21-year-old student in Ibadan who reads YA fantasy, plays a lot of "105 "Afrobeats during study sessions, watches anime and Nollywood comedies, "106 "and writes short bursty reviews. Quick to give 5 stars when entertained. "107 "Mentions vibes, pacing, and whether something 'hits'."108 ),109 "stated_preferences": ["YA fantasy", "anime", "Nollywood comedies",110 "fast-paced action"],111 "deal_breakers": ["long descriptive passages", "overly serious tone"],112 },113]114 115 116def naija_persona_examples() -> list[dict]:117 """Return demo personas for the Task B UI's cold-start showcase."""118 return [dict(p) for p in NAIJA_DEMO_PERSONAS]119 