Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Coding with ChatGPT and Other LLMs
Coding with ChatGPT and Other LLMs

Coding with ChatGPT and Other LLMs: Navigate LLMs for effective coding, debugging, and AI-driven development

Arrow left icon
Profile Icon Dr. Vincent Austin Hall Profile Icon Chigbo Uzokwelu
Arrow right icon
$19.99 per month
Paperback Nov 2024 304 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Dr. Vincent Austin Hall Profile Icon Chigbo Uzokwelu
Arrow right icon
$19.99 per month
Paperback Nov 2024 304 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Coding with ChatGPT and Other LLMs

What is ChatGPT and What are LLMs?

The world has been strongly influenced by the recent advancements in AI, especially large language models (LLMs) such as ChatGPT and Gemini (formerly Bard). We’ve witnessed stories such as OpenAI reaching one million users in five days, huge tech company lay-offs, history-revising image scandals, more tech companies getting multi-trillion dollar valuations (Microsoft and NVIDIA), a call for funding of $5–7 trillion for the next stage of technology, and talks of revolutions in how everything is done!

Yes, these are all because of new AI technologies, especially LLM tech.

LLMs are large in multiple ways: not just large training sets and large training costs but also large impacts on the world!

This book is about harnessing that power effectively, for your benefit, if you are a coder.

Coding has changed, and we must all keep up or else our skills will become redundant or outdated. In this book are tools needed by coders to quickly...

Introduction to LLMs

ChatGPT is an LLM. LLMs can be used to answer questions and generate emails, marketing materials, blogs, video scripts, code, and even books that look a lot like they’ve been written by humans. However, you probably want to know about the technology.

Let’s start with what an LLM is.

LLMs are deep learning models, specifically, transformer networks or just “transformers.” Transformers certainly have transformed our culture!

An LLM is trained on huge amounts of text data, petabytes (thousands of terabytes) of data, and predicts the next word or words. Due to the way LLMs operate, they are not perfect at outputting text; they can give alternative facts, facts that are “hallucinated.”

ChatGPT is, as of the time of writing, the most popular and famous LLM, created and managed by OpenAI. OpenAI is a charity and a capped-profit organization based in San Francisco [OpenAI_LP, OpenAIStructure].

ChatGPT is now widely...

Origins of LLMs

Earlier neural networks with their ability to read sentences and predict the next word could only read one word at a time and were called recurrent neural networks, (RNNs). RNNs attempted to mimic human-like sequential processing of words and sentences but faced challenges in handling long-term dependencies between words and sentences due to very limited memory capacity.

In 1925, the groundwork was laid by Wilhelm Lenz and Ernst Ising with their non-learning Ising model, considered an early RNN architecture [Brush, Gemini].

In 1972, Shun’ichi Amari made this architecture adaptive, paving the way for learning RNNs. This work was later popularized by John Hopfield in 1982 [Amari, Gemini].

Due to this, there has been a fair amount of research to find ways to stretch this memory to include more text to get more context. RNNs are transformers. There are other transformers, including LSTMs, which are long short-term memory neural networks that are based on...

Early LLMs

There are many LLMs today and they can be put into a family tree; see Figure 1.1. The figure shows the evolution from word2vec to the most advanced LLMs in 2023: GPT-4 and Gemini [Bard].

Figure 1.1: Family tree of LLMs from word2vec to GPT-4 and Bard, from Yang2023 with permission

Figure 1.1: Family tree of LLMs from word2vec to GPT-4 and Bard, from Yang2023 with permission

So, that’s all of them but, for now, we’ll look at the earlier LLMs that lead to the most advanced technologies today. We’ll start with GPT.

GPT lineage

The development of GPT is a constantly changing and iterative process, with each new model building upon the strengths and weaknesses of its ancestors. The GPT series, initiated by OpenAI, has undergone a great deal of evolution, leading to advancements in natural language processing (NLP) and understanding.

GPT-3, the third iteration, brought a significant leap in terms of size and complexity, with an impressive 175 billion parameters. This allowed it to generate pretty human-like text...

Exploring modern LLMs

After the explosive take-off of ChatGPT in late 2022, with 1 million active users in 5 days and 100 million active users in January 2023 (about 2 months), 2023 was a pretty hot year for LLMs, AI research, and the use of AI in general.

Most tech companies have worked on their own LLMs or transformer models to use and make publicly available. Many companies, organizations, and individuals (students included) have used LLMs for a multitude of tasks. OpenAI keeps updating its GPT family and Google keeps updating its Bard version. Bard became Gemini in February 2024, so all references to Bard have changed to Gemini. Many companies use ChatGPT or GPT-4 as the core of their offering, just creating a wrapper and selling it.

This might change as OpenAI keeps adding modalities (speech, image, etc.) to the GPTs and even a new marketplace platform where users can create and sell their own GPT agents right on OpenAI servers. This was launched in early January 2024 to...

How Transformers work

Moving on to the general transformers, Figure 1.8 shows the structure of a Transformer:

Figure 1.8: Architecture of a Transformer: an encoder for the inputs and a decoder for the outputs (reproduced from Zahere)

Figure 1.8: Architecture of a Transformer: an encoder for the inputs and a decoder for the outputs (reproduced from Zahere)

You can see that it has an encoder and a decoder. The encoder learns the patterns in the data and the decoder tries to recreate them.

The encoder has multiple neural network layers. In transformers, each layer uses self-attention, allowing the encoder to understand how the different parts of the sentence fit together and understand the context.

Here is a quick version of the transformer process:

  1. Encoder network:

    Uses multiple layers of neural networks.

    Each layer employs self-attention to understand relationships between sentence parts and context.

    Creates a compressed representation of the input.

  2. Decoder network:

    Utilizes the encoder’s representation for generating new outputs.

    Employs multiple layers...

A note on the mathematics of LLMs

Getting into the mathematical center of LLMs can be a bit of work, but understanding their core principles reveals a lot about how the most powerful and widely used AIs today function. So, if you want to make these AI models and research them, the mathematics is very interesting:

  • Foundations in linear algebra: The bedrock of LLMs lies in linear algebra, where matrices and vectors rule. Words are mapped to high-dimensional vectors, capturing their meanings and relationships within a vast semantic space. Each word is a point in a multi-dimensional space, with related words clustering closer together.
  • Backpropagation and optimization: Training LLMs requires massive datasets and sophisticated optimization algorithms. One powerful tool is backpropagation, a mathematical technique that calculates the error gradient – how much each parameter in the model contributes to the overall deviation from the desired output. By iteratively adjusting...

Applications of LLMs

