29,99 €
This book is for people who want to learn Python 3 and how to use ChatGPT with Python. It starts with an introduction to Python programming, covering data types, number formatting, Unicode handling, and text manipulation. The book then covers loops, conditional logic, reserved words, user input, exception management, and command-line arguments.
The journey continues into Generative AI, discussing its distinction from Conversational AI. Popular platforms like ChatGPT and GPT-4 are explored, along with their strengths, weaknesses, and potential applications. The book shows how to generate Python 3 code samples via ChatGPT using the “Code Interpreter” plugin.
Understanding these concepts is crucial for navigating Python and AI. This book transitions readers from basic Python programming to advanced AI applications, blending theory with practical skills. Companion files with code samples and figures enhance learning, making this an essential resource for mastering Python and ChatGPT.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Veröffentlichungsjahr: 2024
LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY
By purchasing or using this book and companion files (the “Work”), you agree that this license grants permission to use the contents contained herein, including the disc, but does not give you the right of ownership to any of the textual content in the book / disc or ownership to any of the information or products contained in it. This license does not permit uploading of the Work onto the Internet or on a network (of any kind) without the written consent of the Publisher. Duplication or dissemination of any text, code, simulations, images, etc. contained herein is limited to and subject to licensing terms for the respective products, and permission must be obtained from the Publisher or the owner of the content, etc., in order to reproduce or network any portion of the textual material (in any media) that is contained in the Work.
MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in the creation, writing, or production of the companion disc, accompanying algorithms, code, or computer programs (“the software”), and any accompanying Web site or software of the Work, cannot and do not warrant the performance or results that might be obtained by using the contents of the Work. The author, developers, and the Publisher have used their best efforts to ensure the accuracy and functionality of the textual material and/or programs contained in this package; we, however, make no warranty of any kind, express or implied, regarding the performance of these contents or programs. The Work is sold “as is” without warranty (except for defective materials used in manufacturing the book or due to faulty workmanship).
The author, developers, and the publisher of any accompanying content, and anyone involved in the composition, production, and manufacturing of this work will not be liable for damages of any kind arising out of the use of (or the inability to use) the algorithms, source code, computer programs, or textual material contained in this publication. This includes, but is not limited to, loss of revenue or profit, or other incidental, physical, or consequential damages arising out of the use of this Work.
The sole remedy in the event of a claim of any kind is expressly limited to replacement of the book and/or disc, and only at the discretion of the Publisher. The use of “implied warranty” and certain “exclusions” vary from state to state, and might not apply to the purchaser of this product.
Companion files for this title are available by writing to the publisher at info@merclearning.com.
Oswald Campesato
MERCURY LEARNING AND INFORMATION
Boston, Massachusetts
Copyright ©2024 by MERCURY LEARNING AND INFORMATION LLC. All rights reserved. An Imprint of DeGruyter Inc.
This publication, portions of it, or any accompanying software may not be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means, media, electronic display or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning, without prior permission in writing from the publisher.
Publisher: David Pallai
MERCURY LEARNING AND INFORMATION
121 High Street, 3rd Floor
Boston, MA 02110
info@merclearning.com
www.merclearning.com
800-232-0223
O. Campesato. Python 3 Using ChatGPT/GPT-4
ISBN: 978-1-50152-228-4
The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others.
Library of Congress Control Number: 2023947162
232425321 This book is printed on acid-free paper in the United States of America.
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc. For additional information, please contact the Customer Service Dept. at 800-232-0223(toll free).
All of our titles are available in digital format at academiccourseware.com and other digital vendors. Companion files (figures and code listings) for this title are available by contacting info@merclearning.com. The sole obligation of MERCURY LEARNING AND INFORMATION to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not based on the operation or functionality of the product.
I’d like to dedicate this book to my parents– may this bring joy and happiness into their lives.
Preface
Chapter 1: Introduction to Python 3
Tools for Python
easy_install and pip
virtualenv
IPython
Python Installation
Setting the PATH Environment Variable (Windows Only)
Launching Python on Your Machine
The Python Interactive Interpreter
Python Identifiers
Lines, Indentation, and Multilines
Quotation and Comments in Python
Saving Your Code in a Module
Some Standard Modules in Python
The help() and dir() Functions
Compile Time and Runtime Code Checking
Simple Data Types in Python
Working With Numbers
Working With Other Bases
The chr() Function
The round() Function in Python
Formatting Numbers in Python
Working With Fractions
Unicode and UTF-8
Working With Unicode
Working With Strings
Comparing Strings
Formatting Strings in Python
Slicing and Splicing Strings
Testing for Digits and Alphabetic Characters
Search and Replace a String in Other Strings
Remove Leading and Trailing Characters
Printing Text without NewLine Characters
Text Alignment
Working With Dates
Converting Strings to Dates
Exception Handling in Python
Handling User Input
Command-Line Arguments
Summary
Chapter 2: Conditional Logic, Loops, and Functions
Precedence of Operators in Python
Python Reserved Words
Working with Loops in Python
Python for Loops
A for Loop with try/except in Python
Numeric Exponents in Python
Nested Loops
The split() Function With for Loops
Using the split() Function to Compare Words
Using the split() Function to Print Justified Text
Using the split() Function to Print Fixed-Width Text
Using the split() Function to Compare Text Strings
Using the split() Function to Display Characters in a String
The join() Function
Python while Loops
Conditional Logic in Python
The break/continue/pass Statements
Comparison and Boolean Operators
The in/not in/is/is not Comparison Operators
The and, or, and not Boolean Operators
Local and Global Variables
Uninitialized Variables and the Value None
Scope of Variables
Pass by Reference Versus Value
Arguments and Parameters
Using a while loop to Find the Divisors of a Number
Using a while loop to Find Prime Numbers
User-Defined Functions in Python
Specifying Default Values in a Function
Returning Multiple Values From a Function
Functions With a Variable Number of Arguments
Lambda Expressions
Recursion
Calculating Factorial Values
Calculating Fibonacci Numbers
Calculating the GCD of Two Numbers
Calculating the LCM of Two Numbers
Summary
Chapter 3: Python Data Structures
Working With Lists
Lists and Basic Operations
Reversing and Sorting a List
Lists and Arithmetic Operations
Lists and Filter-Related Operations
Sorting Lists of Numbers and Strings
Expressions in Lists
Concatenating a List of Words
The BubbleSort in Python
The Python range() Function
Counting Digits, Uppercase, and Lowercase Letters
Arrays and the append() Function
Working with Lists and the split() Function
Counting Words in a List
Iterating Through Pairs of Lists
Other List-Related Functions
Using a List as a Stack and a Queue
Working With Vectors
Working With Matrices
The NumPy Library for Matrices
Queues
Tuples (Immutable Lists)
Sets
Dictionaries
Creating a Dictionary
Displaying the Contents of a Dictionary
Checking for Keys in a Dictionary
Deleting Keys From a Dictionary
Iterating Through a Dictionary
Interpolating Data From a Dictionary
Dictionary Functions and Methods
Dictionary Formatting
Ordered Dictionaries
Sorting Dictionaries
Python Multidictionaries
Other Sequence Types in Python
Mutable and Immutable Types in Python
The type() Function
Summary
Chapter 4: Introduction to NumPy and Pandas
What Is NumPy?
Useful NumPy Features
What Are NumPy arrays?
Working With Loops
Appending Elements to Arrays (1)
Appending Elements to Arrays (2)
Multiply Lists and Arrays
Doubling the Elements in a List
Lists and Exponents
Arrays and Exponents
Math Operations and Arrays
Working With “–1” Subranges With Vectors
Working With “–1” Subranges With Arrays
Other Useful NumPy Methods
Arrays and Vector Operations
NumPy and Dot Products (1)
NumPy and Dot Products (2)
NumPy and the “Norm” of Vectors
NumPy and Other Operations
NumPy and the reshape() Method
Calculating the Mean and Standard Deviation
Calculating Mean and Standard Deviation
What Is Pandas?
Pandas DataFrames
Dataframes and Data Cleaning Tasks
A Labeled Pandas DataFrame
Pandas Numeric DataFrames
Pandas Boolean DataFrames
Transposing a Pandas DataFrame
Pandas DataFrames and Random Numbers
Combining Pandas DataFrames (1)
Combining Pandas DataFrames (2)
Data Manipulation With Pandas DataFrames (1)
Data Manipulation With Pandas DataFrames (2)
Data Manipulation With Pandas DataFrames (3)
Pandas DataFrames and CSV Files
Pandas DataFrames and Excel Spreadsheets
Select, Add, and Delete Columns in DataFrames
Pandas DataFrames and Scatterplots
Pandas DataFrames and Simple Statistics
Useful One-Line Commands in Pandas
Summary
Chapter 5: ChatGPT and GPT-4
What Is Generative AI?
Key Features of Generative AI
Popular Techniques in Generative AI
What Makes Generative AI Different
Conversational AI Versus Generative AI
Primary Objective
Applications
Technologies Used
Training and Interaction
Evaluation
Data Requirements
Is DALL-E Part of Generative AI?
Are ChatGPT-3 and GPT-4 Part of Generative AI?
DeepMind
DeepMind and Games
Player of Games (PoG)
OpenAI
Cohere
Hugging Face
Hugging Face Libraries
Hugging Face Model Hub
AI21
InflectionAI
Anthropic
What Is Prompt Engineering?
Prompts and Completions
Types of Prompts
Instruction Prompts
Reverse Prompts
System Prompts Versus Agent Prompts
Prompt Templates
Prompts for Different LLMs
Poorly Worded Prompts
What Is ChatGPT?
ChatGPT: GPT-3 “on Steroids”?
ChatGPT: Google “Code Red”
ChatGPT Versus Google Search
ChatGPT Custom Instructions
ChatGPT on Mobile Devices and Browsers
ChatGPT and Prompts
GPTBot
ChatGPT Playground
Plugins, Advanced Data Analysis, and Code Whisperer
Plugins
Advanced Data Analysis
Advanced Data Analysis Versus Claude-2
Advanced Data Analysis and Charts and Graphs
Code Whisperer
Detecting Generated Text
Concerns About ChatGPT
Code Generation and Dangerous Topics
ChatGPT Strengths and Weaknesses
Sample Queries and Responses From ChatGPT
Alternatives to ChatGPT
Google Bard
YouChat
Pi From Inflection
What Is InstructGPT?
VizGPT and Data Visualization
What Is GPT-4?
GPT-4 and Test-Taking Scores
GPT-4 Parameters
GPT-4 Fine Tuning
ChatGPT and GPT-4 Competitors
Bard
CoPilot (OpenAI/Microsoft)
Codex (OpenAI)
Apple GPT
PaLM-2
Med-PaLM M
Claude 2
LlaMa-2
How to Download LlaMa-2
LlaMa-2 Architecture Features
Fine Tuning LlaMa-2
When Is GPT-5 Available?
Summary
Chapter 6: ChatGPT and Python Code
Simple Calculator
Simple File Handling
Simple Web Scraping
Basic Chat Bot
Basic Data Visualization
Basic Pandas
Generate Random Data
Recursion: Fibonacci Numbers
Object-Oriented Programming
Asynchronous Programming With asyncio
Working With Requests in Python
Image Processing With PIL
Exception Handling
Generators in Python
Roll 7 or 11 With Two Dice
Roll 7 or 11 With Three Dice
Roll 7 or 11 With Four Dice
Mean and Standard Deviation
Summary
Index
This book starts with an introduction to fundamental aspects of Python programming, which include various data types, number formatting, Unicode and UTF-8 handling, and text manipulation techniques. In addition you will learn about loops, conditional logic, and reserved words in Python. You will also see how to handle user input, manage exceptions, and work with command-line arguments.
Next, the text transitions to the realm of Generative AI, discussing its distinction from Conversational AI. Popular platforms and models, including ChatGPT, GPT-4, and their competitors, are presented to give readers an understanding of the current AI landscape. The book also sheds light on the capabilities of ChatGPT, its strengths, weaknesses, and potential applications. In addition, you will learn how to generate a variety of Python 3 code samples via ChatGPT using the “Advanced Data Analysis” plugin (formerly known as the “Code Interpreter” plugin).
In essence, this book provides a modest bridge between the worlds of Python programming and AI, aiming to equip readers with the knowledge and skills to navigate both domains confidently.
This book is intended primarily for people who want to learn both Python and how to use ChatGPT with Python. This book is also intended to reach an international audience of readers with highly diverse backgrounds in various age groups. In addition, it uses standard English rather than colloquial expressions that might be confusing to those readers. This book provides a comfortable and meaningful learning experience for the intended readers.
The answer depends on the extent to which you plan to become involved in working with ChatGPT and Python, perhaps involving LLMs and generative AI. In general, it’s probably worthwhile to learn the more theoretical aspects of LLMs that are discussed in this book.
Some people learn well from prose, others learn well from sample code (and large amounts of it), which means that there’s no single style that can be used for everyone.
Moreover, some programmers want to run the code first, see what it does, and then return to the code to delve into the details (and others use the opposite approach).
Consequently, there are various types of code samples in this book: some are short, and some are long.
Although this book is introductory in nature, some knowledge of Python 3.x will certainly be helpful for the code samples. Knowledge of other programming languages (such as Java) can also be helpful because of the exposure to programming concepts and constructs. The less technical knowledge that you have, the more diligence will be required in order to understand the various topics that are covered.
If you want to be sure that you can grasp the material in this book, glance through some of the code samples to get an idea of how much is familiar to you and how much is new for you.
This book contains basic code samples that are written in Python, and their primary purpose is to familiarize you with basic Python to help you understand the Python code generated via ChatGPT. Moreover, clarity has higher priority than writing more compact code that is more difficult to understand (and possibly more prone to bugs). If you decide to use any of the code in this book, you ought to subject that code to the same rigorous analysis as the other parts of your code base.
Although the answer to this question is more difficult to quantify, it’s especially important to have a strong desire to learn about NLP, along with the motivation and discipline to read and understand the code samples. As a reminder, even simple APIs can be a challenge to understand the first time you encounter them, so be prepared to read the code samples several times.
If you are a Mac user, there are three ways to do so. The first method is to use Finder to navigate to Applications > Utilities and then double click on the Utilities application. Next, if you already have a command shell available, you can launch a new command shell by typing the following command:
open /Applications/Utilities/Terminal.app
A second method for Mac users is to open a new command shell on a MacBook from a command shell that is already visible simply by clicking command+n in that command shell, and your Mac will launch another command shell.
If you are a PC user, you can install Cygwin (open source https://cygwin.com/) that simulates bash commands, or use another toolkit such as MKS (a commercial product). Please read the online documentation that describes the download and installation process. Note that custom aliases are not automatically set if they are defined in a file other than the main start-up file (such as .bash_login).
All the code samples and figures in this book may be obtained by writing to the publisher at info@merclearning.com.
The answer to this question varies widely, mainly because the answer depends heavily on your objectives. If you are interested primarily in NLP, then you can learn about other LLMs (large language models).
If you are primarily interested in machine learning, there are some subfields of machine learning, such as deep learning and reinforcement learning (and deep reinforcement learning) that might appeal to you. Fortunately, there are many resources available, and you can perform an Internet search for those resources. One other point: the aspects of machine learning for you to learn depend on who you are: the needs of a machine learning engineer, data scientist, manager, student or software developer are all different.
O. Campesato
October 2023
Tausende von E-Books und Hörbücher
Ihre Zahl wächst ständig und Sie haben eine Fixpreisgarantie.
Sie haben über uns geschrieben: