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
€33.99
Paperback Nov 2024 304 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Dr. Vincent Austin Hall Profile Icon Chigbo Uzokwelu
Arrow right icon
€33.99
Paperback Nov 2024 304 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€17.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Slovenia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Slovenia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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
€18.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
€189.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
€264.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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela