KuangDW commited on
Commit
03c399b
·
1 Parent(s): 773aaec

fix llama3.1 translation

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. vecalign/plan2align.py +2 -2
app.py CHANGED
@@ -145,9 +145,12 @@ def basic_translate(source_sentence, src_language, tgt_language):
145
  translations.append(translation)
146
  return translations
147
 
148
- def plan2align_translate_text(text, session_id, src_language, task_language, max_iterations_value, threshold_value, good_ref_contexts_num_value, reward_model_type):
149
  result = translate_text(
150
- text,
 
 
 
151
  src_language=src_language,
152
  task_language=task_language,
153
  max_iterations_value=max_iterations_value,
@@ -318,7 +321,7 @@ with gr.Blocks(title="Test-Time Machine Translation with Plan2Align") as demo:
318
 
319
  gr.Examples(
320
  examples=[
321
- ["夜市文化豐富多彩,從士林夜市到饒河街夜市,提供各種美食、遊戲和購物體驗,吸引了無數遊客。", "Chinese", "English", 2, 0.7, 1],
322
  ["台北101曾經是世界最高的建築物,它不僅是台灣的地標,也象徵著經濟成就和創新精神。", "Chinese", "Russian", 2, 0.7, 1],
323
  ["阿里山日出和森林鐵路是台灣最著名的自然景觀之一,每年吸引數十萬遊客前來欣賞雲海和壯麗的日出。", "Chinese", "German", 2, 0.7, 1],
324
  ["珍珠奶茶,這款源自台灣的獨特飲品,不僅在台灣本地深受喜愛,更以其獨特的風味和口感,在全球掀起了一股熱潮,成為了一種跨越文化、風靡全球的時尚飲品。", "Chinese", "Japanese", 3, 0.7, 3],
 
145
  translations.append(translation)
146
  return translations
147
 
148
+ def plan2align_translate_text(text, session_id, model, tokenizer, device, src_language, task_language, max_iterations_value, threshold_value, good_ref_contexts_num_value, reward_model_type):
149
  result = translate_text(
150
+ text = text,
151
+ model = model,
152
+ tokenizer = tokenizer,
153
+ device = device,
154
  src_language=src_language,
155
  task_language=task_language,
156
  max_iterations_value=max_iterations_value,
 
321
 
322
  gr.Examples(
323
  examples=[
324
+ ["台灣夜市文化豐富多彩,從士林夜市到饒河街夜市,提供各種美食、遊戲和購物體驗,吸引了無數遊客。", "Chinese", "English", 2, 0.7, 1],
325
  ["台北101曾經是世界最高的建築物,它不僅是台灣的地標,也象徵著經濟成就和創新精神。", "Chinese", "Russian", 2, 0.7, 1],
326
  ["阿里山日出和森林鐵路是台灣最著名的自然景觀之一,每年吸引數十萬遊客前來欣賞雲海和壯麗的日出。", "Chinese", "German", 2, 0.7, 1],
327
  ["珍珠奶茶,這款源自台灣的獨特飲品,不僅在台灣本地深受喜愛,更以其獨特的風味和口感,在全球掀起了一股熱潮,成為了一種跨越文化、風靡全球的時尚飲品。", "Chinese", "Japanese", 3, 0.7, 3],
vecalign/plan2align.py CHANGED
@@ -178,7 +178,7 @@ def translate_with_deepinfra(model, tokenizer, device, source_sentence, buffer,
178
  system_prompts = [
179
  "You are a meticulous translator. Provide a literal, word-for-word translation that preserves the structure and meaning of each individual word.",
180
  "You are a professional translator. Deliver a clear, formal, and precise translation that faithfully conveys the original meaning.",
181
- "You are a creative and expressive translator. Render the text in a vivid and imaginative way, as if narrating a captivating story."
182
  ]
183
 
184
  context_prompt = f"Below is a specialized, intermediate translation task. The input text is a mix of {src_language} and partial {tgt_language} translations. "
@@ -210,7 +210,7 @@ def translate_with_deepinfra(model, tokenizer, device, source_sentence, buffer,
210
  context_prompt += "Apply the above guidelines to produce an improved, coherent translation that strictly follows the original order of the text.\n"
211
 
212
  if len(buffer) == 0:
213
- context_prompt = f"### Translate this from {src_language} to {tgt_language} and only output the result."
214
  context_prompt += f"\n### {src_language}:\n {source_sentence}"
215
  context_prompt += f"\n### {tgt_language}:\n"
216
 
 
178
  system_prompts = [
179
  "You are a meticulous translator. Provide a literal, word-for-word translation that preserves the structure and meaning of each individual word.",
180
  "You are a professional translator. Deliver a clear, formal, and precise translation that faithfully conveys the original meaning.",
181
+ "You are a creative and expressive translator. Render the text in a vivid way, as if narrating a captivating story."
182
  ]
183
 
184
  context_prompt = f"Below is a specialized, intermediate translation task. The input text is a mix of {src_language} and partial {tgt_language} translations. "
 
210
  context_prompt += "Apply the above guidelines to produce an improved, coherent translation that strictly follows the original order of the text.\n"
211
 
212
  if len(buffer) == 0:
213
+ context_prompt = f"### Translate this from {src_language} to {tgt_language} and **only** output the result."
214
  context_prompt += f"\n### {src_language}:\n {source_sentence}"
215
  context_prompt += f"\n### {tgt_language}:\n"
216