字幕拆分策略提示

생성일: 2024년 10월 24일

답변에 사용된 모델 O1 Preview by Chat01

질문

import os,sys,json
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(file))))
from core.step2_whisper import get_whisper_language
from core.config_utils import load_key

================================================================

@ step4_splitbymeaning.py

def get_split_prompt(sentence, num_parts = 2, word_limit = 20):
# ! only support num_parts = 2
language = get_whisper_language()
split_prompt = f"""

Role

You are a professional and experienced Netflix subtitle splitter in {language}.

Task

Your task is to split the given subtitle text into {num_parts} parts, each should be less than {word_limit} words.

Requirements

  1. Try to maintain the coherence of the sentence meaning, split according to Netflix subtitle standards, ensuring the two parts are relatively independent.
  2. The length of each part should be roughly equal, no part should be less than 3 words, but the integrity of the sentence is more important.
  3. Prioritize splitting at punctuation marks, such as periods, commas, and conjunctions (e.g., "and", "but", "because", "when", "then", "if", "so", "that").

Steps

  1. Analyze the grammar and structure of the given text.
  2. Provide 2 different ways to split the text, each with different split points, output complete sentences (do not change any letters or punctuation), insert [br] tags at the split positions.
  3. Briefly compare and evaluate the above 2 split methods, considering readability, grammatical structure, and contextual coherence, choose the best split method.
  4. Give the best split method number, 1 or 2.

Output Format

Please provide your answer in the following JSON format, <<>> represents placeholders:
{{
"analysis": "Brief analysis of the text structure and split strategy",
"split_1": "<<The first split method, output complete sentences, insert [br] as a delimiter at the split position. e.g. this is the first part [br] this is the second part.>>",
"split_2": "<<The second split method>>",
"eval": "<<Unified brief evaluation of the 2 split methods, written in one sentence, no line breaks>>",
"best": "<<The best split method number, 1 or 2>>"
}}

Given Text

<split_this_sentence>\n{sentence}\n</split_this_sentence>

""".strip()

return split_prompt

================================================================

@ step4_1_summarize.py

def get_summary_prompt(source_content):
src_language = get_whisper_language()
TARGET_LANGUAGE = load_key("target_language")
summary_prompt = f"""

Role

You are a professional video translation expert and terminology consultant. Your expertise lies not only in accurately understanding the original {src_language} text but also in extracting key professional terms and optimizing the translation to better suit the expression habits and cultural background of {TARGET_LANGUAGE}.

Task Description

For the provided original {src_language} video text, you need to:

  1. Summarize the video's main topic in one sentence
  2. Extract professional terms and names that appear in the video, and provide {TARGET_LANGUAGE} translations or suggest keeping the original language terms. Avoid extracting simple, common words.
  3. For each translated term or name, provide a brief explanation

Analysis and Summary Steps

Please think in two steps, processing the text line by line:

  1. Topic summarization:
    • Quickly skim through the entire text to understand the general idea
    • Summarize the topic in one concise sentence
  2. Term and name extraction:
    • Carefully read the entire text, marking professional terms and names
    • For each term or name, provide a {TARGET_LANGUAGE} translation or suggest keeping the original, only the word itself is needed, not the pronunciation
    • Add a brief explanation for each term or name to help the translator understand
    • If the word is a fixed abbreviation or a proper name, please keep the original.

Output Format

Please output your analysis results in the following JSON format, where <> represents placeholders:
{{
"theme": "<Briefly summarize the theme of this video in 1 sentence>",
"terms": [
{{
"original": "<Term or name 1 in the {src_language}>",
"translation": "<{TARGET_LANGUAGE} translation or keep original>",
"explanation": "<Brief explanation of the term or name>"
}},
{{
"original": "<Term or name 2 in the {src_language}>",
"translation": "<{TARGET_LANGUAGE} translation or keep original>",
"explanation": "<Brief explanation of the term or name>"
}},
...
]
}}

Single Output Example (Using French as an example)

{{
"theme": "Ce vidéo résume le musée du Louvre à Paris.",
"terms": [
{{
"original": "Mona Lisa",
"translation": "La Joconde",
"explanation": "Le tableau le plus célèbre du Louvre, un portrait de Léonard de Vinci"
}},
{{
"original": "pyramid",
"translation": "la pyramide",
"explanation": "Une grande structure en verre et métal en forme de pyramide située à l'entrée principale du Louvre"
}},
{{
"original": "I.M. Pei",
"translation": "I.M. Pei",
"explanation": "L'architecte américain d'origine chinoise qui a conçu la pyramide du Louvre"
}},
...
]
}}

Video text data to be processed

<video_text_to_summarize>
{source_content}
</video_text_to_summarize>
""".strip()

return summary_prompt

================================================================

@ step5_translate.py & translate_lines.py

def generate_shared_prompt(previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt):
return f'''### Context Information
<previous_content>
{previous_content_prompt}
</previous_content>

<subsequent_content>
{after_content_prompt}
</subsequent_content>

Content Summary

{summary_prompt}

Points to Note

{things_to_note_prompt}'''

def get_prompt_faithfulness(lines, shared_prompt):
TARGET_LANGUAGE = load_key("target_language")
# Split lines by \n
line_splits = lines.split('\n')

text
# Create JSON return format example json_format = {} for i, line in enumerate(line_splits, 1): json_format[i] = { "origin": line, "direct": f"<<direct {TARGET_LANGUAGE} translation>>" } src_language = get_whisper_language() prompt_faithfulness = f'''

Role Definition

You are a professional Netflix subtitle translator, fluent in both {src_language} and {TARGET_LANGUAGE}, as well as their respective cultures. Your expertise lies in accurately understanding the semantics and structure of the original {src_language} text and faithfully translating it into {TARGET_LANGUAGE} while preserving the original meaning.

Task Background

We have a segment of original {src_language} subtitles that need to be directly translated into {TARGET_LANGUAGE}. These subtitles come from a specific context and may contain specific themes and terminology.

Task Description

Based on the provided original {src_language} subtitles, you need to:

  1. Translate the original {src_language} subtitles into {TARGET_LANGUAGE} line by line
  2. Ensure the translation is faithful to the original, accurately conveying the original meaning
  3. Consider the context and professional terminology

{shared_prompt}

Translation Principles

  1. Faithful to the original: Accurately convey the content and meaning of the original text, without arbitrarily changing, adding, or omitting content.
  2. Accurate terminology: Use professional terms correctly and maintain consistency in terminology.
  3. Understand the context: Fully comprehend and reflect the background and contextual relationships of the text.

Subtitle Data

<subtitles> {lines} </subtitles>

Output Format

