How to Use Pretrained Models from Hugging Face in a Few Lines of Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome to the new win in this d blowing tutorial in this video here we're going to talk about the hawk and face pipeline so in the last video we just had a short introduction to the hawking face framework we went into the website saw like what is this framework actually cable off and then we just talked that through source some of the documentation and so on but this would here we're going to cover the hacking phase pipeline and see how we can actually use models like pre-trained models very fast and very uh very easily but first of all remember to hit the subscribe button and bellow vacation on the video here only 10 of you guys watching these videos i actually like subscribe to the channel it's just a single click and it helps me and youtube channel out in a massive way you can also come and remember the channel if you want to support the channel with a small monthly fee everything will go to create more embedded quality content here on the channel also if you remember the channel i can help you out in your own projects if you have some problems i can help you out and give some guidance if you remember the channel so thank you guys so in this video here we're just going to jump straight into google collab and then we're going to see how we can actually use this pipeline from hawkenface i went over the documentation in the last video so definitely check that out first of all we need to install the transformers and the datasets from hawkenface so put the pipeline function here is actually like the easiest way to use a pre-trained model for a given task as already already mentioned in the last video so basically we just need to specify in this pipeline function what model do we want to use and then we just pass our input into our pipeline then we'll get the output and then we can process that afterwards so here we're just going to run the blob code and then we'll pip install the transformers and also the data sets because we're going to use that throughout this video here the pipeline here supports many common tasks out of the box so we can use it for like text images like different kind of like natural language processing tasks we can also use it for audio as you can read here so we can use like do it for like sentiment analysis classify the polarity of a given text so we want to classify it if this text is positive or negative we can do like text generation in english we can generate text from uh from a given input we can do like uh both summarization we can do translations or if you want to translate between different kind of like languages you can also do a summary so you can basically just take a whole text of maybe like 100 lines of text you can just pass that into our model and then it will make a summary of that text and you can actually specify how long do you want that summary to be and then you'll just just get an output of uh or like you just get a summary out of that text that you passed through the model we can also use it for images so we can use it for image classification we can also use it for segmentation and update detection we can also use it for audio so we have both audio clarification and also speech recognition which can be used for a lot of different kind of applications and again the cool thing about this hawking face framework is that we only need to call this pipeline function here we can play around with it a bit more we can have some more like settings that we can play around with if we go in and use some other different kind of classes but i'll cover that in another video or like other different kind of videos because we can actually do a lot of stuff with this hawking face without writing that much of code we just need to know like how it works and how we can set it up so definitely hit the subscribe button so you know when i upload those videos in that tutorial so here we're just going to see how we can actually use this pipeline so from the transformers that we just piv installed we can import the pipeline and then we can basically just set up a classifier so we just set that equal to the pipeline function and then we just specify what classifier directs like want to create and then in this example here we're going to set up a sentiment analysis you can also do classification or all these other different kind of like um all these other different kind of tasks that is shown up here at the top so we're going to create sentiment sentiment analysis here the pipeline here downloads and and cast as a default pre-trained model and a token tokenizer force and sentiment analysis and then you can actually specify your own models but if you don't specify anything it will just like choose the default pre-trained model which is always uh good and if you don't like really know what you're doing and if you don't want to use a specific model you should definitely just go with the default one so here we're just going to run this bluff code so we can actually create our classifier and then we download it and we cast a default pre-trained model then we can basically just have our classifier down here at the bottom we also download and and and caches the tokenizer so a tokenizer is basically just how we take our data then we create a token from that data so basically we're just converting our data to tokens because tokens uh we're using that tracks like create embeddings and then we can pass those embeddings in as the input to our transformers so here we see that we've downloaded all these different things that were used at pytorch model we also have a tokenizer and we have a vocabulary for our tokenizer so these are all very pre-trained models and also both the models is pre-trained and also the tokenizer so here we have a classifier we can basically just pass in some text that we want to do sentiment analysis on so basically we just have this line of code here we just write this line of code and then we just have our classifier we pass in the text and then we'll get the output here under so basically we're just going to run the flower code and see the results so first of all we get a label of if if this text is actually positive or negative and then we also give a confidence score of like how certain are we that this is act like a positive text or like some different you know like messages and so on that we're analyzing so here text says thanks a lot for watching the video really appreciate it it says it this is positive and it has a really high confidence it is really confident that this act like a positive uh text ever passed into our classifier again it is probably like when we're using the attention and the transformation mechanism is act like attending to some specific works and words and then it uses those to do the classification so here the transformer is probably like attending two things and also like maybe watching and and also appreciate and really uh really appreciate it this is act like positive words and then it thinks that this act like a positive sentence or like text that were passed through our classifier down here we can actually pass in more than one sentence so you can basically just have an array or like multiple arrays of text that you want to classify so let's say you have like a whole text or you have like just uh different different lines maybe you have like a lot of different kind of like emails you just want to do sentiment analysis and all those emails to see like if they're actually like positive or negative then we can basically just have the results here which is equal to classifier then you just throw in an array here with all that with all the sentences that you actually want to do predictions on and then it just returns um a list of dictionaries as well where you can go in and get the actual like labels and also the confidence score then we can just have a for loop running through all the results that we have then we can print out the label and also the score so here we're just going to run the vlog code we can see that the first text is thanks a lot guys this is a positive text with a 99 9 confidence score and then here at the uh at the end or like the second sentence that we passed through the model is this video is not cool and it says that this is act like a negative uh sentence that were passed for a model with a really high confidence score as well so again here we're probably attending to thanks and here over here to right we're probably attending to not cool so if we act like just delete this word here so if we just have this video is cool then we should actually get positive down here in the label so now we get positive top positive again with a really high confidence score so again if we just add not here so cool in the other example here with positive it is attending to cool but here it acts like takes in not cool as well because that actually plays a huge uh a huge difference when we're talking about like if we should do sentiment analysis so that's it for this video here guys we've been through like how we can set up the pipeline with the hawk and phase framework in google collab so we did this sentiment analysis where we can act like a label or like we can classify if uh if if a text or like if a sentence is actually like positive or negative this can be used for a lot of different things and in the upcoming videos we're going to cover more of these different kind of like tasks that i showed you up at the top so this is just to get started with this hawk and phase framework how to set it up and how to just get started and set up this really easy classifier with only a couple of lines of code so thank you guys for watching this video here and again remember the subscribe button and qualification on the video also like this video here if you like the content and you want more in the future it just really helps me and youtube channel out in a massive way i'm currently doing this deep learning tutorial where we're talking about like the basic theory behind deep learning neural networks how we can train neural networks how we can create our own neural networks and all those different kind of things with optimization regularization how we can do like uh how we can train on neural networks and so on so if you're interested in that tutorial i'll link to it up here or else on the scene next where you guys bye for now
Info
Channel: Nicolai Nielsen
Views: 47,866
Rating: undefined out of 5
Keywords: hugging face, hugging face pipeline, hugging face tutorial, hugging face transformer, how to use hugging face, hugging face pretrained models, transfer learning, transfer learning neural networks, pretrained models, pretrained neural networks, how to use pretrained models from github, huggingface pytorch, huggingface, huggingface tensorflow, huggingface datasets, sentiment analysis, sentiment analysis hugging face, sentiment analysis python, sentiment analysis deep learning
Id: ntz160EnWIc
Channel Id: undefined
Length: 8min 43sec (523 seconds)
Published: Thu Aug 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.