The Illustrated Zen of Python vol. 1 - Beautiful is Better than Ugly

zensorflow izop 1.jpg

Python is a versatile, high-level programming language that works great for data science. The best thing about Python is that it’s easy to get started with. If you’re clever enough to drive stick, you too can build something useful with Python. However, while writing functional Python code is quite intuitive, writing truly beautiful code takes time, practice, and guidance.

Beautiful code is a rare breed of poetry. It’s easier to feel the qualities of beautiful code than to describe them. Tim Peters, a noted Pythonic paragon, left us some helpful breadcrumbs to follow in the form of his essential design principles: The Zen of Python. These pithy koans are so wildly popular in the Python community that they were hidden as an Easter Egg. Any time you wish to review them, simply type ‘import this’ into your Python interpreter and they’ll pop up.

The first aphorism of The Zen of Python is “Beautiful is Better than Ugly” let’s take a look at what that means in practice. Do your best to read the two examples below, don’t worry about what they mean, just read them.

code sample 1.jpg

Both these examples are true and say the same thing, but the second example is markedly easier to read. Beautiful Python code should require as little thinking as possible on behalf of the reader. That means using logical operators like ‘and’ and ‘or’ rather than ‘&&’ or ‘||’ respectively as one might in other languages. It’s not only efficiency that Pythonic developers strive for, it’s clarity.

Here’s another two examples to ponder. Both of these examples aim to take a list object called ‘my_list’ and print a new list that adds one to each element in the original list. Again, don’t bother trying to understand exactly what each line of code says, just scan through them quickly and ask yourself which one is more beautiful.

code sample 2 (better).jpg

Example one, while interesting from a systems perspective, is clearly uglier. Conversely, even someone with no background in coding could probably sniff out the gist of example two.  If they were to apply a little thought, they could probably even decipher the meaning of each aspect of that one line of code and even change it to suit their purposes. All that without cracking open a textbook or looking up the documentation online. Code that confers meaning which transcends language and explains itself even as it performs its function, that’s a rare breed of poetry indeed. Write like that.

For more reading on developing beautiful Python code, we suggest you peruse the official Python Developer’s Guide and The Hitchhiker’s Guide to Python.  Good luck!

The A.I. Turducken

AI Turducken.jpg

A.I. literacy is quickly rising in the technical pecking order to become a must-have feather in the cap of developers, professionals, and entrepreneurs of all stripes.  Like any new field enduring a sudden rise in notoriety, the terminology of A.I. has often run afoul of misuse, misunderstanding, and general henpecking at the hands and pens of hasty bloggers. In this article we’ll provide a simple explanation of three essential terms in the field: Artificial Intelligence, Machine Leaning, and Deep Learning.

Artificial Intelligence (A.I.) is our big turkey. Essentially, A.I. is any type of program that asks a computer to think or act more like a person (or animal). A.I. has been theorized about for a long time, but has often remained just beyond the grasp of researchers. Computers are, after all, very different from living things. While most turkeys are too birdbrained to do basic math, they can almost immediately tell the difference between a tasty bug and an inedible rock. Computers on the other hand are excellent at math, but until recently were not very good at bug vs. rock identification. Thanks to our second bird, that’s begun to change.

Machine Learning is our fat duck. Nestled inside A.I., machine learning is a process of getting a computer to learn how to do something rather than telling it exactly what to do. This is accomplished through the clever use of statistics. Think about the spam filter on your email account, how does it know the difference between a real email and junk? The simple answer is, you’ve helped train it to do so.

Every time you’ve marked something as spam you’ve been helping improve an algorithm that does that work for you. If a statistically relevant number of emails with the title “The Prince of Norway Wants to Give You Money” from are marked as spam, the spam filter will begin to catch wise. Eventually it will start to block emails with a title like “The [Title] of [Place Name] Wants to Give You [Something]” from [Anybody] The spam filter is not blocking those emails because it was explicitly told to do so, it’s doing so because people helped it learn how through their behavior. More correctly labeled emails (data) leads to better, smarter algorithms. That’s machine learning and it’s just ducky, but very recently learning algorithms have gone even deeper. 

Deep Learning, the clever chicken nested at the center of our feathered trio, is the secret ingredient for making really smart A.I.. A subset of machine learning, deep learning is poised to fundamentally change the way people work, live, and even think. It’s an enormously powerful discovery in computer science, but it’s not terribly difficult to understand or even to code.

Have you ever pulled your hand away from something hot without thinking about it? That simple, instinctive reaction is hardwired in your mind and body. You don’t need to consider the pros and cons of leaving your hand on a flame, you simply pull away because that’s what your nervous system is biologically programed to do.

With enough data and processing power, deep learning frameworks like Tensorflow, Caffe, and PyTorch allow data scientists to create what’s called neural networks which take in tons of information and output desired results. How they do this is no less complex than the series of steps your nervous system takes to pull your hand away from a fire. We can only really understand neural networks after they’ve accomplished what we’ve asked of them using a process called backpropagation.

Deep learning technology is helping us create programs that can drive cars, identify health problems, and even search for habitable planets in space. These programs can perceive of things that no human can. That’s one smart chicken. What’s truly incredible about deep learning frameworks is that they can create customized neural networks on your home computer in a relatively short period of time (a decent graphics card helps).

To recap:

·       The Turkey: A.I. is a program that asks a computer to be more like a brain

·       The Duck: Machine Learning, is the ability of an A.I. to learn how to do something rather than be told

·       The Chicken: Deep Learning is a type of machine learning that uses big data to create neural networks, essentially digital instincts for an A.I.

To learn more about A.I. we suggest you check out Siraj Raval’s YouTube channel, The Deep Learning Book, and Udacity’s free course: Intro to Machine Learning.

If you have need for professional consulting in machine learning, feel free to contact us directly. If we can’t help answer your questions, we can at least point you in the right direction.

Thanks for checking out our blog. Stay Hungry!