Please complete the following JSON data, where << >> represents placeholders that should not appear in your answer, and return your translation results in JSON format:
{json.dumps(json_format, ensure_ascii=False, indent=4)}
'''
return prompt_faithfulness.strip()

def get_prompt_expressiveness(faithfulness_result, lines, shared_prompt):
TARGET_LANGUAGE = load_key("target_language")
json_format = {}
for key, value in faithfulness_result.items():
json_format[key] = {
"origin": value['origin'],
"direct": value['direct'],
"reflection": "<<reflection on the direct translation version>>",
"free": f"<<retranslated result, aiming for fluency and naturalness, conforming to {TARGET_LANGUAGE} expression habits, DO NOT leave empty line here!>>"
}

text
src_language = get_whisper_language() prompt_expressiveness = f'''

Role Definition

You are a professional Netflix subtitle translator and language consultant. Your expertise lies not only in accurately understanding the original {src_language} but also in optimizing the {TARGET_LANGUAGE} translation to better suit the target language's expression habits and cultural background.

Task Background

We already have a direct translation version of the original {src_language} subtitles. Now we need you to reflect on and improve these direct translations to create more natural and fluent {TARGET_LANGUAGE} subtitles.

Task Description

Based on the provided original {src_language} text and {TARGET_LANGUAGE} direct translation, you need to:

  1. Analyze the direct translation results line by line, pointing out existing issues
  2. Provide detailed modification suggestions
  3. Perform free translation based on your analysis

{shared_prompt}

Translation Analysis Steps

Please use a two-step thinking process to handle the text line by line:

  1. Direct Translation Reflection:

    • Evaluate language fluency
    • Check if the language style is consistent with the original text
    • Check the conciseness of the subtitles, point out where the translation is too wordy, the translation should be close to the original text in length
  2. {TARGET_LANGUAGE} Free Translation:

    • Based on the reflection in step 1, perform free translation
    • Aim for contextual smoothness and naturalness, conforming to {TARGET_LANGUAGE} expression habits
    • Ensure it's easy for {TARGET_LANGUAGE} audience to understand and accept
    • Keep the subtitles concise, with a plain and natural language style, and maintain consistency in structure between the free translation and the {src_language} original

Subtitle Data

<subtitles> {lines} </subtitles>

Output Format

Make sure to generate the correct Json format, don't output " in the value.
Please complete the following JSON data, where << >> represents placeholders that should not appear in your answer, and return your translation results in JSON format:
{json.dumps(json_format, ensure_ascii=False, indent=4)}
'''
return prompt_expressiveness.strip()

================================================================

@ step6_splitforsub.py

def get_align_prompt(src_sub, tr_sub, src_part):
TARGET_LANGUAGE = load_key("target_language")
src_language = get_whisper_language()
src_splits = src_part.split('\n')
num_parts = len(src_splits)
src_part = src_part.replace('\n', ' [br] ')
align_prompt = '''

Role Definition

You are a Netflix subtitle alignment expert fluent in both {src_language} and {target_language}. Your expertise lies in accurately understanding the semantics and structure of both languages, enabling you to flexibly split sentences while preserving the original meaning.

Task Background

We have {src_language} and {target_language} original subtitles for a Netflix program, as well as a pre-processed split version of {src_language} subtitles. Your task is to create the best splitting scheme for the {target_language} subtitles based on this information.

Task Description

Based on the provided original {src_language} and {target_language} original subtitles, as well as the pre-processed split version, you need to:

  1. Analyze the word order and structural correspondence between {src_language} and {target_language} subtitles
  2. Provide 2 different splitting schemes for the {target_language} subtitles
  3. Evaluate these schemes and select the best one
  4. Never leave empty lines. If it's difficult to split based on meaning, you may appropriately rewrite the sentences that need to be aligned

Subtitle Data

<subtitles> {src_language} Original: "{src_sub}" {target_language} Original: "{tr_sub}" Pre-processed {src_language} Subtitles ([br] indicates split points): {src_part} </subtitles>

Processing Steps

Please follow these steps and provide the results for each step in the JSON output:

  1. Analysis and Comparison: Briefly analyze the word order, sentence structure, and semantic correspondence between {src_language} and {target_language} subtitles. Point out key word correspondences, similarities and differences in sentence patterns, and language features that may affect splitting.
  2. Start Alignment: Based on your analysis, provide 2 different alignment methods for {target_language} subtitles according to the format. The split positions in {src_language} must be consistent with the pre-processed {src_language} split version and cannot be changed arbitrarily.
  3. Evaluation and Selection: Examine and briefly evaluate the 2 schemes, considering factors such as sentence completeness, semantic coherence, and appropriateness of split points.
  4. Best Scheme: Select the best alignment scheme, output only a single number, 1 or 2.

Output Format

Please complete the following JSON data, where << >> represents placeholders, and return your results in JSON format:
{{
"analysis": "<<Detailed analysis of word order, structure, and semantic correspondence between {src_language} and {target_language} subtitles>>",
"align_1": [
{align_parts_json}
],
"align_2": [
{align_parts_json}
],
"comparison": "<<Brief evaluation and comparison of the 2 alignment schemes>>",
"best": "<<Number of the best alignment scheme, 1 or 2>>"
}}
'''

text
align_parts_json = ','.join( f''' {{ "src_part_{i+1}": "<<{src_splits[i]}>>", "target_part_{i+1}": "<<Corresponding aligned {TARGET_LANGUAGE} subtitle part>>" }}''' for i in range(num_parts) ) return align_prompt.format( src_language=src_language, target_language=TARGET_LANGUAGE, src_sub=src_sub, tr_sub=tr_sub, src_part=src_part, align_parts_json=align_parts_json, )

================================================================

@ step8_gen_audio_task.py @ step10_gen_audio.py

def get_subtitle_trim_prompt(trans_text, duration):

text
rule = '''Consider a. Reducing filler words without modifying meaningful content. b. Omitting unnecessary modifiers or pronouns, for example: - "Please explain your thought process" can be shortened to "Please explain thought process" - "We need to carefully analyze this complex problem" can be shortened to "We need to analyze this problem" - "Let's discuss the various different perspectives on this topic" can be shortened to "Let's discuss different perspectives on this topic" - "Can you describe in detail your experience from yesterday" can be shortened to "Can you describe yesterday's experience" ''' trim_prompt = '''

Role

You are a professional subtitle editor, editing and optimizing lengthy subtitles that exceed voiceover time before handing them to voice actors. Your expertise lies in cleverly shortening subtitles slightly while ensuring the original meaning and structure remain unchanged.

Subtitle Data

<subtitles> Subtitle: "{trans_text}" Duration: {duration} seconds </subtitles>

Processing Rules

{rule}

Processing Steps

Please follow these steps and provide the results in the JSON output:

  1. Analysis: Briefly analyze the subtitle's structure, key information, and filler words that can be omitted.
  2. Trimming: Based on the rules and analysis, optimize the subtitle by making it more concise according to the processing rules.

Output Format

