feat(nlp): tuning prompt for regional language translation#1156
Open
madsysharma wants to merge 2 commits into
Open
feat(nlp): tuning prompt for regional language translation#1156madsysharma wants to merge 2 commits into
madsysharma wants to merge 2 commits into
Conversation
|
@madsysharma is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @madsysharma, thanks for contributing to Nyay Setu! 🎉 I have automatically:
Our workflows will now analyze your changes to classify:
Tip Ensure your PR description references the issue it resolves (e.g. Happy coding! 🚀 |
Contributor
Author
|
Hi @viru0909-dev , please review this PR. Also, please add the gssoc:approved label to it if everything is good to go. Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Tune prompt for regional language translation
Summary
The Hinglish dialogue spoken by the Nyay Saarthi avatar sometimes came out in a very formal, Sanskritised "shuddh" Hindi (words like nyayalaya, adhiniyam, praavdhaan, kshatipoorti), which is harder for everyday users to understand than the plain, mixed Hinglish they actually speak. This PR tunes the
HINGLISH_CONVERSION_PROMPTsystem prompt innlp-orchestrator/avatar_speech.pyso the model produces colloquial, easy-to-understand Hinglish, and adds tests to lock the new register in.Closes #849
What's in this PR
nlp-orchestrator/avatar_speech.py: rewrote the system prompt used byconvert_to_hinglish()to steer register without touching any conversion logic, the model, generation params, or the{markdown_answer}placeholder contract:Register guidance up top: instructs the model to talk like an educated bilingual Indian explaining things to a friend, not like a government notice, news anchor, or court order, and to prefer the easy word over the heavy "shuddh"/Sanskritised one.
Keep-in-English whitelist: common terms users already know in English (court, police, FIR, bail, case, lawyer, compensation, insurance, etc.) are explicitly kept in English rather than force-translated into formal Hindi.
Avoid-list with substitutions: an explicit "use this, not that" mapping (eg: nyayalaya -> court, adhiniyam -> Act/kanoon, kshatipoorti -> compensation/muaavza) to anchor the model away from the specific formal words that triggered the issue.
One-shot style example: a short sample line in the target register so the model matches tone and not just rules.
Preserved all original constraints: 4 to 6 sentence spoken length, warm tone, accurate section numbers / law names,
aap(nottum), and plain text only (no markdown) for text-to-speech.nlp-orchestrator/tests/test_avatar_speech.py: new test module (there was none for this file before):Prompt-contract regression guards: the placeholder is intact and
.format()still works; the colloquial-register cue is present; the formal words to avoid and the English terms to keep are named; the original constraints (length,aap/tum, plain-text, persona, section accuracy) all survive.convert_to_hinglish()behaviour with a mocked Groq client (no network): output is stripped and built from the tuned prompt; the error path falls back to the first three sentences.Light coverage of the untouched
detect_domain/get_interim_messageshelpers.Why prompt-only (no logic change)
The only LLM-driven translation path is this system prompt;
report_generator's avatar script uses fixed templates that are already colloquial. Keeping the change to the prompt string makes it low-risk, reviewable, and easy to iterate on.Type of change
Checklist:
Testing
Manual testing
Before-and-after harness:
Testing the actual function:
Running the service:
NOTE: this is after running
uvicorn main:app --port 8001 --reloadon a separate terminal.