 I'm Karthik. So this would be a presentation on some talk, maybe a discussion, whatever you may call it, on sentiment analysis with TensorFlow. We'll also be discussing some details about how we can leverage Cloud and LPAPI, as well as we'll be talking about how to use the Google Cloud machine learning, the GPUs on Google Cloud to actually do some TensorFlow training as well. So there are mainly three topics. So let's begin. So yeah, so before I begin, let me give you a brief introduction to myself. As I introduced myself, I am Karthik. I'm currently a data science researcher at SAP Innovation Center Networks. That's right across the street, where my day job is to design models, so not the type of models that you think. So the models that we talk about are about neural networks, and so these are the models we talk about day in and day out. So that's the type of, so generally my work revolves around natural language processing. How do we deal with text? How do we understand what text is about? And how do we resolve text, the context in which someone has written something? So under this, we are actually working on the machine learning API, which is called the SAP CLIA, which is a broader framework, but today I'll be talking about the machine learning aspect behind what I'm working on. I'm also currently the Google Developer Expert in machine learning. So that's one more. And I'm a proud islander as of NTU, so yeah. So before I begin, I just want to know how many of you have just a show of hands? Have you written code in TensorFlow? So how many of you have written code in TensorFlow here? So we have two, three, four people. That's nice. So how many of you have written a deep learning network, maybe like a machine learning framework itself? So I think only four of you, so maybe that is even lesser. So I presume we have a big introductory audience here. So OK, so we'll still keep the content pretty technical, but the objective that this talk is trying to have is basically it's trying to target three types of audience, the theoreticians, basically people who have some introductory knowledge about natural language processing, someone who's interested to know what natural language processing about, someone who wants to know what sentiment analysis is and probably some business use cases that could come along with sentiment analysis. So the theoreticians, as I may call it, the practitioners are people who are actually involved in developing NLP things, but not particularly developing the NLP framework itself, but probably using some of the best practices for NLP and probably using an NLP API to actually integrate into another app or probably another business use case. So the practitioners is maybe another set of people. And so in this case, the second objective that we would try to deal with in this talk is basically figuring out how do we have NLP, how do we use these APIs and understand probably the scalability of what Google Cloud NLP API could give us. And the third one is basically the theoretical practitioners, so people who are both interested in the theory behind NLP, probably developing, writing on reading papers and having developing general purpose classifiers for TensorFlow and probably training a deep learning network itself. So these are the three objectives and the three types of audience that we are planning to cater to in this talk. Because this is actually being projected over the internet, I think there is some lag in what you might see, so probably I might have to be a bit more slower than if it was actually projected directly. So let's dive in. So going in, so what is sentiment analysis? So this is one of the biggest topics because it has quite a lot of influence on what it can do, what it can achieve. So this is a text that I would probably, this is taken from one of the data sets that was actually used. So probably could you tell me that whether this is positive, negative, neutral? Anyone? Is this positive? Yeah, it looks positive, that's correct. So the second one is this one. So could it be positive, negative? Yeah, it looks, I would say negative, yeah. Because it says shattered image, it is in complex. The third one, so this one is stuck in the past again, but at least this time he has something better to do than quote sitcom lines and try to woo Alicia Silverstone. So this again, could you tell me if it is positive or negative? So I can hear some negative, some positive here. So this is the kind of ambiguity that we are trying to deal with here. So there are some lines which are positive. It says Brendan Fraser is stuck here in the past again, but he's at least trying something good, not just who Alicia Silverstone, but actually this is negative. So according to the data set that we are trying to train, so we'll be training this as well. So this is actually a negative sentence. Let's move on. So there's a fourth one. So far from bewitching, the crucible tests the patient. So this is kind of again, kind of here and there, but this is actually negative. So these are all types of texts that we are trying to deal with and figure out what is happening. So what is the user or what is the text trying to convey? And how can we automate this? And these are the reasons why we want to actually understand sentiment analysis. We'll go deeper as to some of the use cases here. So one particular use case that is about probably some of the developers would be interested in understanding the app popularity. So I develop an app. I upload it on to, say, Google Play Store or the Apple App Store. And I want to know what does the people sentiment. So the predominant problem here is that I would rate something, so I would give it a 5 on 5. But I might actually give some complaints. So the reason here is that, so this is one of the reasons why YouTube actually removed the star rating, if you realize that. So because people are actually giving some stars without knowing what it actually meant. So let's see what happens here. So for example, let's take Pokemon Go. So in this case, Pokemon Go is still one of the biggest apps on Google Play Store. So if you see on the right, we have a five-star rating, which is saying that the AR function is one of the best. And he's never seen something like this before. But if you move out to the middle, I think it's not pretty clear. But it says the game has some issues, where if I don't have a reliable internet connection, it won't work. Which means no fun hunting Pokemon in exotic areas. You would think it might let you do something offline, but exploring. So the point here is that, although he's given three stars, the point is he's pretty ambiguous whether it's actually a full five star or a zero star or a one star. So this is the problem with star ratings. So you don't know exactly if your sentiment actually is reflective of the number of stars that you give. The third one that we would see is pretty straightforward. Over one million negatives. Congratulations, Zuzwa. So he's actually pretty going on the negative streak. So he's giving negative because of the fact that he sees that there are actually some low stars. So these are all the types of reviews that we have. And in general, as an app developer, I would like to know if these stars and the text itself actually has any correlation or not. So in general, not just the correlation, but what is the part of the text that is actually very useful? In this case, probably I would say he's given a three star because he's not able to find out that there is a reliable internet connection. So this is one part which I might highlight in this case. And this is actually something called the attention here. So we have a reliable internet connection. So in exotic areas, so these are all points which are going to contribute to why this is actually negative. So this is one example of what sentiment can do and what we can do with the analyzed sentiment. Moving on. So the next thing is one of the biggest issues is Twitter right now. So the effect that Twitter has on the stack market is actually pretty big. So for instance, I'm not sure if you remember the wonderful Donald Trump actually came up with a wonderful tweet about Boeing and him not actually taking up the order for Boeing for the Air Force One. And the minute he tweeted that, within a few hours later, Boeing's stock value actually plummeted. So the impact of Twitter or any social media text in particular has a big effect on stock markets. So in general, this is another big example of how much the negative trend is actually propelling another company's stock market value. For example, here what happened is everyone might know right now because we all travel frequently and invariably we would have heard this. Samsung Galaxy S7, the Note 7, had a huge problem. And then people started talking about it. So the more people spoke about it, actually the sentiment on the stock market was actually quite reflective about how the Twitter trend was. So there are also a few papers that discuss about how the Twitter sentiment or social media sentiment affects company's stock value. So all these contribute to the reason why we want to have or understand sentiment behind users and the feedback that they give. So some of the potential use cases. So there is some lag. So one of the biggest use cases is prediction. So as I said earlier, so analyzing stock market trends from tweets or probably news articles is a big area. So if you think that if you can actually have or develop some sort of ML framework that can actually sift through news articles or sift through the social media and figure out that there is some issue with some of the trends, some of the stocks that you're monitoring, then you are in for actually quite a big game here. Because doing a technical analysis or just looking at the star open and the close and then trying to build a neural network alone is not sufficient to actually understand the stock market. So in this case, this is trying to understand the emotion behind what affects the stock market value. The second case is where this is again market sentiment to a new product. So something like, for example, Samsung's Galaxy Note 7 was a prime example where people started giving some negative reviews. And I think there is one thing that started today as well about Samsung S8, so where there is a red tint. And I think it's going on again, and people are actually coming back with more Instagram photos. And it's actually becoming, I hope it does not become another Note 7. So that's the thing that's happening. So people are now starting to look at Samsung's stock value already. So this is the kind of impact that the sentiment of all these texts actually has. The third one is estimating a movie success. So for example, if we can actually come up with some way of figuring out what the reviews are saying and how this is actually impacting the revenues for the movie, then we can also have some way of understanding probably what will happen the next time we have something similar over here. One of the biggest, another areas of interest is on products. So how do consumers react to probably a new update? So for example, iOS, I think 10.3 was out a few weeks ago. And so immediately there were some people who actually came and said, I had some issues, and then some people. So these are all very important actually to a company to understand what are people talking about its products or probably its updates, its apps. So these are all important areas of interest. And of course, in politics, this becomes a very important topic because, for example, yesterday Theresa May had actually proposed an election in June, I think. Now there is already an impact on the stock market. So the British pound actually raised by two cents, I think. So everything deals with what we are saying as a sentiment versus it directly having an impact on the stock market or on the foreign exchange. So these are all prime examples where we can actually see there is a correlation with money here. So moving on, the last thing is the review itself again. So does the movie actually reflect commercial success? So that's one more point here. So the biggest question is why is sentiment analysis so hard? To deal with, if you're saying TLDR, then you're saying one of the problems is language, itself, the usage. And then the second one is sarcasm and the lingo. So we'll see what these three actually mean. In terms of language usage, we are seeing that this movie is just brilliant. Actors are first grade, but the camera work is shoddy at best. So this is again an example from all the data sets we have. If you see there are actually mixed positive as well as negative sentiments here. The first part of the sentence is brilliant. So it's positive. And the second part is OK. It's first grade, but the camera work is shoddy. So how do we actually rate this sort of review? So this is more like saying, OK, there is two out of three is good. So probably it's still 70% positive. So this is one way of doing it. But still this is difficult. This is one of the reasons why sentiment analysis is a big reason why we want to understand how we can see the sentiment here. Second one is the film runs for a slick 140 minutes. I was blown away by how true Einstein was after all. So this is sheer sarcasm. So what happens is if you throw this to a neural network or any machine learning framework that's trying to understand sentiment, what this will try to say is, OK, the film runs for a slick 140 minutes, which means that this has a positive sentiment. And the second thing is I was blown away by how true. So this is, again, these are all positive. So as a human being, we can understand what sarcasm is and how this actually makes sense to us. That is actually a negative review. But to an algorithm or someone who does not care about and then trying to come up with simply a classifier that's trying to understand the sentiment, this would actually fail miserably. So this is one another reason why sentiment analysis as just an algorithm will actually fail. The third one is very local. So this one was very interesting when I actually found it on one of the data sets. So OKlar, I double checked with the hairdresser already. He said, won't cut very short. He said, will cut until I look nice. So I don't know what this means. Maybe there's a discussion on why there was a haircut and then why the hairdresser was not going to cut it very short. But if you see, the point here is that local lingo and local sentiments, the cultural usage actually changes a lot of the sentiment. So if you train a neural network or any machine learning network on this data, it would invariably not understand what it's trying to say. So probably you will have a pre-trained model doing some sort of a test on this one. And then it would completely fail. Because some of the words highlighted over here in italics would have no sense to the model. So this is one of the reasons why it's important to understand local culture and why companies like Google are actually setting up local data centers where actually local sentiment is captured. So that's one reason again. So these are the three main reasons why sentiment analysis fails time and again moving on. So for us to do sentiment analysis, we still need to move from words to vectors because in the end, we are trying to feed text into a computer. So that's the reason why we are trying to move from word. So let's see how we could probably do that. So one of the reasons is that words are represented as features. And when we do that, we are trying to build a vector from possibly the words in the English language. So could I maybe, is there a guess about how many words are present in the English language? Any guess? Sorry? One million? So I'm talking about probably the most widely used words. So one million is, I think, still correct. But according to Oxford, I don't know, the Oxford dictionary is here. It says that there is actually 171476 words. So if you do a Google search for how many words are there in the English language, this is the first answer that it gives and the link to that. So effectively, when we want to build a word, probably an index, we would still require some vector of, say, probably 171476. So the size of the vector would be as big as that to represent a word then, because we are trying to represent it as an index. So now the challenge here is that if I'm going to, say, have a 10 word sentence, then what will happen is effectively I would have to have a large matrix, which is going to be a 10 by 171k matrix. So that's huge. So just to represent a sentence, which is just 10 words, it's probably a waste of compute and a waste of space. So that's the biggest problem here. So we have a large data set, a large vocabulary, and we want to represent sentences or words, and then we want to make it comprehensible to the computer. So one of the approaches that was actually very successful, still successful, is the bag of words approach. So what bag of words does is it basically collects all the words in a sentence or in a document, and then it tries to come up with a vocabulary. So in this case, just like how 1-7-1-4-7-6 is probably the most widely used words, what bag of words tries to do does is it basically takes probably, say, 1,000 documents and then reads through the documents to figure out how many words are present in the document and then come up with a vector that's only probably representative of all these words in the documents. And so that is how we build the bag of words model. So we have a vocabulary that's pretty small. That's very local to the documents that we have and the words in the documents. And once we do that, so now we limit the word dimensions to only the size of the vocabulary. I'll give you an explanation of what this is. I'll give you an example. And then finally, we represent the words as basic counts of all these. We represent a sentence or a word as a count of all these words. So let me see here. So for example, so these are the two sentences. Probably if we are talking about, we are not meant to save the word. We are meant to leave it. So does anyone know where these two sentences come from? Any idea? That's correct. Yeah. So yeah, this is from Interstellar. So the idea here is that we have two sentences and we are actually building a vocabulary just as an example. So in this case, we have a vocabulary of size one, two, three, four, five, six, eight, so about nine words. And what we would do is every time we represent this sentence, we are probably representing as the number of word counts. So for example, if we build a list, then the list would basically have only we are not meant to save the world, leave it. Because the second sentence is going to be we are meant, so these three words are again repeating. So when we represent the first document, we would be representing as all ones except the last two words, which are basically leave and it. There is no count of this in the first sentence. And the second sentence would be one, one, and zero, one, one, and the rest three, zeros, and one, one. Because we have leave it, which is going to, which is occurring in the last two. And the rest of this meant to save the world is not present in the first. So this is how we would represent these two sentences. So if you see, this is actually pretty slick, very small representation. For if you consider one, seven, one thousand words, if you had represented this as a one, seven, one thousand words, then probably it's a waste of space. But this way we are actually reducing the vocabulary size. And we are actually having a good representation of all the data. But can anyone tell me what is the potential problem here by representing it as counts? And any idea of what the problem is? Sorry? Exactly, yes. That's correct. So the word ordering is non-maintained. So if you look at it, the second sentence is actually over here, this is one, one, zero, one, one. So the word order is completely missed here. So there is no way that we are. So if we suppose we say, so for example, John runs behind Jim. And Jim runs behind John would basically be the same sentence representation. So that is the biggest problem with the bag of words approach. So but still this would still work in a majority of cases because what we are trying to do here is we are trying to figure out the sentiment or we are trying to, in our use case, this would be a very good example where we could still use a bag of words set of representation and then we could still get away with it. So I'll show you what is going to happen. And then we will discuss probably more about this problem. So we would move into something called the term frequency or the inverse document frequency, which is basically how we actually give weights to different words in the sentence. So we are meant to leave this world. So in this case, world would be probably occurring once. So we give it a higher weightage. So V is again and again repeating. So what term frequency does is it basically sees how many times a given word occurs again and again. And it's going to give it a weight based on how many times it presents itself in a given set of documents. So we can discuss in detail about this. If you're interested, we can talk about this. But we can use this representation to actually have weighed the earlier vector as a better form. And what we can do is we can get a better vector in terms of these weightage. Once we get this, we can actually train a simple sentiment classifier. So I'll just show an example of what is going to happen. But in this case, what we would do is we would take the movie review data set, which is basically from Connell. This is a movie review for probably about 1,800 movies. And what we would be doing is we would build the vocabulary, like I showed earlier. We would just simply take a vector. And then we would do a term frequency, inverse document frequency. And then we would train a simple linear SVM classifier to say whether it's a positive sentiment or a negative sentiment. So let's get in. So all my code is available on my GitHub. So if you're interested in training your own sentiment classifier, or if you're interested in training your own neural network or TensorFlow network, so you can go to this GitHub link, and then you can try it yourself. So let's just move to the example. Yeah, that's good. So let's get to the first example here. That's pretty slow. So I hope you can see. Let me just do a plus here. So this is the example that I'm talking about. So in this case, first, we would have some imports. So the imports are basically going to be scikit-learn. So we don't want to be writing the TFIDF vectorizer and things like that. So we can use something off the shelf. It's an open source, very well optimized code. So in this case, we would basically be importing scikit-learn. And we would also be importing the linear SVM from scikit-learn. So once we do these two, so these are the import statements, so we are also importing the data. So the data is going to be something like the polarity data. So here it's positive or negative. And we'll see how this data looks like. How am I going? All right, let's run through the score. All right, rather slow. All right, OK. Let me then move to. So we finished the imports. So now, like I said earlier, there are 2,000 reviews. And each of these reviews, so we split the review into 90 and 10. And basically, we have 1,800 reviews for training. And 200 for testing. So this is a very small data set. What we are trying to see is we want to know what are the types of data that we have. So if we take just a debug here, we will just see that the train review has, in the recent years, Harrison Ford has been such a grave screen presence, calling through the likes of, so this is basically, there are actually quite a lot more. But I'm actually truncating it to 100 characters. And this is actually positive. I don't know why, but it's positive. So bear with me. And the second is basically another test review. So in the most interesting part of can't hardly wait, just happens not to be the most human part. So this is another example where the sentiment is negative. So these are two cases where we have the training data and the test data. So this is just a small debunk to see if everything is good. Next is we will build the vectorizer itself. So the vectorizer, like I said earlier, is basically scikit-learn's TFID vectorizer. What this basic tries to do is it comes up with, takes in the data that we have provided. And it's going to build its own vector. So when we do the vocabulary, it will tell us that there are certain, the vocabulary size. And how much of the vectors it's going to actually train and build rather. So when we run this, let's just run this and see what happens. So we see that the result, it fails. Fantastic. So perhaps, what it says, the document only contains top words. That's interesting. So what did I do wrong here? So this is Murphy's law running right here. Anyway, so that's why we have a nice Python notebook. So the reason is we can store all the outputs here. So in this case, the vocabulary length is 1,495. And we can actually see this from the vectorizer here. And once we are able to, so in this case, what vectorizer means is that, like I showed earlier, we have nine words and we were able to build a vector with a size of nine. And now, with these 2,000 documents or 1,000 data documents, what the TFID vectorizer is telling is that there are 12,495 words. And we can actually vectorize these words into such a dimensional vector. And once we do this, we are actually basically training a classifier. That's it. So we are actually fitting the test data to this sort of a vectorizer data. And we are actually training a linear classifier. And once we train this classifier, we have some results, which is going to be, this is the matrix. So it's going to say that the precision is such and such. And the F1 score, so it's basically saying what are the type of data, the average accuracy, the average F1 score, and all that. So we can see that with a simple linear SVM and with a simple TFIDF vectorizer, we can actually do a pretty reasonably good classifier for sentiments. So this is, of course, with only 2,000 documents. Now, the real challenge comes in when there are actually large data sets. So for example, IMDB has released its data set. So you can actually go, there is an ACLIMDB data set, which has about, I think, 60,000 or 25,000 reviews. It's actually quite comprehensive. So it's not just positive or negative. It's from a rating 0 to 5, or I think 1 to 5. And basically, the task is not just to say whether it's 0 or positive or negative, but also whether it's actually having any sentiment that's on the rating scale as well. So over and above, we will actually see another example of doing that. So let's switch back to the presentation here. OK. So did we move back? So yeah. So one of the reasons, like I said earlier, the problem with this sort of a framework is that TFIDF wouldn't give any sort of representation and that any sort of dealing with respect to the word ordering. So one of the improvements that we could do is have our train a smarter network. So in this case, we can use word vectors like GLOB or Word2Vec. So these two are other sort of a framework which actually has word embeddings which are trained on shallow neural networks. So GLOB is not a neural network itself, but Word2Vec is a neural network which is actually trained on a shallow neural network. What Word2Vec can do is it's trying to come up with some embeddings where something like we can actually do an inference on these embeddings to say, so probably we can do very interesting things like king minus man plus woman is what. And then it'll come up and say queen. So things like those sort of a wonderful inference can be done with Word2Vec or even with GLOB because the training actually makes it semantically close to its peers. So for example, man would be close to king. Queen would be close to women. So these vectors are actually placed close by with one another. So that's one way to actually improve on our TF IDF. But we are not going to do that today. We can do that for another topic for another day. Another method is something called skip thoughts. So skip thoughts is another research project or research where what we do is we train an encoder decoder where we actually train the sentence and we try to get an encoding for the sentence. So again, this will give a sentence encoding, sentence level encoding. And this is not going to be like a word level encoding, but this is another way of improving classification accuracy. And one of the good things with skip thoughts is that you can apply it on a wide variety of applications, wide variety of problems. And it's actually very, very interesting to use skip thoughts. So if we want to try it out, skip thoughts is one way to go. And then the paper is even well written. So if you want to give it a try, give it that. So let's go to the sentiment classification. This would be the demo. Let me move on. So like I said earlier, one of the good things with Google Cloud is that you get to try, as a developer, if you don't care about what NLP is, if you don't want to bother about how it's doing behind the scenes, then what you could do is you could use the Google Cloud NLP API, which gives similar sort of settings. So where you throw in some text, you would be able to get back the sentiment value. I'll show you examples of what it's doing and how, what we can use. But first of all, I'll give you an example of how you need to set up the Google Cloud API. So the first thing you would do when you actually set up the API itself is, sorry? Is it full? Is it full? OK. So I'll quit the presentation. OK. I think this will work. Yeah. OK, that's because it's in full screen. Yeah, that's correct. So OK. Let me go back here. One of the first things when you do is you can go to cloud.google.com and yeah. So as soon as you go here, you can actually set up your console. I think you can set up your own with some free credits the first time you test it out. So once you get in, so you have to create a project. Once you create a project, you can actually set up billing and all that. So with your $300 credit, you can do quite a lot. I have a $100 credit and my billing is still at zero. So that's one good thing about the Cloud API here. So once you come here, you have to activate the different sets of APIs. One is the machine learning API here and the Cloud NLP API. So you need to activate those two APIs. And then when you create a project, you actually create this project and download a JSON, which actually accompanies the project. So these are all pretty straightforward. The documentation is very good. So all you need to do is just go to cloud.google.com and then create a project. And then you can start working on these projects. So I'll give you an example of what you can achieve. So just earlier, I actually gave the reason. So we had to import quite a few things and do a lot more. So if you're a developer who's not interested in actually running through TFIDF and figuring out what are the parameters to set, minimum frequency, maximum. So what you can basically do is do the same thing, but only load the API, the data. So in this case, let me do the same thing here. Hopefully it does not fail on me this time. Let me try out the same data. I should be getting the same data here. But the only thing that I would have to do here is to import the Google Cloud language. So you can import the language API if you actually enable the Google NLP API. So once you go to cloud, you have to enable the NLP API. Once you have that, you download the credentials. It's basically a JSON file. And you have to set it as export Google. I'll show you the export part as well. So once you do that, you can actually install the G Cloud. And once you install G Cloud, you should be able to use it on a Python. So you can use your Python to import the language and you can run different things. So from here in this case, so we can let me run if this is going to work. Yeah, this is working. Perfect. So I create a client. So every time I create a client, it's going to actually create an instance. And then it is going to give me with my API keys. So every time I create certain calls, it's going to actually see what are the capabilities that I have. If I enable the NLP API, then it is going to give me all these access. Otherwise, it will throw an error right now. So this is the DIR. So basically I can do so many things. Forget all the underscore underscore. You can go down here. So I can actually do analyze entities. I can analyze sentiment. And I can analyze syntax. So these are three big tasks that we can do with NLP API. And the last thing is annotate text, which can actually do all three combined. So we will see an example of how this does and what we can do with it. So the next call is basically going to be annotated. It fails again. So because of the doc. I think I didn't run a doc here. Now it should work. Hopefully, yeah, it does. So yes. So what I've passed here is basically taking this, I'm telling annotate text to get the sentiment, to include syntax, and to include, sorry. So I'm only telling it to do sentiment analysis. I don't care about the syntax and the entity recognition. So for this task, we would just do sentiment analysis alone. And what we would basically do is we are actually, this is a print result. It's basically just a decorator function. It's going to beautify the sentiment itself. So for example, in the example that we have earlier, so I'm passing the sentiment of, what am I passing here, because of the doc. So the doc is going to take trained data of IDX, which is basically a positive, or what is in recent years, Harrison Ford. So this is a text that I'm passing it, which is positive. And when I pass it through this, I can actually get different scores. The overall score is zero. And the magnitude is 7.2. So we will go through what this means. And what it actually has. So yeah, let's go back. OK. So once we've set up, so you need to export your Google application credentials, which is basically the JSON file, the path to a JSON file. And once you do that, you activate your G Cloud account itself. So it will basically pass you some SSH keys, and it will actually create. So once you do this, you don't have to set it up again. So this is only a one-time thing. And once you have this, you can run this Jupyter notebook. So effectively, you need these three steps beforehand. You need to enable billing, create a project, and then you need to set up the Cloud NLP API access. And then you can follow these two steps. And then you're good to go with actually creating your first NLP API application. So one thing is you need to set up, OK. So in this movie NLP API case, you need to set up the path. So like I said here, this is a kernel data set. So you can set up whatever data you want. And you can pass in the data. And you can see the results. So what we still need to analyze or understand what the result is saying. So the score is basically the document. What it says is basically the emotion of the text itself that you passed. And the magnitude is basically given a document. It basically says how much of the emotional content is present in the particular document. So the score is an overall estimate. And the magnitude is going to be individual estimates of different lines in the document. So if I have 10 lines, it's going to give me magnitudes for all 10 lines. And the score is going to be an overall score of the sentiment of the document. So if a score of 0, then invariably in this case that we had, so we actually see that there is actually a low emotion, which maybe could also mean that it's a mixed emotion, which is basically something like the example that we had earlier, where there is also a positive, as well as a negative sentiment present in the text. So how do we deal with this case? We actually look at the magnitude. The magnitude will basically tell which part of the sentence is going to have positive, or which part of the sentence is having negative, and things like that. So this could be a way to actually disambiguate between sentiments. And another, this is an example that is available from the cloud. It's actually clearly positive if the score is 0.8, so it's completely positive. And the magnitude is, say, for example, 3.0. But it's actually neutral if the score is somewhere close to zero, and the magnitude is close to zero. So the way you actually disambiguate between different sentiments is by actually having the magnitude. So magnitude is one way, rather the biggest way you can actually figure out if a sentiment is actually leaning on one of the sides or the other. And in general, the score will range from minus 1 to plus 1. And magnitude will be only from 0 to, it's going to be a positive value. So you can get even a score of, I think, about 6 or 5. So this is how you actually disambiguate. And you would try to figure out the sentiment of any given text, or a list of lines, for example. Moving on. So yeah, we just finished the API in a demo as well. So one of the other things that the Cloud API gives is the GPU access. So we actually showed an example where there's a toy data set. It's pretty small, about 2,000 sentiments. And then we just classified it using a linear classifier. It just trains within a span of, I think, 20, 25 seconds. But the biggest challenge is, what if I have a huge data set? And I want to actually, say, probably classify on a daily basis millions of Twitter sentiments. And then I want to know what people are talking about. And so this is where you might want to develop your own classifier. And then you might want to see how to use it and deploy the model on to probably a TensorFlow serving sort of an environment. So this is where Google actually competes with AWS. So one of the good things that I saw with this is that when you set up an AWS account, the costs are actually quite cheap right now. So I think this should be the case for some time now. Right now for an hour, so you first need to set up, similar to the last Google console that I showed you, you need to still go to that place. So just like how you have an AWS VM instance, you can create a VM instance on a Google Cloud. So what happens is it actually creates an virtual infrastructure for you. But you can actually not use the GPU out of the box. What you need to do is you still need to request access. And I actually requested access this morning. And within a span of five minutes, I was actually given access to one of them. So this is actually a K80 GPU available. So you can actually do, the instance actually comes out of the box with a K80. So you can actually have some of the libraries installed. Or you can actually choose to install everything yourself. So I didn't know that you could actually install it yourself when it actually creates the instance. So I had to do everything myself. So once you actually set up the account, all you need to do is just authorize the ML API and just create the VM instance and request GPU access. So the GPU access is currently on a different page right now. So it's a Google form that you have to fill. And once you fill the form, you will actually get a response within a span of five to 10 minutes. So you need to say which region you want the GPU from. And there are currently, I think, only three regions that have a GPU. I chose Asia region one, Asia east region one. And I think there is one in US and one in Europe right now. So this is the way you actually need to set up a GPU access for training your ML, having GPU on your ML infrastructure on the cloud. And yeah, one point to note is that currently Asia costs the highest. So I think it makes sense to actually use the ML infrastructure on in the US. But the quota, actually, it exceeds in general because everyone's using a US cloud, the GPU. So you might actually exhaust your quota very soon. So I chose Asia because I wanted to probably have access any time and every time. So there is a lot of documentation. You can actually go through these sets here. So these documents actually give a comprehensive overview of what you need to do to set up your infrastructure. And suppose, in my case, my Mac does not have a GPU. I want to actually run some training. My personal, in this case, I can actually do that. I'm actually running the GPU behind the scenes. And actually, it has not costed me anything. So I've been running this for the past three hours. And till now, I have not yet built any single sense. So maybe I'll have to see tonight or something like that. But anyway, so the infrastructure is pretty good. So you get a K80 GPU to actually play with. So if you're assigning a new, so then you will get a $300 credit. And if you're running some GPU experiments, I think it will be quite interesting to see if you can actually play around with $300. And you can get quite a lot of value for money for the $300 because you wouldn't pay anything for it. And then once you complete all this, your instance would be ready. And I can show you what happens. You can basically either configure your command line to connect to the instance similar to if you used AWS before, then you can directly connect it by configuring SSH keys. I just wanted to see how the browser interacted. So I just kept my direct command line access from the browser directly. So the minute you run this, so let me exit this. So this is where you actually come to this. What am I? Is this doing something? Yeah, OK. I moved it from here to there. OK. It's just slow. Sorry? It's just slow. Oh, OK. So yeah, so this is the case. So the minute you land on the page, you need to go to Compute Engine. And when you go to Compute Engine, you can go to your VM instances. And then you can create your own instance. When you create your instance, all you need to do is you need to actually do quite a lot of customizations. If you used Ubuntu or if you trained some ML infrastructure before, you will actually see that this is very similar to what you might have seen earlier. So in this case, you need to choose the region that might be of interest for you. In my case, it was Asia East. And you need to customize this. So it depends on how many CPUs you would like to use. This is a virtual CPU. So in general, two should be sufficient. And you need to still go down. And then you need to choose, OK, so this is not the one Asia East, Asia East A. Yeah, here you have. So you can choose either 1, 2, or 1, 2, 4, or 8. So if you have one, apparently it's half of the GPU that's allocated to you because every die comes with two GPUs. And then you're allocated half of it, apparently. And you are allocated a Tesla K80. And again, you will get an access to this only if you request access and you're provided access. Otherwise, you will keep getting a weird notification saying that you have exhausted your quota of zero GPUs. So that's a weird access that I could show here. Yeah, it will keep saying that create VM instance of the boot disk. You have reached your limit of zero GPU access. So that's one thing that was quite weird because it never told me what the error was. It just kept saying that it was a zero. I tried this for quite a few days. I thought maybe it was because the servers were busy. But it's not because of the servers. It's because of the quota. You can go to your quotas page. You can see that there is actually a quota here. If you click on this, you will know what are the quotas here. And then you can actually see which one. So if you see this Asia East is actually at 100%. So my GPU is full. But otherwise, I have not used any of my quota here. So this is how you actually figure out or understand what the quota thing is about. And you can actually fix this. So it's pretty straightforward once you understand what it is. Going back to the cloud. Going back to my processor. OK, so let's go back to my instance. So like I said earlier, you can basically open a new SSH console right from the console window there. So what it does is it basically creates a command line window if you're used to using Linux. Then this will be very familiar to you. You can do this again on your own command line. But this is a command line that is going to have everything pre-configured. You don't have to do anything for your SSH keys and all that. So yeah, here we are. So one more thing that I forgot to mention is when you create an instance, you can also customize the type of OS that you want. So in this example, in this case, I actually forgot to tell you that I had actually chosen an Ubuntu 14.16.04. So you can actually see that there are quite a few distributions available. For example, if you want Windows, you can use that as well. But right now, since we are trying out something like a GPU on an Ubuntu machine, I use 16.04 because I'm used to 16.04. But it's up to you whatever you would like to choose. You can choose that sort of an OS over here. And once you do that, you can customize this as well. And you can go back. I can choose 16.04 LTS and persistent hard disk. OK. So once this is done, you just create this. And it clearly says that you will be built for this instance. So yes, so you have to be careful if you're running something. You will be built for that instance. So whatever instance you create, because you're using a GPU, it would take a few, I think, about 30 seconds to create your instance. But otherwise, you can actually allocate this pretty fast. And one more thing is when you are creating, if you want to configure your SSH keys, if you have a project that you would like to share with your teammates, then you can actually create SSH keys to share with your project. So you can create one. And then you can share the key with your project mates. So this is one way, a place where you have to do. So these are things that are actually hidden somewhere. So you might have to figure out where this is. And then you will have to customize it for your own needs. But in general, out of the box, you get the most widely used OS with the more commonly used CPUs and things like that. So once you create this, you would be back here, wherein you will actually have this sort of a yes. Yes, so I think it's still under, I don't think this is running a TPU yet because I can see that it's actually running an NVIDIA K80. So TPU, I don't think it's running on the infrastructure yet, but I heard that it's gonna be there soon. So yeah, let's hope it's gonna be there soon. There was a paper, so I hope you read the paper recently. So they actually showed that the TPU infrastructure is actually quite good at low computes. So sorry, low energy consumption. So it's actually a very interesting paper. If you want, you can actually read through the paper also. So that gives a lot more idea about what is the cost that you have. So not just the cost in terms of money, but in terms of the impact that your server is going to have on the environment. So in that sense, the TPU paper was actually very, very interesting. So yeah, so now that we have our console up and running, so you can see it's a 16.04 Ubuntu machine. So out of the box, you might not have most of the, if you're used to using NVIDIA, the GPU and stuff like that, you might not find, say probably NVIDIA SMI running, but you could install it directly though. So there are some scripts that you can actually follow to install it. For example, you can actually go over here. You can actually see, they actually give you a script that is actually going to run out of the box. So that you can either manually install it, or when you create an instance, you can install it out of the, so when it creates instance, it's going to install some of the libraries pre-installed. So you can do that as well. So once you do that, you should be back here. So one of the ways you test if your machine is running, GPU is by doing an NVIDIA SMI. So NVIDIA SMI is going to tell you what is, how much of memory is available, what sort of GPU is running, the CUDA drivers and things like that. So before, if you cannot run this, then your machine is not running a GPU instance. So just, even if it might be running a GPU instance, but it is not enabled with a CUDA drivers for it to do the actual compute on the GPU. So that's one thing you will have to note. So once you do this, once you're set with this, then you will have to go to Python, you can just install Python. So in my case, I wanted 3.6. So I just installed Anaconda on this as well. So because Anaconda comes in with a lot more packages installed out of the box again. And once you do that, you can just install TensorFlow from PIP. So PIP install TensorFlow-GPU would actually say, would actually install GPU. So this, okay, this is my thing I should say install. So this is going to come back and say everything is fulfilled, but this is what you might have to do out of the box. So when you create an instance, you need to check your GPU and then you just have to install TensorFlow. And once you're good to go, all you have to do, you can actually go forward with some of the examples. So on the GitHub repository, I have actually uploaded some examples. So let me just go quickly here. So one thing is the TensorFlow itself. So it's going to be sentiment analysis using a simple single-layer neural network. So that's not fun to test out. So what we can, let me just show you what are the cases here. So we have, so these are some of the examples. So I actually installed the CUDA repository, that's a Debian file, and I installed Anaconda. So these are the only two things I've actually installed on this machine. And everything else is just working out of the box. And let's go into sentiment analyzer. So in this case, what we can also test it out is, so like I actually told, we want to actually see the power of the GPU. So let me show you what I've had here for TensorFlow. So in this case, so this is running a VI, so I'm just using an editor. So in this case, all I'm doing is basically running a classifier for training on something called a spam dataset. So it's going to classify emails as spam or ham. It is basically emails or not. So this is going to be a very simple dataset, but it's actually quite a large dataset. In this case, it's quite challenging because you have, so what I'm trying to do is it's actually making the dataset challenging rather. I'm making a batch size of 500, and then I'm basically trying to train a huge neural network and see the effect. This would actually take some time on my local machine, but let's just see how quickly it can actually do out of the box here. So one more thing that you could notice when you actually run TensorFlow on GPU is that the first few lines are going to tell you that TensorFlow is running CUDA. It will tell you that some of the libraries are available. It will tell that it's actually good to go, and it will start training. So if you see this case here, there's actually the first 500 iterations. This is an example where it's actually saying that there is a loss. So it's the training loss and the test loss. It's just doing a very simple classification, but in this case, we are actually training on a batch of 500 emails at a single chart, at a single iteration, and we are training this for close to, I think this is 2,000 iterations or 20,000 iterations, and you should see that the loss is actually quickly falling, and the accuracy is raising for some time, and then after I think 0.85, it should saturate. So this neural network is capable of running only up to about 85 percent accuracy, but this is a standard example of how you can actually train and test everything just on the Cloud, and you don't need to actually have an expensive infrastructure on your local machine. So all you have to do is, you just need a browser that can actually create, you go to the Cloud, and then you can actually run some simple examples like this. So Chrome should be more than sufficient for these examples. In general, it trains pretty fast. I've actually done some evaluations with the CPU as well as the GPU. This is close to 10 times faster than the evaluation on my CPU. So that's some case that we might have to consider when you're actually training huge deep learning models on the Cloud. So one more thing is that because it's an SSH level access, you have an IP address that you can actually copy into. So this is actually very easy to, just like how you might have a server on your local infrastructure. It's just that this Cloud is actually running somewhere else, and then all you need is the public IP, the global external IP over here that I can show here. So with this, I can actually copy, and then all I have to do is use this external IP to just SSH into this machine and use my credentials. If I have configured my SSH keys on my local command line, I can copy files directly into this. Otherwise, you can do a Git clone, or you can actually download data directly into the VM instance as well. So that's one more thing that you can do. So those are different ways of access. So I think by the time I finish talking, it's already trained it. So that is it. Yeah, it's done already. So this is the performance. So I also have the notebook itself running behind that actually did this, and then it took quite some time. Let me show you what it did. Yeah. So in the notebook, actually it actually does a few more things. It's actually going to plot the graph, and because there's no display on the server, I just deleted all that part. So if you see the training loss and the test loss are actually going to go on considerably, and if you see there's actually not much overfitting here, there's actually no overfitting at all, and you can actually see that the train accuracy is stagnating after say probably about 6,000 iterations. So that shows that the network needs to be more deeper, and that you can probably have some ways of improving this because the loss is still, the training loss and the validation loss is still at about 0.4. So which shows that there is some way to improve this network and gain some more accuracy in this. So this is an example of how you can actually train and then just copy the model and then do some evaluation locally here. So all you need to do is download the checkpoint and the models from the server, and then you can actually locally use that for inference on CPU. So that is one way even we do. So when we actually train on training infrastructure for all these machine learnings algorithms, and then what we do is once it's trained, we copy the model locally and then we do the inference on our CPU. So that's in general the way we actually train in neural networks. So there is also one more example that you can actually try out on the GitHub repository. It's basically the word vectors. So what the word vectors are basically, again, like I said, it's a way to actually see and visualize the fact that I was telling you earlier about the king minus man plus woman is equal to queen. That's sort of an evaluation that's the word to web. So if you see what TensorFlow can do, you can actually see that it's actually very interesting that it can actually do this and I somehow seem to. Yeah. So this cloud is basically all the word vectors, and this is basically an embedding cloud. This is on TensorBoard. What TensorBoard does is it basically gives you a way to see these or rather visualize these in terms of a cloud. So I can actually go down here. I can actually see different, I think it's slow to refresh, but it's basically a 3D cloud that I can actually choose these actually numbers right now. But I should have actually converted this into words. But effectively what I can do is I can choose some words here and then see which are the words that are close to one another. If you actually choose the words properly, you can actually see that the example that I gave, where man and woman are probably numbers are actually clustered close to one another, and city names are actually close to one another. If you see here, France and we still need to do some work over here. But if you see the actual word embeddings here, the index behind the words behind these index, it would be probably France, so things like country names, things like people. So all these would actually be clustered in some space. So one more thing that you can do with this tensor board is you can actually select some of the characters, and then you can actually see what are the, so in this case, I can see, okay, I'm interested in this particular area. I can see what are the embeddings in that particular area. Then I can zoom in and zoom out and see how far these embeddings are from one another. So those are things that you can actually do with tensor board. So you train on the cloud, and then you can actually save all these embeddings to a file, and all you need to do is copy those file, and then see you can just view tensor board locally. So there's also another way to configure tensor board on the cloud as well. So that's also another way to go. But this is an easier way, and all you need to do is you just have tensor flow installed locally, and you can already evaluate and see how these embeddings are. So that's one more example here. Let's go back to our presentation. So yeah, so we have come towards the final press here. So we actually started off with a simple introduction to what sentiment analysis is, and how we actually used our term frequency and I know inverse document frequency to probably classify text into positive and negative classes, and we also discussed some improvements like probably you could use Word2Vec or use Glob vectors. We also saw an example or running example of how to use Cloud NLP API itself to do the inference to get sentiment values, to get the scores and the magnitudes. So you can actually use that. So one more thing that is also available is there are actually the Cloud API is now, I think it can work on Spanish, it can work on Japanese, and it can work on one more language with English. So these are also some capabilities of the NLP API right now. So that is also possible. One, if you're interested, you can also do entity recognition, and you can also do, I think I'm not sure, but it has one more capability to actually go along with sentiment and with entity recognition. In the third case, we actually developed a general purpose classifier for the TensorFlow. So if you want to get deeper into the TensorFlow classifier, you can actually download the code. So the Python notebook is available on my repository. So the network itself is a straightforward network, but the idea is to use the TF IDF vectors. How would you actually interchangeably use TF IDF vectors with TensorFlow? Seamlessly, you can just move from scikit-learn sort of a simple model to something like a TensorFlow machine learning toolkit, which can actually do complex inferences and train deep neural networks. Finally, we also give an example of how you can use the GPU on the Cloud and how this is actually, you can actually use this for inference and for training as well. So if you're also interested, sentiment analysis recently, there was a wonderful paper from mine. So it's called Unsupervised Neurons. So it's actually another paper that's pretty much tuned towards the theoretical practitioners. So who are interested in reading what the current state of the art is. So this paper actually talks about unsupervised methods for which it actually learns to classify sentiment by itself. So this is actually a very, very cool paper. So when you read it, it's actually phenomenal how they even the authors claim that we don't know how it actually did that, but it did that. So that's the paper actually gives how much the field is progressing and how exciting it is to develop such models and see what it can actually do. So that's one paper that probably you can also read. It does not matter if you can not understand all of it or part of it, but it's still worth reading the paper because it's so cool and the way it can actually do things. So if you have the chance, go ahead and read the paper. Thank you very much. So if you have any questions, you can ask me. Hi. Hi. This is a good talk about sentiment. My question is, is there any solution for an ironic detection of security detection? Okay. So the question was, is there any work that's actually there on irony? So that's the problem. That's the irony here. So we do everything that, so it's very difficult to understand irony. So in most cases, we actually train supervised data sets. So in this case, we have a positive or a negative sentiment. We have something like training on something that's actually, so all the data sets are actually tuned towards certain large tasks. For example, detecting if an email is ham or spam. So things like that are actually pretty much big topics that are actually of interest to the major audience. Since still we have a lot more things to achieve, so we have a lot more places to go before we can come to the point of irony detection. But the use case for irony detection is actually, could you maybe let me know what you have an idea of use case for irony detection? Do you have an idea? Like is there a reason for you to? I use the data from site-based to the detection, detect the anomaly. Okay. But how did you do the evaluation for that? I used many algorithms to do evaluation. So you have an actual irony data set? Yeah. Oh, okay. I didn't know that. Okay, thank you. Yes? The end of the API, if I'm right, actually uses an ensemble method. So maybe I could look it up, but it uses quite a few methods. So if you read the Google TensorFlow has open-sourced the syntax net. So syntax net is basically ways to actually identify the entities in a sentence. So you can use these entities to figure out what is the sentiment as well. So I think it could probably be an extension of syntax net and a lot more than just the, yeah. It should be pre-trained on, so because Google would have a lot more access to data. So it is, of course, pre-trained on probably all of the data set that Google has probably a huge data set. Yes? Yeah. So if you have no other questions, then thank you very much. Thank you, everyone.