Please complete the following JSON data, where << >> represents content you need to fill in:
{{
"analysis": "<<Brief analysis of the subtitle, including structure, key information, and potential processing locations>>",
"trans_text_processed": "<<Optimized and shortened subtitle in the original subtitle language>>"
}}
'''
return trim_prompt.format(
trans_text=trans_text,
duration=duration,
rule=rule
)
解释一下这个代码

사고

分析代码

正在审查代码,识别功能定义和文件注释,确保解释准确且无误。让我看看这些注释和函数的作用如何。

处理数据和调整路径

代码启动时,导入了一些模块和函数,并调整了系统路径。接着定义了一个函数,目的是将给定的字幕文本分成两部分,每部分不超过20个单词,保持句意连贯。**

分析和拆分

首先,我分析给定文本的语法和结构,对于拆分点进行标记,确保每部分长度大致相等且涵盖完整句子。然后,我提出两种不同的拆分策略,插入[br]标签,并比较这两种方法的可读性、语法结构和上下文连贯性,以选择最佳拆分方法。

将文本分割为两部分

我正在将句子拆分为两部分,使用标签"split_this_sentence"和"sentence"来标识。这种方法可以确保句子被完整地分割并且每个部分都能独立显示。

处理字幕

답변

这段代码是一系列用于处理字幕的函数,主要用于以下任务:

  • 拆分字幕:根据句子的语法和长度,将长句子拆分成适合字幕显示的短句子。
  • 摘要和术语提取:从视频文本中提取主题和专业术语,帮助翻译人员更好地理解和翻译内容。
  • 翻译:将原始字幕逐行翻译,同时确保翻译的准确性和流畅性。
  • 对齐字幕:在不同语言的字幕之间进行对齐,确保翻译后的字幕与原始字幕在结构和意义上保持一致。
  • 精简字幕:在语音配音的时间限制内,对过长的字幕进行精简,保持原意的同时减少字数。

以下是对代码中每个部分的详细解释:


导入模块和设置

python
import os, sys, json sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from core.step2_whisper import get_whisper_language from core.config_utils import load_key
  • os, sys, json:导入Python的标准库模块,用于文件路径操作和JSON处理。
  • sys.path.append(...):将上级目录添加到系统路径,方便导入其他模块。
  • from core.step2_whisper import get_whisper_language:从core.step2_whisper模块中导入get_whisper_language函数,用于获取当前处理的语言。
  • from core.config_utils import load_key:从core.config_utils模块中导入load_key函数,用于加载配置中的键值。

1. 拆分字幕函数

python
def get_split_prompt(sentence, num_parts=2, word_limit=20): # 仅支持将句子拆分成两个部分 language = get_whisper_language() split_prompt = f""" ### 角色 你是一名专业且经验丰富的{language}Netflix字幕拆分师。 ### 任务 你的任务是将给定的字幕文本拆分成 **{num_parts}** 部分,每部分应少于 {word_limit} 个单词。 ### 要求 1. 尽量保持句子意义的连贯性,根据Netflix字幕标准进行拆分,确保两个部分相对独立。 2. 每部分的长度应大致相等,且不少于3个单词,但句子的完整性更为重要。 3. 优先在标点符号处拆分,如句号、逗号和连词(例如:"and", "but", "because", "when", "then", "if", "so", "that")。 ### 步骤 1. 分析给定文本的语法和结构。 2. 提供两种不同的拆分方式,每种方式的拆分点不同,输出完整的句子(不要更改任何字母或标点),在拆分位置插入 [br] 标签。 3. 简要比较和评估上述两种拆分方法,考虑可读性、语法结构和上下文连贯性,选择最佳的拆分方法。 4. 给出最佳拆分方法的编号,1 或 2。 ### 输出格式 请以以下JSON格式提供你的答案,<<>> 表示需要填写的内容: {{ "analysis": "对文本结构和拆分策略的简要分析", "split_1": "<<第一种拆分方法,输出完整句子,在拆分位置插入 [br] 作为分隔符>>", "split_2": "<<第二种拆分方法>>", "eval": "<<对两种拆分方法的统一简要评估,用一句话,不要换行>>", "best": "<<最佳拆分方法的编号,1 或 2>>" }} ### 给定文本 <split_this_sentence> {sentence} </split_this_sentence> """.strip() return split_prompt

解释

  • 功能:根据给定的句子生成一个提示,指导语言模型如何将句子拆分成两个部分,以适应字幕显示的要求。
  • 参数
    • sentence:需要拆分的原始句子。
    • num_parts:希望将句子拆分成的部分数量,默认为2。
    • word_limit:每部分的最大单词数限制,默认为20。
  • 过程
    • 获取当前处理的语言(例如,英语、法语等)。
    • 定义一个多行字符串split_prompt,包含详细的任务描述、要求、步骤和输出格式。
    • 返回生成的提示split_prompt

2. 摘要和术语提取函数

python
def get_summary_prompt(source_content): src_language = get_whisper_language() TARGET_LANGUAGE = load_key("target_language") summary_prompt = f""" ### 角色 你是一名专业的视频翻译专家和术语顾问。你不仅擅长准确理解原始的{src_language}文本,还能提取关键的专业术语,并优化翻译以更好地适应{TARGET_LANGUAGE}的表达习惯和文化背景。 ### 任务描述 对于提供的原始{src_language}视频文本,你需要: 1. 用一句话总结视频的主要主题。 2. 提取视频中出现的专业术语和名称,提供{TARGET_LANGUAGE}翻译或建议保留原文。避免提取简单、常见的词汇。 3. 对每个翻译的术语或名称,提供简要的解释。 ### 分析和总结步骤 请分两步思考,逐行处理文本: 1. 主题总结: - 快速浏览全文,理解大意。 - 用一句简洁的话总结主题。 2. 术语和名称提取: - 仔细阅读全文,标记专业术语和名称。 - 对于每个术语或名称,提供{TARGET_LANGUAGE}翻译或建议保留原文,只需要词语本身,不需要发音。 - 为每个术语或名称添加简要的解释,帮助翻译人员理解。 - 如果词语是固定缩写或专有名称,请保留原文。 ### 输出格式 请以以下JSON格式输出你的分析结果,其中 <> 表示需要填写的内容: {{ "theme": "<用一句话简要总结视频的主题>", "terms": [ {{ "original": "<{src_language}中的术语或名称1>", "translation": "<{TARGET_LANGUAGE}翻译或保留原文>", "explanation": "<对术语或名称的简要解释>" }}, ... ] }} ### 视频文本数据 <video_text_to_summarize> {source_content} </video_text_to_summarize> """.strip() return summary_prompt

解释

  • 功能:为语言模型生成一个提示,用于从原始视频文本中提取主题和专业术语,帮助翻译人员理解内容并进行准确翻译。
  • 参数
    • source_content:原始视频文本内容。
  • 过程
    • 获取源语言和目标语言。
    • 定义任务角色和描述,详细说明需要完成的任务和步骤。
    • 提供输出格式示例,指导模型生成符合要求的JSON格式输出。
    • 返回生成的提示summary_prompt

3. 生成共享提示函数

python
def generate_shared_prompt(previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt): return f'''### 上下文信息 <previous_content> {previous_content_prompt} </previous_content> <subsequent_content> {after_content_prompt} </subsequent_content> ### 内容摘要 {summary_prompt} ### 注意事项 {things_to_note_prompt}'''

