logo资料库

Machine Learning with TensorFlow (Manning 20180.pdf

第1页 / 共244页
第2页 / 共244页
第3页 / 共244页
第4页 / 共244页
第5页 / 共244页
第6页 / 共244页
第7页 / 共244页
第8页 / 共244页
资料共244页,剩余部分请下载后查看
Machine Learning with TensorFlow MEAP v10
Copyright
Welcome
Brief contents
Chapter 1: A machine-learning odyssey
1.1 Machine learning fundamentals
1.2 Data representation and features
1.3 Distance Metrics
1.4 Types of Learning
1.4.1 Supervised Learning
1.4.2 Unsupervised Learning
1.4.3 Reinforcement Learning
1.5 Existing Tools
1.5.1 Theano
1.5.2 Caffe
1.5.3 Torch
1.5.4 Computational Graph Toolkit
1.6 TensorFlow
1.7 Overview of future chapters
1.8 Summary
Chapter 2: TensorFlow essentials
2.1 Ensuring TensorFlow works
2.2 Representing tensors
2.3 Creating operators
2.4 Executing operators with sessions
2.4.1 Understanding code as a graph
2.4.2 Session configurations
2.5 Writing code in Jupyter
2.6 Using variables
2.7 Saving and Loading Variables
2.8 Visualizing data using TensorBoard
2.8.1 Implementing a moving average
2.8.2 Visualizing the moving average
2.9 Summary
Chapter 3: Linear regression and beyond
3.1 Formal notation
3.1.1 How do you know the regression algorithm is working?
3.2 Linear Regression
3.3 Polynomial Model
3.4 Regularization
3.5 Application of linear regression
3.6 Summary
Chapter 4: A gentle introduction to classification
4.1 Formal Notation
4.2 Measuring Performance
4.2.1 Accuracy
4.2.2 Precision and Recall
4.2.3 Receiver operating characteristic curve
4.3 Using linear regression for classification
4.4 Using logistic regression
4.4.1 Solving one-dimensional logistic regression
4.4.2 Solving two-dimensional logistic regression
4.5 Multiclass classifier
4.5.1 One versus all
4.5.2 One versus one
4.5.3 Softmax regression
4.6 Application of classification
4.7 Summary
Chapter 5: Automatically clustering data
5.1 Traversing files in TensorFlow
5.2 Extracting features from audio
5.3 K-means clustering
5.4 Audio segmentation
5.5 Clustering using a self-organizing map
5.6 Application of clustering
5.7 Summary
Chapter 6: Hidden Markov models
6.1 Example of a not-so-interpretable model
6.2 Markov Model
6.3 Hidden Markov Model
6.4 Forward algorithm
6.5 Viterbi decode
6.6 Uses of Hidden Markov Models
6.6.1 Modeling a video
6.6.2 Modeling DNA
6.6.3 Modeling an image
6.7 Application of hidden Markov models
6.8 Summary
Chapter 7: A peek into autoencoders
7.1 Neural Networks
7.2 Autoencoder
7.3 Batch training
7.4 Working with images
7.5 Application of autoencoders
7.6 Summary
Chapter 8: Reinforcement learning
8.1 Formal notions
8.1.1 Policy
8.1.2 Utility
8.2 Applying reinforcement learning
8.3 Implementation
8.4 Applications of reinforcement learning
8.5 Summary
Chapter 9: Convolutional neural networks
9.1 Drawback of neural networks
9.2 Convolutional neural networks
9.3 Preparing the image
9.3.1 Generate filters
9.3.2 Convolve using filters
9.3.3 Max-pooling
9.4 Implementing a convolutional neural network in TensorFlow
9.4.1 Measuring performance
9.4.2 Training the classifier
9.5 Tips and tricks to improve performance
9.6 Application of convolutional neural networks
9.7 Summary
Chapter 10: Recurrent neural networks
10.1 Contextual information
10.2 Introduction to recurrent neural networks
10.3 Implementing a recurrent neural network
10.4 A predictive model for timeseries data
10.5 Application of recurrent neural networks
10.6 Summary
Chapter 11: Sequence-to-sequence models for chatbots
11.1.1 Classification
11.1.2 Recurrent neural networks
11.1.3 Classification and RNNs
11.2 Seq-to-seq architecture
11.3 Vector representation of symbols
11.4 Putting it all together
11.5 Gathering dialogue data
11.6 Summary
Chapter 12: Utility landscape
12.1 Preference model
12.2 Image embedding
12.3 Ranking images
12.4 Summary
12.5 What's next?
Appendix A: Installation
A.1 Installing TensorFlow using Docker
A.1.1 Install Docker on Windows
A.1.2 Install Docker on Linux
A.1.3 Install Docker on OSX
A.1.4 How to user Docker
A.2 Installing Matplotlib
MEAP Edition Manning Early Access Program Machine Learning with TensorFlow Version 10 Copyright 2017 Manning Publications For more information on this and other Manning titles go to www.manning.com Licensed to Shashank Nainwal ©Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders. https://forums.manning.com/forums/machine-learning-with-tensorflow
welcome Dear fellow early adopters, curious readers, and puzzled newcomers, Thank you all for every bit of communication with me, whether it be through the official book forums, through email, on GitHub, or even on Reddit. I’ve listened carefully to your questions, suggestions, and concerns, regardless of whether or not I’ve replied to you (and I do apologize for not replying to you). In the latest edition, I am proud to announce a beautiful makeover of every chapter. The text is greatly improved and slowed down to better cover complex matters, especially the areas where you requested more explanation. Most figures and mathematical equations have been updated to look crisp and professional. The code is now updated to TensorFlow v1.0, and it is also available on GitHub at https://github.com/BinRoot/TensorFlow-Book/. Also, the chapters are rearranged to better deliver the right skills at the right time, if the book were read in order. Thank you for investing in the MEAP edition of Machine Learning with TensorFlow. You’re one of the first to dive into this introductory book about cutting-edge machine learning techniques using the hottest technology (spoiler alert: I’m talking about TensorFlow). You’re a brave one, dear reader. And for that, I reward you generously with the following. You’re about to learn machine learning from scratch, both the theory and how to easily implement it. As long as you roughly understand object-oriented programming and know how to use Python, this book will teach you everything you need to know to start solving your own big-data problems, whether it be for work or research. TensorFlow was released just over a year ago by some company that specializes in search engine technology. Okay, I’m being a little facetious; well-known researchers at Google engineered this library. But with such prowess comes intimidating documentation and assumed knowledge. Fortunately for you, this book is down-to-earth and greets you with open arms. Each chapter zooms into a prominent example of machine learning, such as classification, regression, anomaly detection, clustering, and many modern neural networks. Cover them all to master the basics, or cater it to your needs by skipping around. Keep me updated on typos, mistakes, and improvements because this book is undergoing heavy development. It’s like living in a house that’s still actively under construction; at least you won’t have to pay rent. But on a serious note, your feedback along the way will be appreciated. With gratitude, —Nishant Shukla Licensed to Shashank Nainwal ©Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders. https://forums.manning.com/forums/machine-learning-with-tensorflow
brief contents PART 1 MY MACHINE LEARNING RIG 1 A machine learning odyssey 2 TensorFlow essentials PART 2 CORE LEARNING ALGORITHMS 3 Linear regression and beyond 4 A gentle introduction to classification 5 Automatically clustering data 6 Hidden Markov models PART 3 THE NEURAL NETWORK PARADIGM 7 A peek into autoencoders 8 Reinforcement learning 9 Convolutional neural networks 10 Recurrent neural networks 11 Sequence-to-sequence models for chatbots 12 Utility landscape APPENDIX A Installation Licensed to Shashank Nainwal ©Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders. https://forums.manning.com/forums/machine-learning-with-tensorflow
1 A machine-learning odyssey This chapter covers • Machine learning fundamentals • Data representation, features, and vector norms • Existing machine learning tools • Why TensorFlow Have you ever wondered if there are limits to what computer programs can solve? Nowadays, computers appear to do a lot more than simply unravel mathematical equations. In the last half-century, programming has become the ultimate tool to automate tasks and save time, but how much can we automate, and how do we go about doing so? Licensed to Shashank Nainwal 1
Can a computer observe a photograph and say “ah ha, I see a lovely couple walking over a bridge under an umbrella in the rain?” Can software make medical decisions as accurately as that of trained professionals? Can software predictions about the stock market perform better than human reasoning? The achievements of the past decade hint that the answer to all these questions is a resounding “yes,” and the implementations appear to share a common strategy. Recent theoretic advances coupled with newly available technologies have enabled anyone with access to a computer to attempt their own approach at solving these incredibly hard problems. Okay, not just anyone, but that’s why you’re reading this book, right? A programmer no longer needs to know the intricate details of a problem to solve it. Consider converting speech to text: a traditional approach may involve understanding the biological structure of human vocal chords to decipher utterances using many hand-designed, domain-specific, un-generalizable pieces of code. Nowadays, it’s possible to write code that simply looks at many examples, and figures out how to solve the problem given enough time and examples. The algorithm learns from data, similar to how humans learn from experiences. Humans learn by reading books, observing situations, studying in school, exchanging conversations, browsing websites, among other means. How can a machine possibly develop a brain capable of learning? There’s no definitive answer, but world-class researchers have developed intelligent programs from different angles. Among the implementations, scholars have noticed recurring patterns in solving these kinds of problems that has led to a standardized field that we today label as machine learning (ML). As the study of ML matures, the tools have become more standardized, robust, performant, and scalable. This is where TensorFlow comes in. It’s a software library with an intuitive interface that lets programmers dive into using complex ML ideas. The next chapter will go through the ins and outs of this library, and every chapter thereafter will explain how to use TensorFlow for each of the various ML applications. Trusting machine learning output Detecting patterns is a trait that’s no longer unique to humans. The explosive growth of computer clock-speed and memory has led us to an unusual situation: computers now can be used to make predictions, catch anomalies, rank items, and automatically label images. This new set of tools provides intelligent answers to ill-defined problems, but at the subtle cost of trust. Would you trust a computer algorithm to dispense vital medical advice such as whether to perform heart surgery? There is no place for mediocre machine learning solutions. Human trust is too fragile, and our algorithms must be robust against doubt. Follow along closely and carefully in this chapter. 1.1 Machine learning fundamentals Have you ever tried to explain to someone how to swim? Describing the rhythmic joint movements and fluid patterns is overwhelming in its complexity. Similarly, some software Licensed to Shashank Nainwal 2
problems are too complicated for us to easily wrap our minds around. For this, machine learning may be just the tool to use. Hand-crafting carefully tuned algorithms to get the job done was once the only way of building software. From a simplistic point of view, traditional programming assumes a deterministic output for each of its input. Machine learning, on the other hand, can solve a class of problems where the input-output correspondences are not well understood. Full speed ahead! Machine learning is a relatively young technology, so imagine you're a geometer in Euclid's era, paving the way to a newly discovered field. Or, treat yourself as a physicist during the time of Newton, possibly pondering something equivalent to general relativity for the field of machine learning. Machine Learning is about software that learns from previous experiences. Such a computer program improves performance as more and more examples are available. The hope is that if you throw enough data at this machinery, it will learn patterns and produce intelligent results for newly fed input. Another name for machine learning is inductive learning, because the code is trying to infer structure from data alone. It’s like going on vacation in a foreign country, and reading a local fashion magazine to mimic how to dress up. You can develop an idea of the culture from images of people wearing local articles of clothing. You are learning inductively. You might have never used such an approach when programming before because inductive learning is not always necessary. Consider the task of determining whether the sum of two arbitrary numbers is even or odd. Sure, you can imagine training a machine learning algorithm with millions of training examples (outlined in Figure 1.1), but you certainly know that's overkill. A more direct approach can easily do the trick. Figure 1.1 Each pair of integers, when summed together, results in an even or odd number. The input and output correspondences listed are called the ground-truth dataset. For example, the sum of two odd numbers is always an even number. Convince yourself: take any two odd numbers, add them up, and check whether the sum is an even number. Here’s how you can prove that fact directly: Licensed to Shashank Nainwal 3
For any integer n, the formula 2n+1 produces an odd number. Moreover, any odd number can be written as 2n+1 for some value n. So the number 3 can be written 2(1) + 1. And the number 5 can be written 2(2) + 1. So, let's say we have two different odd numbers 2n+1 and 2m+1, where n and m are integers. Adding two odd numbers together yields (2n+1) + (2m+1) = 2n + 2m + 2 = 2(n+m+1). This is an even number because 2 times anything is even. Likewise, we see that the sum of two even numbers is also an even number: 2m + 2n = 2(m+n). And lastly, we also deduce that the sum of an even with an odd is an odd number: 2m + (2n+1) = 2(m+n) + 1. Figure 1.2 visualizes this logic more clearly. Figure 1.2 This table reveals the inner logic behind how the output response corresponds to the input pairs. That's it! With absolutely no use of machine learning, you can solve this task on any pair of integers someone throws at you. Simply applying mathematical rules directly can solve this problem. However, in ML algorithms, we can treat the inner logic as a black box, meaning the logic happening inside might not be obvious to interpret. Licensed to Shashank Nainwal 4
分享到:
收藏