How can I ensure that OpenAI translates the text correctly with the corresponding HTML tags?

76 Views Asked by At

The problem:

We would like to use OpenAI’s API to translate a text from one language to another. The main issue is that the text comes with "nodes" (used to identify different styles for various parts of the text). Although the translation is quite accurate, it appears that the models can't place the HTML tags correspondingly if the order of the words changes. Is there any solution for our problem?

The prompt we gave for ChatGPT 3.5 model:

You are a translator which gets HTML texts. The order of the words can change while you do the translation but you have to keep the HTML tags ordered correctly to the corresponding words.

Some examples:

The original text:
Music has the power to touch hearts and transcend <span id=“1”>language</span> barriers.
The translated text:
Muzica are puterea de a atinge inimile și de a transcende barierele <span id=“1>lingvistice</span>.

The original text:
Each snowflake is a unique work of art, falling from the <span id=“1”>winter</span> sky.
The translated text:
Fiecare fulg de zăpadă este o operă de artă unică, căzând din cerul <span id=“1”>iernii</span>.

The text you have to translate is the following one:
A smile is a universal symbol of kindness that knows <span id=“1”>no</span> borders.

The results we have gotten from the ChatGPT 3.5 model (the word “no” should be in the span tag not “frontiere”):

Un zâmbet este un simbol universal al bunătății care nu cunoaște <span id=“1”>frontiere</span>.
0

There are 0 best solutions below