Monday, August 28, 2017

Visual Information

http://colah.github.io/posts/2015-09-Visual-Information/


    Posted on October 14, 2015

    I love the feeling of having a new way to think about the world. I especially love when there’s some vague idea that gets formalized into a concrete concept. Information theory is a prime example of this.
    Information theory gives us precise language for describing a lot of things. How uncertain am I? How much does knowing the answer to question A tell me about the answer to question B? How similar is one set of beliefs to another? I’ve had informal versions of these ideas since I was a young child, but information theory crystallizes them into precise, powerful ideas. These ideas have an enormous variety of applications, from the compression of data, to quantum physics, to machine learning, and vast fields in between.
    Unfortunately, information theory can seem kind of intimidating. I don’t think there’s any reason it should be. In fact, many core ideas can be explained completely visually!

    Visualizing Probability Distributions

    Before we dive into information theory, let’s think about how we can visualize simple probability distributions. We’ll need this later on, and it’s convenient to address now. As a bonus, these tricks for visualizing probability are pretty useful in and of themselves!
    I’m in California. Sometimes it rains, but mostly there’s sun! Let’s say it’s sunny 75% of the time. It’s easy to make a picture of that:
    Most days, I wear a t-shirt, but some days I wear a coat. Let’s say I wear a coat 38% of the time. It’s also easy to make a picture for that!
    What if I want to visualize both at the same time? We’ll, it’s easy if they don’t interact – if they’re what we call independent. For example, whether I wear a t-shirt or a raincoat today doesn’t really interact with what the weather is next week. We can draw this by using one axis for one variable and one for the other:
    Notice the straight vertical and horizontal lines going all the way through. That’s what independence looks like! 1 The probability I’m wearing a coat doesn’t change in response to the fact that it will be raining in a week. In other words, the probability that I’m wearing a coat and that it will rain next week is just the probability that I’m wearing a coat, times the probability that it will rain. They don’t interact.
    When variables interact, there’s extra probability for particular pairs of variables and missing probability for others. There’s extra probability that I’m wearing a coat and it’s raining because the variables are correlated, they make each other more likely. It’s more likely that I’m wearing a coat on a day that it rains than the probability I wear a coat on one day and it rains on some other random day.
    Visually, this looks like some of the squares swelling with extra probability, and other squares shrinking because the pair of events is unlikely together:
    But while that might look kind of cool, it’s isn’t very useful for understanding what’s going on.
    Instead, let’s focus on one variable like the weather. We know how probable it is that it’s sunny or raining. For both cases, we can look at the conditional probabilities. How likely am I to wear a t-shirt if it’s sunny? How likely am I to wear a coat if it’s raining?
    There’s a 25% chance that it’s raining. If it is raining, there’s a 75% chance that I’d wear a coat. So, the probability that it is raining and I’m wearing a coat is 25% times 75% which is approximately 19%. The probability that it’s raining and I’m wearing a coat is the probability that it is raining, times the probability that I’d wear a coat if it is raining. We write this:
    p(rain,coat)=p(rain)⋅p(coat | rain)
    This is a single case of one of the most fundamental identities of probability theory:
    p(x,y)=p(x)⋅p(y|x)
    We’re factoring the distribution, breaking it down into the product of two pieces. First we look at the probability that one variable, like the weather, will take on a certain value. Then we look at the probability that another variable, like my clothing, will take on a certain value conditioned on the first variable.
    The choice of which variable to start with is arbitrary. We could just as easily start by focusing on my clothing and then look at the weather conditioned on it. This might feel a bit less intuitive, because we understand that there’s a causal relationship of the weather influencing what I wear and not the other way around… but it still works!
    Let’s go through an example. If we pick a random day, there’s a 38% chance that I’d be wearing a coat. If we know that I’m wearing a coat, how likely is it that it’s raining? Well, I’m more likely to wear a coat in the rain than in the sun, but rain is kind of rare in California, and so it works out that there’s a 50% chance that it’s raining. And so, the probability that it’s raining and I’m wearing a coat is the probability that I’m wearing a coat (38%), times the probability that it would be raining if I was wearing a coat (50%) which is approximately 19%.
    p(rain,coat)=p(coat)⋅p(rain | coat)
    This gives us a second way to visualize the exact same probability distribution.
    Note that the labels have slightly different meanings than in the previous diagram: t-shirt and coat are now marginal probabilities, the probability of me wearing that clothing without consideration of the weather. On the other hand, there are now two rain and sunny labels, for the probabilities of them conditional on me wearing a t-shirt and me wearing a coat respectively.
    (You may have heard of Bayes’ Theorem. If you want, you can think of it as the way to translate between these two different ways of displaying the probability distribution!)

    Aside: Simpson’s Paradox

    Are these tricks for visualizing probability distributions actually helpful? I think they are! It will be a little while before we use them for visualizing information theory, so I’d like to go on a little tangent and use them to explore Simpson’s paradox. Simpson’s paradox is an extremely unintuitive statistical situation. It’s just really hard to understand at an intuitive level. Michael Nielsen wrote a lovely essay, Reinventing Explanation, which explored different ways to explain it. I’d like to try and take my own shot at it, using the tricks we developed in the previous section.
    Two treatments for kidney stones are tested. Half the patients are given treatment A while the other half are given treatment B. The patients who received treatment B were more likely to survive than those who received treatment A.
    However, patients with small kidney stones were more likely to survive if they took treatment A. Patients with large kidney stones were also more likely to survive if they took treatment A! how can this be?
    The core of the issue is that the study wasn’t properly randomized. The patients who received treatment A were likely to have large kidney stones, while the patients who received treatment B were more likely to have small kidney stones.
    As it turns out, patients with small kidney stones are much more likely to survive in general.
    To understand this better, we can combine the two previous diagrams. The result is a 3-dimensional diagram with the survival rate split apart for small and large kidney stones.
    We can now see that in both the small case and the large case, Treatment A beats Treatment B. Treatment B only seemed better because the patients it was applied to were more likely to survive in the first place!

    Codes

    Now that we have ways of visualizing probability, we can dive into information theory.
    Let me tell you about my imaginary friend, Bob. Bob really likes animals. He constantly talks about animals. In fact, he only ever says four words: “dog”, “cat”, “fish” and “bird”.
    A couple weeks ago, despite being a figment of my imagination, Bob moved to Australia. Further, he decided he only wanted to communicate in binary. All my (imaginary) messages from Bob look like this:
    To communicate, Bob and I have to establish a code, a way of mapping words into sequences of bits.
    To send a message, Bob replaces each symbol (word) with the corresponding codeword, and then concatenates them together to form the encoded string.

    Variable-Length Codes

    Unfortunately, communication services in imaginary-Australia are expensive. I have to pay $5 per bit of every message I receive from Bob. Have I mentioned that Bob likes to talk a lot? To prevent me from going bankrupt, Bob and I decided we should investigate whether there was some way we could make our average message length shorter.
    As it turns out Bob doesn’t say all words equally often. Bob really likes dogs. He talks about dogs all the time. On occasion, he’ll talk about other animals – especially the cat his dog likes to chase – but mostly he talks about dogs. Here’s a graph of his word frequency:
    That seems promising. Our old code uses codewords that are 2 bits long, regardless of how common they are.
    There’s a nice way to visualize this. In the following diagram, we use the vertical axis to visualize the probability of each word, p(x)
    , and the horizontal axis to visualize the length of the corresponding codeword, L(x)
    . Notice that the area is the average length of a codeword we send – in this case 2 bits.
    Perhaps we could be very clever and make a variable-length code where codewords for common words are made especially short. The challenge is that there’s competition between codewords – making some shorter forces us to make others longer. To minimize the message length, we’d ideally like all codewords to be short, but we especially want the commonly used ones to be. So the resulting code has shorter codewords for common words (like “dog”) and longer codewords for less common words (like “bird”).
    Let’s visualize this again. Notice that the most common codeword became shorter, even as the uncommon ones became longer. The result was, on net, a smaller amount of area. This corresponds to a smaller expected codeword length. On average, the length of a codeword is now 1.75 bits!
    (You may wonder: why not use 1 by itself as a codeword? Sadly, this would cause ambiguity when we decode encoded strings. We’ll talk about this more shortly.)
    It turns out that this code is the best possible code. There is no code which, for this distribution, will give us an average codeword length of less than 1.75 bits.
    There is simply a fundamental limit. Communicating what word was said, what event from this distribution occurred, requires us to communicate at least 1.75 bits on average. No matter how clever our code, it’s impossible to get the average message length to be less. We call this fundamental limit the entropy of the distribution – we’ll discuss it in much more detail shortly.
    If we want to understand this limit, the crux of the matter is understanding the trade off between making some codewords short and others long. Once we understand that, we’ll be able to understand what the best possible codes are like.

    The Space of Codewords

    There are two codes with a length of 1 bit: 0 and 1. There are four codes with a length of 2 bits: 00, 01, 10, and 11. Every bit you add on doubles the number of possible codes.
    We’re interested in variable-length codes, where some codewords are longer than others. We might have simple situations where we have eight codewords that are 3 bits long. We might also have more complicated mixtures, like two codewords of length 2, and four codewords of length 3. What decides how many codewords we can have of different lengths?
    Recall that Bob turns his messages into encoded strings by replacing each word with its codeword and concatenating them.
    There’s a slightly subtle issue one needs to be careful of, when crafting a variable length code. How do we split the encoded string back into the codewords? When all the codewords are the same length, it’s easy – just split the string every couple of steps. But since there are codewords of different lengths, we need to actually pay attention to the content.
    We really want our code to be uniquely decodable, with only one way to decode an encoded string. We never want it to be ambiguous which codewords make up the encoded string. If we had some special “end of codeword” symbol, this would be easy.2 But we don’t – we’re only sending 0s and 1s. We need to be able to look at a sequence of concatenated codewords and tell where each one stops.
    It’s very possible to make codes that aren’t uniquely decodable. For example, imagine that 0 and 01 were both codewords. Then it would be unclear what the first codeword of the encoded string 0100111 is – it could be either! The property we want is that if we see a particular codeword, there shouldn’t be some longer version that is also a codeword. Another way of putting this is that no codeword should be the prefix of another codeword. This is called the prefix property, and codes that obey it are called prefix codes.
    One useful way to think about this is that every codeword requires a sacrifice from the space of possible codewords. If we take the codeword 01, we lose the ability to use any codewords it’s a prefix of. We can’t use 010 or 011010110 anymore because of ambiguity – they’re lost to us.
    Since a quarter of all codewords start with 01, we’ve sacrificed a quarter of all possible codewords. That’s the price we pay in exchange for having one codeword that’s only 2 bits long! In turn this sacrifice means that all the other codewords need to be a bit longer. There’s always this sort of trade off between the lengths of the different codewords. A short codeword requires you to sacrifice more of the space of possible codewords, preventing other codewords from being short. What we need to figure out is what the right trade off to make is!

    Optimal Encodings

    You can think of this like having a limited budget to spend on getting short codewords. We pay for one codeword by sacrificing a fraction of possible codewords.
    The cost of buying a codeword of length 0 is 1, all possible codewords – if you want to have a codeword of length 0, you can’t have any other codeword. The cost of a codeword of length 1, like “0”, is 1/2 because half of possible codewords start with “0”. The cost of a codeword of length 2, like “01”, is 1/4 because a quarter of all possible codewords start with “01”. In general, the cost of codewords decreases exponentially with the length of the codeword.
    Note that if the cost decays as a (natural) exponential, it is both the height and the area!3
    We want short codewords because we want short average message lengths. Each codeword makes the average message length longer by its probability times the length of the codeword. For example, if we need to send a codeword that is 4 bits long 50% of the time, our average message length is 2 bits longer than it would be if we weren’t sending that codeword. We can picture this as a rectangle.
    These two values are related by the length of the codeword. The amount we pay decides the length of the codeword. The length of the codeword controls how much it adds to the average message length. We can picture the two of these together, like so.
    Short codewords reduce the average message length but are expensive, while long codewords increase the average message length but are cheap.
    What’s the best way to use our limited budget? How much should we spend on the codeword for each event?
    Just like one wants to invest more in tools that one uses regularly, we want to spend more on frequently used codewords. There’s one particularly natural way to do this: distribute our budget in proportion to how common an event is. So, if one event happens 50% of the time, we spend 50% of our budget buying a short codeword for it. But if an event only happens 1% of the time, we only spend 1% of our budget, because we don’t care very much if the codeword is long.
    That’s a pretty natural thing to do, but is it the optimal thing to do? It is, and I’ll prove it!
    The following proof is visual and should be accessible, but will take work to get through and is definitely the hardest part of this essay. Readers should feel free to skip to accept this as a given and jump to the next section.
    Let’s picture a concrete example where we need to communicate which of two possible events happened. Event a
    happens p(a) of the time and event b happens p(b) of the time. We distribute our budget in the natural way described above, spending p(a) of our budget on getting a a short codeword, and p(b) on getting b
    a short codeword.
    The cost and length contribution boundaries nicely line up. Does that mean anything?
    Well, consider what happens to the cost and the length contribution if we slightly change the length of the codeword. If we slightly increase the length of the codeword, the message length contribution will increase in proportion to its height at the boundary, while the cost will decrease in proportion to its height at the boundary.
    So, the cost to make the codeword for a
    shorter is p(a). At the same time, we don’t care about the length of each codeword equally, we care about them in proportion to how much we have to use them. In the case of a, that is p(a). The benefit to us of making the codeword for a a bit shorter is p(a)
    .
    It’s interesting that both derivatives are the same. It means that our initial budget has the interesting property that, if you had a bit more to spend, it would be equally good to invest in making any codeword shorter. What we really care about, in the end, is the benefit/cost ratio – that’s what decides what we should invest more in. In this case, the ratio is p(a)p(a)
    , which is equal to one. This is independent of the value of p(a)
    – it’s always one. And we can apply the same argument to other events. The benefit/cost is always one, so it makes equal sense to invest a bit more in any of them.
    Infinitesimally, it doesn’t make sense to change the budget. But that isn’t a proof that it’s the best budget. To prove that, we’ll consider a different budget, where we spend a bit extra on one codeword at the expense of another. We’ll invest ϵ
    less in b, and invest it in a instead. This makes the codeword for a a bit shorter, and the codeword for b
    a bit longer.
    Now the cost of buying a shorter codeword for a
    is p(a)+ϵ, and the cost of buying a shorter codeword for b is p(b)−ϵ. But the benefits are still the same. This leads the benefit cost ratio for buying a to be p(a)p(a)+ϵ which is less than one. On the other hand, the benefit cost ratio of buying b is p(b)p(b)−ϵ
    which is greater than one.
    The prices are no longer balanced. b
    is a better deal than a. The investors scream: “Buy b! Sell a
    !” We do this, and end back at our original budget plan. All budgets can be improved by shifting towards our original plan.
    The original budget – investing in each codeword in proportion to how often we use it – wasn’t just the natural thing to do, it was the optimal thing to do. (While this proof only works for two codewords, it easily generalizes to more.)
    (A careful reader may have noticed that it is possible for our optimal budget to suggest codes where codewords have fractional lengths. That seems pretty concerning! What does it mean? Well, of course, in practice, if you want to communicate by sending a single codeword, you have to round. But as we’ll see later, there’s a very real sense in which it is possible to send fractional codewords when we send many at a time! I’ll ask you be patient with me on this for now!)

    Calculating Entropy

    Recall that the cost of a message of length L
    is 12L. We can invert this to get the length of a message that costs a given amount: log2(1cost). Since we spend p(x) on a codeword for x, the length is log2(1p(x))
    . Those are the best choices of lengths.
    Earlier, we discussed how there is a fundamental limit to how short one can get the average message to communicate events from a particular probability distribution, p
    . This limit, the average message length using the best possible code, is called the entropy of p, H(p)
    . Now that we know the optimal lengths of the codewords, we can actually calculate it!
    H(p)=∑xp(x)log2(1p(x))
    (People often write entropy as H(p)=−∑p(x)log2(p(x))
    using the identity log(1/a)=−log(a)
    . I think the first version is more intuitive, and will continue to use it in this essay.)
    No matter what I do, on average I need to send at least that number of bits if I want to communicate which event occurred.
    The average amount of information needed to communicate something has clear implications for compression. But are there other reasons we should care about it? Yes! It describes how uncertain I am and gives a way to quantify information.
    If I knew for sure what was going to happen, I wouldn’t have to send a message at all! If there’s two things that could happen with 50% probability, I only need to send 1 bit. But if there’s 64 different things that could happen with equal probability, I’d have to send 6 bits. The more concentrated the probability, the more I can craft a clever code with short average messages. The more diffuse the probability, the longer my messages have to be.
    The more uncertain the outcome, the more I learn, on average, when I find out what happened.

    Cross-Entropy

    Shortly before his move to Australia, Bob married Alice, another figment of my imagination. To the surprise of myself, and also the other characters in my head, Alice was not a dog lover. She was a cat lover. Despite this, the two of them were able to find common ground in their shared obsession with animals and very limited vocabulary size.
    The two of them say the same words, just at different frequencies. Bob talks about dogs all the time, Alice talks about cats all the time.
    Initially, Alice sent me messages using Bob’s code. Unfortunately, her messages were longer than they needed to be. Bob’s code was optimized to his probability distribution. Alice has a different probability distribution, and the code is suboptimal for it. While the average length of a codeword when Bob uses his own code is 1.75 bits, when Alice uses his code it's 2.25. It would be worse if the two weren’t so similar!
    This length – the average length of communicating an event from one distribution with the optimal code for another distribution – is called the cross-entropy. Formally, we can define cross-entropy as:4
    Hp(q)=∑xq(x)log2(1p(x))
    In this case, it’s the cross-entropy of Alice the cat-lovers word frequency with respect to the Bob the dog-lovers word frequency.
    To keep the cost of our communications down, I asked Alice to use her own code. To my relief, this pushed down her average message length. But it introduced a new problem: sometimes Bob would accidentally use Alice’s code. Surprisingly, it’s worse for Bob to accidentally use Alice's code than for Alice to use his!
    So, now we have four possibilities:
    • Bob using his own code (H(p)=1.75 bits)

  1. Alice using Bob’s code (Hp(q)=2.25 bits)

  2. Alice using her own code (H(q)=1.75 bits)

  3. Bob using Alice’s code (Hq(p)=2.375 bits)

    This isn’t necessarily as intuitive as one might think. For example, we can see that Hp(q)≠Hq(p)
    . Is there some way we can see how these four values relate to each other?
    In the following diagram, each subplot represents one of these 4 possibilities. Each subplot visualizes average message length the same way our previous diagrams did. They are organized in a square, so that if the messages are coming from the same distribution the plots are beside each other, and if they use the same codes they are on top of each other. This allows you to kind of visually slide the distributions and codes together.
    Can you see why Hp(q)≠Hq(p)
    ? Hq(p) is large because there is an event (blue) which is very common under p but gets a long code because it is very uncommon under q. On the other hand, common events under q are less common under p, but the difference is less drastic, so Hp(q)
    isn’t as high.
    Cross-entropy isn’t symmetric.
    So, why should you care about cross-entropy? Well, cross-entropy gives us a way to express how different two probability distributions are. The more different the distributions p
    and q are, the more the cross-entropy of p with respect to q will be bigger than the entropy of p
    .
    Similarly, the more different p
    is from q, the more the cross-entropy of q with respect to p will be bigger than the entropy of q
    .
    The really interesting thing is the difference between the entropy and the cross-entropy. That difference is how much longer our messages are because we used a code optimized for a different distribution. If the distributions are the same, this difference will be zero. As the difference grows, it will get bigger.
    We call this difference the Kullback–Leibler divergence, or just the KL divergence. The KL divergence of p
    with respect to q, Dq(p)
    ,5 is defined:6
    Dq(p)=Hq(p)−H(p)
    The really neat thing about KL divergence is that it’s like a distance between two distributions. It measures how different they are! (If you take that idea seriously, you end up with information geometry.)
    Cross-Entropy and KL divergence are incredibly useful in machine learning. Often, we want one distribution to be close to another. For example, we might want a predicted distribution to be close to the ground truth. KL divergence gives us a natural way to do this, and so it shows up everywhere.

    Entropy and Multiple Variables

    Let’s return to our weather and clothing example from earlier:
    My mother, like many parents, sometimes worries that I don’t dress appropriately for the weather. (She has reasonable cause for suspicion – I have often failed to wear coats in winter.) So, she often wants to know both the weather and what clothing I’m wearing. How many bits do I have to send her to communicate this?
    Well, the easy way to think about this is to flatten the probability distribution:
    Now we can figure out the optimal codewords for events of these probabilities and compute the average message length:
    We call this the joint entropy of X
    and Y
    , defined
    H(X,Y)=∑x,yp(x,y)log2(1p(x,y))
    This is the exact same as our normal definition, except with two variables instead of one.
    A slightly nicer way to think about this is to avoid flattening the distribution, and just think of the code lengths as a third dimension. Now the entropy is the volume!
    But suppose my mom already knows the weather. She can check it on the news. Now how much information do I need to provide?
    It seems like I need to send however much information I need to communicate the clothes I’m wearing. But I actually need to send less, because the weather strongly implies what clothing I’ll wear! Let’s consider the case where it’s raining and where it’s sunny separately.
    In both cases, I don’t need to send very much information on average, because the weather gives me a good guess at what the right answer will be. When it’s sunny, I can use a special sunny-optimized code, and when it’s raining I can use a raining optimized code. In both cases, I send less information than if I used a generic code for both. To get the average amount of information I need to send my mother, I just put these two cases together…
    We call this the conditional entropy. If you formalize it into an equation, you get:
    H(X|Y)=∑yp(y)∑xp(x|y)log2(1p(x|y))
        =∑x,yp(x,y)log2(1p(x|y))

    Mutual Information

    In the previous section, we observed that knowing one variable can mean that communicating another variable requires less information.
    One nice way to think about this is to imagine amounts of information as bars. These bars overlap if there’s shared information between them. For example, some of the information in X
    and Y is shared between them, so H(X) and H(Y) are overlapping bars. And since H(X,Y) is the information in both, it’s the union of the bars H(X) and H(Y)
    .7
    Once we think about things this way, a lot of things become easier to see.
    For example, we previously noted it takes more information to communicate both X
    and Y (the “joint entropy,” H(X,Y)) than it takes to just communicate X (the “marginal entropy,” H(X)). But if you already know Y, then it takes less information to communicate X (the “conditional entropy,” H(X|Y)
    ) than it would if you didn’t!
    That sounds a bit complicated, but it’s very simple when we think about it from the bar perspective. H(X|Y)
    is the information we need to send to communicate X to someone who already knows Y, the information in X which isn’t also in Y. Visually, that means H(X|Y) is the part of H(X) bar which doesn’t overlap with H(Y)
    .
    You can now read the inequality H(X,Y)≥H(X)≥H(X|Y)
    right off the following diagram.
    Another identity is that H(X,Y)=H(Y)+H(X|Y)
    . That is, the information in X and Y is the information in Y plus the information in X which is not in Y
    .
    Again, it’s difficult to see in the equations, but easy to see if you’re thinking in terms of these overlapping bars of information.
    At this point, we’ve broken the information in X
    and Y up in several ways. We have the information in each variable, H(X) and H(Y). We have the the union of the information in both, H(X,Y). We have the information which is in one but not the other, H(X|Y) and H(Y|X). A lot of this seems to revolve around the information shared between the variables, the intersection of their information. We call this “mutual information,” I(X,Y), defined as:8
    I(X,Y)=H(X)+H(Y)−H(X,Y)
    This definition works because H(X)+H(Y) has two copies of the mutual information, since it’s in both X and Y, while H(X,Y)
    only has one. (Consider the previous bar diagram.)
    Closely related to the mutual information is the variation of information. The variation of information is the information which isn’t shared between the variables. We can define it like so:
    V(X,Y)=H(X,Y)−I(X,Y)
    Variation of information is interesting because it gives us a metric, a notion of distance, between different variables. The variation of information between two variables is zero if knowing the value of one tells you the value of the other and increases as they become more independent.
    How does this relate to KL divergence, which also gave us a notion of distance? Well, KL divergence gives us a distance between two distributions over the same variable or set of variables. In contrast, variation of information gives us distance between two jointly distributed variables. KL divergence is between distributions, variation of information within a distribution.
    We can bring this all together into a single diagram relating all these different kinds of information:

    Fractional Bits

    A very unintuitive thing about information theory is that we can have fractional numbers of bits. That’s pretty weird. What does it mean to have half a bit?
    Here’s the easy answer: often, we’re interested in the average length of a message rather than any particular message length. If half the time one sends a single bit, and half the time one sends two bits, on average one sends one and a half bits. There’s nothing strange about averages being fractional.
    But that answer is really dodging the issue. Often, the optimal lengths of codewords are fractional. What do those mean?
    To be concrete, let’s consider a probability distribution where one event, a
    , happens 71% of the time and another event, b
    , occurs 29% of the time.
    The optimal code would use 0.5 bits to represent a
    , and 1.7 bits to represent b
    . Well, if we want to send a single one of these codewords, it simply isn’t possible. We’re forced to round to a whole number of bits, and send on average 1 bit.
    … But if we’re sending multiple messages at once, it turns out that we can do better. Let’s consider communicating two events from this distribution. If we sent them independently, we’d need to send two bits. Can we do better?
    Half the time, we need to communicate aa
    , 21% of the time we need to send ab or ba, and 8% of the time we need to communicate bb
    . Again, the ideal code involves fractional numbers of bits.
    If we round the codeword lengths, we’ll get something like this:
    This codes give us an average message length of 1.8 bits. That’s less than the 2 bits when we send them independently. Another way of thinking of this is that we’re sending 0.9 bits on average for each event. If we were to send more events at once, it would become smaller still. As n
    tends to infinity, the overhead due to rounding our code would vanish, and the number of bits per codeword would approach the entropy.
    Further, notice that the ideal codeword length for a
    was 0.5 bits, and the ideal codeword length for aa
    was 1 bit. Ideal codeword lengths add, even when they’re fractional! So, if we communicate a lot of events at once, the lengths will add.
    There is a very real sense in which one can have fractional numbers of bits of information, even if actual codes can only use whole numbers.
    (In practice, people use particular coding schemes which are efficient to different extents. Huffman coding, which is basically the kind of code we've sketched out here, doesn't handle fractional bits very gracefully -- you have to group symbols, like we did above, or use more complicated tricks to approach the entropy limit. Arithmetic coding is a bit different, but elegantly handles fractional bits to be asymptotically optimal.)

    Conclusion

    If we care about communicating in a minimum number of bits, these ideas are clearly fundamental. If we care about compressing data, information theory addresses the core questions and gives us the fundamentally right abstractions. But what if we don’t care – are they anything other than curiosities?
    Ideas from information theory turn up in lots of contexts: machine learning, quantum physics, genetics, thermodynamics, and even gambling. Practitioners in these fields typically don’t care about information theory because they want to compress information. They care because it has a compelling connection to their field. Quantum entanglement can be described with entropy.9 Many results in statistical mechanics and thermodynamics can be derived by assuming maximum entropy about the things you don’t know.10 A gambler’s wins or losses are directly connected to KL divergence, in particular iterated setups.11
    Information theory turns up in all these places because it offers concrete, principled formalizations for many things we need to express. It gives us ways of measuring and expressing uncertainty, how different two sets of beliefs are, and how much an answer to one question tells us about others: how diffuse probability is, the distance between probability distributions, and how dependent two variables are. Are there alternative, similar ideas? Sure. But the ideas from information theory are clean, they have really nice properties, and a principled origin. In some cases, they’re precisely what you care about, and in other cases they’re a convenient proxy in a messy world.
    Machine learning is what I know best, so let’s talk about that for a minute. A very common kind of task in machine learning is classification. Let’s say we want to look at a picture and predict whether it’s a picture of a dog or a cat. Our model might say something like “there’s a 80% chance this image is a dog, and a 20% chance it’s a cat.” Let’s say the correct answer is dog – how good or bad is it that we only said there was an 80% chance it was a dog? How much better would it have been to say 85%?
    This is an important question because we need some notion of how good or bad our model is, in order to optimize it to do well. What should we optimize? The correct answer really depends on what we’re using the model for: Do we only care about whether the top guess was right, or do we care about how confident we are in the correct answer? How bad is it to be confidently wrong? There isn’t one right answer to this. And often it isn’t possible to know the right answer, because we don’t know how the model will be used in a precise enough way to formalize what we ultimately care about. The result is that there are situations where cross-entropy really is precisely what we care about, but that isn’t always the case. Much more often we don’t know exactly what we care about and cross-entropy is a really nice proxy.12
    Information gives us a powerful new framework for thinking about the world. Sometimes it perfectly fits the problem at hand; other times it’s not an exact fit, but still extremely useful. This essay has only scratched the surface of information theory – there are major topics, like error-correcting codes, that we haven’t touched at all – but I hope I’ve shown that information theory is a beautiful subject that doesn’t need to be intimidating.
    To help me become a better writer, please consider filling out this feedback form.

    Further Reading

    Claude Shannon’s original paper on information theory, A Mathematical Theory of Communication, is remarkably accessible. (This seems to be a recurring pattern in early information theory papers. Was it the era? A lack of page limits? A culture emanating from Bell Labs?)
    Cover & Thomas’ Elements of Information Theory seems to be the standard reference. I found it helpful.

    Acknowledgments

    I’m very grateful to Dan Mané, David Andersen, Emma Pierson and Dario Amodei for taking time to give really incredibly detailed and extensive comments on this essay. I’m also grateful for the comments of Michael Nielsen, Greg Corrado, Yoshua Bengio, Aaron Courville, Nick Beckstead, Jon Shlens, Andrew Dai, Christian Howard, and Martin Wattenberg.
    Thanks also to my first two neural network seminar series for acting as guinea pigs for these ideas.
    Finally, thanks to the readers who caught errors and omissions. In particular, thanks to Connor Zwick, Kai Arulkumaran, Jonathan Heusser, Otavio Good, and an anonymous commenter.

    More Posts

    Understanding Convolutions

    Groups & Group Convolutions

    Neural Networks, Manifolds, and Topology

    Visualizing Representations

    Deep Learning and Human Beings



    1. It’s fun to use this to visualize naive Bayesian classifiers, which assume independence…↩
    2. But horribly inefficient! If we have an extra symbol to use in our codes, only using it at the end of codewords like this would be a terrible waste.↩
    3. I’m cheating a little here. I’ve been using an exponential of base 2 where this is not true, and am going to switch to a natural exponential. This saves us having a lot of log(2)
  4. s in our proof, and makes it visually a lot nicer.↩
  5. Note that this notation for cross-entropy is non-standard. The normal notation is H(p,q)
  6. . This notation is horrible for two reasons. Firstly, the exact same notation is also used for joint entropy. Secondly, it makes it seem like cross-entropy is symmetric. This is ridiculous, and I’ll be writing Hq(p)
  7. instead.↩
  8. Also non-standard notation.↩
  9. If you expand the definition of KL divergence, you get:
    Dq(p)=∑xp(x)log2(p(x)q(x))
  10. That might look a bit strange. How should we interpret it? Well, log2(p(x)q(x)) is just the difference between how many bits a code optimized for q and a code optimized for p would use to represent x
  11. . The expression as a whole is the expected difference in how many bits the two codes would use.↩
  12. This builds off the set interpretation of information theory layed out in Raymond W. Yeung’s paper A New Outlook on Shannon’s Information Measures.↩
  13. If you expand the definition of mutual information out, you get:

    I(X,Y)=∑x,yp(x,y)log2(p(x,y)p(x)p(y))

  14. That looks suspiciously like KL divergence!
    What’s going on? Well, it is KL divergence. It’s the KL divergence of P(X,Y) and its naive approximation P(X)P(Y). That is, it’s the number of bits you save representing X
    and Y
  15. if you understand the relationship between them instead of assuming they’re independent.
    One cute way to visualize this is to literally picture the ratio between a distribution and its naive approximation:
    ↩
  16. There’s an entire field of quantum information theory. I know precisely nothing about the subject, but I’d bet with extremely high confidence, based on Michael’s other work, that Michael Nielsen and Issac Chuang’s Quantum Computation and Quantum Information is an excellent introduction.↩
  17. As someone who knows nothing about statistical physics, I’ll very nervously try to sketch its connection to information theory as I understand it.
    After Shannon discovered information theory, many noted suspicious similarities between equations in thermodynamics and equations in information theory. E.T. Jaynes found a very deep and principled connection. Suppose you have some system, and take some measurements like the pressure and temperature. How probable should you think a particular state of the system is? Jaynes suggested we should assume the probability distribution which, subject to the constraints of our measurement, maximizes the entropy. (Note that this “principle of maximum entropy” is much more general than physics!) That is, we should assume the possibility with the most unknown information. Many results can be derived from this perspective.
    (Reading the first few sections of Jaynes’ papers (part 1, part 2) I was impressed by how accessible they seem.)
    If you’re interested in this connection but don’t want to work through the original papers, there’s a section in Cover & Thomas which derives a statistical version of the Second Law of Thermodynamics from Markov Chains!↩
  18. The connection between information theory and gambling was originally laid out by John Kelly in his paper ‘A New Interpretation of Information Rate.’ It’s a remarkably accessible paper, although it requires a few ideas we didn’t develop in this essay.
    Kelly had an interesting motivation for his work. He noticed that entropy was being used in many cost functions which had no connection to encoding information and wanted some principled reason for it. In writing this essay, I’ve been troubled by the same thing, and have really appreciated Kelly’s work as an additional perspective. That said, I don’t find it completely convincing: Kelly only winds up with entropy because he considers iterated betting where one reinvests all their capital each bet. Different setups do not lead to entropy.
    A nice discussion of Kelly’s connection between betting and information theory can be found in the standard reference on information theory, Cover & Thomas’ ‘Elements of Information Theory.’↩
  19. It doesn’t resolve the issue, but I can’t resist offering a small further defense of KL divergence.
    There’s a result which Cover & Thomas call Stein’s Lemma, although it seems unrelated to the result generally called Stein’s Lemma. At a high level, it goes like this:
    Suppose you have some data which you know comes from one of two probability distributions. How confidently can you determine which of the two distributions it came from? In general, as you get more data points, your confidence should increase exponentially. For example, on average you might become 1.5 times as confident about which distribution is the truth for every data point you see.
    How much your confidence gets multiplied depends on how different the distributions are. If they are very different, you might very quickly become confident. But if they’re only very slightly different, you might need to see lots of data before you have even a mildly confident answer.
    Stein’s Lemma says, roughly, that the amount you multiply by is controlled by the KL divergence. (There’s some subtlety about the trade off between false-positives and false-negatives.) This seems like a really good reason to care about KL divergence!↩

Saturday, August 19, 2017

Machine Learning for Humans

https://medium.com/machine-learning-for-humans/why-machine-learning-matters-6164faf1df12

Roadmap

Part 1: Why Machine Learning Matters. The big picture of artificial intelligence and machine learning — past, present, and future.
Part 2.1: Supervised Learning. Learning with an answer key. Introducing linear regression, loss functions, overfitting, and gradient descent.
Part 2.2: Supervised Learning II. Two methods of classification: logistic regression and SVMs.
Part 2.3: Supervised Learning III. Non-parametric learners: k-nearest neighbors, decision trees, random forests. Introducing cross-validation, hyperparameter tuning, and ensemble models.
Part 3: Unsupervised Learning. Clustering: k-means, hierarchical. Dimensionality reduction: principal components analysis (PCA), singular value decomposition (SVD).
Part 4: Neural Networks & Deep Learning. Why, where, and how deep learning works. Drawing inspiration from the brain. Convolutional neural networks (CNNs), recurrent neural networks (RNNs). Real-world applications.
Part 5: Reinforcement Learning. Exploration and exploitation. Markov decision processes. Q-learning, policy learning, and deep reinforcement learning. The value learning problem.
Appendix: The Best Machine Learning Resources. A curated list of resources for creating your machine learning curriculum.

Who should read this?

  • Technical people who want to get up to speed on machine learning quickly
  • Non-technical people who want a primer on machine learning and are willing to engage with technical concepts
  • Anyone who is curious about how machines think
This guide is intended to be accessible to anyone. Basic concepts in probability, statistics, programming, linear algebra, and calculus will be discussed, but it isn’t necessary to have prior knowledge of them to gain value from this series.

Why machine learning matters

Artificial intelligence will shape our future more powerfully than any other innovation this century. Anyone who does not understand it will soon find themselves feeling left behind, waking up in a world full of technology that feels more and more like magic.
The rate of acceleration is already astounding. After a couple of AI winters and periods of false hope over the past four decades, rapid advances in data storage and computer processing power have dramatically changed the game in recent years.
In 2015, Google trained a conversational agent (AI) that could not only convincingly interact with humans as a tech support helpdesk, but also discuss morality, express opinions, and answer general facts-based questions.
(Vinyals & Le, 2017)
The same year, DeepMind developed an agent that surpassed human-level performance at 49 Atari games, receiving only the pixels and game score as inputs. Soon after, in 2016, DeepMind obsoleted their own this achievement by releasing a new state-of-the-art gameplay method called A3C.
Meanwhile, AlphaGo defeated one of the best human players at Go — an extraordinary achievement in a game dominated by humans for two decades after machines first conquered chess. Many masters could not fathom how it would be possible for a machine to grasp the full nuance and complexity of this ancient Chinese war strategy game, with its 10¹⁷⁰ possible board positions (there are only 10⁸⁰atoms in the universe).
Professional Go player Lee Sedol reviewing his match with AlphaGo after defeat. Photo via The Atlantic.
In March 2017, OpenAI created agents that invented their own language to cooperate and more effectively achieve their goal. Soon after, Facebook reportedly successfully training agents to negotiate and even lie.
Just a few days ago (as of this writing), on August 11, 2017, OpenAI reached yet another incredible milestone by defeating the world’s top professionals in 1v1 matches of the online multiplayer game Dota 2.
See the full match at The International 2017, with Dendi (human) vs. OpenAI (bot), on YouTube.
Much of our day-to-day technology is powered by artificial intelligence. Point your camera at the menu during your next trip to Taiwan and the restaurant’s selections will magically appear in English via the Google Translate app.
Google Translate overlaying English translations on a drink menu in real time using convolutional neural networks.
Today AI is used to design evidence-based treatment plans for cancer patients, instantly analyze results from medical tests to escalate to the appropriate specialist immediately, and conduct scientific research for drug discovery.
A bold proclamation by London-based BenevolentAI (screenshot from About Us page, August 2017).
Law enforcement uses visual recognition and natural language processing to process footage from body cameras. The Mars rover Curiosity even utilizes AI to autonomously select inspection-worthy soil and rock samples with high accuracy.
In everyday life, it’s increasingly commonplace to discover machines in roles traditionally occupied by humans. Really, don’t be surprised if a little housekeeping delivery bot shows up instead of a human next time you call the hotel desk to send up some toothpaste.
In this series, we’ll explore the core machine learning concepts behind these technologies. By the end, you should be able to describe how they work at a conceptual level and be equipped with the tools to start building similar applications yourself.

The semantic tree: artificial intelligence and machine learning

One bit of advice: it is important to view knowledge as sort of a semantic tree — make sure you understand the fundamental principles, ie the trunk and big branches, before you get into the leaves/details or there is nothing for them to hang on to. — Elon Musk, Reddit AMA
Machine learning is one of many subfields of artificial intelligence, concerning the ways that computers learn from experience to improve their ability to think, plan, decide, and act.
Artificial intelligence is the study of agents that perceive the world around them, form plans, and make decisions to achieve their goals. Its foundations include mathematics, logic, philosophy, probability, linguistics, neuroscience, and decision theory. Many fields fall under the umbrella of AI, such as computer vision, robotics, machine learning, and natural language processing.
Machine learning is a subfield of artificial intelligence. Its goal is to enable computers to learn on their own. A machine’s learning algorithm enables it to identify patterns in observed data, build models that explain the world, and predict things without having explicit pre-programmed rules and models.
The AI effect: what actually qualifies as “artificial intelligence”?
The exact standard for technology that qualifies as “AI” is a bit fuzzy, and interpretations change over time. The AI label tends to describe machines doing tasks traditionally in the domain of humans. Interestingly, once computers figure out how to do one of these tasks, humans have a tendency to say it wasn’t really intelligence. This is known as the AI effect.
For example, when IBM’s Deep Blue defeated world chess champion Garry Kasparov in 1997, people complained that it was using "brute force" methods and it wasn’t “real” intelligence at all. As Pamela McCorduck wrote, “It’s part of the history of the field of artificial intelligence that every time somebody figured out how to make a computer do something — play good checkers, solve simple but relatively informal problems — there was chorus of critics to say, ‘that’s not thinking’”(McCorduck, 2004).
Perhaps there is a certain je ne sais quoi inherent to what people will reliably accept as “artificial intelligence”:
"AI is whatever hasn't been done yet." - Douglas Hofstadter
So does a calculator count as AI? Maybe by some interpretation. What about a self-driving car? Today, yes. In the future, perhaps not. Your cool new chatbot startup that automates a flow chart? Sure… why not.

Strong AI will change our world forever; to understand how, studying machine learning is a good place to start

The technologies discussed above are examples of artificial narrow intelligence (ANI), which can effectively perform a narrowly defined task.
Meanwhile, we’re continuing to make foundational advances towards human-level artificial general intelligence (AGI), also known as strong AI. The definition of an AGI is an artificial intelligence that can successfully perform any intellectual task that a human being can, including learning, planning and decision-making under uncertainty, communicating in natural language, making jokes, manipulating people, trading stocks, or… reprogramming itself.
And this last one is a big deal. Once we create an AI that can improve itself, it will unlock a cycle of recursive self-improvement that could lead to an intelligence explosion over some unknown time period, ranging from many decades to a single day.
Let an ultraintelligent machine be defined as a machine that can far surpass all the intellectual activities of any man however clever. Since the design of machines is one of these intellectual activities, an ultraintelligent machine could design even better machines; there would then unquestionably be an ‘intelligence explosion,’ and the intelligence of man would be left far behind. Thus the first ultraintelligent machine is the last invention that man need ever make, provided that the machine is docile enough to tell us how to keep it under control. — I.J. Good, 1965
You may have heard this point referred to as the singularity. The term is borrowed from the gravitational singularity that occurs at the center of a black hole, an infinitely dense one-dimensional point where the laws of physics as we understand them start to break down.
We have zero visibility into what happens beyond the event horizon of a black hole because no light can escape. Similarly, after we unlock AI’s ability to recursively improve itself, it’s impossible to predict what will happen, just as mice who intentionally designed a human might have trouble predicting what the human would do to their world. Would it keep helping them get more cheese, as they originally intended? (Image via WIRED)
A recent report by the Future of Humanity Institute surveyed a panel of AI researchers on timelines for AGI, and found that “researchers believe there is a 50% chance of AI outperforming humans in all tasks in 45 years” (Grace et al, 2017). We’ve personally spoken with a number of sane and reasonable AI practitioners who predict much longer timelines (the upper limit being “never”), and others whose timelines are alarmingly short — as little as a few years.
Image from Kurzweil’s The Singularity Is Near, published in 2005. Now, in 2017, only a couple of these posters could justifiably remain on the wall.
The advent of greater-than-human-level artificial superintelligence (ASI) could be one of the best or worst things to happen to our species. It carries with it the immense challenge of specifying what AIs will want in a way that is friendly to humans.
While it’s impossible to say what the future holds, one thing is certain: 2017 is a good time to start understanding how machines think. To go beyond the abstractions of armchair philosophy and intelligently shape our roadmaps and policies with respect to AI, we must engage with the details of how machines see the world — what they “want”, their potential biases and failure modes, their temperamental quirks — just as we study psychology and neuroscience to understand how humans learn, decide, act, and feel.
There are complex, high-stakes questions about AI that will require  our careful attention in the coming years. It is our duty to thoughtfully approach these questions from an informed and intentional standpoint.
How can we combat AI’s propensity to further entrench systemic biases evident in existing data sets? What should we make of fundamental disagreements among the world’s most powerful technologists about the potential risks and benefits of artificial intelligence? What are the most promising technical approaches to teaching AI systems to behave themselves? What will happen to human's sense of purpose in a world without work?
Machine learning is at the core of our journey towards artificial general intelligence, and in the meantime, it will change every industry and have a massive impact on our day-to-day lives. That’s why we believe it’s worth understanding machine learning, at least at a conceptual level — and we designed this series to be the best place to start.

How to read this series

You don’t necessarily need to read the series cover-to-cover to get value out of it. Here are three suggestions on how to approach it, depending on your interests and how much time you have:
  1. T-shaped approach. Read from beginning to end. Summarize each section in your own words as you go (see: Feynman technique); this encourages active reading & stronger retention. Go deeper into areas that are most relevant to your interests or work. We’ll include resources for further exploration at the end of each section.
  2. Focused approach. Jump straight to the sections you’re most curious about and focus your mental energy there.
  3. 80/20 approach. Skim everything in one go, make a few notes on interesting high-level concepts, and call it a night. 😉

Wednesday, August 16, 2017

Must-read Path-breaking Papers About Image Classification

http://blog.paralleldots.com/technology/deep-learning/must-read-path-breaking-papers-about-image-classification/


shares

Image Classification graph
The ILSVRC saw an exponential decline in top 5 error rate for neural network architecture for Image Classification over past few years
Deep Learning models for Image Classification have achieved an exponential decline in error rate through last few years. Since then, Deep Learning has become prime focus area for AI research. However, Deep Learning has been around for a few decades now. Yann Lecun, presented a paper pioneering the Convolutional Neural Networks (CNN) in 1998. But it wasn’t until the start of the current decade that Deep Learning really took off. The recent disruption can be attributed to increased processing power (aka GPUs), the availability of abundant data (aka Imagenet dataset) and new algorithms and techniques. It all started in 2012 with the AlexNet, a large, deep Convolutional Neural Network which won the annual ImageNet Large Scale Visual Recognition Challenge (ILSVRC). ILSVRC is a competition where research teams evaluate their algorithms on the given data set and compete to achieve higher accuracy on several visual recognition tasks.
Since then, variants of CNNs have dominated the ILSVRC and have surpassed the level of human accuracy, which is considered to lie in the 5-10% error range.
For us as humans, it very easy to understand contents of an image. For example, while watching a movie (like Lord of The Rings) I just need to see one example of a Dwarf and that allows me to identify other dwarves without any effort. However, for a machine, the task is extremely challenging because all it can see in an image is an array of numbers. If the task is to identify a cat in an image, you can appreciate the difficulty in finding a cat from this vast array of numbers. Also, cats come in all shapes, sizes, colors and poses, making the task even more challenging.

