<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Patrick Mesana on Medium]]></title>
        <description><![CDATA[Stories by Patrick Mesana on Medium]]></description>
        <link>https://medium.com/@patrickmesana?source=rss-ebee5d00b24b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NMJFbqBFmSlIl4tq.jpg</url>
            <title>Stories by Patrick Mesana on Medium</title>
            <link>https://medium.com/@patrickmesana?source=rss-ebee5d00b24b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:43:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patrickmesana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Short Text Analytics Web tool (React + D3.js)]]></title>
            <link>https://medium.com/@patrickmesana/textlab-nlp-and-text-analytics-react-components-d83acee20288?source=rss-ebee5d00b24b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d83acee20288</guid>
            <category><![CDATA[text-analytics]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[text-mining]]></category>
            <dc:creator><![CDATA[Patrick Mesana]]></dc:creator>
            <pubDate>Wed, 29 Aug 2018 17:18:09 GMT</pubDate>
            <atom:updated>2022-02-08T21:01:49.733Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple of months ago I finished my Master’s degree at<a href="http://www.hec.ca/en/"> HEC Montreal </a>in Business Analytics. My research was on extracting topics/trends in thousands of textual employee feedbacks answering questions about their work environment and quality of life. If you are interested in my research, <a href="https://www.dropbox.com/s/18sgzg6to7rxa2d/PresentationOptimDays.pptx?dl=0">this</a> is a presentation I did at the <a href="https://www.gerad.ca/en/events/1532">Optimization Days 2018</a>, don’t hesitate to <a href="http://patrickmesana.com/">contact me</a> directly for more details.</p><p>This article is about the tools I developed during the last year. Like many Data Science projects, I spent most of my time on engineering and preparing my dataset. I decided to open source many parts you can find on a repository I named <a href="https://github.com/patrickmesana/textlab"><strong>TextLab</strong></a>.</p><p>In a nutshell, my approach to finding the main topics was to vectorise feedbacks (with or without dimension reduction) and then use clustering algorithms to select good aggregates of documents automatically.<br>I also used <a href="https://lvdmaaten.github.io/tsne/">t-SNE</a>, a dimension reduction technique for visualisation, to evaluate if my vectors and clusters made any sense.</p><p>At the end of my project, I realised a lot of the code I wrote could be reused for many text analytics problems, such as sentiment analysis.<br>Because I used a private dataset, I couldn’t open source my code immediately. Fortunately, there are many public datasets available I could use as a substitute. For fun**, I chose the <a href="https://www.yelp.com/dataset">Yelp Dataset </a>and selected all Las Vegas Caesars Palace textual reviews since 2016, which corresponds to 2393 reviews.</p><h3>Project Architecture</h3><p>My project is separated into 2 parts, an NLP pipeline and an Analytic Web App to help me explore results and find new insights. The following diagram gives you more details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*5b4Hz69GPp6VqifCHmvBTA.png" /></figure><h4>Why develop a web user interface when there are so many useful data visualisation libraries?</h4><p>The main reason is that the UI components I needed didn’t exist in libraries such as Bokeh or Vega.<br>For example, I developed a t-SNE explorer that allows you to look at points under a lense to validate clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B2cZGKLKUAKDz1GZDoEAKg.png" /><figcaption>Shows reviews talking about the buffet</figcaption></figure><p>One other reason is it’s also a lot easier to build a web UI than 10 years ago. Thanks to UI libraries such as React, you have a layer of abstraction that help you build “smart” components you can easily share with everyone.<br>To cut many boilerplate code, I used <a href="http://vx-demo.now.sh/">Vx</a>, a small React library that wraps D3 code into components. I built higher level components on top of it.</p><p>Having interactive UIs to explore the data is helpful. Even for just exploring the distribution of words in the reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smlJQhxjFxbHKWqVk7_KGA.png" /><figcaption>The distribution of words of the reviews</figcaption></figure><p>I don’t know if this code will help anyone else, but it’s my way of publishing my work and contributing to the Data Science community.</p><p>TextLab repository : <a href="https://github.com/patrickmesana/textlab">https://github.com/patrickmesana/textlab</a><br>My NLP Helpers : <a href="https://github.com/patrickmesana/nlpkit/tree/f4c42d7121437bbb31f12c5a7dfa47fa87db7514">https://github.com/patrickmesana/nlpkit</a></p><p>**My goal was not to achieve a complete analysis on this public (sub-)dataset. It was only useful to me for open sourcing my project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d83acee20288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modeling Dynamic Decision-Making]]></title>
            <link>https://medium.com/@patrickmesana/reinforcement-learning-for-managers-15b4030b5e87?source=rss-ebee5d00b24b------2</link>
            <guid isPermaLink="false">https://medium.com/p/15b4030b5e87</guid>
            <category><![CDATA[management]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[modeling]]></category>
            <category><![CDATA[decision-making]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <dc:creator><![CDATA[Patrick Mesana]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 16:14:51 GMT</pubDate>
            <atom:updated>2023-11-23T17:49:21.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*WHzoVB2Uuv4DykQ-9gB2uw@2x.png" /></figure><h3><strong>The Science Of Dynamic Decision-Making</strong></h3><p><em>Note: I’ve refreshed and republished this article in light of the recent buzz around the Q* rumor on X, suggesting OpenAI’s discovery of a new AGI algorithm. Given the widespread speculation that this relates to Q-learning, it seemed like the perfect time to revisit and share these insights on dynamic and stochastic decision-making, which are more relevant than ever in our rapidly advancing tech landscape.</em></p><p>In today’s world, where uncertainty is the only certainty, mastering decision-making is crucial for any manager. This article unpacks the world of dynamic and stochastic decision-making, showing how these frameworks are not just academic concepts, but vital tools for navigating the complex decisions that modern leaders face every day.</p><p>In Eliyahu M. Goldratt’s book<a href="https://en.wikipedia.org/wiki/The_Goal_(novel)"> ‘The Goal’</a>, we meet the protagonist, Alex Rogo, who is at the helm of a struggling production plant plagued by chronic delays and dire prospects. Faced with a daunting three-month deadline to effect a turnaround, Alex finds an unexpected ally in his former physics teacher. This mentor guides him to a pivotal realization about the fundamental objective of any business.</p><blockquote>The goal of a company is to make money.</blockquote><p>While one might contest Goldratt’s focus on profit, the underlying principle is clear: defining the objective, whether for a company or in your professional life, is a personal and crucial decision. What, then, is the true goal if not monetary gain? Not fixing goals is like throwing darts at a wall without a target. How can you know you’re making the right decisions if you don’t know where you’re aiming at?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*L7s8CpY13w0sZrO4TmZnDw.png" /></figure><p>If you agree with this, you agree that running a business — much like navigating many life’s challenges — is like solving an <strong>optimization problem</strong>.</p><p>Once Alex Rogo understood this, he started measuring the contribution of every part of his plant’s manufacturing process. He managed to reduce the impact of bottlenecks, by rescheduling the production process or by exploiting the inventory capacity. I don’t want to spoil the book for you, but you can imagine it ends on a positive note.</p><p>This optimization framework is also a must if you want to start modeling your business problems mathematically. In fact, the first step is often specifying an <strong>objective function</strong>. If the objective function represents costs, you want to minimize it. If it represents the total rewards, you want to maximize it.</p><p>In the context of ‘The Goal,’ the factory’s daily operations are characterized by a series of interconnected decisions, each shaping future choices in what’s known as a <strong>dynamic decision process</strong>. Let use now explore how to model and solve such dynamic optimization problem in real-world scenarios.</p><h3>Optimal Planning</h3><p>Up to this point, our discussion has revolved around the concept of framing business challenges as optimization problems. Now, let’s move from theory to practice. We will model a straightforward dynamic problem, illustrating these principles in a tangible context.</p><p><em>The UniCo company wants to plan its production for the next three months. The demand for the product is 3 units per month. Production cost is $13 plus $2 per unit. Inventory cost is $1 per unit per month. Production capacity is 5 units per month, and inventory capacity is 4 units per month. Any excess of production goes directly to inventory.</em></p><p>This scenario qualifies as a dynamic problem due to the fluctuating inventory levels that change monthly, based on your production decisions. The choice of how many units to produce each month doesn’t just impact the immediate situation; it also shapes your decision-making in the months to follow</p><p>For example, this is one possible sequence of the decision process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*e1sLVd1RLBKQJDRsxFPHMw.png" /></figure><p>To effectively model this dynamic problem, consider the following guiding questions:</p><ol><li><strong>Breaking Down the Problem</strong>: Can you segment your problem into discrete steps? In our case, each step represents one month.</li><li><strong>Understanding the</strong> <strong>State at Each Step</strong>: What factors define the problem’s state at each step? Here, the critical variable is the inventory level. Knowing the current inventory level suffices, as past levels are not necessary for decision-making.</li><li><strong>Decision-Making</strong> : What choices are available at each step? Monthly decisions involve determining the number of units to produce, while adhering to demand, production capabilities, and inventory constraints.</li><li><strong>Evaluating</strong> <strong>Immediate Rewards or Costs</strong>: Is it possible to quantify the immediate impact of these actions at each step? For our model, we can calculate the cost each month based on production decisions and inventory levels.</li><li><strong>Defining the Objective</strong>: What are you aiming to achieve? In this scenario, the objective is to minimize the cumulative cost over the coming three months.”</li></ol><p>By integrating all these variables into an equation, you create a comprehensive model of the problem. However, to spare you the complexities of mathematical formulas, let’s visualize this concept through a graph. This graph will illustrate all possible states, offering a clearer understanding of the dynamics at play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*-oTRZNZI24pkzRL0QlACsA.png" /><figcaption>The x-axis is time, and the y-axis is the inventory level</figcaption></figure><p>Contrary to the intuitive approach of planning forward in time, our strategy will be the reverse. When you plan forward, the value of being in a specific state at a future point (for example, the significance of having an inventory level of 2 in the first month) remains unclear. To truly understand the worth of a current state, it’s essential to look ahead and then trace your steps backward to the present. This retrospective approach helps determine whether a particular state is advantageous or not.</p><p>This method is known as <strong>Dynamic Programming</strong>. Through this approach, we ultimately derive the cumulative value of every possible state within our model. This cumulative value is formally referred to as the ‘value function.’ It represents a key element in understanding and solving dynamic optimization problems.</p><p>After computing the value function through a backward approach, the process of making the right decisions becomes significantly more straightforward. This clarity transforms what might seem like a complex task into a relatively simple one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*EH1y_SlyQdogauvwloFIaA.png" /></figure><p>Why is this method so effective? The answer lies in the <strong>principle of optimality</strong>. Suppose you’ve identified the best trajectory from a given step to the final one. By moving just one step backward and selecting the optimal action for the next step, you establish the most efficient trajectory from this new point to the end. This process is repeated, step by step, moving backwards until you reach the initial stage. And there you have it: the optimal trajectory, meticulously charted from start to finish</p><p>You may have observed a particular pattern in this production problem. Whenever the inventory level exceeds 2, there’s a need to reduce it to below that threshold. Conversely, if the inventory falls below 3, it should be increased to a level above 2. This consistent approach to managing inventory levels is what we refer to as a <strong>policy.</strong> In the context of our problem, it’s not just any policy, but an optimal one, designed to reduce costs.</p><p>You could come up with your own policy and evaluate it with the value function. Often, if not always, we search for an optimal policy more than finding the best trajectory. The policy is there to guide you. It tells you how to behave in all situations: if something goes wrong and you fall into a surprising state, your policy keeps you on an optimal track.</p><p>While the example we’ve just discussed was straightforward and deterministic, devoid of any randomness, it represents a relatively simplified scenario. In the real world, however, decision-making often involves navigating through uncertainties. This complexity adds a layer of unpredictability to the modeling process. Acknowledging this, our next chapter will delve into strategies for making decisions when faced with such uncertainty.</p><h3>Stochastic Processes</h3><p>In your model, consider the selling price per unit as an exogenous variable, fluctuating based on market demand and known only at each month’s start. This uncertainty raises a critical question: should your planning approach or policy change?</p><p>If reliable data on price variations is available, you can create a distribution of potential prices, allowing for informed decision-making despite the uncertainty of this variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*_eoaUWYkm-Li8vdDY0yMaA.png" /><figcaption>x-axis is the price, y-axis is the probability</figcaption></figure><p>Yet, the question remains: how do you make decisions when probabilities are involved? The answer largely hinges on your level of risk aversion.</p><p>In 1947, John von Neumann and Oskar Morgenstern developed a framework to help you decide in uncertain circumstances. It’s <strong>the utility theorem</strong>. It shows that, under certain axioms of rational behavior, you will behave as if you are maximizing the expected utility of potential outcomes.</p><p>What does it mean for dynamic programming?<br>In the deterministic case, we were taking the value of the best action in each iteration. In the stochastic case, we take <strong>the expected value of all actions </strong>at a given state, and we plan accordingly.</p><p>The decision-making process we’re now examining is stochastic in nature, fitting into the category of a <strong>Markov Decision Process (MDP)</strong>. MDPs are characterized by the Markov property, which posits that the future can be predicted solely based on the present state, eliminating the need to consider the entire history of events. In short, an MDP is applicable when the current decision affects future decisions, and the current state contains all the information we need from the past.</p><p>The Markov Decision Process (MDP) is a powerful model, applicable regardless of whether you view the world as deterministic or non-deterministic. What’s your perspective? Are you convinced that an MDP underlies every problem now?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*-qGPE4XTGqZPWiB2Eabirg.png" /></figure><h3>Model Free</h3><p>There is just one small problem with this picture.</p><p>To do <em>planning</em> with dynamic programming, we need a value function. Having a value function means having a model of the world. We have to know the dynamics of the world, and we have to frame it as an MDP.</p><p>When we lack a model of the world, or when the dynamics of the environment are unknown, we find ourselves in a model-free situation. In such cases, traditional planning becomes challenging, if not impossible, due to the absence of a clear framework to guide our decisions.</p><p>Game Over? Not quite. The solution lies in assuming the existence of an MDP. By actively experiencing the environment, assessing the costs or rewards of our actions, we can learn and adapt. This experiential learning becomes our guide in the absence of a predefined model.</p><h4>Welcome to <strong>Reinforcement Learning!</strong></h4><p>The framework for tackling such model-free scenarios, known as Reinforcement Learning, isn’t drastically different from what we’ve already discussed. It builds upon the existing principles of decision-making and optimization, but introduces a few additional nuances to ensure its effectiveness in these more unpredictable situations.</p><p>In a stochastic process, the value function, as previously explained, denotes the expected value of all possible actions for a given state across all states. However, in a model-free context, we lack prior knowledge of the value of actions. Instead, we learn by making decisions within the environment and assessing the rewards or consequences of transitioning into new states. For instance, while driving a car, it may be challenging to quantify the cost of each individual action leading to an accident. But, we can approximate the overall cost of the accident itself.</p><p>The first trick involves defining a <strong>Q-value function</strong>. This function represents the expected value of all states given that I took a decision while being in a specific state. Each time a decision is made and feedback is received, this Q-value function can be updated with the new information. This process is analogous to calculating a sample mean in basic statistics, especially in how it can be computed incrementally. Understanding this principle is crucial for effectively updating our estimates of the Q-value function.</p><p>Once I have a reasonably accurate estimate of the Q-value function, I can engage in a bit of planning by adopting a ‘greedy’ approach — choosing the best action based on the current information for one step. Through numerous iterations, the goal is to develop a robust policy. However, this leads to one of the primary challenges in Reinforcement Learning: uncertainty about the true value function. This uncertainty raises a critical question — which states should be explored next? Without complete certainty, there’s always the risk of overlooking states that could yield better rewards.</p><p>This is called <strong>the Exploration-Exploitation dilemma. </strong>You want to find balance between exploring new states to gather more information and exploiting those states that are already known to yield favorable outcomes.</p><h3>The curse of dimensionality</h3><p>Sometimes, the complexity of the world makes it overly optimistic to assume that mere experiential learning will enable us to accurately estimate the value function and develop an optimal policy. In such cases, it becomes necessary to introduce a certain level of bias into our perception of the world.</p><p>One effective approach to overcome this ‘curse of dimensionality’ is Model-based Reinforcement Learning. This strategy involves creating a sufficiently accurate Markov Decision Process (MDP) that represents the world, followed by detailed planning based on this model.</p><p>To conclude this article, I’d like to present a diagram from Nate Silver’s lectures. It elegantly places Reinforcement Learning at the intersection of multiple disciplines, showcasing its central role in integrating various perspectives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCLK308Ks9eofDUstcPCFw.png" /></figure><h4>References</h4><p><em>- I took the little production problem from a Dynamic Optimization class I followed in 2016 at HEC Montreal given by Michèle BRETON. Also, I thank her for many great insights on this topic.<br>- I watched all David Silver’s lectures on RL and took a couple of diagrams out of his slides. You can find the first lecture </em><a href="https://www.youtube.com/watch?v=2pWv7GOvuf0"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15b4030b5e87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Learning Class Project Journal — Day3]]></title>
            <link>https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day3-d3226fe944a4?source=rss-ebee5d00b24b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3226fe944a4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Patrick Mesana]]></dc:creator>
            <pubDate>Sun, 30 Apr 2017 03:58:25 GMT</pubDate>
            <atom:updated>2019-01-27T19:39:14.075Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@patrickmesana/deeplearning-project-conditional-image-generation-day1-c9ff38e2bfc8">Early on</a>, while I was working on <a href="https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day2-ebadbf3ce1a">deep autoencoders</a>, I had an idea. Could we train the autoencoder with complete images then train with corrupted images? I tried it, didn’t work. The network was not stabilizing for weights associated with the pixels in the middle of the image, most of the time I was getting black centres. I gave up and went on with other inconclusive strategies until I realized what I was searching for is a…</p><h4>GAN</h4><p>More specifically, a <a href="https://arxiv.org/abs/1511.06434">Deep Convolutional Generative Adversarial Networks</a>. This type of network, also invented at University of Montreal by Ian Goodfellow, makes two tasks compete against each other. The first task is generating images, fake images, and the second task is distinguishing fake from real images. They compete because training is divided in two phases, the first one consists of generating images to deceive the discriminator, the second phase consists of training the discriminator. This is repeated many many times.</p><p>With this brilliant model, I can build a generative task similar to my autoencoder, and a classification task trained with both fixed/fake images and complete/real images.</p><h4>Implementation</h4><p>Easier said than done, I decided to look for existing implementations and found <a href="https://github.com/osh/KerasGAN">this one</a>. The code is broken and I spent time fixing it, but it gave me a head start.</p><p>I started by generating images from noise, just to get the grasp on GANs. Then, I moved to my original idea, I used my pre-trained convolution autoencoder as my generator. For every iteration, I train the discriminator on 5 batches (300 examples each) and the generator on 1 batch.</p><h4><strong>My model</strong></h4><p><strong>Generator:</strong> <a href="https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day2-ebadbf3ce1a">A Convolution autoencoder </a>with corrupted images as input. Learning rate of 1e-4 (Very important!)</p><p><strong>Discriminator :</strong></p><ul><li>Layers : 5 Conv layers, 4 MaxPooling, 2 Dense</li><li>Activations : LeakyReLU and Softmax as output</li><li>Regularizer : Dropout (0.25)</li><li>Loss : Categorical crossentropy</li><li>Optimizer : Adam</li><li>Learning Rate : 1e-3</li></ul><h4>Results</h4><p>I’ll save you the suspense, it was really hard to train this type of model. GANs converge slowly, balance between generator loss and discriminator loss is tricky, oscillating gradient …</p><p>Fortunately, I found a couple of good articles, especially<a href="https://github.com/soumith/ganhacks"> this one</a>, which guide me in reasonable directions. After many fails I managed to have a first version that seems to converge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVz-Yxz_QUuZriRX-WrVMw.png" /><figcaption>GAN v1 training</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*BQ3IS1gsvcrbatfdoFOo6g.png" /><figcaption>GAN v1 predicted images</figcaption></figure><p>Reading more about GANs, I found inpainting projects (<a href="http://bamos.github.io/2016/08/09/deep-completion/">this one</a> in particular) close to our task. I am realizing I am not training the network properly. My intuition was to pretrain the generative autoencoder and add adversarial loss to improve my blurry results. The problem with this logic is well explained in <a href="https://arxiv.org/abs/1607.07539">this paper</a>, the corrupted data is not drawn from the distribution of the dataset, so convergence in my case does not mean improvement.</p><h3>Project Conclusion</h3><p>I did not manage to implement a GAN in Keras that gives me qualitatively better results. I tried many things, no pretraining on discriminator (and generator), adding noise, adding L2 generative loss to fake discrimator loss, generating only the middle part and merge it with cropped image…</p><p>The main reason I think it didn’t work was my understanding on the theory behind, but I learned a lot since. GANs are not for beginners, DON’T GUESS ANYTHING! I also feel I pushed Keras to its limit, you can’t train the discriminator and generator without recompiling, CPU is used more than it should be and it’s a big hit on performance. In addition to that, BatchNorm in Keras/Theano is extremely slow. It’s still a great library, especially to build complicated graphs, but I don’t recommend it for GANs (at least for the moment).</p><p>The class project is now over. Since, I found an <a href="http://www.cc.gatech.edu/~hays/7476/projects/Avery_Wenchen/">article</a> very close to what I was trying to achieve, and they manage to make it work on celebA which contains only faces and much less image variance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3226fe944a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Learning Class Project Journal — Day2]]></title>
            <link>https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day2-ebadbf3ce1a?source=rss-ebee5d00b24b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebadbf3ce1a</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Patrick Mesana]]></dc:creator>
            <pubDate>Sun, 30 Apr 2017 03:57:40 GMT</pubDate>
            <atom:updated>2017-05-27T14:58:34.561Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@patrickmesana/deeplearning-project-conditional-image-generation-day1-c9ff38e2bfc8">Last time</a>, I showed my first results fixing corrupted images using undercomplete autoencoders.</p><p>I also tried overcomplete autoencoders, but I could not add many units to my layers without an acceptable performance cost. In fact, my GPU memory was rapidly full, and working configurations would take forever to run. Also, the results were awful.</p><p>Instead of wasting more time on fully connected networks, I decided to take a chance with convolution networks.</p><h4><strong>Convolution autoencoders</strong></h4><p>Not surprisingly, pixels that are nearby in space are more correlated than those further apart. Knowing this, you would expect a neural network to be more accurate on pixels closer to the missing middle’s borders. Fully connected networks are not that smart and do not take these connections into account.</p><p>A convolution network allows you to add this key aspect with one simple trick : Shared parameters across space.</p><p>Notions of undercomplete and overcomplete are not as useful in the convolutional context, but we still want to keep the idea of compacting the useful information, this is done with downsampling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*nUJo3XUaTfSryW5EyyYZ9g.png" /><figcaption><a href="http://www.inference.vc/">http://www.inference.vc</a></figcaption></figure><h4><strong>My first model</strong></h4><p>There are many ways to do downsampling, I chose convolution+maxpooling instead of striding because striding is more aggressive. You may lose a lot of information to downsample and for this task, capturing good features from the border is important.</p><ul><li>Layers : 7 Conv, 2 Maxpooling, 2 Upsampling</li><li>Activations : ReLu</li><li>Optimization : Adam</li><li>Loss : binary crossentropy</li><li>Input : Full image without middle</li><li>Target : Full image</li></ul><p>Since last time, I also added a couple of useful features to my code so I can understand what is going on. Below, you can see a summary of the model (just described) I trained for a 100 epochs (9h58):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZQqUVEQ83W4dlVLxY_wlQ.png" /><figcaption>Loss/Acc for ConvNet v1</figcaption></figure><p>Training loss is slowly converging and I was surprised to see validation loss following this curve. I decided to double the convolution layers to add more capacity to my network. I wanted to see if I could make my network overfit to training set. The loss curves were similar, slightly better, and the results as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*MY9Sd0pPvXndFf8fbAfrWQ.png" /><figcaption>Predictided images ConvNet v2</figcaption></figure><p>The images are blurry but there is a clear difference with the results obtained with FC networks. Keep in mind this is just a sample, these are not the best or the worst predictions.</p><p>I then tried to add techniques to improve these results. The first one was batch normalization. An advantage of BN is faster convergence without overfitting. I added BN for each conv layer. Loss did converge faster in terms of iterations, but each epoch took significantly longer to run. I am not sure why, maybe because of Theano backend. Another problem was the quality of the images, they were all darker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*nZIAVoA4XH4xqFyse5Hnkw.png" /><figcaption>ConvNet v1 with BatchNorm results</figcaption></figure><p>I also tried Dropout for fun, even though the network was not overfitting. The result was the opposite of what I expected, validation loss increased and the images were darker as well. I think this is mainly because it is dropping strong links (from the border) randomly and weakening the network instead of making it stronger.</p><blockquote>Hours and hours of computations…</blockquote><p>I tried many other variants, changing the droping rate, learning rate, leaky ReLU, different number of filters … Hours and hours of computations, but nothing significantly better than the results already shown. There’s probably a lot more I could have done with deep convolution autoencoders, but I feel I need more reading/experience on DL at this point.</p><p>You can track all these changes on <a href="https://github.com/patrickmesana/conditional-image-generation">Github</a>.</p><h4><strong>Conclusion</strong></h4><p>Convolution networks did not disappoint in their capacity of generating more “believable” images, but the results are still not satisfying. In the beginning, I assumed I could treat these corrupted inputs as images with a lot of noise, and it justified the use of autoencoders. But the missing part is too big, it seems all the networks I have been working on are lacking “imagination”.</p><p>Stay tuned for <a href="https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day3-d3226fe944a4">more</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebadbf3ce1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Learning Class Project Journal — Day1]]></title>
            <link>https://becominghuman.ai/deeplearning-project-conditional-image-generation-day1-c9ff38e2bfc8?source=rss-ebee5d00b24b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9ff38e2bfc8</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[autoencoder]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Patrick Mesana]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 02:00:47 GMT</pubDate>
            <atom:updated>2017-05-27T14:57:55.684Z</atom:updated>
            <content:encoded><![CDATA[<h4>Building a Generative Neural Network that can fill the missing center of an Image</h4><p>I am taking Montreal University’s deep learning graduate course, given by one of the pioneer of deep learning, <a href="https://aaroncourville.wordpress.com/">Aaron Courville</a>.</p><p>The class project consists of building a generative neural network that can fill the missing center of an image. <br>Images have a 64x64 resolution and the missing center is 32x32, which is quite a lot. The dataset also contains sentences, attached to each image, describing the scene in the center.</p><p><strong>Training set : ~82K images and sentences</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*L3WJN3P-hTphjGxR2L19XA.png" /><figcaption>Inputs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*5ZJTw_2Acx8t81JhMdyaBQ.png" /><figcaption>Targets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*1ShKcU092pmCbkEN2U5Dyw.png" /><figcaption>Text caption for the first image on the left</figcaption></figure><p>If you want to read the full project description, here’s <a href="https://ift6266h17.wordpress.com/project-description/">the website</a>.</p><h4><strong>What to do?</strong></h4><p>Since I am new to the field, I will not start by implementing papers I don’t fully understand, I will take this opportunity to work iteratively and keep it simple.</p><p>First, I am supposing that text captions won’t bring much to the table. I suspect that even with word embedding, because of sparsity, the added value of text to “pixel”context will be negligible. Thus, I will prioritize models on images only.</p><p>One type of generative networks we learned during the class are <strong>auto-encoders</strong>. I think they make sense in that context, because we can think of the inputs as “corrupted” images . <br>For my first day, I am going to explore this familly of models.</p><h4><strong>How to do it?</strong></h4><p>Although it would be fun to code this from scratch, the main goal of this project is to try many variants and get quick results. It was suggested to use <strong>Theano</strong>, but it is still to much boilerplate for me. I needed a higher abstraction, and I found the amazing <strong>Keras</strong> library.</p><p>Keras has a higher level Functional API and it allows you to use Theano or TensorFlow as backend, so you get powerful GPU optimsations for “free”. If you want to use Theano, as I did, you have to change the “backend” attribute of $HOME/.keras/keras.json.</p><p>Keras’s <a href="https://blog.keras.io/building-autoencoders-in-keras.html">blog</a> is also a great thing, I adapted their code to implement just what I needed.</p><h4><strong>First model : Fully connected deep auto-encoder</strong></h4><p>Hyper parameters:</p><ul><li>Number of layers : 4 (following under-complete scheme)</li><li>Batch size : 250</li><li>Epochs : 60</li><li>Optimization method : Adam</li><li>Activation Functions : ReLU for hidden layers and Sigmoid for output</li></ul><p><strong>Results after ~1.5h:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Lv5Fqz2vDQXvMrQHAtngkw.png" /><figcaption>autoencoder</figcaption></figure><p>At least it gets the colors ok… I realized one thing while waiting, my auto-encoder output layer has 64x64x3 units, but the task we have to perform on is to generate the middle part only (32x32x3). The loss is biased because it is calculated on complete images. I decided to change my model to output only the middle part. I don’t think we can call it an auto-encoder anymore, since the input is not included in the target.</p><p>Results of the second model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*29RARfWZxeTewtY8_SMsiw.png" /><figcaption>weird autoencoder</figcaption></figure><p>Close to borders of the middle part, the colors looks a tiny bit more accurate (qualitatively).</p><p>Loss of training the last model was around 0.62 (validation was close) and it was achieved in about 10 epochs. I clearly need better tracking of accuracy and loss, I will include this in my next models.</p><h4><strong>Conclusion</strong></h4><p>My auto-encoder implementation seems to capture brightness and colors, but the images are very blurry and not that great. I will move on to models more suited for images, replacing fully connected layers by convolution and pooling layers. See you <a href="https://medium.com/@patrickmesana/deeplearning-conditional-image-generation-day2-ebadbf3ce1a">tomorrow</a>.</p><p><a href="https://github.com/patrickmesana/conditional-image-generation">Github source code</a></p><p>Specs:</p><ul><li>GTX 1070 8GB RAM</li><li>Windows 10</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F8f5f8b%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F8f5f8b&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c43026df6fee7cdb1aab8aaf916125ea/href">https://medium.com/media/c43026df6fee7cdb1aab8aaf916125ea/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*bQlRSzFHJEmF4Q7PyrLgng.gif" /></figure><figure><a href="https://medium.com/becoming-human/artificial-intelligence-communities-c305f28e674c"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*2f7OqE2AJK1KSrhkmD9ZMw.png" /></a></figure><figure><a href="https://upscri.be/8f5f8b"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*v-PpfkSWHbvlWWamSVHHWg.png" /></a></figure><figure><a href="https://medium.com/becoming-human/write-for-us-48270209de63"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*Wt2auqISiEAOZxJ-I7brDQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9ff38e2bfc8" width="1" height="1" alt=""><hr><p><a href="https://becominghuman.ai/deeplearning-project-conditional-image-generation-day1-c9ff38e2bfc8">Deep Learning Class Project Journal — Day1</a> was originally published in <a href="https://becominghuman.ai/">Becoming Human: Artificial Intelligence Magazine</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>