The LLM revolution is reaching its virtual tentacles into every corner of life, from writing your college essay to generating personalized Coca-Cola ads and customer services. Here’s a quick peek into just 16 diverse applications:

  • DIYVA: Designs stunning visuals and logos, making even the artistically challenged look like Picassos (https://diyva.life/).
  • LimeWire: Conjures up unique AI-generated artwork, turning your wildest creative visions into reality. Start here: https://limewire.com/studio?referrer=ml736b1k7k.
  • Coca-Cola: Creates targeted ad campaigns, crafting personalized marketing messages for each individual Coke-sipper (https://www.coca-cola.com/gb/en).
  • Slack: Transcribes meetings and automatically summarizes key points, saving you precious time and attention (https://slack.com/intl/en-gb).
  • Octopus Energy: Predicts your energy usage and suggests personalized plans, optimizing your home’s power with LLM intelligence...

Summary

In this chapter, we covered what ChatGPT is and what LLMs in general are, the origins of some widely used LLMs such as BERT, the GPT family, LlaMDA, LlaMA, and modern LLMs such as GPT-4 and Gemini. We looked at some architecture of LLMs and transformers. We had a go at fully processing a sentence in the way an LLM model would: tokenizing, Word2Vec contextual embedding, and more. We also touched on the types of mathematics involved and the applications of this fantastic technology deployed by companies.

Hopefully, you now understand the nature of LLMs such as ChatGPT/Gemini; understand the architectures of LLMs; understand some mathematics of LLMs; and are enlightened about competition in the field and how to teach LLMs to others.

In Chapter 2, we will look at the advantages of coding with LLMs, planning your LLM-powered coding, doing some coding with LLMs, and making it work for you.

Bibliography

  • Amari: “Learning Patterns and Pattern Sequences by Self-Organizing Nets of Threshold Elements”, S. I. Amari https://ieeexplore.ieee.org/document/1672070 in IEEE Transactions on Computers, vol. C-21, no. 11, pp. 1197-1206, Nov. 1972, doi: 10.1109/T-C.1972.223477

    keywords: {Associative memory, brain model, concept formation, logic nets of threshold elements, self-organization, sequential recalling, stability of state transition}

  • AnswerIQ: “25+ Google Bard Statistics 2024 (Usage, Traffic & Cost)”, Paul Rogers: https://www.answeriq.com/google-bard-statistics/ 6th Jan 2024
  • Brownlee_LLMs: “What are Large Language Models”, Adrian Tam: https://machinelearningmastery.com/what-are-large-language-models/
  • Brownlee_BLEU: “A Gentle Introduction to Calculating the BLEU Score for Text in Python”, Jason Brownlee, https://machinelearningmastery.com/calculate-bleu-score-for-text-python/
  • Brush: “History...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand the strengths and weaknesses of LLM-powered software for enhancing performance while minimizing potential issues
  • Grasp the ethical considerations, biases, and legal aspects of LLM-generated code for responsible AI usage
  • Boost your coding speed and improve quality with IDE integration
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Keeping up with the AI revolution and its application in coding can be challenging, but with guidance from AI and ML expert Dr. Vincent Hall—who holds a PhD in machine learning and has extensive experience in licensed software development—this book helps both new and experienced coders to quickly adopt best practices and stay relevant in the field. You’ll learn how to use LLMs such as ChatGPT and Gemini to produce efficient, explainable, and shareable code and discover techniques to maximize the potential of LLMs. The book focuses on integrated development environments (IDEs) and provides tips to avoid pitfalls, such as bias and unexplainable code, to accelerate your coding speed. You’ll master advanced coding applications with LLMs, including refactoring, debugging, and optimization, while examining ethical considerations, biases, and legal implications. You’ll also use cutting-edge tools for code generation, architecting, description, and testing to avoid legal hassles while advancing your career. By the end of this book, you’ll be well-prepared for future innovations in AI-driven software development, with the ability to anticipate emerging LLM technologies and generate ideas that shape the future of development.

Who is this book for?

This book is for experienced coders and new developers aiming to master LLMs, data scientists and machine learning engineers looking for advanced techniques for coding with LLMs, and AI enthusiasts exploring ethical and legal implications. Tech professionals will find practical insights for innovation and career growth in this book, while AI consultants and tech hobbyists will discover new methods for training and personal projects.

What you will learn

  • Utilize LLMs for advanced coding tasks, such as refactoring and optimization
  • Understand how IDEs and LLM tools help coding productivity
  • Master advanced debugging to resolve complex coding issues
  • Identify and avoid common pitfalls in LLM-generated code
  • Explore advanced strategies for code generation, testing, and description
  • Develop practical skills to advance your coding career with LLMs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 29, 2024
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781805125051
Category :
Languages :
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 29, 2024
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781805125051
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

18 Chapters
Part 1: Introduction to LLMs and Their Applications Chevron down icon Chevron up icon
Chapter 1: What is ChatGPT and What are LLMs? Chevron down icon Chevron up icon
Chapter 2: Unleashing the Power of LLMs for Coding: A Paradigm Shift Chevron down icon Chevron up icon
Chapter 3: Code Refactoring, Debugging, and Optimization: A Practical Guide Chevron down icon Chevron up icon
Part 2: Be Wary of the Dark Side of LLM-Powered Coding Chevron down icon Chevron up icon
Chapter 4: Demystifying Generated Code for Readability Chevron down icon Chevron up icon
Chapter 5: Addressing Bias and Ethical Concerns in LLM-Generated Code Chevron down icon Chevron up icon
Chapter 6: Navigating the Legal Landscape of LLM-Generated Code Chevron down icon Chevron up icon
Chapter 7: Security Considerations and Measures Chevron down icon Chevron up icon
Part 3: Explainability, Shareability, and the Future of LLM-Powered Coding Chevron down icon Chevron up icon
Chapter 8: Limitations of Coding with LLMs Chevron down icon Chevron up icon
Chapter 9: Cultivating Collaboration in LLM-Enhanced Coding Chevron down icon Chevron up icon
Chapter 10: Expanding the LLM Toolkit for Coders: Beyond LLMs Chevron down icon Chevron up icon
Part 4: Maximizing Your Potential with LLMs: Beyond the Basics Chevron down icon Chevron up icon
Chapter 11: Helping Others and Maximizing Your Career with LLMs Chevron down icon Chevron up icon
Chapter 12: The Future of LLMs in Software Development Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.