<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/human-in-a-i-loop/"></div></div><div><a data-url="https://www.r-bloggers.com/human-in-a-i-loop/" data-counturl="https://www.r-bloggers.com/human-in-a-i-loop/" data-count="horizontal" data-text="Human in A.I. loop" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://sanealytics.com/2016/09/09/human-in-a-i-loop/"> R – sane.a.lytics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A.I is out to get us. It will replace us all.. or maybe, it’s just another tool that we will get used to like calculators or iPhones.</p>
<p><img alt="fashion" class="wp-image-456" src="https://i1.wp.com/sanealytics.files.wordpress.com/2016/09/fashion.jpg?w=456&ssl=1" data-recalc-dims="1"></p>
<p>If you are reading this post, chances are you are familiar with Artificial Intelligence, Deep Learning, Neural nets.  I am not going to be pedantic and use them interchangeably.</p>
<p>If you don’t care for any of that, feel free to read this article as “Human in Machine Learning loop”. Or how to debug beyond metrics (smell a pattern in this blog?).</p>
<p>Let’s start with a practical example of something I built at <a target="_blank" href="https://www.renttherunway.com/">Rent The Runway</a>. RTR rents out high end designer dresses for a mass market price.  We have a lot of folks who love us. And they are not shy about tagging us on their Instagram posts.</p>
<p>Wouldn’t it be great if  we could show those Instagram photos on our product pages and help our customers find fashion inspiration through these high quality shots?</p>
<p>We already have photo reviews that our customers post on our site showing us how they wore it. It is a highly used feature for visitors. But customers have to submit to us directly for that to work.</p>
<p>My mind was set. It had to be done.</p>
<p>But how? While it is true that they tag <a target="_blank" href="https://www.instagram.com/explore/tags/renttherunway/">#renttherunway</a> or <a target="_blank" href="https://www.instagram.com/explore/tags/myrtr/">#myRTR</a>, they don’t tag the exact dress name.</p>
<p>Obviously I brought a tank to a knife fight and built a convolutional neural net. This A.I that would look at these natural images and classify them as one of the thousands of dresses that we have currently on site. I named it DeepDress, but probably should have called it Dress2Vec… too late now. I used <a target="_blank" href="http://torch.ch/">Torch</a> to train and Benjamin’s <a target="_blank" href="https://github.com/benglard/waffle">waffle</a> package to create an internal API that I can hit from any language. Since I have little patience, I used NVIDIA GPUs to speed up the training and tests.</p>
<p>I got all 30k Instagram posts at the time and I stored the metadata in Mongo (I know, I know but it’s great for unstructured).</p>
<p>Here is the code for that –</p>
<p></p>
<p>Then I looped through them and called my API to identify the dress and saved that.</p>
<p></p>
<p>Mission accomplished and moving on.</p>
<p>Well my friends, if that were the case, I wouldn’t have written this post. So here is how a production system is really built.</p>
<p>One problem I knew ahead of time is that our inventory changes over time as we retire older styles and acquire new ones. DeepDress did not know of some very new dresses and none of the old ones. Old ones aren’t an issue since we wouldn’t want to display them anyway but there is a cold start problem that I hadn’t solved at the time.</p>
<p>Another issue is that I had trained the algorithm only on our dresses. While that is our bread and butter, we also rent bags, earrings, necklaces, bracelets, activewear, etc. I always start simple for v1. This means there were bound to be things classified incorrectly as the convnet sweats bullets trying to figure out which dress that Diane Von Furstenberg minaudiere looks like. We could use a lower bound on the probability of most likely class, but what should that threshold be?</p>
<p>Besides the above red flags, even if the identification were 100% accurate (ha), it would make sense to have someone in RTR verify that the image is in fact, fit for display on our site and consistent with our branding.</p>
<p>What we need to build is a gamified quick truther thingy that all our 200 employees in main office can log in during their lunch break and rate a few items. It better be interesting and fast because they have important things to do. It wouldn’t hurt to get verification of the same image from a few different folks so we build our confidence. Then there are nice to haves like responsive, reactive, and other fancy words that mean fun to use.</p>
<p>I could have built this in ruby or react or something that pleases my web developer friends. But I am a data scientist who is very familiar with R, so I built another shiny little thing in an hour. I am in good company. My friend Rajiv also <a target="_blank" href="http://projects.rajivshah.com/sportvu/Traj_RNN.html">loves</a> <a target="_blank" href="http://projects.rajivshah.com/blog/2016/04/01/tensorflow_shiny/">understanding</a> his A.I. <a target="_blank" href="http://projects.rajivshah.com/blog/2016/04/05/rnn_addition/">creations</a> in R.</p>
<p>Rough outline on what we want –</p>
<ol>
<li>Start with a random seed for each session</li>
<li>Retrieve Instagram Images from that seed backwards</li>
<li>User has to choose one of N options</li>
<li>Upon choice, store the result back in Mongo</li>
<li>Automatically move on to the next one (shiny is responsive)</li>
<li>Every day, a job would restart the server, freezing what was done and starting on the next batch, moving back in time.</li>
</ol>
<p>First we set up the global.R to get the relevant Instagram posts we will verify –</p>
<p></p>
<p>Then we create ui.R that my colleagues will see –</p>
<p></p>
<p>Finally we need to hook up some logic –</p>
<p></p>
<p>And shiny does the rest. Here is what this looks like in practice –</p>
<p><a target="_blank" href="https://sanealytics.com/2016/09/09/human-in-a-i-loop/#gallery-177-1-slideshow">Click to view slideshow.</a></p>
<p>This was so successful that in the two weeks the POC was up, we had 3,281 verifications. Some colleagues (thanks Sam/Sandy) did as many as 350+ verifications over that time. It should be pointed out that besides an announcement email, there was no other push to do this.</p>
<p>We found that there were a significant number of posts that were not even dresses. I guess our fashionistas really love us. This is not a problem I knew about going into building this and was certainly not expecting high probability scores for the suggested class in some cases. It helped me fix it by adding a class for “not a dress” with actual training data (and noise).</p>
<p>Most importantly, we answered important questions like what this cute puppy wore.</p>
<p><img alt="puppy" class="wp-image-495" src="https://i1.wp.com/sanealytics.files.wordpress.com/2016/09/puppy1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p> </p>
<p>And if that isn’t the most satisfying result, I don’t know what is.</p>
<p>We have some amazing employees (hi Sam/Liz/Amanda) who have can remember single dress on site. For mere mortals, matching a photo to something we have is nearly impossible.</p>
<p>DeepDress A.I toiled through all 30k photos and narrowing each down to 3 possible choices from our thousands. But it is humans who really save the day. As a result we have a golden database of Instagram photos mapped to exact product that took advantage of both their strengths. Look at that – humans and A.I can play together.</p>
<p>Hopefully this example demonstrates why it is useful to use your resources (company employees) to check your systems beyond the metrics before releasing things in the wild. I end up using shiny a lot for these sort of internal demos because I slice and dice the results in R. But do them in whatever you are comfortable in and aggressively re-evaluate those choices should they reach production. For example, we will rewrite the truther in Ruby now that it will be production to comply with our other standards. For demos, I have no emotional attachment to any language (close your ears C++).</p>
<p>I’m sure you guessed that could not have been the <em>only</em> reason I built DeepDress and you would be right. But today’s not a day to talk about that.</p>
<p> </p>
<p> </p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sanealytics.wordpress.com/177/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/sanealytics.wordpress.com/177/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/human-in-a-i-loop/"></div></div><div><a data-url="https://www.r-bloggers.com/human-in-a-i-loop/" data-counturl="https://www.r-bloggers.com/human-in-a-i-loop/" data-count="vertical" data-text="Human in A.I. loop" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://sanealytics.com/2016/09/09/human-in-a-i-loop/"> R – sane.a.lytics</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/LWpz8fxBwI8"></a></div>