Open B1gM8c opened 1 year ago
You are right, it does it ever now and then and I could not get around it. This is the reason I send in only 10 lines for conversion, so the sift caused by the missing line will fix itself. Otherwise 40-50 lines could be translated in one go.
In my experience it happens only once out of 10 rounds, so not that disturbing. Maybe in Chinese it merges more line.
I've tried to phrase the prompt many different ways without any success.
Let me know if you can figure out how to do it.
Apart from the shift, how is the quality of the translation?
Apart from the shift, how is the quality of the translation?
I think the performance of translating sentence by sentence is better than some other machine translation tools, as it has a certain contextual foundation. However, if GPT could read the entire SRT content before translating, the results would be even better. Currently, I feel that the prompts could be optimized.
It does read the context of the lines send together, unfortunately the number of lines sent together must be optmimized to avoid shifts. More-lines more context more shifts...
I've played with the Norwegian translation and there were only 3 shifts during a 40 minutes episode. Hungarian results in 5-10 shifts.
I found another project that is simliar to this
https://github.com/gnehs/subtitle-translator-electron/blob/main/src/components/translator.tsx
It provided a pretty good prompt
{
role: "system",
content: `You are a program responsible for translating subtitles. Your task is to output the specified target language based on the input text. Please do not create the following subtitles on your own. Please do not output any text other than the translation. You will receive the subtitles as array that needs to be translated, as well as the previous translation results and next subtitle. If you need to merge the subtitles with the following line, simply repeat the translation. Please transliterate the person's name into the local language. Target language: ${targetLanguage}\n\n${additionalNotes}`
},
However I didn't think that's the prompt cause the good result.
The translation method they use: Simply put it translates one subtitle line at a time and takes the previous 4 lines with it, this ensures that only one subtitle is returned at a time but that the result is accurate without the worry of ChatGPT taking it upon itself to merge the subtitles for you.
I'm thinking about analyzing the length of the returned lines and then add an empty block if two lines were merged. Based on my visual checks it might be possible, probably could even prompt the user to decide what should happen. The prompt matters a lot, I might try the strictness of the referred project.
This might make a little difference: "If you need to merge the subtitles with the following line, simply repeat the translation"
I've tested the modified prompt and it does have some effect: it fixes the missing line when a clear new sentence starts in the text - it skips one of the timestamps and re-aligns with the original intent. It might allow to send in longer slices.
Check the latest version. I tested it with Norwegian--> English and English--> Hungarian, only misses a few lines and fixes the shift within the next 2-3 subtitles. Best result so-far.
It also finds the end of sentences before sending them in, so there is not half sentence at the beginning or at the end of the slice when translating.
Maybe there's some small problem and it will jump out of the code
video : 0%| | 0/249 [00:00<?, ?it/s]Missing 2 line(s)
video : 6%|██▏ | 14/249 [00:18<05:04, 1.30s/it]Missing 1 line(s)
video : 15%|██████ | 38/249 [00:50<04:41, 1.33s/it]Missing 1 line(s)
video : 20%|████████ | 50/249 [01:04<04:14, 1.28s/it]Missing 1 line(s)
video : 35%|█████████████▉ | 87/249 [01:47<03:12, 1.19s/it]Unsuccesful OpenAI operation. Error: HTTP code 502 from API (<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
)
Error during translation, wating for 10 sec to overcome rate limitation...
Trying again...
Missing 1 line(s)
video : 40%|███████████████▉ | 99/249 [07:34<24:38, 9.86s/it]Missing 4 line(s)
video : 45%|█████████████████▊ | 111/249 [07:48<16:29, 7.17s/it]Missing 1 line(s)
video : 50%|███████████████████▉ | 124/249 [08:03<10:53, 5.23s/it]Missing 2 line(s)
video : 55%|██████████████████████ | 137/249 [08:18<07:22, 3.95s/it]Missing 3 line(s)
video : 80%|███████████████████████████████▊ | 198/249 [09:26<01:21, 1.61s/it]Missing 1 line(s)
video : | | 251/? [10:22<00:00, 2.48s/it]
I was wondering if the api key was on rate limitation
Maybe I should try it later.
If you happen to chat with chatgpt while running this you might end up in conflict, because you are allowed to have only one session.
I've improved logging and messages.
There are always a few lines merged during translation but it straightens itself out after 2-3 additional subtitles. I think this is the best it can do, it needs a file compare after the end and those can be easily fixed manually.
The quality of the text is pretty good when translating to Hungarian. The mis-translations are usually from the context, when literally it is correct but looking at the video there could be other meanings as well.
I have encounted the issue either... I thought it shift caused by the subsentences... So I have a idea but not have a try. If we use langchain to make the task into two subtask, one is merge sentences, the other one in charge of translate. Maybe can solved the issue?
Might worth a try, let me know if it works and we can tinker the script.
Hello, I used the script you provided. Is there a way to optimize the prompt words? It seems that the content returned by GPT will merge closely related text in the SRT file into one line, causing a shortage of line numbers.
this is the example, having the issues about Missing 5 lines: