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
$24.99 $35.99
eBook 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
$24.99 $35.99
eBook 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 eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781805127963
Category :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 29, 2024
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781805127963
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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.