[0:00] In this video course learn Hugging Face and  its concepts Hugging Face is a company and   [0:08] open-source community that focuses on Natural  Language Processing and Artificial Intelligence   [0:17] It is best known for its transformers library  which provides tools and pre-trained models for a   [0:26] wide range of NLP task such as text classification  sentiment analysis machine translation and more In   [0:36] this course we have covered the following lessons  with live running examples Let us start with the   [0:43] first lesson In this lesson we will learn what is  hugging face With that we will also understand the   [0:51] features Let us start Hugging face is a widely  known company and open-source community that   [0:59] focuses on NLP that is natural language processing  It also focuses on artificial intelligence   [1:07] Hugging face is best known for its transformers  library that provides tools and pre-trained models   [1:16] so that wide range of NLP tasks such as sentiment  analysis machine translation text summarization   [1:26] can be performed The most widely used hugging face  libraries are transformers datasets and tokenizers   [1:36] Let us see the features It includes lots  of libraries One of the key library is   [1:43] transformers that includes pre-trained  models such as BERT Hugging face also   [1:50] includes model hub that is a platform  where users can share and download   [1:55] pre-trained models With that users can  also download data sets and other resources   [2:01] Hugging face also includes a library for a variety  of data sets The library is called datasets   [2:09] library and is used for NLP task Hugging face is  also having a platform for hosting and sharing   [2:18] machine learning demos and applications which is  called spaces With that using hugging face you   [2:25] can easily deploy and use models in production  environments Hugging face is having a strong   [2:31] community and collaboration that is a community  of developers AI lovers that contribute to the [2:39] ecosystem Let us see some of the popular models  on hugging face The widely used BERT It is used   [2:49] for understanding the context of words in a  sentence Its full form is birectional encoder   [2:56] representations from transformers It is a powerful  open-source machine learning framework developed   [3:01] by Google for NLP It excels at understanding  the context of words and sentences by analyzing   [3:08] relationships between them in a birectional manner  that allows computers to better understand the   [3:13] meaning of ambiguous language It also includes GPT  that is generative pre-trained transformer also   [3:20] textto text transformer with that robata that  is a robustly optimized BERT approach RoBERTa   [3:29] is a transformerbased language model that employs  self attention to analyze input sequences RoBERTa   [3:37] applies dynamic masking where the masking pattern  is changed It offers enhanced performance on   [3:44] various NLP task So you can also relate BERT with  RoBERTa Consider that the main goal of the roba   [3:52] model is to improve the performance of the B model  by addressing its limitations So these were the   [3:58] popular models of hugging face In this lesson we  saw what is hugging face its introduction features   [4:04] and some popular models Thank you for watching  the video In this lesson we will understand the   [4:10] use cases of hugging face Hugging face supports  a wide range of use cases across NLP computer   [4:17] vision and even multimodel applications Let us see  the use cases Hugging face is widely used We have   [4:27] discussed some key use cases here Beginning with  conversational AI which you already know that is   [4:32] chat bots Okay They build intelligent chat bots  using models like GPT Blenderbot and others These   [4:42] chat bots can be used for customer support like  virtual assistants With that you can also create   [4:49] interactive dialogue systems These can be used  as educational assistants as well as therapy   [4:57] bots Next comes sentiment analysis As the name  suggest you can easily analyze customer feedback   [5:06] analyze their social media post or the responses  to service so that you can determine the sentiment   [5:14] that is it is positive negative or neutral With  that easily generate text generate articles blogs   [5:22] even poems using models like GPT codes can also  be easily generated generate code snippets in any   [5:31] programming language With that content can  be generated including product descriptions   [5:40] review marketing plans and others Next comes text  summarization If you want to summarize your text   [5:49] let's say you want to summarize news you can  easily do it with that let's say you have some   [5:53] PDF documents and you only want to summarize it  Those lengthy documents can be easily summarized   [6:01] into important points With that you can also  jot down meeting notes Then comes your named   [6:10] entity recognition Easily extract name skills  and experience from rums It is also useful   [6:16] in healthcare to identify diagnosis the name of  patients some medical terms and others With that   [6:25] you can also extract name of companies how they  are working from their financial reports as well   [6:31] Therefore it is also used in the finance domain  Machine translation as the name suggests you can   [6:38] translate your website app and even documents from  one language to another Let's say from English to   [6:46] Spanish It can also be used in languages which  have low resources that is for translation   [6:54] Question Answering use case is mostly useful  for customer support with that easily answer the   [7:02] questions asked by students based on a specific  textbook or notes FAQs can be easily answered and   [7:11] when I said customer support that itself means  like we have seen support tickets on websites so   [7:17] that users can easily ask questions with that you  can easily retrieve answers from large documents   [7:24] or databases Also use it for speech recognition  and synthesis You can also convert speech to   [7:31] text Build voice controlled applications  using speech to text and texttospech models   [7:38] You can also provide real-time captioning generate  descriptions for images Let's say you have scanned   [7:46] document or images and you want text from it  You can easily achieve this Also if you want   [7:52] to read or scan images that can also be achieved  That means visual question answering Then comes   [8:00] your recommendation systems You must have seen it  on Netflix or Amazon Prime can easily recommend   [8:06] movies or web series using what people are  actually liking in their account With that enhance   [8:16] the search results by understanding the intent  of users and their context also detect frauds   [8:23] easily with that regarding emails Easily detect  and filter spam emails Mental health can also   [8:31] be monitored using a model Easily analyze text  or speech so that the emotions can be detected   [8:38] such as stress anxiety or even depression With  that understand the emotions of customers during   [8:45] support calls or even chat Text to speech and  speech to text can also be achieved and realtime   [8:52] translations can be easily worked upon Multimodel  applications analyze video content easily With   [9:01] multimodel applications you can easily analyze  not even text but also video and audio Augmented   [9:09] reality applications can also be built Easily  generate synthetic text data for training machine   [9:16] learning models You can also paraphrase text Also  identify relationship between entities in text   [9:25] Grade the essays or assignments of students easily  Build tools for grammar correction vocabulary   [9:32] rephrasing content and others Use in healthcare  and life sciences from the medical records of a   [9:41] patient You can easily extract the insights from  legal documents Easily extract the key clauses   [9:49] obligation or any possible risk With that you can  also create AIdriven narratives for games Analyze   [9:59] social media easily so that you can identify the  trending topics or even hashtags Also analyze the   [10:08] impact of post done by influencers Multilingual  applications can also be created so that you can   [10:16] enable search across multiple languages Hate  speech and harmful content is something that   [10:24] needs to work on With this you can easily detect  and moderate them Easily predict the stock market   [10:32] trends by analyzing news articles social media  sentiments Twitter post and others Predict events   [10:41] like a product launch Personalize email content  for marketing campaigns Customize website or app   [10:49] content based on user preferences and behavior  Fine-tune pre-trained models for your specific   [10:56] task Also you can compare the performance of  different models on custom data sets So guys we   [11:02] saw some of the great use cases of hugging face  In the upcoming lessons we will implement some   [11:08] of them In this lesson we will understand  the transformers library of hugging face   [11:15] We will also learn how to install it Let's see  The transformers library is the core library for   [11:23] pre-trained models and pipelines It is an open  source Python library As I said before hugging   [11:30] face developed the transformers library and it  is modular and extensible It includes thousands   [11:38] of pre-trained models for a wide range of NLP  tasks such as translation text summarization text   [11:44] classification and others So in this lesson we  will understand what is the transformers library   [11:50] why use the transformers library its use cases as  well as how to install Let us start So we already   [11:58] saw what is the transformers library here Now  we will see why use the transformers library   [12:04] Transformers library is widely used because it  is quite simple to use with complex NLP models   [12:12] It provides you access to cutting edge models With  that it is backed by a large and active community   [12:19] It supports customization and fine-tuning With  that you can integrate the transformers library   [12:28] with other tools Here are some use cases of  the transformers library classify text into   [12:34] categories like text classification in the case  of spam detection in emails Also identify entities   [12:42] like names dates and locations in text which is  called named entity recognition Translate text   [12:49] between different languages like from English to  German with that generate text using models like   [12:56] GPT also implement question answering that is  to answer on the basis of a given context Let   [13:07] us see how to install the transformers library  So here are different ways Use pip to install   [13:13] the transformers library PIP is a package manager  to download install and manage Python packages and   [13:20] libraries With that you can also use Google Colab  Here you can find some difference in the syntax   [13:27] There is a exclamation sign if you are installing  it on Google Colab With that you can also install   [13:35] the transformers library directly from the  hugging face GitHub repository So let us see   [13:40] how to install it We will use Google Colab for it  We will add the following command Let's see Here   [13:49] is a browser I'll type Google Colab and press  enter Here is the link provided by Google only [14:00] collab.resarch.google.com Here you can see  I already logged into my Gmail account So   [14:06] it will directly open I clicked on it So it is  asking me to create a new notebook here These   [14:14] are my already created notebooks I'll click  new notebook So it is a free web application   [14:22] So now we will use the same command here to  install it I'll show you again Here is the   [14:27] command Okay let us type the same command Okay  pip space install space transformers After that   [14:40] what we need to do we need to just click  this It's written run here Can you see run [14:44] cell okay Okay So in this way we can install  the transformers library using Google colab   [14:54] You can add the name of your Python notebook  here So this created a Python notebook If you   [15:00] know Anaconda you can easily guess what is a  Python notebook Save it from here and rename it [15:07] later So here I've just implemented this  syntax to install the transformers library   [15:18] In this lesson we saw what is the transformers  library We also saw that why it is so popular With   [15:26] that we also saw some use cases and how to install  it In this lesson we will understand the datasets   [15:33] library on hugging face With that we will also  see how to install it Let us start The datasets   [15:42] library provides easy access to a wide variety  of data sets for NLP and other machine learning   [15:50] task It is developed by hugging face and is a  Python library It makes it easier for developers   [15:59] and researchers to work with data for training  and evaluating models So in this lesson we will   [16:06] see what is the datasets library Why to use it  some use cases of the datasets library With that   [16:14] how to install it Let us start We already covered  what is the datasets library So let us start with   [16:20] why use the datasets library One of the reasons is  efficiency Lazy loading and streaming make it easy   [16:30] to work with large data sets The data sets can be  huge and we always need a library or a technology   [16:39] to ease the work of accessing and working on  those data sets So this library really helps   [16:47] It has a unified API for processing data sets You  can also work with the transformers library and   [16:54] other ML frameworks with the datasets library So  that integration and interoperability is possible   [17:00] Thousands of data sets are provided by  hugging face It supports custom data sets and   [17:06] pre-processing pipelines So before installing  the datasets library let me show you its [17:13] website So here is the link huggingface.co the  official website of huggingface/datas So you can   [17:22] see how many data sets are provided over 350K and  here it is If you'll click on any one of them you   [17:28] can get all the details In this tutorial we will  also show you how to download and access a data   [17:36] set easily using hugging face Now let us see the  use cases of the datasets library with the easily   [17:44] load and pre-process data sets for task like spam  detection that comes under text classification   [17:51] With that you can also work with sentiment  analysis and question answering Using this you   [17:59] can easily build question answering systems Some  data sets are also provided for translation with   [18:05] that named entity recognition purpose can also be  fulfilled with some data sets already provided by   [18:13] hugging face load and pre-process your custom data  sets using the datasets library Now let us see how   [18:23] to install the datasets library So you can use  pip PIP is a package manager to download install   [18:31] and manage Python packages and libraries Just use  the command pip space install space datasets With   [18:37] that you can also use Google Colab easily But  there is a difference between both the syntaxes   [18:43] You have an exclamation mark for Google Colab  We will see it later With that you can directly   [18:50] download it from the hugging face GitHub  repository using the provided syntax The   [18:57] g plus github.com huggingface/datas tell pip to  install the package from the hugging face data   [19:05] sets repository on github Now let us see how  to install the datasets library We already saw   [19:10] Google colab So I'll just use the second syntax  to install the datasets library on Google Colab   [19:21] So this was our Google Colab We already saw  how to install the transformers library We   [19:28] can install the data set library here itself But  let me create a new notebook Go to file Click new [19:38] notebook Now a new Python notebook  opened Let us type the command to   [19:44] install data sets pip install pip  space install space data sets and   [19:52] just run the cell from here I have  shown this before as well Let's [19:56] wait Tick mark is visible That means we  successfully installed it You can also   [20:04] save it from here I told you before also save and  let us add the name to our Python notebook So in   [20:13] this way guys we can easily install the datasets  library In the upcoming lessons we will also see   [20:20] how to work with them and its use cases Guys  we saw what is the datasets library We easily   [20:30] understood the concept its use cases also and  we also saw how to install the datasets library   [20:39] In this lesson we will understand the tokenizers  library of hugging face With that we will also see   [20:46] how to install it The tokenizers library is a fast  and efficient library for tokenizing text which is   [20:55] often used alongside the transformers library We  already saw the transformers library before in the   [21:01] previous lessons So the tokenizers library is a  fast efficient and flexible library designed for   [21:07] tokenizing text data which is a crucial step in  natural language processing Tokenization involves   [21:16] splitting text into smaller units such as words  subwords or characters Then these are converted   [21:22] into numerical representations that ML models can  process In this lesson we will understand what is   [21:29] the tokenizers library why use it its use cases  as well as how to install it So let us start We   [21:38] already saw what is the tokenizers library So now  we will see why use the tokenizers library It is   [21:46] quite quick for tokenization that means optimized  for fast tokenization even on large data sets   [21:54] It also supports custom tokenizers as well  as flexible enough to support multiple   [22:00] tokenization algorithms Integration is possible  that means you can work it with other hugging face   [22:07] libraries like transformers It has an easy API for  tokenizing decoding and managing vocabularies With   [22:17] that you can easily access pre-trained  tokenizers Now let us see the use cases   [22:24] easily tokenize the textual data for classifying  text like for spam detection in emails With   [22:31] that you can also analyze the spam easily  perform sentiment analysis Align the tokens   [22:39] with entity labels It is also used for machine  translation Some of its other use cases includes   [22:48] text generation and even question answering  with that train and use tokenizers for domain   [22:59] specific data sets Now let us see how to install  the tokenizers library We can use pip PIP is a   [23:08] package manager to download install and manage  Python packages use the syntax pip space install   [23:13] space tokenizers to install it With that we can  also use the tokenizers library on Google colab   [23:20] We already saw how to install a library on Google  colab So similarly we can use the exclamation mark   [23:27] pip space install space tokenizers to install it  Also the third way you can tell pip to install the   [23:36] package from the hugging face data sets repository  You can also use the third way that is directly   [23:44] install from the GitHub repository Type pip space  install space get plus the GitHub path to install   [23:51] it Now let us see how to install tokenizers  library on Google Colab We will open Google Colab [24:02] again So here is our Google Colab We already  installed the transformers and datasets library   [24:09] We can install the tokenizer library here itself   [24:13] But let me create a new Python  notebook Go to file Click new [24:18] notebook Now let us type the command  exclamation mark pip space install   [24:30] space tokenizers and click on  the cell Click here run cell [24:40] Now the tokenizers library will get [24:42] installed You can also save [24:46] this As I told before it will create a Python  notebook So here I'll type AIT you can add any   [24:59] name And this is our Python notebook Okay We will  utilize all these libraries later on when we will   [25:09] work on the use cases of hugging face So guys  we saw what is the tokenizers library We also   [25:17] saw its purpose as well as the use cases With  that we also installed the tokenizers library   [25:23] on Google Colab In this lesson we will learn  what is a hugging face access token With that   [25:31] we will also learn how to create it Let us start  Consider an access token as a secure string of   [25:42] characters This is mainly used to access hugging  face services and resources The hugging face API   [25:50] key and hugging face access token are the same  thing So in this lesson we will see what is an   [25:57] access token that is an API key With that we will  learn when do we need a hugging face access token   [26:06] Also we will understand that when the hugging  face access token isn't required In the end   [26:14] we will learn how to create an API key Let us  start So we covered what is an API key that is   [26:22] an access token in hugging face Now let us see  when do we need a hugging face access token Here   [26:29] it is When you're using a private or gated model  or an inference API okay you need a hugging face   [26:38] access token You must have heard about metas lama  It is a private model To access it you need to   [26:46] authenticate That means you need to create an API  key You need a token with that If you're using the   [26:53] hugging face inference API then you need an access  token to make API calls Also if you're uploading   [27:01] models or data sets or even spaces to the hugging  face hub you need an access token Now let us see   [27:10] when do you not need a hugging face access token  Obviously if you're accessing public models which   [27:15] are publicly available to download and use you  don't need an access token just like GPD2 Also   [27:23] if you're using the models via the transformers  library of hugging face you don't need an access   [27:28] token These are publicly available and can be  easily downloadable without any authentication   [27:33] without any API key Also a lot of open source  models are available To access these models   [27:40] you don't need an API key You don't need an access  token because they are freely available So in the   [27:45] upcoming lessons we'll be working on these public  and open source models only so that there's no   [27:50] need to create a hugging face access token Now  let us see how to create a hugging face access   [27:57] token So we will go to the hugging face website  and we will create an access token So let us [28:05] start Open the official website huggingface.co [28:11] /join and press [28:15] enter So here it is you need to join that means  you need to create an account on hugging face Here   [28:25] you can use your email address So let me create my  account So here I have added my account my email   [28:35] id Now enter the password Here it is Now  click next Complete your profile here Add a [28:45] username Add your name You can also  add your Twitter username These are   [28:54] optional LinkedIn profile also You  can also upload your aftar I'll [28:58] click Also you can add your GitHub  username as well as your website [29:10] As you can see these are optional Click  I have read and after that click create [29:17] account We have created an account  You need to check your email address   [29:23] for a confirmation link Now your account is [29:27] verified Your email address has been verified [29:36] Click on your profile Go below It's written  excess tokens Here it is Click on it Now you   [29:47] need to create a new token by clicking here  Remember do not share your excess tokens with   [29:52] anyone Create new token Add the token name  Let's say I'll type demo key Okay Now go [30:03] below click create token The key created  successfully You can copy it and save it   [30:16] Here it's written save it somewhere safe You will  not be able to see it again after you close this   [30:21] model Click done Now all your keys are visible  Here it is We created a single key just now   [30:31] And when you'll click here you can edit it  You can edit the permissions and also delete   [30:35] it Okay we saw what are access tokens or API  key in hugging face With that we also learned   [30:44] how to create it In this lesson we will learn  how to download a data set from hugging face   [30:51] For that we will use the datasets library Let  us see A data set refers to a collection of   [30:59] structured data which can be used for training  evaluating or testing machine learning models   [31:05] So hugging face is having a lot of data sets on  his platform which can be used for various use   [31:12] cases like NLP We will use the datasets library  to download a data set from hugging face Let us   [31:20] see First let us see the data sets Go to the  hugging face website/data sets So these are   [31:30] the data sets provided by hugging face You  can see a lot of them Let us see how we can   [31:35] download it So we will go to the same platform  Google colab which we have used before in this [31:40] tutorial Here it is Okay So  this is the notebook we already [31:49] created In this first we installed the  datasets library I already told you how   [31:58] to install it on Google Colab using the  pip command After that we loaded a data [32:05] set using the load data set function This  function can download data sets from the   [32:15] hugging face hub or load them from local  files We are downloading a data set from   [32:21] the hugging face hub right now Here it is Okay  Here we are loading the IMDB dataset After that   [32:30] I'm printing the data set using the print method  Here we are importing the load data set function   [32:38] This provides access to various public data sets  like IMDB In this case here we are loading the   [32:44] IMDB dataset The IMDB dataset contains movie  reviews labeled as positive or negative for   [32:51] sentiment classification When you'll run it will  automatically download and process the data set   [32:58] Here we are printing the data set This will split  the data set into train and test Okay that is   [33:07] it will display an overview of the data  set including the number of samples in   [33:11] each split Let us see after running Here  it is It is showing us the structure of   [33:19] the IMDb data set as data set dictionary which  organizes the data set into different splits   [33:27] The train contains 25k rows with features text  for movie reviews and label for sentiment like   [33:35] positive or negative Here for test that is 25k  rows for testing purposes with the same features   [33:44] It contains 50k rows but this plate typically  doesn't have labels for sentiment analysis   [33:49] It's often used for tasks like pre-training or  semi-supervised learning In this way guys we can   [33:55] download a data set In this lesson we will learn  how we can download a model from hugging face Let   [34:02] us see So to download we will use the transformers  library where that we can also download directly   [34:08] from the hugging face hub So let us see a  step-by-step guide to download and use models from   [34:17] hugging face We will use the transformers library  which we already discussed Let us see Here is our   [34:26] VS code We already created a notebook file open  notebook So here we created amit_d download model [34:36] already In this what we did first we installed  the transformers library We already discussed   [34:45] that hugging face developed this library So we  used pip to install it on Google Colab After   [34:52] that what we did here we downloaded a model using  the transformers library We have used the from   [35:02] pre-trained method for this This method downloads  the model weights configuration and tokenizer   [35:08] from the hugging face hub We are downloading a  pre-trained BERT model Here it is After running   [35:16] what we will get we ran this and we got the shape  This shape is commonly seen in models like BERT   [35:26] where each token in a sequence is represented  by a 768 dimensional vector When we use the   [35:33] BERT hyphen base uncased model and pass the input  hello hugging face the last hidden state output   [35:45] shape represents the tensor dimensions For this  example the shape you would typically see is the [35:52] following Here one is visible Okay it  is the batch size since there is one   [36:02] input sentence Seven is the sequence length  This corresponds to the tokenized version of   [36:09] hello hugging face including special tokens  Okay that means the following hello hugging [36:14] face 768 is the hidden size Each token  is represented as a 768 dimensional   [36:24] vector standard for BERTs base architecture In  this way guys we can easily download a model   [36:31] using the transformers library with Google  Colab In this lesson we will learn how to   [36:38] implement sentiment analysis with hugging  face We will understand what is sentiment   [36:44] analysis with its type After that we will run  a coding example on Google Colab Let us see   [36:55] So we already discussed the transformers library  provided by hugging face It is a powerful tool   [37:00] for task like sentiment analysis Now what is  sentiment analysis as the name suggest it includes   [37:06] determining the sentiment expressed in a piece of  text like positive negative or neutral So let's   [37:14] say I love cricket So this is a positive sentence  Okay I don't like something I'll hate something So   [37:22] that is a negative sentiment Similarly when I'll  explain the types of sentiment analysis things   [37:30] will be more clear First one is polarity detection  that is positive negative or neutral I love this   [37:37] product is positive Obviously the service is  terrible is not good is negative and and when   [37:42] the things are not clear it will be neutral like  the package arrived on time Next comes emotion   [37:48] detection Let's say you said this is not good  This is pathetic this is so frustrating That is   [37:57] anger And joy is expressed by a sentence like I'm  thrilled about the results So emotion detection   [38:05] includes happiness frustration and other emotions  Then comes aspect based sentiment analysis like   [38:17] sentiment towards a specific product or service  like the food was great but the service was   [38:22] slow In this case the food is having a positive  sentiment obviously but since the service was not   [38:29] good it is a negative sentiment Then the intent  analysis like the intent to purchase something to   [38:37] complain Let's say you said where can I buy this  product so that is a purchase intent So these were   [38:45] the types of sentiment analysis Now let us see the  coding example In this we will use a public model   [38:54] So we won't be creating an access token  because for public models as I already   [39:00] told we don't need it We will run the code  on Google Colab for efficiency we can also   [39:05] change the runtime on Google Colab So I'll  also show you that with the example Let us [39:12] start Here is our Google Colab  Okay Let me open the code file   [39:19] Open notebook I already created  the project Here it is Sentiment [39:26] analysis Here it is So for efficiency we can  change the runtime type Click the runtime menu   [39:39] Here click change runtime type Okay We can see  we already selected the T4 GPU Not a problem   [39:48] If your project is quite complex or you are  having a large scale project you can select   [39:56] the V2-8 TPU also I'll keep the same Okay So  initially here what we did first we installed   [40:04] the required libraries that is transformers  and torch Okay we used the paper We already   [40:11] discussed how to install it in the previous  lessons After that we ran it using this run [40:17] cell In this we imported the necessary modules in  this line Here we loaded the sentiment analysis   [40:28] pipeline The pipeline function provides  a simple way to perform various NLP task   [40:35] including sentiment analysis You can load a  pre-trained sentiment analysis model as follows   [40:42] So here what we did we loaded the following  model Okay After that we performed sentiment   [40:53] analysis Since we have loaded the sentiment  analysis pipeline use it to analyze the   [41:00] sentiment of a piece of text So here I love  playing and watching cricket These are my   [41:06] text and I hate when Virat Kohli misses a  century So obviously you can guess this is   [41:10] a positive sentence and this is a negative  sentence You can easily guess it So this is   [41:15] the sentiment analysis Here the output you  can see is a list of dictionaries Here it [41:22] is Here each dictionary contains the sentiment  label and the confidence score Here it is label   [41:31] and the confidence score So here we have analyzed  multiple text at once by passing a list of strings   [41:40] to the sentiment analyzer Now let us understand  the output completely The score in the output   [41:47] of the hugging face sentiment analysis pipeline  represents the confidence level or probability   [41:54] that the model assigns to the predicted sentiment  label It indicates how confident the model is that   [42:02] the given text corresponds to the predicted  sentiment The score is a value between 0 and   [42:08] one As you can see the score closer to one means  the model is very confident in its prediction If   [42:14] the score was closer to zero that would have mean  the model is less confident in its prediction The   [42:20] label positive indicates that the model predicts  the sentiment of the text is positive That is   [42:27] the following The negative means the opposite  that is negative Here it is So here you would   [42:34] be wondering why the score is so high close to  one This is because the model we are using has   [42:39] been fine-tuned on a large data set and is  highly accurate for sentiment analysis task   [42:47] The input text likely contains strong unambiguous  language that makes it easy for a model to predict   [42:54] the sentiment with high confidence like hate  means negative and love means positive So in   [43:01] this way guys we can work on sentiment analysis  with hugging face In this lesson we will learn   [43:09] how we can use the hugging face for text  classification First we will understand   [43:16] what is text classification With that we will also  see the difference between sentiment analysis and   [43:23] text classification After that we will create and  run an example on Google Colab Let us start Text   [43:35] classification as the name suggests can be used  for spam detection So on your email id you must   [43:42] have seen that some emails go to spam some emails  are not considered as spam In a similar way you   [43:48] can also classify news articles or documents like  sports article under the sports category a tech   [43:55] related article under the technology category  and with that it also includes a use case for   [44:00] intent detection like to cancel an order to book  a flight and others So let us see till now we have   [44:08] covered the sentiment analysis So here is the  difference between sentiment analysis and text   [44:15] classification As the name suggest sentiment  analysis are narrow that is specific to the   [44:23] sentiment Let's say positive sentiment for a  text like I love cricket In a similar way the   [44:32] labels for text classification depends on the  task like I just discussed about spam or not   [44:39] spam or different topics with that For sentiment  analysis we discussed before it is mainly positive   [44:46] negative or neutral Some use cases include  classifying email as spam or not spam Under text   [44:53] classification under sentiment analysis one of the  use case can be a positive product review Now let   [45:04] us see a coding example where we will detect spam  or not spam based on a text We will use a publicly   [45:15] available model that is the following So we won't  be needing any access token from hugging face for   [45:24] this So let us see the example and classify  text as spam or not spam Here is our Google   [45:30] Colab We created these notebooks till now Let  us open our text classification notebook Open [45:38] notebook So here it is We already created it  Let us see the steps First we will install   [45:48] the required libraries that is to begin with  the hugging face transformers library as well   [45:56] as the torch library So we have used the pip  install command for this Let's go below After   [46:07] that we will import the necessary modules  Here we have imported the pipeline module   [46:15] Then we have loaded a pre-trained spam detection  model that is the following here It is freely [46:21] available So we did not applied any key for it  from hugging face Now the next step includes   [46:30] performing the spam detection So first we have  set multiple text so that we can detect whether   [46:36] these text are spam or not spam We have classified  multiple text at once by passing a list of strings   [46:43] Here it is We have mapped labels to spam and not  spam Here here it is Label mapping Negative means   [46:52] spam Neutral means not spam Positive means not  spam Okay To display the results we have used the   [46:59] for in loop Here it is What will happen a score  will be visible in the output Okay The output   [47:11] will also include the label whether the text is a  spam or not spam With that the score will also be   [47:17] visible These are the confidence scores Here it is  So according to our model the first text is a spam   [47:27] obviously because it is showing congratulations  you have won a 500 INR Amazon gift card Click   [47:33] here to claim Now the second one is not a spam  obviously Hi myth Let's have a meeting tomorrow   [47:38] at 12 p.m So obviously this is not a spam The  last one is also considered as a spam We get   [47:48] a lot of such spam emails that your Gmail account  has been compromised Here the confidence interval   [47:55] is displaying the score Low confidence scores  indicate that the model is uncertain about its   [48:04] predictions The following model is fine-tuned for  sentiment analysis Okay but not specifically for   [48:13] spam detection We are still adapting it for spam  detection Okay that's why here it is showing not   [48:21] spam but the confidence score is even less than  0.7 And I told you that low confidence scores   [48:28] indicate that the model is uncertain about  its predictions You can set a different model   [48:34] here from the hugging face Here we are showing an  example So in this way we can use the transformers   [48:43] library on hugging face to detect spam that is  to perform text classification In this lesson we   [48:52] will understand how to perform text summarizations  using hugging face First we will understand that   [48:58] why we need to summarize and then we will see a  coding example on Google Colab to summarize text   [49:06] Let us start The hugging face transformers  library as you already know is used for NLP   [49:13] task that includes summarizing text as well So  why summarization summarization is actually used   [49:22] in a lot of real world applications You must  have seen summarizing long articles into short   [49:29] snippets With that summarizing documents or  research papers chatbots also provide quick   [49:37] concise responses With that you can extract key  points and summarizations from a document and from   [49:45] large data sets also Now let us see an example  here We will use the following model which is   [49:52] publicly available on hugging face So we don't  need to add the access token Okay Okay we will   [50:00] run the code on Google Colab like we saw before So  let us see the code So here is our Google Colab We   [50:07] will open our code file Open notebook So here we  are discussing about summarization Here is our [50:17] code First what we did we installed the required  libraries So we have installed the transformers   [50:30] as well as the PyTorch library here using the pip  space install command We already discussed this   [50:36] command before After that we will use automodel  for sequence to sequence LM and auto tokenizer   [50:46] for more control over the process so that we  can load the model and tokenizer directly So   [50:52] this is what we have done here Here we have  loaded the following pre-trained model for [50:58] summarization So here we have set the input  text to summarize So this is a text We will   [51:05] summarize this First we have tokenized the  input text using the following Okay So here   [51:14] you can see some parameters These parameters  will control the summaries length and quality   [51:22] Max_length is the maximum number of tokens  in the summary We have set 512 So here the   [51:28] summary will be no longer than 512 tokens  We have tokenized the input text Here to   [51:37] generate the summary we have used the generate  method Here we have some parameters First the   [51:41] input the following tokenized Then the  max length which is the maximum number   [51:46] of tokens in the summary This is the  minimum number of tokens in the summary [51:53] Length penalty What is this this encourages  longer or shorter summaries Here it is two   [52:01] That means longer summaries Num beams controls  the beam search width Higher values improve   [52:08] quality but slow down inference Here we have  set it to four That means four beams for [52:15] decoding Okay So here was our input and this is  the summary Here we have printed the summary Here   [52:26] we have summarized it Okay So in this way guys  we can use hugging face So in this way guys we   [52:35] can summarize text easily In this lesson we will  understand how we can perform translation using   [52:43] hugging face that is textto text generation Let us  see for translation task We will use the hugging   [52:52] face transformers library Some models are already  provided for this So translation as we all know   [52:59] includes let's say translating English text to  Spanish This is a part of texttoext models that   [53:06] requires a task prefix to specify the type of task  For example translation summarization and others   [53:14] Textto text generation includes not only  translation but also summarization paraphrasing   [53:20] question answering and even sentiment  classification So let us see the difference   [53:25] between text to text and text generation So  text generation is used for auto reggressive   [53:32] text generation where the model generates text  sequentially one token at a time like dialogue   [53:38] systems text completions and others The text  to text generation class is used for sequence   [53:45] tosequence task where the model will take an  input sequence and generate an output sequence   [53:51] like your text summarization paraphrasing and even  translation Now let us see an example to perform   [53:59] translation using the hugging face transformers  library In this we will use a model t5-small which   [54:08] is publicly available on hugging face This model  is a smaller version of the T5 model and can be   [54:14] used for task like summarization translation and  even question answering Let us see the example   [54:20] on Google Colab Here is a Google Colab We just  saw the text summarization example Now let us [54:27] open Now let us open the  translation example Here it is [54:42] First we will install the required libraries that  is the following Here we have used the pip space   [54:49] install command We already saw this command  before After that we will load a pre-trained   [54:56] translation model that is here we have loaded  the T5 model It is a versatile textto-ext [55:04] model that can handle translation  by prefixing the input with a task   [55:12] specific prompt So we are loading a T5 model [55:18] here Here we have prepared the input text So this  is the text we will translate Translate English   [55:32] to Spanish That is the following text will get  translated Tokenize the input text into input   [55:41] ids that the model can process Use the model to  generate the translated text You can customize   [55:50] the generation process with parameters like  max length num beams We saw in the previous   [55:57] lesson also Here the output tokens will be  decoded to text and after that we will print   [56:04] the translated text So here is the output  translated text My name is Amit Diwan and   [56:12] I love cricket So here it is translated to  Spanish So in this way guys we can perform   [56:19] translation In this lesson we will understand how  to use the hugging face for question answering   [56:27] We will also see an example Let us start So we  will use the transformers library of hugging   [56:34] face for performing question answering task  We will run the code on Google Colab So here   [56:42] we will use the following model which  is publicly available on hugging face   [56:46] So we don't need to create an access token for  this So let us see the example on Google colab [56:59] So here we will open our [57:00] code First we will install the required  libraries we have shown We have used the   [57:12] same pip install command which we saw  before to install the required libraries   [57:18] After that we will load a pre-trained QA  model and tokenizer Here is our model and the [57:28] tokenizer prepare the input for QA task  that is for the question answering task   [57:36] we need a context as well as a question What  is a context now it is a paragraph or text   [57:41] where the answer might be found that is the  following I'm providing a context also and   [57:47] here is the question So this is about me and  here is the question the question you want   [57:52] to answer Okay So we have said both After  that we will tokenize the input Tokenize   [57:58] the context and question using the tokenizer  We have done both Get the model's prediction   [58:05] Pass the tokenized input to the model  to get the answer That is the following [58:13] It will extract the start and end scores [58:16] also Okay it will get the most likely start and  end positions Okay here And it will use the same   [58:28] to convert token ids back to words so that the  answer is displayed here Answer tokens will be   [58:38] set here and it will be decoded back to words  This will have your output So here the question   [58:44] was where Amit Diwan is based The context was  the following and the answer is Delhi So in   [58:52] this way guys we can perform question answering  easily In this lesson we will understand how we   [59:00] can perform text to image using hugging  face Let us understand with an example   [59:08] So here we will use the hugging face diffusers  library This example will use the stable diffusion   [59:16] model also which is one of the most popular text  to image models available in the diffusers library   [59:24] Now what is the diffusers library and stable  diffusion the diffusers library is an open-source   [59:29] Python library to focus on diffusion models for  generating images audio and other types of data   [59:36] These are a class of generative models only  developed by hugging face What is stable   [59:44] diffusion it is a latent diffusion model  designed for high quality image generation   [59:50] So you can generate images from text prompts  using this It is also one of the most popular   [59:58] generative model Let us see the example here Here  we will use a publicly available model on hugging   [60:08] face Let us see the example and convert text to  image The output will be generated as an image   [60:18] on Google colab itself So let us see here is our  Google colab Let us open our notebook for text to [60:27] image [60:30] Here it [60:34] is First we will install the required libraries  using the same pip install command we already   [60:45] discussed So now we will load the stable  diffusion pipeline The diffusers library   [60:54] provides a stable diffusion pipeline that makes  it easy to generate images from text prompts   [61:01] We will load the stable diffusion model here  Now generate an image from a text prompt Easily   [61:08] generate an image by passing a text prompt to the  pipeline Here is a prompt Flying cars soar over   [61:14] a futuristic cityscape at sunset The following  will generate the image Okay here is our image   [61:25] This image will get saved on Google Colab  only using the same method and it will   [61:31] also print image saved as generated  image.png So a PNG file will get   [61:38] generated Okay where it will be visible  on Google Colab Click here You can see [61:44] files Now I'll run it [61:56] I'll run [61:56] it I'll run this now [62:22] Now I'm running to generate an image and save [62:24] it Okay So here is our image It's  written image saved as generated image [62:37] dotpng Okay So it generated it I'll just go here   [62:43] From here you can download it You  can also copy the path I'll click [62:48] download It downloaded Okay Here it is So  we generated an image that is text to image   [63:08] In this lesson we will understand how to perform  text to video using hardinface This is called   [63:14] text to video synthesis We will understand what  it is and we will also run a sample example So   [63:21] let us start Text to video includes generating  video from textual descriptions like typing a   [63:28] text and generating a video Like we saw in  the previous lesson text to image we typed   [63:33] a text and generated an image In this case  we will generate a video So we have a lot of   [63:40] pre-trained models and tools for generating  videos Hugging face provides the same models   [63:46] The text to video synthesis term I just told it  includes generating a sequence of frames based on   [63:54] a textual description Since it's a complex task  it requires combining different NLP models with   [64:03] generative models or even diffusion models Okay  division models we saw in the previous lesson   [64:08] It is used for generating images or videos Let  us see some video generation frameworks Before   [64:14] moving towards the example one of the most  popular ones are Runway ML It offers tools   [64:20] for video generation and editing Mostly for AI  generated videos you can use pickabs with that   [64:28] deep minds perceiver IO can also be used to  handle multimodel inputs Multimodel input can   [64:35] include text even images and even videos You need  to use the libraries like pytor or tensorflow so   [64:42] that you can build pipelines for generating  video frames Let us see an example So here we   [64:48] will use the diffuser library also We already  discussed the diffuser library It is an open   [64:53] source library developed by hugging face and used  for generating images and even videos We will use   [65:01] the publicly available stable division model  In our example we will run the code on Google   [65:09] Colab like we saw before Let us start Here is  a Google Colab Let us open our code file Open   [65:18] notebook We will open our notebook for text to  video I'll type video only to search Here it [65:25] is First we will install So here we have used the  pip install command to install the transformers as   [65:35] well as the diffusers library also with PyTorch  After that we will load a text to image model So   [65:43] here we are loading it This is the model I already  told you We have used the diffusers library to   [65:52] load a pre-trained text image model like stable  diffusion Generate frames from text First we have   [65:59] set the prompt Here we will generate individual  frames based on the text description So this is   [66:06] the text description A futuristic cityscape at  night with flying cars This will generate 10   [66:13] frames using the for in loop Here it is 10 and  it will append Later on we have used the open   [66:22] CV library to stitch the frames into a video Here  we are using the Open CV inside the for in loop   [66:32] so that we can stitch it We have also used the  numpy library We are using the numpy array in it   [66:40] So this will save frames as images and this will  stitch the frames into videos and the following   [66:48] will display the output which is gathering the  frames using the for in loop and the output will   [66:56] be displayed like this in a form of frames So  here when I'll run it will display me 10 frames   [67:03] because we are generating 10 frames here and  after that in the end it will display the video   [67:10] So here is the output The output video will have  the following name output video.mpp4 but it will   [67:16] also generate frames How many frames 10 frames  The format of the frame will be the following   [67:23] Frame i the value of i So the frames would be  like frame_0.png frame_1.png and it will go   [67:34] until 9 that means 10 frames and the output  will be here I told you Now let us run it [68:21] Now we will click here and here you can see I told  you it will generate 10 frames frame_0.png till 9   [68:32] and output video will be here So this was the  output I'll just click here and click download [68:42] It downloaded right-click and [68:44] open Here is our video Okay You can see 10 [68:51] frames So in this way guys we can generate  video from text with hugging face Thank you   [69:06] for watching the video guys If you like the video  you can directly go to our channel and support us   [69:13] by subscribing and joining Click on the Join  button here and you can support us Okay by   [69:19] clicking join here and you can also go to any  of our video okay here in click on the three   [69:26] dots and click thanks You can also directly  support us here Okay thank you for watching