解释

  • 功能:生成一个包含上下文信息、内容摘要和注意事项的共享提示,用于在翻译和处理过程中提供参考。
  • 参数
    • previous_content_prompt:前文内容提示。
    • after_content_prompt:后文内容提示。
    • summary_prompt:内容摘要提示。
    • things_to_note_prompt:需要注意的事项提示。
  • 过程
    • 将各个部分组合成一个完整的提示字符串。
    • 返回生成的共享提示。

4. 获取忠实翻译提示函数

python
def get_prompt_faithfulness(lines, shared_prompt): TARGET_LANGUAGE = load_key("target_language") # 按行分割字幕 line_splits = lines.split('\n') # 创建JSON返回格式示例 json_format = {} for i, line in enumerate(line_splits, 1): json_format[i] = { "origin": line, "direct": f"<<直接翻译成{TARGET_LANGUAGE}>>" } src_language = get_whisper_language() prompt_faithfulness = f''' ### 角色定义 你是一名专业的Netflix字幕翻译,精通{src_language}{TARGET_LANGUAGE},以及它们各自的文化。你的专长在于准确理解原始{src_language}文本的语义和结构,并忠实地将其翻译成{TARGET_LANGUAGE},同时保留原始含义。 ### 任务背景 我们有一段原始的{src_language}字幕,需要直接翻译成{TARGET_LANGUAGE}。这些字幕来自特定的上下文,可能包含特定的主题和术语。 ### 任务描述 基于提供的原始{src_language}字幕,你需要: 1. 将原始{src_language}字幕逐行翻译成{TARGET_LANGUAGE}2. 确保翻译忠实于原文,准确传达原始含义。 3. 考虑上下文和专业术语。 {shared_prompt} ### 翻译原则 1. 忠实于原文:准确传达原文的内容和意义,不得随意更改、添加或遗漏内容。 2. 术语准确:正确使用专业术语,并保持术语的一致性。 3. 理解上下文:充分理解并反映文本的背景和上下文关系。 ### 字幕数据 <subtitles> {lines} </subtitles> ### 输出格式 请完成以下JSON数据,其中 << >> 表示占位符,不应出现在你的答案中,并以JSON格式返回翻译结果: {json.dumps(json_format, ensure_ascii=False, indent=4)} ''' return prompt_faithfulness.strip()

解释

  • 功能:生成一个提示,指导模型将原始字幕逐行忠实地翻译成目标语言。
  • 参数
    • lines:原始字幕文本,按行分割。
    • shared_prompt:共享的上下文信息和注意事项提示。
  • 过程
    • 获取目标语言和源语言。
    • 创建一个JSON格式的模板,包含原文和需要填写的直接翻译字段。
    • 定义任务角色、背景、描述和翻译原则。
    • 提供字幕数据和输出格式要求。
    • 返回生成的提示prompt_faithfulness

5. 获取流畅翻译提示函数

python
def get_prompt_expressiveness(faithfulness_result, lines, shared_prompt): TARGET_LANGUAGE = load_key("target_language") json_format = {} for key, value in faithfulness_result.items(): json_format[key] = { "origin": value['origin'], "direct": value['direct'], "reflection": "<<对直接翻译版本的反思>>", "free": f"<<重新翻译的结果,旨在流畅自然,符合{TARGET_LANGUAGE}的表达习惯,不要留空行!>>" } src_language = get_whisper_language() prompt_expressiveness = f''' ### 角色定义 你是一名专业的Netflix字幕翻译和语言顾问。你的专长不仅在于准确理解原始的{src_language},还在于优化{TARGET_LANGUAGE}翻译,使其更适合目标语言的表达习惯和文化背景。 ### 任务背景 我们已经有了原始{src_language}字幕的直接翻译版本。现在,我们需要你反思和改进这些直接翻译,创造出更自然流畅的{TARGET_LANGUAGE}字幕。 ### 任务描述 基于提供的原始{src_language}文本和{TARGET_LANGUAGE}直接翻译,你需要: 1. 逐行分析直接翻译结果,指出存在的问题。 2. 提供详细的修改建议。 3. 根据你的分析进行自由翻译。 {shared_prompt} ### 翻译分析步骤 请使用两步思考过程逐行处理文本: 1. 直接翻译反思: - 评估语言流畅度。 - 检查语言风格是否与原文一致。 - 检查字幕的简洁性,指出翻译过于冗长的地方,翻译应与原文长度接近。 2. {TARGET_LANGUAGE}自由翻译: - 基于第1步的反思,进行自由翻译。 - 旨在上下文的顺畅和自然,符合{TARGET_LANGUAGE}的表达习惯。 - 确保{TARGET_LANGUAGE}观众容易理解和接受。 - 保持字幕简洁,语言风格朴实自然,保持自由翻译与{src_language}原文在结构上的一致性。 ### 字幕数据 <subtitles> {lines} </subtitles> ### 输出格式 确保生成正确的JSON格式,不要在值中输出引号。 请完成以下JSON数据,其中 << >> 表示占位符,不应出现在你的答案中,并以JSON格式返回翻译结果: {json.dumps(json_format, ensure_ascii=False, indent=4)} ''' return prompt_expressiveness.strip()

解释

  • 功能:生成一个提示,指导模型对直接翻译的字幕进行反思和改进,创造出更流畅自然的翻译版本。
  • 参数
    • faithfulness_result:之前忠实翻译步骤的结果,包括原文和直接翻译。
    • lines:原始字幕文本。
    • shared_prompt:共享的上下文信息和注意事项提示。
  • 过程
    • 创建一个JSON格式的模板,包含原文、直接翻译、需要填写的反思和自由翻译字段。
    • 定义任务角色、背景、描述和翻译分析步骤。
    • 提供字幕数据和输出格式要求。
    • 返回生成的提示prompt_expressiveness

6. 获取字幕对齐提示函数

