Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Preserve non ascii characters when json.dumps and json.dump #1335

Closed
wants to merge 2 commits into from

Conversation

dlutwy
Copy link

@dlutwy dlutwy commented Sep 20, 2024

Description

This pull request addresses an issue related to the use of the json.dumps and json.dump methods in the prompt construction process. Currently, the ensure_ascii parameter is not set, which results in non-ASCII characters being escaped in the \uXXXX format. This can hinder the LLM's ability to understand the intended language meaning.

Changes Made

  • Updated the json.dumps and json.dump methods calls to include the parameter ensure_ascii=False. This change will retain non-ASCII characters in their original form, improving the LLM's comprehension of the input.

Impact

By allowing non-ASCII characters to remain unescaped, this modification will enhance the language processing capabilities of our model, leading to more accurate interpretations.

Sample Code

from ragas.metrics import context_recall

print(context_recall.context_recall_prompt.format(
    question='超级碗第一次举办是在什么时候 xx सूरज को क्या चलाता',
    context="\n".join(['第一次AFL–NFL世界冠军赛是一场美式足球比赛,于1967年1月15日在洛杉矶纪念体育场举行,位于洛杉矶。']),
    answer='第一次超级碗于1967年1月15日举行'
).to_string())

Before

...
Your actual task:

question: "\u8d85\u7ea7\u7897\u7b2c\u4e00\u6b21\u4e3e\u529e\u662f\u5728\u4ec0\u4e48\u65f6\u5019 xx \u0938\u0942\u0930\u091c \u0915\u094b \u0915\u094d\u092f\u093e \u091a\u0932\u093e\u0924\u093e"
context: "\u7b2c\u4e00\u6b21AFL\u2013NFL\u4e16\u754c\u51a0\u519b\u8d5b\u662f\u4e00\u573a\u7f8e\u5f0f\u8db3\u7403\u6bd4\u8d5b\uff0c\u4e8e1967\u5e741\u670815\u65e5\u5728\u6d1b\u6749\u77f6\u7eaa\u5ff5\u4f53\u80b2\u573a\u4e3e\u884c\uff0c\u4f4d\u4e8e\u6d1b\u6749\u77f6\u3002"
answer: "\u7b2c\u4e00\u6b21\u8d85\u7ea7\u7897\u4e8e1967\u5e741\u670815\u65e5\u4e3e\u884c"
classification: 

After

...
Your actual task:

question: "超级碗第一次举办是在什么时候 xx सूरज को क्या चलाता"
context: "第一次AFL–NFL世界冠军赛是一场美式足球比赛,于1967年1月15日在洛杉矶纪念体育场举行,位于洛杉矶。"
answer: "第一次超级碗于1967年1月15日举行"
classification: 

Please let me know if there are any questions or further changes needed.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Sep 20, 2024
@jjmachan
Copy link
Member

jjmachan commented Nov 3, 2024

we merged a fix for this earlier

closing this for now but I'm really sorry we couldn't merge it 🙁 but at the same time thanks a million for taking the time to raise this, really grateful too and do checkout this form https://docs.google.com/forms/d/e/1FAIpQLSdM9FrrZrnpByG4XxuTbcAB-zn-Z7i_a7CsMkgBVOWQjRJckg/viewform - our way of saying thank you 🙂

@jjmachan jjmachan closed this Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants