top of page

ChatGPT, an ML Marvel and a Coder's New Best Friend

Unless you’ve been living under a rock recently, you’ve undoubtably heard of ChatGPT. ChatGPT is a language generation AI model, that since it’s release by OpenAI back in November 30th of 2022, has made a huge splash in the world of data, coding, machine learning and AI. If you code at all, and you haven’t learned about ChatGPT, you’ll definitely want to keep reading.


If you were turned off by Natural Language Processing (NLP) AI tools in the past like me, it is probably because their ability to understand you was lacking. ChatGPT is a completely different breed. It’s ability to understand what you are typing, and then generate an appropriate response is game-changing (I’ll get to why shortly). The main reasons ChatGPT can “understand” you so well resides in the underlying ML model it is built on top of, GPT-3.5. The latter is a deep neural network built using a Transformer Architecture, "Attention is All You Need" by Vaswani et al., which relies on attention mechanisms that essentially allow the model to focus on different parts of the input sequence, rather than processing the entire sequence in a fixed order.


From FastAI's FAQ:


“ChatGPT is fine-tuned from GPT-3.5, a language model trained to produce text. ChatGPT was optimized for dialogue by using Reinforcement Learning with Human Feedback (RLHF) – a method that uses human demonstrations and preference comparisons to guide the model toward desired behavior.”


That’s cool… but what does ChatGPT do?


I’m glad you asked. ChatGPT is a conversational language model that can generate human-like text based on whatever you type. Some of the less relevant things (for the purpose of this blog) it can do in the NLP realm are language translation, question answering, and text summarization. However, what makes ChatGPT particularly exciting for us coders is its ability to generate code.


Behold:

Wait! What is going to happen to my job?


Relax, although there have been some arguments made that these models could eventually replace human coders, I think it will merely empower coders to work more efficiently and effectively. It is important to understand that ChatGPT is NOT a replacement for human coders.


Firstly, if you were to try and run the code ChatGPT produced, you will find that it doesn’t work. It almost looks like it could though.

CREATE OR REPLACE STAGE my_stage URL = 's3://mybucket/data/';

COPY INTO my_table
FROM (SELECT $1:* FROM @my_stage/data.csv)
FILE_FORMAT = (TYPE = 'CSV' FIELD_OPTIONALLY_ENCLOSED_BY = '"' 
              FIELD_DELIMITER = ',' SKIP_HEADER = 1);

Now, what I asked ChatGPT to here, I think, is impossible without the use of a UDF, but I was also spoiled by having this feature when doing some data work in databricks so I honestly was hoping I was just missing something.


My purpose for showing this is to bring to attention some of the shortcomings of ChatGPT to assuage any concerns early on and disabuse the notion of AI eliminating coding jobs. Someone without coding knowledge would have a difficult time using the code ChatGPT generates due to some of its limitations which include:

  1. Its ability to generate erroneous code, as you have seen from the above example.

  2. The model may not always generate code that is optimized for performance or scalability.

  3. The code it produces may not be compliant with best practices and coding standards.

  4. The model is sensitive to the prompts it is given, and the more complex code required, the more carefully a request needs to be structured.

These are the most prominent reasons why it is essential for coders to use ChatGPT in conjunction with their own skills and expertise, and to carefully evaluate the code generated by the model before implementing it.


Now that you are aware of some of the limitations of ChatGPT, hopefully you are convinced that the model will not be eliminating coding jobs any time soon. Instead, it is a tool that coders can use to enhance their productivity and efficiency.


The code generated may not be perfect but in many cases it can serve as a great way to boilerplate or template out your code snippets. Offloading the simple, somewhat repetitive code creation to ChatGPT will free up time for coders to think about the more complex problems they need to address with their code. Additionally, ChatGPT can also be used for the laborious yet extremely important task of generating documentation so that the code someone produces is easier to understand, use, and modify.


I want to show one example here of me using to generate a docstring for a simple function and use it to address one of the nuances of one of the limitations mentioned above. After I asked to model to generate it, I decided I wanted it to be embedded in the code as oppose to just provide a standalone piece of code because I thought it would look nicer for the picture.


Observe what happened:

Notice how the actual doc string changed when the only thing l added was “and embed it within my code”.


Both responses are correct in terms of what I requested, but the embedded one provided examples as well. The takeaway point here is that the limitations can be circumvented and even utilized to get ChatGPT to produce a response more in line with what you are looking for.


I only scratched the surface here on the uses of ChatGPT and my examples were limited so you should try it out for yourself if you still aren’t convinced. All in all, ChatGPT is an exciting development in the world of AI and ML, and its ability to generate code has the potential to revolutionize the way coders work. However, it is important to understand that it is not a replacement for human coders, but rather a tool that can be used to enhance their productivity and efficiency. With the right balance of human skills and technology, coders can use ChatGPT to enhance their productivity and spend their time in more impactful ways.

bottom of page