What is Codex?
In its essence, OpenAI Codex translates natural language into code. And, can translate code (back) into natural language…or at least explain what the software does.
How might Codex be used?
There are a few practical implementations for Codex…
- As a coding tutor, helping developers in their coding endeavors. Software principles and functionality can be illustrated & explained. Functions and applications can be created from natural language input.
- Codex can be implemented as an AI powered Stack Overflow where users can ask questions in natural language, and Codex responds with code examples.
- Or code can be explained.
- Codex can act as a general resource for a company’s internal development team. Code can be generated or data insights can be gleaned etc.
- For individual use, of course. For any developer this is the ultimate Google for anything code related.
- Quality assessment.
- Automation of code validation.
What will Codex not be used for?
The brilliance of Codex is really evident and undisputable. The code generated is accurate and works. But…
- Codex will not replace developers and software engineers. Not now, at least. This is AI assisting & augmenting developers, not replacing developers.
- Codex does well in affording you various options, anticipating what your next question might be. Context is maintained and questions from users need not always be explicit. It is not autonomous and does not perform orchestration. Typos are absorbed. But…it is not autonomous, problems need to be broken down into smaller pieces and those presented to Codex. You need to know what you want to achieve, and how to get there. Basically define your algorithm.
The best approach to take when building an application using Codex…
- Break a problem down into simpler problems or modules, and…
- …then convert those simpler problems into code segments which can be combined and executed.
- As a user, you need to know what you want to achieve; have an idea of what the best software is for the application.
- You need to be able break your algorithm into into smaller tasks or modules.
- If you have an idea, you can ask Codex for best practice. For instance, when a data frame is loaded via Python, you can ask, give me visualizing suggestions. Or, how can Crosstab be implemented, and Codex takes the initiative.
More about Codex…
Codex is the model that powers GitHub Copilot, which OpenAI built and launched in partnership with GitHub.
Codex is proficient in more than a 12 programming languages. Codex takes simple commands in natural language and execute them on the user’s behalf.
OpenAI Codex is based on GPT-3. According to OpenAI, Codex’s training data contains both natural language and billions of lines of source code from publicly available sources, including code in public GitHub repositories.
OpenAI Codex is most proficient in Python, but also incorporates languages like:
What surprised me about Codex?
- How natural and coherent the comments added tot the code are. The Natural Language Generation (NLG) is obviously on par with GPT-3. The cadence of comments in code is also tight.
- Context is maintained within the conversation and where user input is not comprehensive or explicit, accurate implicit assumptions are made by Codex.
- The code works. Users can copy it out of the Codex preview, paste it into a Notebook and execute. I did not have an instance where the code did not execute.
- The process of generating code is very modular and a request is broken up in to separate sequential steps. Even if your request is quite encompassing, Codex with break it down and present the code in a modular fashion.
- Codex is AI with which users most probably will interact on a daily basis.
- Mistakes in spelling and grammar are absorbed by Codex with surprising resilience.
pip install openai
openai.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"response = openai.Completion.create(
You can see the typos in the user input, but it does not cause any fallback proliferation.
Below is the JSON response…
var arr1 = [1, 2, 3];\n
var arr2 = [4, 5, 6];\n
var arr3 = arr1.concat(arr2);\n
Practical Example: Python Notebook
This is an example of a user asking Codex basic questions about Python implementations of data frames and analyzing data.
This is the playground view where the user asks Codex to create a test data frame.
An implementation in a Notebook of the Python code created by Codex.
The complete data frame printed out in the Notebook…
When Codex is asked to provide a few examples of visualizing the data frame data, the following code is generated by Codex.
# Scatter plot
df.plot(kind='scatter', x='A', y='B')# Hexbin plot
df.plot(kind='hexbin', x='A', y='B')# Box plot
df.plot(kind='hist', alpha=0.5)# Bar plot
df.plot(kind='bar')# Line plot
df.plot(kind='line')# Area plot
The rendering from the Notebook.
Python To Natural Language
A simple three line implementation of Python is provided and and Codex gives a detailed natural language generated explanation of the code.
In this example below, the Python code generated by Codex earlier in the notebook example is submitted back to Codex. The explanation is again very accurate.
The paragraph wit the explanation from Codex below…
# The code above creates a dataframe with 20 rows and 5 columns. The columns are named A, B, C, D, and E. The dataframe is then filled with random integers from 0 to 100. The product column is created by concatenating the string 'product_' with a random integer from 0 to 100. The product column is then set as the index.
A Python example with buggy code and the fixed version from Codex:
##### Fix bugs in the below function
### Buggy Python
### Fixed Pythona=20
To boot, Codex adds a tutorial on Python loops. This is good initiative Codex takes, seeing my buggy code is a very basic piece of code.
# Python Loops
# Python has two primitive loop commands:
# * while loops
# * for loops
# The while Loop
# With the while loop we can execute a set of statements as long as a condition is true.
# **while** *expression*:
# * statement(s)
# The **while** loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.
i = 1
while i < 6:
i += 1# **Note: remember to increment i, or else the loop will continue forever.**
# The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.
# The **break** statement can be used to stop the loop even if the while condition is true:
i = 1
while i < 6:
if i == 3:
i += 1# The **continue** statement can be used to stop the current iteration, and continue with the next:
i = 0
while i < 6:
i += 1
if i == 3:
print(i)# The for loop
# A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
# This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.
# With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
# **for** *variable* **in** *expression*:
# * statement(s)
# **Note:** The expression is executed only once.
# Print each fruit in a fruit list:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)# Looping Through a String
# Even strings are iterable objects, they contain a sequence of characters
There has been much discussion on Low Code versus handcrafted or traditional coding. It is not a case of the one or the other. There is a place and an application for both. With advantages and disadvantages.
I discuss that topic in detail here.
And the same holds true for Codex. Will enterprise systems be built this way, most probably not. Will Fortune 500 companies go the Codex route in principle…no.
But, there are some defernite niche applications, these can include:
- Solving coding challenge and problems in certain routines.
- Establishing best practice.
- Quality assurance.
- Interactive Learning
- Generating specific components for subsequent human review.
Subscribe to my newsletter.
NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces, Ambient…
Cobus Greyling - Medium
Read writing from Cobus Greyling on Medium. NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer…
OpenAI is an AI research and deployment company. Our mission is to ensure that artificial general intelligence benefits…
We've created an improved version of OpenAI Codex, our AI system that translates natural language to code, and we are…
OpenAI Codex: The Next Step In Conversational UI
Using Chatbots To Create Applications & Interfaces
OpenAI Codex & Conversational AI
Creating Code Using Natural Language Understanding