python
def get_align_prompt(src_sub, tr_sub, src_part): TARGET_LANGUAGE = load_key("target_language") src_language = get_whisper_language() src_splits = src_part.split('\n') num_parts = len(src_splits) src_part = src_part.replace('\n', ' [br] ') align_prompt = ''' ### 角色定义 你是一名精通{src_language}和{target_language}的Netflix字幕对齐专家。你的专长在于准确理解两种语言的语义和结构,使你能够灵活地拆分句子,同时保留原始含义。 ### 任务背景 我们有{src_language}和{target_language}的原始字幕,以及预处理后的{src_language}字幕拆分版本。你的任务是基于此信息,为{target_language}字幕创建最佳的拆分方案。 ### 任务描述 基于提供的{src_language}和{target_language}原始字幕,以及预处理后的拆分版本,你需要: 1. 分析{src_language}和{target_language}字幕的词序和结构对应关系。 2. 提供{target_language}字幕的两种不同拆分方案。 3. 评估这些方案并选择最佳方案。 4. 切勿留下空行。如果根据意义难以拆分,你可以适当重写需要对齐的句子。 ### 字幕数据 <subtitles> {src_language}原文: "{src_sub}" {target_language}原文: "{tr_sub}" 预处理的{src_language}字幕([br]表示拆分点): {src_part} </subtitles> ### 处理步骤 请按照以下步骤操作,并在JSON输出中提供每个步骤的结果: 1. 分析和比较:简要分析{src_language}和{target_language}字幕的词序、句子结构和语义对应关系。指出关键的词语对应、句型异同,以及可能影响拆分的语言特征。 2. 开始对齐:根据你的分析,按照格式为{target_language}字幕提供两种不同的对齐方法。{src_language}的拆分位置必须与预处理的{src_language}拆分版本一致,不能随意更改。 3. 评估和选择:检查并简要评估两种方案,考虑句子完整性、语义连贯性和拆分点的适当性等因素。 4. 最佳方案:选择最佳的对齐方案,仅输出一个数字,1或2。 ### 输出格式 请完成以下JSON数据,其中 << >> 表示需要填写的内容,并以JSON格式返回结果: {{ "analysis": "<<对{src_language}和{target_language}字幕的词序、结构和语义对应关系的详细分析>>", "align_1": [ {align_parts_json} ], "align_2": [ {align_parts_json} ], "comparison": "<<对两种对齐方案的简要评估和比较>>", "best": "<<最佳对齐方案的编号,1或2>>" }} ''' align_parts_json = ','.join( f''' {{ "src_part_{i+1}": "<<{src_splits[i]}>>", "target_part_{i+1}": "<<对应对齐的{TARGET_LANGUAGE}字幕部分>>" }}''' for i in range(num_parts) ) return align_prompt.format( src_language=src_language, target_language=TARGET_LANGUAGE, src_sub=src_sub, tr_sub=tr_sub, src_part=src_part, align_parts_json=align_parts_json, )

解释

  • 功能:生成一个提示,指导模型在源语言和目标语言字幕之间进行对齐,提供最佳的拆分方案。
  • 参数
    • src_sub:源语言的原始字幕。
    • tr_sub:目标语言的原始字幕。
    • src_part:预处理后的源语言字幕拆分版本。
  • 过程
    • 获取目标语言和源语言。
    • 将源语言的拆分版本按行分割,并生成对齐部分的JSON模板。
    • 定义任务角色、背景、描述和处理步骤。
    • 提供字幕数据和输出格式要求。
    • 返回生成的提示align_prompt

7. 获取字幕精简提示函数

python
def get_subtitle_trim_prompt(trans_text, duration): rule = '''考虑: a. 在不修改有意义内容的情况下减少填充词。 b. 省略不必要的修饰词或代词,例如: - "Please explain your thought process" 可以简化为 "Please explain thought process" - "We need to carefully analyze this complex problem" 可以简化为 "We need to analyze this problem" - "Let's discuss the various different perspectives on this topic" 可以简化为 "Let's discuss different perspectives on this topic" - "Can you describe in detail your experience from yesterday" 可以简化为 "Can you describe yesterday's experience" ''' trim_prompt = ''' ### 角色 你是一名专业的字幕编辑,负责在交给配音演员之前编辑和优化超过配音时间的冗长字幕。你的专长在于巧妙地略微缩短字幕,同时确保原意和结构保持不变。 ### 字幕数据 <subtitles> 字幕: "{trans_text}" 持续时间: {duration} 秒 </subtitles> ### 处理规则 {rule} ### 处理步骤 请按照以下步骤操作,并在JSON输出中提供结果: 1. 分析:简要分析字幕的结构、关键信息和可省略的填充词。 2. 精简:根据规则和分析,优化字幕,使其更加简洁。 ### 输出格式 请完成以下JSON数据,其中 << >> 表示需要填写的内容: {{ "analysis": "<<对字幕的简要分析,包括结构、关键信息和可能的处理位置>>", "trans_text_processed": "<<优化和缩短后的原字幕语言的字幕>>" }} ''' return trim_prompt.format( trans_text=trans_text, duration=duration, rule=rule )

解释

  • 功能:生成一个提示,指导模型在不改变原意的情况下,对过长的字幕进行精简,以适应配音的时间限制。
  • 参数
    • trans_text:需要精简的字幕文本。
    • duration:配音的持续时间,单位为秒。
  • 过程
    • 定义处理规则,提供具体的精简方法示例。
    • 定义任务角色、字幕数据、处理步骤和输出格式。
    • 返回生成的提示trim_prompt

总结

这段代码提供了一系列用于字幕处理的函数,每个函数都生成了一个详细的提示,指导语言模型完成特定的任务。这些提示包括角色定义、任务描述、处理步骤和输出格式,确保模型能够按照预期生成符合要求的结果。

通过使用这些函数,开发者可以构建一个完整的字幕处理流水线,从拆分、摘要、翻译、对齐到精简,每个步骤都有明确的指导和格式规范,提高了处理效率和结果的一致性。

질문

非常好,如你所见,上面是一个英文的关于口腔正畸学机制的视频内容提取字幕,上面是我给上述文字打上时间轴之后的字幕文本,请结合其口腔正畸学力学机制专业术语的内容和整体意思进行中文翻译,并保留时间轴不变,并以代码框的形式输出翻译内容,
注意弓丝、托槽、槽沟、单力偶、尖牙、前磨牙、磨牙、牵引扣,方丝、圆丝、V型带、刚性弓丝、柔性弓丝、压低力、牵出力,第一序列弯曲、第二序列弯曲、第三序列弯曲、阶梯弯、前牙、后牙、2×4矫治技术、冠状面、矢状面、水平面、well-aligned排列良好等翻译
我想加上上述的提示词,加在哪个位置比较合适

사고

提取字幕文本

我正在从视频中提取口腔正畸学机制的字幕,确保提取的字幕文本包括时间轴,并且能准确叙述相关专业术语。

在代码的关键位置添加术语

添加单词列表

我正在审查代码,识别出最合适的位置来添加单词列表,以确保生成的提示包含这些单词。这样做是为了保证模型可以正确翻译这些术语。

整合翻译
我正在将术语整合到具体代码的翻译提示中,这样做是为了确保翻译时能准确传达特殊术语的含义。

添加翻译术语

思考一下添加翻译术语的最佳方式,包括在代码中的具体位置。

답변

要确保在翻译过程中这些专业术语被正确翻译,您需要将这些术语添加到提示中,以便模型在翻译时特别注意它们。

根据您提供的代码,最合适的位置是将这些术语添加到things_to_note_prompt中,然后传递给generate_shared_prompt函数。这样,这些术语将包含在共享的提示信息中,并在翻译过程中提供给模型参考。

