Dev Talks

Artificial Intelligence (AI) in Javascript

Vincit Talks
May 22nd 2020
Vincit Dev Talks is a quarterly tech meetup held in Southern California. It’s designed to bring directors down from their towers and developers out from their cubicles. We feature speeches on a variety of topics ranging from marketing and business development to software engineering and design. Talks will be brief, but informative. Check out vincitdevtalks.com for upcoming events.
In this talk from our May 2020 event, Gant Laborde talks use cases for AI and Machine learning and using Javascript for building these solutions.
Gant Laborde is an owner of Infinite Red, mentor, adjunct professor, published author, and award-winning speaker. For 20 years, he has been involved in software development and continues strong today. He is recognized as a Google Developer Expert in Web and Machine Learning, but informally he is an “open sourcerer” and aspires to one day become a mad scientist. He blogs, videos, and maintains popular repositories for the community. Follow Gant’s adventures at https://gantlaborde.com
Gant: Hey everybody. Thank you so much for having me, by the way. I love how in this crazy world, where I fell asleep in one world and woke in a completely other. All traveling was gone. I was like, well, I'm not going to meet any new people or talk about anything interesting. Then here wonderful opportunities are still happening. So thank you for making this opportunity for everybody to chat about cool stuff. And I'll definitely say that a big part of how I'm going to talk about this is from the perspective of a mad scientist in a certain way, but it's really practical and financially viable information as well.
Gant: The small print, this is very useful and you can use this all kinds of different places, but I like the exciting, weird things. So I do have the chat open right now. I don't know if I'll see it while I'm actually chatting, we'll see. I would love to know if people can throw in there, are you afraid of AI? Are you like super familiar with it or have you just heard about it a bit? And then I'll curtail the presentation to fit the messages I've seen so far. So be sure to send that to all panelists and I'll continue to try to read as I go through.
Gant: So I'm going to share my screen and we are going to dig into adventures and JavaScript and AI and TensorFlow. Let me actually pull open over here. I think can get a chat window to show up over there. Let's do this. Chats, so I can stay along with the chats. Yes, this is everything I ever wanted, okay.
Gant: So let's dig in here and y'all can consistently tell me what's going on in the chat as we go through. What's good? Lots of people say they don't know too much about it. That's fantastic, because that's the presentation I'll go through real quick. So real quick. You've already heard a bit about me. I am the CIO at Infinite Red. I actually work with JavaScript quite often, especially with React Native stuff. I'm a core contributor back on the React Native Group and Google developer expert in web and machine learning.
Gant: I think that that places me in this unique position to say, "Hey, let's talk about AI and let's talk about AI in JavaScript." So I want to say, this is my Twitter account. Go follow me on Twitter. I give away all kinds of cool stuff. I'll give away one of our courses right after this. I'll put the code up on Twitter and pick one of you. So, that's a $300 value. Someone just go follow me right now, and then I will pick one of y'all and then I'll send you the code and then you can get that entire course for free. So I really hope that person I pick actually enjoys my talk.
Gant: Also, you might've seen me around GitHub. I have these ridiculous stickers and cartoons. I have a friend in Japan and she loves drawing these characters, so I have no limit to the amount of silly stickers in situations that I'm actually in, and I put these through my blog posts and plenty other presentation materials.
Gant: So seeing that people are not very familiar with AI, I want to take a moment and say, I used to be afraid of this entire concept. AI was like really complex mini max algorithms for board games, and I was excited because I'd play Street Fighter, and there's no person next to me, and it's playing just like an advanced player. I'm sitting there playing this game. I was super excited by it, but I didn't want to code all those, if then statements. And I didn't want to sit there and figure that out. And I was just like, all right, AI's interesting, but it's not for me. I'm going to develop websites. I'm going to develop cool stuff. And I think I'm not going to go into AI.
Gant: And then in 2012, the world woke up from a cool new initiative, which is machine learning. Machine learning is an old, old, old concept. But it's different. AI is a blanket term. If you have tic tac toe and it always goes in the same spot, you can technically say it's AI. It sits under that umbrella. But machine learning is this great aspect.
Gant: In 2012, we started to see machines get enough GPU cycles and enough data to start doing human like capabilities of being able to see what's in a photo or even be able to identify things better than a human can, and that's where things got super exciting. So I'm going to chat a little bit about that. I'm going to try to get that vibe out there in a second, but I don't know if everybody's actually enjoying themselves, but I don't think you know if you're enjoying yourself either.
Gant: So I have this website that'll help us all out. It's called enjoyingthe.show. And what it does is it accesses your webcam, and if you're smiling at it, it'll turn green and it tells you, and this is sitting on your machine. It's not sending it off to a server yet, although I should actually make that happen, that'd be really fun.
Gant: But right now, if you go to Enjoyingthe.show and you access your webcam, currently those of you in this room, they already have their webcam accessed, they're going to be able to share it. But if you smile, it'll turn green. If you're regular, it'll turn sort of like pale green. And if you make this face at it, it turns red. So, that's a lot of fun. So Enjoyingthe.show, just as a little taste of what kind of madness we can get into with JavaScript and staring at your face. And I promise all that information never leaves your machine. It's actually just running in your browser. And that's really cool.
Gant: And if you're having trouble with it, well, that's true that some faces just confound AI completely. No one actually knows what Nicholas Cage is doing at any given moment. It's not the machine's fault, it's his fault. So why now or why ever, where we... enjoying this sort of like philosophy of using data to train? And I'm going to give you an analogy.
Gant: Let's say that you were making Grammarly, and in Grammarly, you got a PhD in English and you know where comma splices are and you know all that information, and you've spent your entire life writing all the, if, then statements necessary for English and good, you've released it. And someone comes along and says, "Hey, we want this in Spanish." Then you go, "Oh no, I'm not going to get a PhD in Spanish. I'm not going to do all that. I'm done. Like I can't program that." Well, the cool thing about machine learning is if I train this, giving it 10,000 English books, then I just simply can train it giving it 10,000 Spanish books or Portuguese or Russian.
Gant: And I don't have to actually know the algorithms that's its coming up with anymore, I just have taught it how to actually interpret that data. So now, I've got this right ones trained for anywhere sort of functionality. And that's the exciting aspect to me. That's the part that really makes us powerful. And I was excited about that, but now it's becoming to get super human like in capabilities. And that just makes it even more exciting because if you have control of this, you can frog hop to the top of anything that you're actually applying machine learning for. People of course are applying it to finance, but training for the language, objects and sound in a generalizable way, that's the beauty of this.
Gant: So ultimately if you want that summed up, the TLDR, it's the power. That's why we do this. It's for the power. And we're a little bit behind the curve because Google figured this out. In 2012, they had less than four TensorFlow models in production or actually machine learning models in production. And then at the end of 2017, they had over 4,000.
Gant: You might've seen the funny pictures of somebody having a sword, trying to cut pancakes, what they're doing there is, it says like Google trying to insert machine learning into a small app, and I've got hundreds of these. It's great. But they are doing that, and they know why. This is a fantastic opportunity. Every single disruptor that we've seen in finding a way to get AI in there, and I think that's why the funding's going crazy. And they're getting machine learning in there. Like I said, AI is a very blanketed term.
Gant: So what kind of stuff can this do? And I think if you're you're new to this, I'm going to dig through few of these. So let's show you some examples, let's just get too excited. I was doing a keynote for Amazon and I had to find a way to get everybody's attention. So I went ahead and I had my good friend, Frank, act out an intro for me for when I did that keynote, and I deep-faked him into being Nicholas Cage. So if you look right here... You should be able to hear it now, maybe.
Gant: It's not a bad impersonation and we did this in a weekend, so it's not perfect, but it's really cool.
Gant: Okay. I'm going to get them off the screen. It's disturbing all of us, right? If you get the slides and you watch the whole video, it's five minutes of Frank doing that. I didn't ask for five minutes, that dude's weird. It's really funny. It actually ends in a movie trailer, so I suggest you check it out.
Gant: You might have seen this from CES 2018. This is a great application using a style transfer, like region detection and segmentation. This person's able to try on different hair dyes without actually having to dye her hair. It was instantaneously being able to identify what our hair would look like with that particular hair dye. And we had a company come to us once, "Hey, we want to see people try and make up, hit the purchase button, and then it tells them the makeup that they need for that particular design." And when we did this, it was really fun.
Gant: Had Leon working late into the night. I think he enjoyed himself a little too much, but with this pull requests came animated gifs like this, which I really, really appreciated. That was a lot of fun. Some of you might be using Crisp to cut out the background audio, which was really cool. You can generate heavy metal, 24 hours a day. Google, when they were working on TensorFlow and TensorFlow JS, or I think they were working with the into websites, they had this Quick Draw, I don't know if you've been to Quickdraw.withgoogle.com, but they had people training, where you're playing Pictionary directly in the browser with the AI. And that datasets available. So if you want to make a Quick Draw app or something tomorrow, you can. Really cool for Google to give that away.
Gant: We have recoloring photos with DealDefy. And those of you who live in an area where there's no parking, it's one of my favorites. Set up a Raspberry Pie to look for your parking and then alerts you. Send you a text message when it's available. So you can jump in your car and go grab that parking spot as fast as available.
Gant: I really like this example because it goes to show that this is one of the great things about the way we can use AI. It doesn't get tired, and it's very scalable. You could have this pointed out five different windows to try to find when you get one that's got a parking spot. And we can use this.
Gant: Someone came up with an idea to have automatic gun detection on all the cameras inside of a bank. And that was so cool. What a great application of this science, because a gun flashes for a second, the security guard, he might be just talking to someone being nice, but it'd be really cool if alerts says, "Look, this is what we saw." And then that's perfect. That's where a human should step in, But sitting there, if any of you have ever watched security cam footage, it is super boring. There's tons of webcams out there that you can get access to, no one watches any of those.
Gant: So if you found some of these examples kind of fun, and you feel yourself limited by the sort of aspect here of the terminology, I did create a hundred percent free course at academy.infinite.red. This is 100% free. You can get the terminology. It's a five day course, and you get a cool little certificate at the end of it. So academy.infinite.red. Get the terminology here and it'll hook you up with what's going on.
Gant: And I could tell you, people like it. We currently are nearing 5,000 people who have taken this class. And they really like it. So your question to me, of course, Gant you're full of BS, how did you know? I asked AI. So here's another part of the adventure. The name of the course is AI demystified, a five day mini course.
Gant: And the cool thing about this is I took the comments and then I grabbed a TensorFlow JS model, which is a model ready for JavaScript, and its a sentiment analysis, which tells me how positive or negative a particular review is. Took the comments in there, loaded it up, and then looked at the comments, and they're almost overwhelmingly positive. And the ones that were really, really negative were mistakes because it didn't understand what was going on because people were answering questions for one another.
Gant: So you could see here, this score says, this is hard. Got you. That's a 0.52, but then people are like interesting and truly awesome stuff, [inaudible 00:14:08]. So that was really cool. It was a great way to read through tons and tons of... And honestly, it's very good at understanding sarcasm. It's like, "Hey, this was badass." It doesn't see the word bad and then immediately think, "Oh, this is just bad."
Gant: It actually has, the structure of the sentence matters. So really cool stuff that people are doing. And you could use this for all kinds of neat stuff. So by the way, I do read the stuff too. That's me. I don't know why I'm on my side. I took a nap, apparently I need more coffee. So if you do leave comments, I will read your comments. Don't worry, I'm not going to ignore them.
Gant: I want to say a few things of what I think it should do real quick, and just throw these out there. One thing I'll say is that here's 14 years of volunteer labor mapped out on open street map. And I want you to watch this image real quick. Ready, boom. That is after 14 years, they had that original part, and then they added that as training data. And then Microsoft generated one pass of their model, added 125 million building footprints, and then gave that code back. And that's an open street map today, because no human should sit there and do that. And it's really cool. You could do inventory management. How many of you have been there on inventory night? It's hell.
Gant: And it could do the things that are really important to us like identify cancer. Help you while you're under surgery or even identify if you're sick before you're actually sick. Really cool stuff. There's research every day. I could basically fill many, many, many, many talks with talking about this, but I feel like since people haven't gotten involved with AI, it's important for me to kind of hit that really hard. You should be excited about this and you can stick it in any technology.
Gant: So I've used some terms here that you might not be familiar with, and I want you to be familiar with them. How many of you know what a model is, or I've heard that term? I know I used it a little while ago when I was talking about a sentiment analysis model. And this is because it comes from math. So if you're very familiar with the term of a model, that's easy, but if you've not, I've got the answer for you.
Gant: A model is a function, that's it. We're developers. We like building apps. We like building cool stuff, mobile, web. A model is a function. Like that thing you saw earlier, if I get this model and as data in, which was like the faces you had earlier, and then I get data out, which is like the sentiment of the sentence or the face or anything like that.
Gant: It's great for complete beginners. The course is great for complete beginners. This is all because I feel like this has been hidden by several companies and really we should be involved in this because I think in the next five years, whether you like it or not, you're going to have AI in your projects. So I'm just happy to be here telling you a model is a function nice and early, because you're all going to figure that out soon enough anyway, especially since you're coming from Google.
Gant: So where can you get these models? There's three different places. You can download them. You can train your own. So downloading them's like npm, train your own is like writing your own code. And that one, honestly, it's going to take a little while, but that's getting there. It's a little bit easier for you to do that.
Gant: And then what everybody actually does. You just look up the Stack Overflow, you find a model that's very close to what you want, and then you change it to do exactly what you want. That's it. If you had something that identified 50 types of birds, and then you modify that to find out 50 types of dogs, that's really easy to do. You do need all that data, but you don't need nearly as much. You only need to train for weeks and months on giant server farms to go ahead and get that kind of code to work.
Gant: So I think that this is a great place to do that. And so I'd say that the status though, is that we're still disconnected in all these different ways, we have online services which are awesome. You can go ahead and send your code off to a server, which is cool. It comes back with that stuff, but you don't want a micro surface too much. You might lose sight of what it was you're building, and that's where JavaScript's awesome.
Gant: Who here doesn't know JavaScript? I think even our designer on our team, he wrote some JavaScript the other day for some form validation. I was like, you're a coder now, Justin. So JavaScript's easier. It's a higher level language. It's not terribly complicated and it's everywhere. So ubiquitous language, we could put it on mobile. We could put it on websites. We could put it on Raspberry Pis, we could put on small helicopters, cool stuff like that.
Gant: And you say, "Oh yeah, that's a toy language. No one uses JavaScript for anything real." And we all know that that's not true. I think JavaScript's a great place for you to learn these things and you can access the GPU, that's how you can get this insane speed. The JavaScript can go through WebGL and access the GPU. So guess what? You can really kick butt and it's easy enough.
Gant: So, that's awesome. JavaScript today, you can use TensorFlow.Js, BrainJS, React Native, which could talk to Native with just a little bit JavaScript on top. It's really not that hard. So I have some code examples. If you're ever interested, here's one where you click on an item, it tells you what it is, that's a Granny Smith apple. And then it clicks on that, it thinks it's an espresso.
Gant: And then I didn't train it on tacos, so when I gave it a taco, it's a pencil box, very wrong. You can see the confidence was extremely low. It was like, I am very sure that if I had to guess, that's a pencil box and it didn't know. And you could use something like this for a picture and translate app. You could do that tomorrow. Just go ahead and download the identification model, walk around your house.
Gant: You remember when you took foreign language, you'd have to put post it notes everywhere to identify how to say that in a different language? I can just take a picture with your phone and identify what it is. This is 100% in JavaScript right here. Where we are actually building the detection of letters. This is classic on AI. It's called the endless dataset, so that people can actually draw what's going on there and you could see what it is. The code here is when you click these links.
Gant: We all know Hot Dog Not Hot Dog from Silicon Valley. Some of us can watch the show and some of them, it hits a little too close to home, but that was actually a real app written by the team. That's a real thing you can download. And so I decided to make a food 101, where you point it at different foods and it tells you what that food is. It can tell you up to 101 different foods, and it's using your live camera view for that. So there's the code in there. And then for the browser, let's get serious for a second here.
Gant: I created an important website, Nicholas Cage or Not, which is NicOrNot.com. You can go to it right now. And then it can in a photo identify where Nicholas cage is. This is groundbreaking. This is something that... I told you I'd have good business ideas, right? This is important stuff. So you can go ahead and get a photo of you and your friends and identify you or not. Or if you actually are Nicholas Cage, who knows?
Gant: And I also made a website called DeclarationOfIndependenceThief.com. Looking at the time, I'm going to skip some of the other fun stuff that I've made. This is really cool. If you have any decent content tracking, Facebook and Google have thousands of people who make sure the content's safe, and they're reading through the notes and they delete stuff. Why not have AI raise the alarm? We're 90% sure this is not good content. So if you have person to person interactions, it can give a warning. And then you don't have to have a team of thousands of people to read all that stuff. And it can never leave the machine, and it's constant.
Gant: So what's great about this is you don't have to have a big company. It's private. The AI doesn't want to send your stuff anywhere. It's specific. You can look at all the code yourself. It's consistent. It's not going to say something and then it changes its mind, and it's free. That's the library that we released for free. I have all kinds of cool stuff about that. But march along here, how do you make a model? Don't have time to talk about that. This link right here, take a snapshot.
Gant: If you want to train a model on your browser right now, you can go to this URL and you can click through the code and then train rock paper scissors on your machine. And it's how fast your machine's GPU is. It's how fast your machine is. But you'll be training rock paper scissors directly on the website. And at the end, you have a rock paper scissor classifier.
Gant: I can go into tons of detail on how this works, but I'm not going to do that one now. So I want to say that I hope this seems approachable. I hope that the aspects of this seem fun and interesting. It's coming to us as developers, for sure. But I want developers to come up with the cool things. And I've seen so many neat things come out in the past two years from people just doing fun, fun stuff.
Gant: And then of course, when we have clients, sure, is this an idea or not? It's like the thing, but once you've made Nicholas Cage or not, you can make an ID or not. Right? You can kind of figure that stuff out. So I'll leave you with a quote here. "Re-imagining everything inspires science." And that famous quote was done by a bot, inspirobot.me. Yeah, we had the bot do the quote that I'm going to close with.
Gant: I have a course that I teach. It's a course online. I am going to give one of these away to one of you. It's a fun course, definitely check it out. If you don't win it, there's a 20% off. That's the code I give, Ganttalk. To People who have actually watched me talk. You don't need to do that. Don't give that code out if they haven't watched me talk. So there's the other stuff that's old, over 3000 students. We're really far beyond that.
Gant: Last pieces here. And I know I'm a little bit over time. I have a Twitter account where I like to post fun, cool machine learning examples in, it's @FunMachineLearn. The hashtag's doing really awesome. I'm not sure why, but everybody seems to be using it. So that's good. So you could definitely follow along there.
Gant: And I also started a newsletter called AI-FYI.com, which is basically like the in case you miss it of the Twitter account. So if you like consuming things on Twitter or newsletter or both, you can definitely see some more ridiculous examples there and some educational content.
Gant: I have to say thank you to the awesome people at Infinite Red who constantly let me be a mad scientist for them. I love that. I always have stickers. So if you ever see me at a conference, ask for one, I will give you a cool sticker. And with that, definitely let's keep in touch.
Rachel: Well, thanks so much Gant, that was really entertaining. I love all the Nick Cage references. Earlier on. We've gotten a few questions, but earlier in the chat, before I forget it, one question that I saw come up was what is the future of libraries like TensorFlow.JS for machine learning in the browser?
Gant: So here's an aspect that I'll say is that Google, they're really good at advocating for developers. And they're really good at helping developers grab this technology and they understand that they need to do an open source portion of this. I think financially, they stand to gain a lot more from regular TensorFlow, but to be in edge, to unleash it and give it to the community. TensorFlow.JS is taking off.
Gant: And so, I think their internal efforts have always been towards TensorFlow, but now we're starting to see if I build something in TensorFlow.JS, I throw a website up there, it doesn't matter, you can't crush my server, it's your machine. So hit it all you want.
Gant: There was this one website that was trying to turn people's photos into anime characters, and when I went to it, it was like, "Hey, our server is like crushed right now, please come back later." It's just not something that would have happened with putting it on the client side. So I think that Google has really amped up their TensorFlow.JS workflow. They hired a developer advocate, Jason Myers or Mayers, I'm saying his last name wrong. And he's been doing a great job. So if anything, we're going to see more and more websites doing some of the stuff that you used to have to get a dedicated machine and get all your Python settings figure it out to go ahead and do.
Rachel: Another question. How much math do you need to know how to use AI? Or can you just use other libraries?
Gant: Zero math. So if you would like to do the math and it's not hard math, it's linear algebra is just multiplication, addition, exponents, square roots, that's it. It's not hard math, it's just done with giant linear algebra matrices. And so if you want to get into that, have at it. You might find out something amazing, have fun. Andrew Ing's Stanford course is so good for that, but you don't have to know anything about math. You don't have to know anything, especially when we wrap up a library like I did for NSFWJS, it's like, give me the image. Done, here's your answers? And you don't really like, I don't even know what to do. You import it like a regular JavaScript import. I could wrap it anywhere between those two, and I think that with auto ML, with TensorFlow.JS, and sort of where things are going, you can choose how much math you really want to kind of get into, but you don't have to have any.
Rachel: And last few questions. Another one was, is most of the AI work you've done web only? Or has any been for mobile with React Native?
Gant: Oh yeah. I've done React Native. Yeah, absolutely. So with React Native, that Food 101 is using Core ML in React Native. The middle one was using Brain JS with React Native and the other one was using TensorFlow Lite, and tying that in, it's easy. It's not hard at all. I'd say that the web stuff is easy for me to put out there. But if I want to put an app, like if I wanted to sell something, I wouldn't do it with a website, I'd do an app.
Rachel: And a final, but very important question. What else do our viewers need to do to enter the course raffle? In addition to following you on Twitter.
Gant: Just follow me on there. I'm going to take a look at the most recent followers, and you know what? I think I can DM you as soon as you follow me. I'm just going to pick one of you and I might send you a code and you'll be set. So if you don't have a code in the next hour, it went to someone else.
Rachel: Awesome. Thank you again so much Gant. We will be sharing this recording. And also thank you so much, Cameron and Viet for your talk as well. For our viewers, we will be sharing this via email, and I believe on our YouTube here over the next day. Be sure to follow along on all of the social media links that Gant shared as well as the video.
Rachel: I like the NicOrNot site. Just as a quick plug, so for those of you that have never attended Vincit Dev Talks before, we used to host them in person on a quarterly basis. Now with the transition to Zoom, we're hoping to do this on a more frequent monthly basis. So be sure to follow our social media at Vincit California, or our meetup page, Vincit Dev Talks for further information, so you can stay in the loop and be sure to participate in future chats as well.
Next up

Want invites to cool events and things?

Boom, Newsletter sign up form.