Skip to content

Commit

Permalink
check and fix some syntax errors in the prompts (#31)
Browse files Browse the repository at this point in the history
* check and fix some syntax errors in the prompts

* Update utils.py

more improvements
  • Loading branch information
fzp0424 authored Jul 8, 2024
1 parent d6fe934 commit b238380
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/translation_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def one_chunk_reflect_on_translation(
target_lang (str): The target language of the translation.
source_text (str): The original text in the source language.
translation_1 (str): The initial translation of the source text.
country (str): Country specified for target language.
country (str): Country specified for the target language.
Returns:
str: The LLM's reflection on the translation, providing constructive criticism and suggestions for improvement.
Expand All @@ -141,15 +141,15 @@ def one_chunk_reflect_on_translation(
When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Each suggestion should address one specific part of the translation.
Output only the suggestions and nothing else."""

else:
reflection_prompt = f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticism and helpful suggestions to improve the translation. \
reflection_prompt = f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticisms and helpful suggestions to improve the translation. \
The source text and initial translation, delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:
Expand All @@ -164,7 +164,7 @@ def one_chunk_reflect_on_translation(
When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Expand Down Expand Up @@ -251,7 +251,7 @@ def one_chunk_translate_text(
source_lang (str): The source language of the text.
target_lang (str): The target language for the translation.
source_text (str): The text to be translated.
country (str): Country specified for target language.
country (str): Country specified for the target language.
Returns:
str: The improved translation of the source text.
"""
Expand Down Expand Up @@ -311,7 +311,7 @@ def multichunk_initial_translation(

system_message = f"You are an expert linguist, specializing in translation from {source_lang} to {target_lang}."

translation_prompt = """Your task is provide a professional translation from {source_lang} to {target_lang} of PART of a text.
translation_prompt = """Your task is to provide a professional translation from {source_lang} to {target_lang} of PART of a text.
The source text is below, delimited by XML tags <SOURCE_TEXT> and </SOURCE_TEXT>. Translate only the part within the source text
delimited by <TRANSLATE_THIS> and </TRANSLATE_THIS>. You can use the rest of the source text as context, but do not translate any
Expand Down Expand Up @@ -368,7 +368,7 @@ def multichunk_reflect_on_translation(
target_lang (str): The target language of the translation.
source_text_chunks (List[str]): The source text divided into chunks.
translation_1_chunks (List[str]): The translated chunks corresponding to the source text chunks.
country (str): Country specified for target language.
country (str): Country specified for the target language.
Returns:
List[str]: A list of reflections containing suggestions for improving each translated chunk.
Expand Down Expand Up @@ -402,7 +402,7 @@ def multichunk_reflect_on_translation(
When writing suggestions, pay attention to whether there are ways to improve the translation's:\n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Expand Down Expand Up @@ -433,7 +433,7 @@ def multichunk_reflect_on_translation(
When writing suggestions, pay attention to whether there are ways to improve the translation's:\n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Expand Down Expand Up @@ -518,7 +518,7 @@ def multichunk_improve_translation(
{translation_1_chunk}
</TRANSLATION>
The expert translations of the indicated part, delimited below by <EXPERT_SUGGESTIONS> and </EXPERT_SUGGESTIONS>, is as follows:
The expert translations of the indicated part, delimited below by <EXPERT_SUGGESTIONS> and </EXPERT_SUGGESTIONS>, are as follows:
<EXPERT_SUGGESTIONS>
{reflection_chunk}
</EXPERT_SUGGESTIONS>
Expand Down Expand Up @@ -572,7 +572,7 @@ def multichunk_translation(
source_text_chunks (List[str]): The list of source text chunks to be translated.
translation_1_chunks (List[str]): The list of initial translations for each source text chunk.
reflection_chunks (List[str]): The list of reflections on the initial translations.
country (str): Country specified for target language
country (str): Country specified for the target language
Returns:
List[str]: The list of improved translations for each source text chunk.
"""
Expand Down Expand Up @@ -655,7 +655,7 @@ def translate(
ic(num_tokens_in_text)

if num_tokens_in_text < max_tokens:
ic("Translating text as single chunk")
ic("Translating text as a single chunk")

final_translation = one_chunk_translate_text(
source_lang, target_lang, source_text, country
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_one_chunk_reflect_on_translation():
When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Expand Down

0 comments on commit b238380

Please sign in to comment.