worldqwq commited on
Commit
7fea39b
1 Parent(s): 882925c

Iterative sentence merge solving

Browse files

Former-commit-id: fed7822ed8df03570c9039576c987a10f90452db

Files changed (1) hide show
  1. SRT.py +29 -22
SRT.py CHANGED
@@ -100,28 +100,35 @@ class SRT_script():
100
 
101
  lines = translate.split('\n\n')
102
  if len(lines) < (end_seg_id - start_seg_id + 1):
103
- input_str = "\n";
104
- #initialize GPT input
105
- for i, seg in enumerate(self.segments[start_seg_id-1:end_seg_id]):
106
- input_str += 'Sentence %d: ' %(i+1)+ seg.source_text + '\n'
107
- #Append to prompt string
108
- #Adds sentence index let GPT keep track of sentence breaks
109
- input_str += translate
110
- #append translate to prompt
111
- response = openai.ChatCompletion.create(
112
- model="gpt-3.5-turbo",
113
- messages = [
114
- {"role": "system", "content": "You are a helpful assistant that help calibrates English to Chinese subtitle translations in starcraft2."},
115
- {"role": "system", "content": "You are provided with a translated Chinese transcript and assigned sentence number; you must modify or split the Chinese sentence to match the meaning and the number of the English transcript exactly one by one. "},
116
- {"role": "system", "content": "There is no need for you to add any comments or notes, and do not modify the English transcript."},
117
- {"role": "user", "content": 'Reformat or split the Chinese to match the English transcript given: "{}"'.format(input_str)}
118
- ],
119
- temperature=0.7
120
- )
121
-
122
- translate = response['choices'][0]['message']['content'].strip()
123
- lines = translate.split('\n\n')
124
- print("Solving Unmatched Lines")
 
 
 
 
 
 
 
125
  #print(id_range)
126
  #for i, seg in enumerate(self.segments[start_seg_id-1:end_seg_id]):
127
  # print(seg.source_text)
 
100
 
101
  lines = translate.split('\n\n')
102
  if len(lines) < (end_seg_id - start_seg_id + 1):
103
+ count = 0
104
+ while count<5 and len(lines) != (end_seg_id - start_seg_id + 1):
105
+
106
+ count += 1
107
+ print("Solving Unmatched Lines|iteration {}".format(count))
108
+ input_str = "\n"
109
+ #initialize GPT input
110
+ for i, seg in enumerate(self.segments[start_seg_id-1:end_seg_id]):
111
+ input_str += 'Sentence %d: ' %(i+1)+ seg.source_text + '\n'
112
+ #Append to prompt string
113
+ #Adds sentence index let GPT keep track of sentence breaks
114
+ input_str += translate
115
+ #append translate to prompt
116
+ response = openai.ChatCompletion.create(
117
+ model="gpt-3.5-turbo",
118
+ messages = [
119
+ {"role": "system", "content": "You are a helpful assistant that help calibrates English to Chinese subtitle translations in starcraft2."},
120
+ {"role": "system", "content": "You are provided with a translated Chinese transcript; you must modify or split the Chinese sentence to match the meaning and the number of the English transcript exactly one by one. You must not merge ANY Chinese lines, you can only split them but the total Chinese lines MUST equals to number of English lines."},
121
+ {"role": "system", "content": "There is no need for you to add any comments or notes, and do not modify the English transcript."},
122
+ {"role": "user", "content": 'You are given the English transcript and line number, your task is to merge or split the Chinese to match the exact number of lines in English transcript, no more no less. For example, if there are more Chinese lines than English lines, merge some the Chinese lines to match the number of English lines. If Chinese lines is less than English lines, split some Chinese lines to match the english lines: "{}"'.format(input_str)}
123
+ ],
124
+ temperature=0.7
125
+ )
126
+ translate = response['choices'][0]['message']['content'].strip()
127
+ lines = translate.split('\n\n')
128
+ if len(lines) < (end_seg_id - start_seg_id + 1):
129
+ print("Failed Solving unmatched lines, Manually parse needed")
130
+
131
+ print(lines)
132
  #print(id_range)
133
  #for i, seg in enumerate(self.segments[start_seg_id-1:end_seg_id]):
134
  # print(seg.source_text)