以下是您可以修改的地方:

  1. 定义things_to_note_prompt并添加术语列表

    在调用generate_shared_prompt之前,您可以创建一个things_to_note_prompt,其中包含您列出的专业术语。例如:

    python
    things_to_note_prompt = """ ### 专业术语 请注意以下口腔正畸学力学机制的专业术语,并确保在翻译过程中准确翻译: - archwire(弓丝) - bracket(托槽) - slot(槽沟) - single force couple(单力偶) - canine(尖牙) - premolar(前磨牙) - molar(磨牙) - tie wing(牵引扣) - rectangular wire(方丝) - round wire(圆丝) - V-bend(V型弯) - stiff wire(刚性弓丝) - flexible wire(柔性弓丝) - intrusive force(压低力) - extrusive force(牵出力) - first-order bend(第一序列弯曲) - second-order bend(第二序列弯曲) - third-order bend(第三序列弯曲) - step bend(阶梯弯) - anterior teeth(前牙) - posterior teeth(后牙) - 2&times;4 appliance(2&times;4矫治技术) - coronal plane(冠状面) - sagittal plane(矢状面) - horizontal plane(水平面) - well-aligned(排列良好) """
  2. 生成共享提示

    然后,将things_to_note_prompt传递给generate_shared_prompt函数:

    python
    shared_prompt = generate_shared_prompt(previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt)
  3. 在翻译提示中包含共享提示

    get_prompt_faithfulnessget_prompt_expressiveness函数中,shared_prompt已经包含在提示中,因此模型在翻译时会参考这些专业术语。


完整示例

假设您已经有了previous_content_promptafter_content_promptsummary_prompt,以下是如何添加专业术语并进行翻译的示例:

python
# 定义专业术语提示 things_to_note_prompt = """ ### 专业术语 请注意以下口腔正畸学力学机制的专业术语,并确保在翻译过程中准确翻译: - archwire(弓丝) - bracket(托槽) - slot(槽沟) - single force couple(单力偶) - canine(尖牙) - premolar(前磨牙) - molar(磨牙) - tie wing(牵引扣) - rectangular wire(方丝) - round wire(圆丝) - V-bend(V型弯) - stiff wire(刚性弓丝) - flexible wire(柔性弓丝) - intrusive force(压低力) - extrusive force(牵出力) - first-order bend(第一序列弯曲) - second-order bend(第二序列弯曲) - third-order bend(第三序列弯曲) - step bend(阶梯弯) - anterior teeth(前牙) - posterior teeth(后牙) - 2&times;4 appliance(2&times;4矫治技术) - coronal plane(冠状面) - sagittal plane(矢状面) - horizontal plane(水平面) - well-aligned(排列良好) """ # 生成共享提示 shared_prompt = generate_shared_prompt(previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt) # 获取需要翻译的字幕文本 lines = """ 00:00:01,000 --> 00:00:04,000 We will now discuss the biomechanics of orthodontic tooth movement. 00:00:05,000 --> 00:00:08,000 The archwire is engaged in the bracket slot to apply force. ... (更多字幕行) """ # 获取忠实翻译提示 faithfulness_prompt = get_prompt_faithfulness(lines, shared_prompt) # 调用模型进行忠实翻译(示例,不实际调用模型) faithfulness_result = model_generate(faithfulness_prompt) # 获取流畅翻译提示 expressiveness_prompt = get_prompt_expressiveness(faithfulness_result, lines, shared_prompt) # 调用模型进行流畅翻译(示例,不实际调用模型) expressiveness_result = model_generate(expressiveness_prompt)

通过将专业术语添加到things_to_note_prompt中,您确保了这些术语在翻译过程中受到特别关注。

注意:在实际调用模型时,请确保模型能够访问到shared_prompt,并按照提示中的要求进行翻译。此外,如果您的字幕已经打上了时间轴,请确保在处理lines时保留时间轴信息,模型在翻译时应保持时间轴不变。

最终输出

模型生成的翻译结果应以代码块的形式输出,并保留时间轴不变。例如:

plaintext
00:00:01,000 --> 00:00:04,000 现在我们将讨论正畸牙齿移动的生物力学。 00:00:05,000 --> 00:00:08,000 弓丝被置入托槽的槽沟中以施加力量。 ... (更多翻译后的字幕行)

希望这能帮助您在翻译过程中正确添加专业术语,并获得准确的中文翻译。

질문

我直接在代码的最开头定义这个函数可以吗?后面是不是就不需要修改什么了

사고

定义函数位置

用户提到可以直接在代码前面定义函数"things_to_note_prompt",后续无需修改。助理接下来回答这个问题。

提出新方案

讨论用户是否可以在代码开头定义"things_to_note_prompt"变量,并询问是否需要进一步修改。

明确问题 boundary

确保导入必要性

我正审查代码,确保有效导入'things_to_note_prompt'。特别关注专业术语的准确性和一致性,以避免潜在的翻译偏差。

引导模型关注关注点

답변

是的,您可以在代码的最开头定义things_to_note_prompt,然后将其传递给generate_shared_prompt函数。这种方式可以确保您的专业术语列表被包含在共享提示中,模型在翻译过程中会参考这些术语。

以下是您可以在代码开头添加的内容:

python
# 定义专业术语提示 things_to_note_prompt = """ ### 专业术语 请注意以下口腔正畸学力学机制的专业术语,并确保在翻译过程中准确翻译: - archwire(弓丝) - bracket(托槽) - slot(槽沟) - single force couple(单力偶) - canine(尖牙) - premolar(前磨牙) - molar(磨牙) - tie wing(牵引扣) - rectangular wire(方丝) - round wire(圆丝) - V-bend(V型弯) - stiff wire(刚性弓丝) - flexible wire(柔性弓丝) - intrusive force(压低力) - extrusive force(牵出力) - first-order bend(第一序列弯曲) - second-order bend(第二序列弯曲) - third-order bend(第三序列弯曲) - step bend(阶梯弯) - anterior teeth(前牙) - posterior teeth(后牙) - 2&times;4 appliance(2&times;4矫治技术) - coronal plane(冠状面) - sagittal plane(矢状面) - horizontal plane(水平面) - well-aligned(排列良好) """

然后,在生成共享提示时,将things_to_note_prompt传递给generate_shared_prompt函数:

python
shared_prompt = generate_shared_prompt( previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt )

注意事项

  • 确保共享提示被正确传递:在调用get_prompt_faithfulnessget_prompt_expressiveness函数时,确保它们使用了包含things_to_note_promptshared_prompt

  • 保持时间轴不变:在处理字幕文本时,确保保留时间轴信息。模型在翻译时应保持时间轴不变。

  • 模型调用:在实际调用模型进行翻译时,使用生成的提示。例如:

    python
    # 获取忠实翻译提示 faithfulness_prompt = get_prompt_faithfulness(lines, shared_prompt) # 调用模型进行忠实翻译(示例) faithfulness_result = model_generate(faithfulness_prompt)
  • 继续后续处理:在得到忠实翻译结果后,您可以继续使用get_prompt_expressiveness函数进行流畅度优化,传递相同的shared_prompt

完整示例

