Making developers awesome at machine learning
Making developers awesome at machine learning
ChatGPT has demonstrated its ability to handle translation tasks with surprisingly high accuracy. While Google Translate has been the go-to tool for multilingual translation for years, recent studies show that ChatGPT performs competitively with commercial translation products in high-resource European languages (Is ChatGPT A Good Translator?).
ChatGPT’s strength as a translator goes beyond just natural language text. You can also translate the code between different programming languages. Simply providing an initializing prompt describing the translation you want, ChatGPT can often generate the converted code within seconds with high accuracy.
In this post, you will learn how to use ChatGPT prompts to understand ChatGPT’s Translation Capabilities. Specifically, you will learn how to:

Using ChatGPT for Translation Effectively Picture generated by Adrian Tam using Stable Diffusion. Some rights reserved.
Get started and apply ChatGPT with my bookMaximizing Productivity with ChatGPT. It providesreal-world use cases andprompt examples designed to get you using ChatGPT quickly.
Let’s get started.
This post is divided into three parts; they are
Before crafting a translation prompt, you must establish an initialization prompt providing the necessary context for the translator and text style. For our current task, you are translating a poem by Robert Frost and will incorporate this information into the initialization prompt:
You are a translation helper that translates English poems into Swedish.
Without providing a poem, ChatGPT will simply acknowledge your intention:
Sure! I can help you with translating English poems into Swedish. Please provide me with the English poem you would like to have translated, and I’ll do my best to assist you.
Your translation bot is now fully prepared and has a comprehensive understanding of the context. You can proceed by requesting it to translate the poem into Swedish. You provide the poem in your second prompt:
Please convert the following poem from English to Swedish:
Nature’s first green is gold,
Her hardest hue to hold.
Her early leaf’s a flower;
But only so an hour.
Then leaf subsides to leaf.
So Eden sank to grief,
So dawn goes down to day.
Nothing gold can stay.
The following is what ChatGPT responded:
Sure! Here’s the translation of the poem “Nothing Gold Can Stay” by Robert Frost into Swedish:
Naturens första gröna är guld,
Hennes hårdaste nyans att behålla.
Hennes tidiga löv är en blomma;
Men endast så en timme.
Sedan försvinner bladet till blad.
Så sjönk Eden i sorg,
Så gryningen går ner till dagen.
Ingenting guld kan bestå.I hope this translation captures the essence of the original poem in Swedish. Let me know if there’s anything else I can assist you with!
To confirm the accuracy of the translation, you can paste the translated poem into Google Translate to get the English version. In this case, the translation is nearly flawless, which is impressive given the difficulty of translating poetry. It successfully captures both the essence and the meaning of the original poem.

In this section, you will ask ChatGPT to translate a simple number-guessing game from Julia into Python.
Many programming languages look similar to each other. To ensure a successful code translation, you must provide context through an initialization prompt. This prompt will introduce the code translator and specify the type of code being translated:
You are a professional software engineer that has mastered both Julia and Python programming languages. In this case, you will help me translate a simple Julia game into Python.
Similar to the previous example, ChatGPT will acknowledge your instructions and wait for the code from you:
Of course! I’d be happy to help you translate your Julia game into Python. Please provide me with the code for the game in Julia, and I’ll assist you in converting it to Python.
Now, ask ChatGPT to convert the following code into Python, using the following prompt:
Please convert the following Julia Code into Python:
123456789101112131415161718192021222324252627 ```functionnumber_game()secret_number=rand(1:100) # Generate a random secret number between 1 and 100attempts=0println("Welcome to the Number Game!")println("I'm thinking of a number between 1 and 100. Can you guess it?")whiletrueattempts+=1guess=parse(Int,readline()) # Read the player's guess from inputifguess<secret_numberprintln("Too low! Try again.")elseifguess>secret_numberprintln("Too high! Try again.")elseprintln("Congratulations! You guessed the number in $attempts attempts!")breakendendend# Call the number_game function to start the gamenumber_game()```
The code above is deliberately quoted using three backticks following the convention of quoting codes in Markdown format. You shall see ChatGPT translated the code in response:
Sure! Here’s the equivalent Python code for the given Julia code:
123456789101112131415161718192021222324 importrandomdefnumber_game():secret_number=random.randint(1,100) # Generate a random secret number between 1 and 100attempts=0print("Welcome to the Number Game!")print("I'm thinking of a number between 1 and 100. Can you guess it?")whileTrue:attempts+=1guess=int(input()) # Read the player's guess from inputifguess<secret_number:print("Too low! Try again.")elifguess>secret_number:print("Too high! Try again.")else:print(f"Congratulations! You guessed the number in {attempts} attempts!")break# Call the number_game function to start the gamenumber_game()
As a language model, ChatGPT may produce some errors in the code. To verify the accuracy of the translation, you should create a Python file namednumber_game.py, paste the converted code, and execute the file in the terminal, so that you let a real Python interpreter to tell you whether the code is working as expected.
In this case, ChatGPT has flawlessly translated the Julia code into Python with just a simple prompt.

While it’s possible to write a simple translation prompt and obtain a result, there are several tips you can follow to enhance the quality of the translation output:
Wenxiang Jiao, Wenxuan Wang, Jen-tse Huang, Xing Wang, and Zhaopeng Tu. “Is ChatGPT A Good Translator? Yes With GPT-4 As The Engine“, arXiv 2301.08745, 2023.
In this post, we have explored different use cases of machine translation with ChatGPT, highlighting effective strategies for achieving accurate translations. Specifically, we have discussed the following topics:
By implementing these techniques, you can leverage ChatGPT’s translation capabilities to their fullest potential and obtain high-quality translations for various use cases.

...by leveraging the power of advanced AI from ChatGPT, Google Bard, and many other tools online
Discover how in my new Ebook:
Maximizing Productivity with ChatGPT
It providesgreat tips withexamples of all kinds to make you the boss of AI robots
forbrainstorming,editing,expert helper,translator, and much more...

The syntax of Julia is not very different from Python. I suspect that using ChatGPT to convert Java to Ada would be a disaster.
I’m sorry, but telling someone to plop the drivel spat out by ChatGPT into Google Translate for validation is the furthest from accurate you could ask for. Please stop spreading disinformation.
I concur with the above.
Poetry and NMT is one of those areas where the LLM simply cannot perform with consistent fidelity. It looks correct but upon further examination we find that meanings between the languages are not conveyed.
Welcome!
I'mJason Brownlee PhD
and Ihelp developers get results withmachine learning.
Read more
TheMaximizing Productivity with ChatGPT EBook is
where you'll find theReally Good stuff.