Image Classification Papers
How we see objects vs how a machine sees them
Based on our experience with Deep Learning for more than four years now, we are listing down some path breaking research papers that are a must-read for anyone associated with computer vision. In this blog-post we focus specifically on image classification and following posts will cover other areas such as object detection and localization.
Also, we have added our two cents about some upcoming algorithms which have the potential to shape the future of computer vision research.

Path-breaking Research Papers on Image Classification

AlexNet

In ILSVRC 2012, Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton presented AlexNet, a deep CNN. AlexNet clocked a 15.4% error rate, bettering the second best entry by more than 10% (The second best entry had the error rate of 26.2%). This impressive feat by AlexNet took the whole Computer Vision community by storm and made Deep Learning and CNNs the disruptions they are today.

Image Classification AlexNet
An illustration of the architecture of our CNN, explicitly showing the delineation of responsibilities between the two GPUs. One GPU runs the layer-parts at the top of the figure while the other runs the layer-parts at the bottom.
This was the first time a model performed so well on a historically difficult ImageNet dataset. AlexNet set the foundation of advanced Deep Learning. It is still one of the highest cited paper concerning Deep Learning, being cited about ~7000 times.

ZFNet

Matthew D Zeiler(Founder of Clarifai) and Rob Fergus won the ILSVRC in 2013, outperforming AlexNet by reducing the error rate to 11.2%. ZFNet introduced a novel visualization technique that gives insight into the function of intermediate feature layers and the operation of the classifier, both of which were missing in AlexNet.

Image Classification ZFNet
Network architecture of ZFNet
ZFNet opened the possibility of examining different feature activations and their relation to the input space using a technique called Deconvolutional Network.

VGG Net

Karen Simonyan and Andrew Zisserman of the University of Oxford created a deep CNN that was chosen as the second best entry in Image Classification task of ISLVRC 2014. VGG Net showed that a significant improvement on the prior-art configurations can be achieved by increasing the depth to 16-19 weight layers, which is substantially deeper than what has been used in the prior art.

Image Classification VGG
Macro-architecture of VGG Net. Credits: Davi Fossard
The architecture was praised because it was way simpler to understand (simpler than GoogleLeNet, winner of ISLVRC 2014) but still could manage optimum accuracy. Its feature maps are used a lot now in transfer learning and other algorithms that require pre-trained networks, like most GANs.

GoogLeNet

The winners of ISLVRC 2014, Christian Szegedy et al. presented a 22 layered neural network called GoogLeNet. It’s a type of Inception Model and solidified Google’s position in the Computer Vision space. GoogleNet clocked an error rate of 6.7%. The main hallmark of this architecture is the improved utilization of the computing resources inside the network. This was achieved by a carefully crafted design that allows for increasing the depth and width of the network while keeping the computational budget constant. GoogLeNet introduced the concept of Inception module, where not everything is happening sequentially, as seen in previous architectures but there are certain pieces of the network that are happening in parallel.

Image Classification Googlenet
A schematic representation of GoogLeNet architecture with the highlighted box being the inception module.
Noticeably, GoogLeNet’s error rate approached human performance (lies in the range 5-10%). GoogLeNet was one of the first models which conceptualized that CNN layers didn’t always have to be stacked up sequentially. The Inception module made sure that a creative and careful structuring of layers improves performance and computationally efficiency.

ResNet

Microsoft’s ResNet, developed by Kaiming He, Xiangyu Zhang, Shaoqing Ren and Jian Sun, is a residual learning framework to ease the training of networks that are substantially deeper than those used previously. The authors provided comprehensive empirical evidence showing that these residual networks are easier to optimize, and can gain accuracy from considerably increased depth.

Image Classification resnet
A residual block in ResNet architecture.
ResNet surpassed human performance with an error rate of 3.57% with a new 152 layer network architecture that set new records in classification, detection, and localization through one incredible architecture.

Wide ResNets

Sergey Zagoruyko and Nikos Komodakis presented this paper in 2016 with a detailed experimental study on the architecture of ResNet blocks, based on which they propose a novel architecture where they decrease depth of the entire network and increase width of residual networks. Increasing width is using more feature maps in residual layers. Although the common wisdom says that this might overfit the network, it actually works.

Image Classification wideresnet
Various residual blocks used by the authors
The authors named the resulting network structures Wide Residual Networks (WRNs) and showed that these were far superior over their commonly used thin and very deep counterparts. A Wide ResNet can have 2-12X more feature maps as compared to ResNet in its convolutional layer.

ResNeXt

ResNeXt secured second place in ILSCRV 2016. It is a simple highly modularized network architecture for image classification. The ResNeXt design results in a homogeneous, multi-branch architecture that have only a few hyper-parameters to set.

Image Classification resnext
A block of ResNeXt(right) compared to a block of ResNet(Left)
This strategy exposes a new dimension, which the authors named “cardinality” (the size of the set of transformations), as an essential factor in addition to the dimensions of depth and width. Increasing cardinality is more effective than going deeper or wider when the capacity is increased. Thus, it fared better than both ResNets and Wide ResNets in accuracy.

DenseNet

Dense Convolutional Networks, developed by Gao Huang, Zhuang Liu, Kilian Q. Weinberger and Laurens van der Maaten in 2016, connects each layer to every other layer in a feed-forward fashion. For each layer, the feature-maps of all preceding layers are used as inputs, and its own feature-maps are used as inputs into all subsequent layers.

Image Classification densenet
A 5-layer dense block. Each layer takes all preceding feature-maps as input.
DenseNets have several compelling advantages such as alleviating the vanishing-gradient problem, strengthening the feature propagation, encouraging feature reuse, and substantially reducing the number of parameters. DenseNets outperformed ResNets whilst requiring less memory and computation to achieve high performance.

New architectures with promising future potential

The variants of CNN are likely to dominate the Image Classification architecture design. Attention Modules and SENets are going to become more important in due course.

SENets