python
# 导入必要的模块和函数 import os, sys, json sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from core.step2_whisper import get_whisper_language from core.config_utils import load_key # 定义专业术语提示 things_to_note_prompt = """ ### 专业术语 请注意以下口腔正畸学力学机制的专业术语,并确保在翻译过程中准确翻译: - archwire(弓丝) - bracket(托槽) - slot(槽沟) - single force couple(单力偶) - canine(尖牙) - premolar(前磨牙) - molar(磨牙) - tie wing(牵引扣) - rectangular wire(方丝) - round wire(圆丝) - V-bend(V型弯) - stiff wire(刚性弓丝) - flexible wire(柔性弓丝) - intrusive force(压低力) - extrusive force(牵出力) - first-order bend(第一序列弯曲) - second-order bend(第二序列弯曲) - third-order bend(第三序列弯曲) - step bend(阶梯弯) - anterior teeth(前牙) - posterior teeth(后牙) - 2&times;4 appliance(2&times;4矫治技术) - coronal plane(冠状面) - sagittal plane(矢状面) - horizontal plane(水平面) - well-aligned(排列良好) """ # 生成共享提示 shared_prompt = generate_shared_prompt( previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt ) # 获取需要翻译的字幕文本(示例) lines = """ 00:00:01,000 --> 00:00:04,000 We will now discuss the biomechanics of orthodontic tooth movement. 00:00:05,000 --> 00:00:08,000 The archwire is engaged in the bracket slot to apply force. """ # 获取忠实翻译提示 faithfulness_prompt = get_prompt_faithfulness(lines, shared_prompt) # 调用模型进行忠实翻译(实际调用时需要替换为您的模型调用代码) # faithfulness_result = model_generate(faithfulness_prompt) # 假设得到的忠实翻译结果如下(示例): faithfulness_result = { 1: { "origin": "We will now discuss the biomechanics of orthodontic tooth movement.", "direct": "我们现在将讨论正畸牙齿移动的生物力学。" }, 2: { "origin": "The archwire is engaged in the bracket slot to apply force.", "direct": "弓丝被置入托槽的槽沟中以施加力量。" } } # 获取流畅翻译提示 expressiveness_prompt = get_prompt_expressiveness(faithfulness_result, lines, shared_prompt) # 调用模型进行流畅翻译(实际调用时需要替换为您的模型调用代码) # expressiveness_result = model_generate(expressiveness_prompt) # 最终,您可以将翻译结果与时间轴组合,并以代码框的形式输出 translated_lines = """ 00:00:01,000 --> 00:00:04,000 现在我们将讨论正畸牙齿移动的生物力学。 00:00:05,000 --> 00:00:08,000 弓丝被放入托槽的槽沟中以施加力量。 """ print("```plaintext\n" + translated_lines + "\n```")

总结

  • 您可以在代码开头定义things_to_note_prompt,这样有助于在整个处理过程中保持一致性。
  • 确保所有使用到共享提示的函数都能访问到包含专业术语的shared_prompt
  • 不需要对后续代码进行其他修改,只要确保专业术语提示被正确传递即可。
  • 在最终输出时,确保时间轴和翻译后的字幕内容以代码框的形式输出,方便查看和使用。

希望这能帮助您顺利完成字幕的专业翻译。如有其他问题,请随时提问!

질문

我想强调这个视频是个口腔正畸学视频,强调这个视频的性质,应该写哪些提示词添加到哪个位置

사고

翻译字幕

用户提供的代码是生成字幕的 Python 函数。我了解到,他需要将英文字幕翻译成中文,并保持时间码不变。

关注术语翻译

确保正确翻译诸如archwire、bracket、slot等技术术语,并将其添加到prompt中,以帮助生成的模型正确翻译这些术语。

定义功能

定义'things_to_note_prompt'并添加术语列表,然后将其传递给'generate_shared_prompt'函数。

确保内容相关性

用户想要确保视频内容专注于牙科正畸,询问应该添加哪些关键词和它们出现的位置。

理解请求

结合OpenAI政策,明确用户请求,提供准确回复,避免政策违规,说明如何添加提示词以增强视频内容。

精确描述视频内容

添加术语到"time_to_note_prompt",强调在"summary_prompt"或其他提示中视频内容涉及牙科正畸。

调整任务背景

通过调整任务背景或描述部分,可以提及字幕来自牙科正畸视频。这有助于在翻译过程中增加专业性和准确性。

更新摘要提示

我在增加视频内容总结时,提到了牙科机械的相关性。细化了见解点,以确保专业术语的准确性。

调整任务描述

我正在get_prompt_faithfulness函数中调整"任务背景"部分。 这一调整是为了确保字幕翻译的准确性和一致性。

复杂手机界面背后的设计思考

답변

要强调视频是关于口腔正畸学的,并让模型在翻译过程中充分理解这一点,您可以在多个提示中加入有关视频性质的信息。这将指导模型在翻译时考虑到视频的专业背景,确保翻译的准确性和一致性。

以下是您可以添加提示词的位置和方法:


1. 在翻译提示的任务描述中添加视频性质

get_prompt_faithfulnessget_prompt_expressiveness函数中,您可以修改“任务背景”或“任务描述”部分,明确指出字幕来自一个关于口腔正畸学的视频。

示例修改:

python
def get_prompt_faithfulness(lines, shared_prompt): TARGET_LANGUAGE = load_key("target_language") src_language = get_whisper_language() # ... 其他代码 ... prompt_faithfulness = f''' ### 角色定义 你是一名专业的Netflix字幕翻译,精通{src_language}{TARGET_LANGUAGE},并熟悉它们各自的文化。 ### 任务背景 我们有一段原始的{src_language}字幕,来自一个关于**口腔正畸学力学机制**的视频。这些字幕包含与口腔正畸学相关的专业术语。 ### 任务描述 基于提供的原始{src_language}字幕,你需要: 1. 将原始{src_language}字幕逐行翻译成{TARGET_LANGUAGE}2. 确保翻译忠实于原文,准确传达原始含义。 3. 特别注意口腔正畸学力学机制的专业术语,确保准确翻译。 {shared_prompt} ### 翻译原则 1. 忠实于原文:准确传达原文的内容和意义,不得随意更改、添加或遗漏内容。 2. 术语准确:正确使用专业术语,并保持术语的一致性。 3. 理解上下文:充分理解并反映文本的背景和上下文关系。 ''' return prompt_faithfulness.strip()

get_prompt_expressiveness函数中,您也可以类似地添加视频性质的信息。


2. 在things_to_note_prompt中添加视频性质和专业术语

将视频的性质和专业术语列表添加到things_to_note_prompt中,这样在生成shared_prompt时,模型会同时获取到视频背景和需要注意的术语。

示例:

