ebook img

Machine Learning with TensorFlow PDF

244 Pages·2018·6.82 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Machine Learning with TensorFlow

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 ©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 Licensed to Shashank Nainwal <[email protected]> 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 ©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 Licensed to Shashank Nainwal <[email protected]> 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 ©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 Licensed to Shashank Nainwal <[email protected]> 1 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 <[email protected]> 2 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 <[email protected]> 3 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 <[email protected]> 4 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 <[email protected]> 5 Figure 1.3 An ML approach to solving problems can be thought of as tuning the parameters of a black box until it produces satisfactory results. PARAMETERS Sometimes the best way to devise an algorithm that transforms an input to its corresponding output is too complicated. For example, if the input were a series of numbers representing a grayscale image, you can imagine the difficulty in writing an algorithm to label every object seen in the image. Machine learning comes in handy when the inner workings are not well understood. It provides us with a toolset to write software without adequately defining every detail of the algorithm. The programmer can leave some values undecided and let the machine learning system figure out the best values by itself. The undecided values are called parameters, and the description is referred to as the model. Your job is to write an algorithm that observes existing examples to figure out how to best tune parameters to achieve the best model. Wow, that’s a mouthful! Don’t worry, this concept will be a reoccurring motif. Machine learning might solve a problem without much insight By mastering this art of inductive problem solving, we wield a double-edged sword. Although ML algorithms may appear to answer correctly to our tests, tracing the steps of deduction to reason why a result is produced may not be as immediate. An elaborate machine learning system learns thousands of parameters, but untangling the meaning behind each parameter is sometimes not the prime directive. With that in mind, I assure you there's a world of magic to unfold. EXERCISE Suppose you’ve collected three months-worth of stock market prices. You would like to predict future trends to outsmart the system for monetary gains. Without using ML, how would you go about solving this problem? (As we’ll see in chapter 8, this problem becomes approachable using ML techniques.) LEARNING AND INFERENCE Suppose you’re trying to bake some desserts in the oven. If you’re new to the kitchen, it can take days to come up with both the right combination and perfect ratio of ingredients to Licensed to Shashank Nainwal <[email protected]> 6 make something that tastes great. By recording recipes, you can remember how to quickly repeat the dessert if you happen to discover the ultimate tasting meal. Similarly, machine learning shares this idea of recipes. Typically, we examine an algorithm in two stages: learning and inference. The objective of the learning stage is to describe the data, which is called the feature vector, and summarize it into a model. The model is our recipe. In effect, the model is a program with a couple of open interpretations, and the data helps disambiguate it. WHAT IS A FEATURE VECTOR? A feature vector is a practical simplification of data. You can think of it as a sufficient summary of real-world objects into a list of attributes. The learning and inference steps rely on the feature vector instead of the data directly. Similar to how recipes can be shared and used by other people, the learned model is also reused by other software. The learning stage is the most time-consuming. Running an algorithm may take hours, if not days or weeks, to converge into a useful model. Figure 1.4 outlines the learning pipeline. Figure 1.4 The general learning approach follows a structured recipe. First, the dataset needs to be transformed into a representation, most often a list of vectors, which can be used by the learning algorithm. The learning algorithm choses a model and efficiently searches for the model’s parameters. The inference stage uses the model to make intelligent remarks about never-before-seen data. It’s like using a recipe you found online. The process typically takes orders of magnitude less time than learning, sometimes even being real-time. Inference is all about testing the model on new data, and observing performance in the process, as shown in figure 1.5. Figure 1.5 The general inference approach uses a model that has already been either learned or simply given. After converting data to a usable representation, such as a feature vector, it uses the model to produce intended Licensed to Shashank Nainwal <[email protected]>

Description:
Summary Machine Learning with TensorFlow gives readers a solid foundation in machine-learning concepts plus hands-on experience coding TensorFlow with Python. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology TensorFlow,
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.