stanfordnlp / dspy

DSPy: The framework for programming—not prompting—language models
https://dspy.ai
MIT License
18.84k stars 1.44k forks source link

Feature request: localization #1803

Open ChrisW-priv opened 2 days ago

ChrisW-priv commented 2 days ago

Hi!

It is me again :-) . As am trying out some basics of the DSPy some more I realised one thing: the currently is no option to set diff. lang than English. The thing is, I want to make sure the LM will respond in Polish for example. All my documents are in polish (not in the notebook example I attach but in actual aplication I build yes) and I would prefer to set the system instruction in Polish too. But currently there is no way of achieving that in DSPy as the templates are still using some english.

I am tiny bit worried that the LM will get "confused" as to what language to generate in but was not able to generate example of that just yet.

TLDR: In current version I use there seems to only exist the english template for sys prompt. But if user inputs the prompt in diff lang, then there is a mix of languages in the prompt which is confusing.

Is localization ever on a roadmap? Do I have to give up on polish system prompt and just code it full english and "hope" the LM responds in the same language as the prompt field?

Personaly I think short term I will have to stick to the later aproach but wanted to consult you first. some localization tests.txt

ChrisW-priv commented 2 days ago

What I found helpful is to include the "Answer in the language present in the prompt section." in the signature field but that feels like manual prompt engineering.

Not necessarily a bad thing, and it is still better than not using the DSPy (now LM knows what is prompt section etc.), just wanted to start a topic. some localization tests (2).txt

okhat commented 2 days ago

Hey @ChrisW-priv ! Thanks for opening this and laying it out so well. Localization is indeed an active direction, led by @sushmanthreddy .

Sushmanth's approach is to build a dspy.LocalizationAdapter(lang='fr', base=dspy.ChatAdapter()) that takes a language and an (English) adapter, and translates the workings of that adapter to the specified language.

Then, users do dspy.configure(adapter=....) to set their language.

This would work for you right?

ChrisW-priv commented 2 days ago

Yes, I think so. Thanks for the reply. Is there a branch for this feature I can subscribe to?

okhat commented 2 days ago

Not yet, @sushmanthreddy started brainstorming some 10 days ago. But we'd want this to become a PR in the next 2 weeks!

sushmanthreddy commented 2 days ago

@ChrisW-priv there will be a pr soon , testing is in pending.Will update it soon

plattenschieber commented 2 days ago

Nice, I'm having similar experiences with German language. Can we help contribute @sushmanthreddy ?