From a2830563a10944339d4ad42d3e16989aec972565 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 30 Jun 2024 00:18:33 +0800 Subject: [PATCH 1/2] check and fix some syntax errors in the prompts --- src/translation_agent/utils.py | 14 +++++++------- tests/test_agent.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/translation_agent/utils.py b/src/translation_agent/utils.py index 45442a2..266e037 100755 --- a/src/translation_agent/utils.py +++ b/src/translation_agent/utils.py @@ -141,7 +141,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. @@ -149,7 +149,7 @@ def one_chunk_reflect_on_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 and , are as follows: @@ -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. @@ -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 and . Translate only the part within the source text delimited by and . You can use the rest of the source text as context, but do not translate any @@ -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. @@ -513,7 +513,7 @@ def multichunk_improve_translation( {chunk_to_translate} -The translation of the indicated part, delimited below by and , is as follows: +The translation of the indicated part, delimited below by and , are as follows: {translation_1_chunk} @@ -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 diff --git a/tests/test_agent.py b/tests/test_agent.py index 6cad42d..7f344aa 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -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. From 0d75a6a0aa1627cf5454c444ea5de4b65ab0cd2b Mon Sep 17 00:00:00 2001 From: fzppp <102568752+fzp0424@users.noreply.github.com> Date: Sun, 30 Jun 2024 00:35:39 +0800 Subject: [PATCH 2/2] Update utils.py more improvements --- src/translation_agent/utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/translation_agent/utils.py b/src/translation_agent/utils.py index 266e037..67dfd5a 100755 --- a/src/translation_agent/utils.py +++ b/src/translation_agent/utils.py @@ -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. @@ -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. """ @@ -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. @@ -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. @@ -513,12 +513,12 @@ def multichunk_improve_translation( {chunk_to_translate} -The translation of the indicated part, delimited below by and , are as follows: +The translation of the indicated part, delimited below by and , is as follows: {translation_1_chunk} -The expert translations of the indicated part, delimited below by and , is as follows: +The expert translations of the indicated part, delimited below by and , are as follows: {reflection_chunk} @@ -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. """