The winning entry of ILSCRV 2017, Squeeze-and-Excitation Networks (SENet), works on Squeeze, Excitation and Scaling operations. Rather than introducing a new spatial for the integration of feature channels, SENets works on a new “feature re-calibration” strategy.

Image Classification SENets
A schematic representation of SENet model: Squeeze, Excitation and Scaling Operations
The authors explicitly modeled the interdependence between feature channels. SENets is trained to automatically obtain the importance of each feature channel and use this importance to enhance useful features. In the ILSVRC 2017 contest, SENet model obtained an incredible  2.251% Top-5 error rate on the test set.

Residual Attention Networks

Residual Attention Network, a convolutional neural network using attention mechanism which can incorporate with state-of-art feed forward network architecture in an end-to-end training fashion. The attention residual learning is used to train very deep Residual Attention Networks which can be easily scaled up to hundreds of layers.

Image Classification AttentionNetworks
Residual Attention Network Classification Illustration: Selected images illustrating that different features have different corresponding attention masks in Residual Attention Network. The sky mask diminishes low-level background blue color features. The balloon instance mask highlights high-level balloon bottom part features.

The Path Forward



unnamed
Credits: Waitbutwhy
Today, the processing power of a computer you can buy for $1000 is 1/1000th of the capacity of the human brain. By Moore’s law, we will reach computing power of human brain by 2025 and all of the humanity by 2050. AI’s effectiveness will only accelerate with time. As the availability of data and processing power are no longer holding researchers back, we can assume that the accuracy of Deep Learning models used for Image Classification is going to get better in due course. As a premier applied AI research group, we are here to be a part of this revolution.

Sunday, August 6, 2017

Image Annotation Tools

Fast Image Data Annotation Tool (FIAT)

FIAT enables image data annotation, data augmentation, data extraction, and result visualisation/validation.
  • annotate images for image classification, optical character reading (digit classification, letter classification), ...
  • extract data into different format (Caffe LMDB, OpenCV Cascade Classifiers, Tesseract ... ) with data augmentation (resizing, noise in translation / rotation / scaling, pepper noise , gaussian noise, rectangle merging, line extraction ...)
The philosophy of this tool is
  • to enable fast annotation : annotate data just by selecting the diagonal of the object, for a fixed ratio. Press Enter if the class is always the same. Type the letter of the class otherwise,
  • to be re-usable for different scenarios, and leave you free to build any other tool as input of the annotation process, using any pre-existing weaky classifier (depending on your case) or bounding box proposal algorithm such as selective search, to facilitate annotation with a list of rectangles to select or discard, by just typing the letter of the class or ESCAPE KEY,
  • to have the extraction tool act like a monad, so that you can apply transformation in any order, at any stage of your process, the format remaining the same : given a directory and a CSV file, extraction tool will produce a new directory and CSV file, in the same format, by default,
  • to feed any classification / training process,
  • to be usable for visualisation and export : a visual check that the data is correctly annotated, after manual annotation, extraction, or even after your own bounding box prediction algorithm if it uses the Output class to its produce results.
Requires OPENCV 3 and Google Protobuf.
https://github.com/christopher5106/FastAnnotationTool

LabelImg is a graphical image annotation tool and label object bounding boxes in images 

https://github.com/tzutalin/labelImg

Saturday, August 5, 2017

Neural Style Tensorflow

https://github.com/cysmith/neural-style-tf

This is a TensorFlow implementation of several techniques described in the papers:
Additionally, techniques are presented for semantic segmentation and multiple style transfer.
The Neural Style algorithm synthesizes a pastiche by separating and combining the content of one image with the style of another image using convolutional neural networks (CNN). Below is an example of transferring the artistic style of The Starry Night onto a photograph of an African lion:

Amazing Tensorflow Github Projects

https://sourcedexter.com/amazing-tensorflow-github-projects/#gettingStarted

Amazing Tensorflow Github Projects

Tensorflow is Google’s open source Deep learning Library. You can build a lot of machine learning based applications using this framework along with Python programming language. Being open source, many people build applications or other frameworks over Tensorflow and publish them on Github. In this article, I will share some amazing Tensorflow Github projects that you can use directly in your application or make it better to suit your needs.

Table of Content

  1. Tensorflow: An intro and getting started
  2. Neural Style
  3. Deep Speech
  4. Sentence Classification
  5. Image classification
  6. Conclusion

Intro to Tensorflow

If you already know what Tensorflow is, and how it works, I will suggest you skip to the next section. But if you are interested in learning Tensorflow with Python, then I will recommend you to visit this course Python for Data Science and Machine Learning Bootcamp. If you are a beginner, then this is perfect for you. As I mentioned earlier, Tensorflow is a deep learning library. Build and test deep neural networks with this framework. Deep learning has enabled us to build
Deep learning has enabled us to build complex applications with great accuracies. Whether it is to do with images, videos, text, audio, deep learning can solve problems in that domain. Tensorflow can be used to achieve all of these applications. Understanding the Tensorflow Concepts and basics isn’t difficult. The reason for its popularity is the ease with which developers can build, test and deploy machine learning application with tensorflow.  The Tensorflow GitHub projects shared in this article are what I have come across to be awesome. As and when I find more, I will keep updating this list.

Project 1: Neural Style

tensorflow github

This has to be one of the coolest Tensorflow Github Projects. The neural style is a process of transferring the style of one picture on to another with out losing out on the characteristics of the first picture. In simple terms, with this project, you can have your own Prisma like application built using Tensorflow. The painting style is combined with the lion’s image to get the first image above. You can combine multiple styles onto one image and also decide the percentage of style to be applied.
Tensorflow Github project link: Neural Style TF ( image source from this Github repository)

Project 2: Mozilla Deep Speech

This Tensorflow Github project uses tensorflow to convert speech to text.  Speech to text is a booming field right now in machine learning. Applications of it include virtual assistants ( like Siri, Cortana, etc)  in smart devices like mobile phones, tablets, and even PCs. People’s accents vary across the world and due to that, speech to text conversions are a difficult topic to crack. However, we can achieve great accuracies with deep learning in place.
Github Link: Mozilla Deep Speech

Project 3: Sentence Classification with Tensorflow

Sentence classification refers to the process of identifying the category of a sentence. For example, if you have a sentence ” The food was extremely bad”, you might want to classify this into either a positive sentence or a negative sentence. This is called sentiment analysis. Now, even in this concept, there are a lot of complexities where categorization of sentences becomes difficult because of the sentence structure. With the convolutional neural networks, we can try to build a strong text based classifier.
Github Link: Sentence classification with CNN

Project 4: Image classification/ Object Recognition

tensorflow github








Image classification refers to training our systems to identify objects like a cat, dog, etc, or scenes like driveway, beach, skyline, etc. The scope of computer vision is huge. From face recognition to emotion recognition, to even visual gas leak detection comes under this category. Though the procedures and pipelines vary, the underlying system remains the same.
I have created the following Tensorflow GitHub repository which has two parts associated with it. First part is where you can setup a tensorflow based classifier just to test it out. In the second part, you can train your own models to identify those classes.
GitHub project link: TF Image Classifier with python

Conclusion on Tensorflow Github Projects

I hope that you have found these projects to be awesome. You can build on top of these or use it as it is. The best way to learn is to actually do something. If you are a beginner, then it’s an amazing investment to buy a course and make use of it completely. Here is the link to the course: Python for Data Science and Machine Learning Bootcamp .You can use a few coupon codes “JULY15UDEMY” or “GROUPONUDEMY” or “UJ1L202” which you can use to get up to 95% off. This reduces the price to just $10.
Do you have any Tensorflow Github project? Let me know in the comments below and you might get your project featured on the next update of this blog post!