python
# 定义专业术语提示和视频性质 things_to_note_prompt = """ ### 视频性质 本视频是关于**口腔正畸学力学机制**的教学视频,涵盖了正畸治疗中的力学原理和技术。 ### 专业术语 请注意以下口腔正畸学力学机制的专业术语,并确保在翻译过程中准确翻译: - archwire(弓丝) - bracket(托槽) - slot(槽沟) - single force couple(单力偶) - canine(尖牙) - premolar(前磨牙) - molar(磨牙) - tie wing(牵引扣) - rectangular wire(方丝) - round wire(圆丝) - V-bend(V型弯) - stiff wire(刚性弓丝) - flexible wire(柔性弓丝) - intrusive force(压低力) - extrusive force(牵出力) - first-order bend(第一序列弯曲) - second-order bend(第二序列弯曲) - third-order bend(第三序列弯曲) - step bend(阶梯弯) - anterior teeth(前牙) - posterior teeth(后牙) - 2&times;4 appliance(2&times;4矫治技术) - coronal plane(冠状面) - sagittal plane(矢状面) - horizontal plane(水平面) - well-aligned(排列良好) """

3. 更新shared_prompt

使用包含视频性质和专业术语的things_to_note_prompt生成shared_prompt,这样所有引用shared_prompt的函数都会获得这些信息。

python
shared_prompt = generate_shared_prompt( previous_content_prompt, after_content_prompt, summary_prompt, things_to_note_prompt )

4. 在摘要提示中强调视频性质

get_summary_prompt函数中,确保生成的摘要明确提到视频是关于口腔正畸学的。

示例修改:

python
def get_summary_prompt(source_content): src_language = get_whisper_language() TARGET_LANGUAGE = load_key("target_language") summary_prompt = f""" ### 角色 你是一名专业的视频翻译专家和术语顾问,专注于口腔正畸学领域。你不仅擅长准确理解原始的{src_language}文本,还能提取关键的专业术语,并优化翻译以更好地适应{TARGET_LANGUAGE}的表达习惯和文化背景。 ### 任务描述 对于提供的原始{src_language}视频文本,你需要: 1. 用一句话总结视频的主要主题,强调其与口腔正畸学力学机制的关联。 2. 提取视频中出现的专业术语和名称,提供{TARGET_LANGUAGE}翻译或建议保留原文。避免提取简单、常见的词汇。 3. 对每个翻译的术语或名称,提供简要的解释。 # ... 其余代码保持不变 ... """ return summary_prompt

5. 在所有相关提示中保持一致

确保在所有涉及到任务背景、任务描述或角色定义的提示中,都明确提到视频是关于口腔正畸学的。这将使模型在整个处理过程中始终关注这一主题。


6. 最终输出示例

在完成所有修改后,模型应能够准确翻译字幕,保留时间轴,并正确翻译专业术语。

示例输出:

plaintext
00:00:01,000 --> 00:00:04,000 现在我们将讨论正畸牙齿移动的生物力学。 00:00:05,000 --> 00:00:08,000 弓丝被放入托槽的槽沟中以施加力量。 ... (更多翻译后的字幕行)

总结

  • 添加视频性质到提示中:在任务描述、任务背景和角色定义中明确指出视频是关于口腔正畸学的。这有助于模型理解整体上下文。

  • 包含专业术语:在things_to_note_prompt中列出专业术语,确保模型在翻译时准确处理这些词汇。

  • 更新共享提示:将包含视频性质和专业术语的things_to_note_prompt传递给generate_shared_prompt,使其在翻译过程中被引用。

  • 保持一致性:在所有相关的提示和函数中,确保关于视频性质的描述一致,以便模型始终关注正确的主题。

通过以上方法,您可以强调视频的性质,使模型在翻译过程中充分理解内容,并提供准确、专业的翻译结果。

如果您有任何其他问题或需要进一步的帮助,请随时告诉我!

질문

def get_summary_prompt(source_content):
src_language = get_whisper_language()
TARGET_LANGUAGE = load_key("target_language")
summary_prompt = f"""

角色

你是一名专业的视频翻译专家和术语顾问,专注于口腔正畸学领域。你不仅擅长准确理解原始的{src_language}文本,还能提取关键的专业术语,并优化翻译以更好地适应{TARGET_LANGUAGE}的表达习惯和文化背景。

任务描述

对于提供的原始{src_language}视频文本,你需要:

  1. 用一句话总结视频的主要主题,强调其与口腔正畸学力学机制的关联。
  2. 提取视频中出现的专业术语和名称,提供{TARGET_LANGUAGE}翻译或建议保留原文。避免提取简单、常见的词汇。
  3. 对每个翻译的术语或名称,提供简要的解释。

... 其余代码保持不变 ...

"""
return summary_prompt
还是写成英文的

사고

调整翻译功能

用户正在调整翻译功能,专注于口腔正畸学领域。现在,用户希望函数 get_summary_prompt 输出英文提示,而不是中文。

调整代码

整理代码以确保get_summary_prompt函数的提示语为英文,并且包括用户所做的修改,突出了矫正学领域。这使得代码更加多样化和国际化。

답변

Certainly! Here's the updated get_summary_prompt function with the prompt written in English and emphasizing the orthodontics field:

python
def get_summary_prompt(source_content): src_language = get_whisper_language() TARGET_LANGUAGE = load_key("target_language") summary_prompt = f""" ### Role You are a professional video translation expert and terminology consultant specializing in orthodontics. You excel not only in accurately understanding the original {src_language} text but also in extracting key professional terms and optimizing the translation to better suit the expression habits and cultural background of {TARGET_LANGUAGE}. ### Task Description For the provided original {src_language} video text, you need to: 1. Summarize the video's main topic in one sentence, emphasizing its relation to the biomechanics of orthodontics. 2. Extract professional terms and names that appear in the video, providing {TARGET_LANGUAGE} translations or suggesting to keep the original terms. Avoid extracting simple, common words. 3. Provide a brief explanation for each translated term or name. ### Analysis and Summary Steps Please think in two steps, processing the text line by line: 1. Topic summarization: - Quickly skim through the entire text to understand the general idea. - Summarize the topic in one concise sentence, highlighting its connection to orthodontic biomechanics. 2. Term and name extraction: - Carefully read the entire text, marking professional terms and names related to orthodontics. - For each term or name, provide a {TARGET_LANGUAGE} translation or suggest keeping the original term; only the word itself is needed, not the pronunciation. - Add a brief explanation for each term or name to help the translator understand. - If the word is a fixed abbreviation or a proper name, please keep the original. ### Output Format Please output your analysis results in the following JSON format, where <> represents placeholders: {{ "theme": "<Briefly summarize the theme of this video in 1 sentence>", "terms": [ {{ "original": "<Term or name 1 in {src_language}>", "translation": "<{TARGET_LANGUAGE} translation or keep original>", "explanation": "<Brief explanation of the term or name>" }}, ... ] }} ### Video Text Data to be Processed <video_text_to_summarize> {source_content} </video_text_to_summarize> """.strip() return summary_prompt

This updated function generates a prompt in English and emphasizes that the video is about orthodontics, specifically the biomechanics of orthodontic treatments. The prompt guides the model to:

  • Summarize the video's main topic with an emphasis on its relation to orthodontic biomechanics.
  • Extract professional terms related to orthodontics.
  • Provide translations and brief explanations for each term.

By making these adjustments, the model should now generate a summary and term extraction that are focused on the orthodontics field, and the prompt is provided in English as per your request.

이 Q&A 공유하기