Sentiment Analysis with BERT Neural Network and Python

Sdílet
Vložit
  • čas přidán 12. 07. 2024
  • Want to leverage advanced NLP to calculate sentiment?
    Can't be bothered building a model from scratch?
    Transformers allows you to easily leverage a pre-trained BERT neural network to do exactly that!
    In this video we'll go through how to get up and running with Hugging Face Transformers and BERT to be able to calculate sentiment. We'll run the model using a single prompt but also leverage BeautifulSoup to scrape reviews from Yelp to be able to calculate sentiment on a larger scale.
    In this video you'll learn how to:
    1. Install Transformers
    2. Perform Sentiment Scoring using BERT and Python
    3. Scrape reviews from Yelp and Calculate their Sentiment
    Get the code for this tutorial: github.com/nicknochnack/BERTS...
    Thanks so much to Mito for sponsoring this video! Mito is an amazing JupyterLab plugin that allows you to work with your data easily using a drag and drop interface that's similar to Excel. Try it out for FREE at trymito.io! If you need a little help getting started, check out the tutorial: docs.trymito.io/getting-start...
    Chapters
    0:00 - Start
    0:23 - How it Works
    1:48 - Tutorial Start
    2:55 - Install and Import Dependencies
    9:20 - Setup BERT and Transformers Neural Network
    11:27 - Encode Sentences for Modelling and Calculate Sentiment
    16:40 - Scrape Reviews from Yelp using BeautifulSoup
    22:41 - Load Reviews into Pandas and Calculate Sentiment
    29:52 - Run the Sentiment Pipeline for Multiple Reviews
    31:32 - Wrap Up
    Oh, and don't forget to connect with me!
    LinkedIn: bit.ly/324Epgo
    Facebook: bit.ly/3mB1sZD
    GitHub: bit.ly/3mDJllD
    Patreon: bit.ly/2OCn3UW
    Join the Discussion on Discord: bit.ly/3dQiZsV
    Happy coding!
    Nick
    P.s. Let me know how you go and drop a comment if you need a hand!
  • Věda a technologie

Komentáře • 204

  • @abrh2793
    @abrh2793 Před 2 lety +23

    I love how you take your time to explain each sentences and what they do! Absolutely love it!
    Very helpful as a beginner!
    Keep up

  • @hemalshah1410
    @hemalshah1410 Před 2 lety

    BERT with multilingual benefit is great advantage for analysis of text (especially with large-diverse dataset ) . This is enlightening ! Thank you Nik

  • @satoshinakamoto5710
    @satoshinakamoto5710 Před 2 lety

    Thanks again for this tutorial Nick. My challenge is to 100% finish all your tutorials. 3hrs, 5hrs, 8hrs, 100hrs. all of it.

  • @sebastianzapata9368
    @sebastianzapata9368 Před rokem +3

    amazing video! I mixed the content from your code with a csv file that I got from extracting tweets and now I can do a sentiment analysis on so many subjects! Thank you!!

    • @JcOnAFieldtrip
      @JcOnAFieldtrip Před rokem

      hi im trying that as well, did you convert your file to a data frame like in the video?

  • @sahilsmohanty2663
    @sahilsmohanty2663 Před 3 lety +17

    These kind of content is what most budding ML enthusiasts need. Thanks for this

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +4

      Anytime, so glad you enjoyed it @Sahil!

    • @madhu1987ful
      @madhu1987ful Před 2 lety

      @@NicholasRenotte Hey, pls do a detailed video on Beautiful Soup. Also my request is pls make a video on other NLP usecases - text summarization, topic modeling, NER, text generation, Q&A with pretrained models (BERT, ROBERTA, GPT and so on)

  • @bhavikdudhrejiya852
    @bhavikdudhrejiya852 Před rokem

    Your channel is a treasure for Data Scientist.

  • @pauliusjanuska4090
    @pauliusjanuska4090 Před 2 lety +4

    Amazing video! Simple, structured, keep up the good work !!! P.S This helped me so much on my course lol

  • @arjumann5480
    @arjumann5480 Před 2 lety +2

    You made it sound so simple! This is apt for beginners like me. Thank you ^^

  • @seherkanwal245
    @seherkanwal245 Před rokem

    I love the way you teach. I'm going to do my final year project on sentimental recommendation system. This will help me a lot

  • @daniel_partida
    @daniel_partida Před 2 lety

    Excellent video explaining multiple concepts. Thank you for the great content!

  • @metinunlu_
    @metinunlu_ Před rokem +1

    Incredible work, love your explanations. Thank you!

  • @superrelaxation508
    @superrelaxation508 Před 2 lety +2

    brother I wanna say that your videos are very easy to understand and along the way to follow practically in our computer please make complete course on NLP and OPENCV And Machine learning because you are very good teacher I very like you god give you long life with a lot of happiness

  • @raznyrazeek
    @raznyrazeek Před 7 měsíci

    You are a life saver man. i was stusked with my research. you saved me.. i understood the basics. Thanks

  • @francescue8128
    @francescue8128 Před 2 lety +1

    Awesome video. Simple and easy to follow. Thank you.

  • @madhu1987ful
    @madhu1987ful Před 2 lety +1

    Awesome video, so neatly explained step by step --- thanks a lot

  • @rolsondeleferme6825
    @rolsondeleferme6825 Před 3 lety +1

    Very good pal. You keep it simple and at high level.
    I would be happy to see those two negative votes to elaborate further why they are not satisfied though..

  • @stefan6825
    @stefan6825 Před 3 lety +5

    Love this video! You have an amazing skill in teaching others and make it look so simple.
    I'm subscribing you and I guess on my journey learning python I will watch a lot of your videos. Thanks a lot!

  • @thaGkillah
    @thaGkillah Před 3 lety +10

    Hey Nik!
    I've been looking left and right for a guide on how to interpret the logits from BERT and thank god you've uploaded something that explains it well! I liked and subscribed.
    (Maybe you could refer me to a source, where you happen to learn it? - looking one for the FinBert variant)
    Also, your crash course on that scraping part is straight on point and I love that you executed each line from it to show you how it gets transformed.
    You are truly blessed with an out-of-this-world tutoring skill!

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +5

      Thanks sooo much @Capt_Kaplan! I'm kinda just doing a lot of googling to learn it atm, there's heaps of examples of custom models in the HF model repo though, check this out: huggingface.co/ProsusAI/finbert

  • @liamalam
    @liamalam Před 3 lety +1

    An excellent tutorial. Thank you much for this.

  • @christophercrager1925
    @christophercrager1925 Před 2 lety +1

    Great video. Would love to see a scraping tutorial. Especially one where you could pass credentials and log in first

  • @Daniel-dv6kw
    @Daniel-dv6kw Před 28 dny

    Awesome stuff man, helping me on my project

  • @shabirahmed6510
    @shabirahmed6510 Před rokem

    Great video! simple and quick to get good results thanks a lot!

  • @GauravKumar-xg4sw
    @GauravKumar-xg4sw Před 2 lety

    This is best content on bert .. loved the explanation ..

  • @sagara5982
    @sagara5982 Před 3 lety +3

    I'm a new subscriber.., loving ur videos already... Cheers man all the best

  • @bertranddol
    @bertranddol Před 2 lety

    Great content, great delivery .... overall great video

  • @luizkrein
    @luizkrein Před 2 lety

    Awesome video, now I need to find a Brazilian Portuguese trained model asap to test it.
    Thanks!

  • @kian69topgun1
    @kian69topgun1 Před 2 lety

    Good conceptual video. I was your 1k'th like

  • @JohnM-ch4to
    @JohnM-ch4to Před 3 lety +1

    Great vid! Not one of the more popular requests here but would be interested on a deep dive in building scrapers. It's kind of a niche topic since it's not the most exciting part of ML or Data Science but at least I get to throw my hat into the table. Haha. Looking forward to more vids =)

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      You got it @John, was planning on doing a live stream on it! But might put it into my Python for Data Science course that's coming!

  • @santiagobardelli5675
    @santiagobardelli5675 Před 7 měsíci

    Great job, Nicholas!

  • @69nukeee
    @69nukeee Před 5 měsíci

    Sweet video, loved it!

  • @Michael-dl4sj
    @Michael-dl4sj Před 3 lety +9

    Awesome video! If its to the extend of your knowledge, a subsequent video about fine-tuning a pre-trained model to a particular dataset would be very interesting. So train, test and validate the accuracy of a model pre- and post-training. I have read some articles which showed accuracy of a model can be improved significantly when trained on the particular dataset.

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +11

      Definitely, plus the models become a lot more practical when tuned to your use case. Definitely will have a series of tutorials or one mega tutorial coming on it soon @Michael!

    • @khouloudsafi1445
      @khouloudsafi1445 Před 2 lety

      @@NicholasRenotte did you make a tutorial about this issue already ?
      I couldn't like your video more,, it's simple, informative, short and just straight to the point :)
      Thank you

  • @dheerajchoudhury
    @dheerajchoudhury Před 3 lety +2

    Love your videos bro 😉
    Feel like lot to learn

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +1

      Thanks a bunch @Dheeraj! Definitely always something new!

  • @rizf800
    @rizf800 Před rokem

    exactly what i was looking for thank you you made my day🥰🥰🥰

  • @celynraquel5982
    @celynraquel5982 Před 3 lety +1

    Amazing video!

  • @joe8ones
    @joe8ones Před 3 lety +14

    Yes, i think a bigger web scraping tutorial would be beneficial

  • @Aynold
    @Aynold Před 3 lety +5

    Hello Nicholas Reynolds, I am a college student, I like your video very much, I keep learning, you are my half teacher, thank you very much, look forward to more videos

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Thanks so much! Stick around, plenty more mega courses to come!!

  • @PriteshRPatel-lr5uh
    @PriteshRPatel-lr5uh Před 4 měsíci

    really loved your video. Would like to see if you can do same video but for stocks such as NVDA or TSLA. Thanks.👍

  • @muzammelmokhtar6498
    @muzammelmokhtar6498 Před 3 lety +1

    Very good explanation and content

  • @morningstar618z8
    @morningstar618z8 Před 2 lety +1

    Great tutorial thanks

  • @krishnamore2281
    @krishnamore2281 Před 3 lety +1

    Thank you for making a video on this

  • @ameerazam3269
    @ameerazam3269 Před 3 lety +1

    Appreciate your work sir

  • @rolandohernandez6627
    @rolandohernandez6627 Před rokem

    Muy util. muchas gracias por la informacion. Saludos desde Mexico

  • @molmock
    @molmock Před rokem

    Thank you so much !

  • @ameerazam3269
    @ameerazam3269 Před 3 lety +1

    Again best explanation

  • @fahnub
    @fahnub Před 11 měsíci

    Cool and informative.

  • @subratasaha8820
    @subratasaha8820 Před 2 lety +4

    awesome explanation. however i have some questions, is text preprocessing included in the BERT model? and what is the thing with 'x[:512]' limitation?

  • @owaisahmad8336
    @owaisahmad8336 Před rokem

    Amazing!

  • @kashishrajput4934
    @kashishrajput4934 Před rokem

    Great Thank you.

  • @dec13666
    @dec13666 Před 3 lety +1

    Nice vid.
    It's an application of BERT, does not quite add much new science... But good enough for some hands on with it.
    Keep it up 👍

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Yah, kept this one super high level. Can definitely get way further down into the weeds!

  • @nimishbansal4752
    @nimishbansal4752 Před 3 lety +1

    Great work bro..pls make a video on activity recognition using mediapipe

  • @yeast1103
    @yeast1103 Před rokem

    Thank you

  • @mamadoumoussabangoura2031

    i like so much your cours

  • @sebasgutierrezjuansgutierr3666

    Awesome as always!! I really appreciated this. Did you finally made a web scraping for data science super tutorial!??. Please tell me you did!😃

  • @shanthiathisayaraj7833
    @shanthiathisayaraj7833 Před 3 lety +1

    Awsome buddy

  • @user-or7ji5hv8y
    @user-or7ji5hv8y Před 3 lety +1

    this is cool!

  • @peterkhoo9606
    @peterkhoo9606 Před 3 lety +1

    Fantastic explanation on all videos. just wondering whether you can do a video on sktime - installation, introduction, processes , etc. Hope to hear from you. cheerio

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Haven't heard of it before, is that a timeseries lib for scikitlearn? Sounds awesome if so!

  • @heisenbergwhite5845
    @heisenbergwhite5845 Před 3 lety +1

    Would love a video on fake news detection.
    Thanks for teaching us!

  • @nandankakadiya1494
    @nandankakadiya1494 Před 3 lety +1

    Another great tutorial thanks man
    Have one question in this video we are able to extract reviews from page 1 only so how to extract reviews from all the pages?
    Thanks once agian

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +1

      Could loop through the subsequent pages as well @Nandan! Would need to build a more sophisticated scraper for that however.

  • @Michael-dl4sj
    @Michael-dl4sj Před 3 lety +2

    Hey Nicholas, is there any way of changing the bert sentiment score from 1-5 to a floating value between 0-1, similar to for example the vader sentiment score? Or do I need another bert sentiment model for this? Thanks in advance :)

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Need another BERT model @Michael, this one is specifically trained to give you a binary value.

  • @RS-vu5um
    @RS-vu5um Před 2 lety

    Excellent Video.
    Can you point me to the changes to be made if TensorFlow is used?

  • @jegadeeswarisridharan341

    wonderful

  • @JC-xl5ti
    @JC-xl5ti Před rokem +1

    Awesome video! But, I was wondering if text preprocessing (removing punctuations, stopwords, lemmatization, etc) is needed before encoding the reviews? Appreciated if can get an answer

    • @faizanyounas4799
      @faizanyounas4799 Před rokem

      Yes, in the preprocessing we remove all the noise from the data.

  • @diveshbhagooli6631
    @diveshbhagooli6631 Před 3 lety +1

    You’re the best around!! Thank you for this!!
    One question: is it possible to extract comments from a Facebook post?
    Thank you.

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      I think it's pretty tricky, FB is notoriously hard to scrape. Can probably get your own comments via the API?

  • @ashaoluayanfe7474
    @ashaoluayanfe7474 Před 2 lety

    Hello Nicholas, many thanks for the vidoe, how can one implement this code in tensorflow or what advantage pytorch has over tensorflow in Bert implementation?

  • @leonvanpersi8044
    @leonvanpersi8044 Před rokem

    Thank you for the video. Can I run a content analysis on short Customer Feedbacks that's releable?

  • @lowwwleechi
    @lowwwleechi Před 3 lety +2

    Hi Nicholas, thank you for the video! It's really helpful for my work. Also, I have a question that is it a must to do text pre-processing by applying NLP model using deep learning? because it seems like you didn't apply any text preprocessing method for the raw text you've scraped.

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +1

      For these models they're able to handle raw unprocessed input as they have a pre-processing pipeline built in @lowwwleechi. If i got sucky results I might add some additional pre-proc to improve the results!

    • @lowwwleechi
      @lowwwleechi Před 2 lety

      @@NicholasRenotte Got it! Thanks a lot!

  • @joaofmoura2
    @joaofmoura2 Před rokem

    Very good !!!! IBM

  • @owenhochwald506
    @owenhochwald506 Před rokem

    instead of using a lambda function for adding the review scores to the dataframe, would it be equally as good to use list comprehension to get a list of the scores then creating a new column out of that in the dataframe?

  • @rainymornings
    @rainymornings Před rokem

    Hmm this is helpful for reviews but not for pos/neu/neg sentiment analysis, which is what I was actually trying to get some examples of regarding score interpretation.

  • @merakshitrading9216
    @merakshitrading9216 Před 9 měsíci

    scraping a web page and using that data as training data within a chat bot would be very interesting.

  • @subhanbasha8813
    @subhanbasha8813 Před 3 lety +1

    Hello Nicholas,
    Is it recommend to code all the machine learning algorithms from scratch so that I can learn math behind it or just understand and start to code?

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      I don't personally think so, I think it's more important to know how to use them as a Data Scientist. If you're looking to get into research however you would probably need a deeper understanding however!

  • @DeliHunV
    @DeliHunV Před 3 měsíci

    Hey Nicholas Great Video!!! I was wondering if I could change the url in the code and give the class name of another website's comments other than YELP will it still work...

  • @asrikinantifebriany6228

    hey what a great videos, can you make a tutorial for sentiment analysis deployment to a simple web?

  • @naresh22081989
    @naresh22081989 Před 2 lety +1

    Hi Nichola, thank you for this video. Good information 👍 I have a doubt, can it handle sarcastic reviews? Also don't we remove shop words from text data?

    • @NicholasRenotte
      @NicholasRenotte  Před 2 lety

      Ooooh, I doubt it tbh. You can definitely do stop word removal, I was just being a little lazy in this.

  • @wsr005
    @wsr005 Před 2 lety

    Hi, I'm just learning NLP and it's totally new to me. Just want to know how to know how tokens / text can be passed for particular nlp pipeline? Thanks in advance

  • @ajithnaidu6978
    @ajithnaidu6978 Před rokem

    Hi Nicholas , can you explain me how can I scrape rating of particular user from the webpage you mentioned

  • @ey5722
    @ey5722 Před 3 lety +1

    Thank you so much. Your video is so helpful. Is it possible to make another one about how to do sentiment analysis with BERTweet for covid -19 tweets? Thanks again.

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      You got it! Working on a bunch of NLP stuff atm.

    • @ey5722
      @ey5722 Před 3 lety

      @@NicholasRenotte Did you make a video about BERTWEET? I didn't find it.

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      @@ey5722 nope, not yet.

  • @akshatkhanna2517
    @akshatkhanna2517 Před 2 lety

    Please make a video tutorial on Web scraping as well.

  • @ghpkishore
    @ghpkishore Před 3 lety +1

    Can you make one on mT5 or m2m100 for language translation models and how they can be trained from huggingface. Would be super helpful for techies across countries where content is limited.

  • @melly-by8tm
    @melly-by8tm Před 8 měsíci

    May I know if this support a multi-language in one sentences or in one review?

  • @interlightstudio1645
    @interlightstudio1645 Před 2 lety

    Do you currently have a video that covers how to do this? ->> "Can't be bothered building a model from scratch?". i would like to learn how to build or fine tune BERT. thanks

  • @harryfeng4199
    @harryfeng4199 Před 2 lety

    What’s the logic behind setting the slice up util 512 when we were making our predictions?

  • @diegotestdireco3494
    @diegotestdireco3494 Před rokem

    Great video, Is there a package for Spanish or only in English?

  • @henkhbit5748
    @henkhbit5748 Před 3 lety +1

    Multi-langual and Dutch too... A double Heineken for u🍻
    Maybe another vid of text classification for different classes/categories based on Bert ( Bert-base, multilangual cased) Not specific sentiment but categorizing sentences/text into subjects like cars, beers,soccer...

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      You got it, actually started work on a mega NLP tutorial. Zero-Shot Classification would be perfect for that!! Can't wait to drink that Heineken this weekend, still hoping Hamilton beats Verstappen though 😂.

    • @henkhbit5748
      @henkhbit5748 Před 3 lety

      @@NicholasRenotte Looking forward👍
      Until this new season the F1 races were dominated by Mercedes. It is like running tensorflow with gpu versus tpu 😁 If Verstappen or other talented drivers got the same racing car as Hamilton then the competition would be more interesting .... But of course I hope Verstappen will win!

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety +1

      @@henkhbit5748 you almost had your wish this weekend 😂 if those tyres didn't blow Verstappen was on a dream run!

    • @henkhbit5748
      @henkhbit5748 Před 3 lety

      @@NicholasRenotte Yes the anomaly detetection algroritjm of Red Bull could be improved and I think Hamilton has not trained with the rigt AI Gym RL algorithm 😎

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      @@henkhbit5748 😂 😂 😂

  • @ariebenzadon6435
    @ariebenzadon6435 Před rokem

    Is there a bert multingual up to date? This program you are using, uses old versions of numpy... between others. If there is an up to date version, it would be amazing to know, where to find it, thanks!

    • @ariebenzadon6435
      @ariebenzadon6435 Před rokem

      if not, could you especify the version of nunmpy that was used

  • @orntunlaya
    @orntunlaya Před rokem

    Thank you for sub Thai💖🥺🙏

  • @ghost_assassinz1877
    @ghost_assassinz1877 Před rokem

    How would I fine tune this because right now im getting some inaccurate reviews. For some some reviews it is giving me 3 when it should be 4 stars or it is giving 5

  • @ravikshdikola6089
    @ravikshdikola6089 Před 2 lety +1

    Can we add fully connected layer on top of that model to use it for other text preprocessing tasks 🤔

    • @NicholasRenotte
      @NicholasRenotte  Před 2 lety

      Could probably pass through the logits to a subsequent layer!

  • @chrisfig2387
    @chrisfig2387 Před 3 lety +2

    Hello Nicholas!, i got a question is there any ML that can extract keywords from a text?

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Could use Named Entity Recognition to extract keyword types. If you're just looking for specific keywords you could just use a find function!

    • @chrisfig2387
      @chrisfig2387 Před 3 lety

      @@NicholasRenotte Thank you, love your work!

  • @monicaaraneda7462
    @monicaaraneda7462 Před rokem

    I have a problem: RuntimeError: Failed to import transformers.models.bert.modeling_bert because of the following error (look up to see its traceback):
    No module named 'torch.utils'

  • @chiranshuadik9818
    @chiranshuadik9818 Před 3 lety +1

    bert is too big (1GB for the one with good quality). What would be the best way to deploy it with my django back end? Any recommendations?

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      Deploy it as an API or use a pre-hosted instance (they're available direct through HF Hosted)

  • @pahadiasd5992
    @pahadiasd5992 Před 2 lety

    @Nicholas Renotte can u help me or tell me how to apply word embeddings in BERT for text classification

  • @ritajohn5102
    @ritajohn5102 Před 18 dny

    can you explain the advantage and disadvantage of using pre-trained model in our data?

  • @ButchCassidyAndSundanceKid

    Can BERT be used on time series data I wondered ?

    • @NicholasRenotte
      @NicholasRenotte  Před 3 lety

      It's mainly for NLP :), take a look at the Facebook prophet vids for time series forecasting!

  • @sitiauniamaram3422
    @sitiauniamaram3422 Před 2 lety +1

    How to validate the output of the sentiment?

  • @souhamahmoudi7745
    @souhamahmoudi7745 Před rokem

    you should be downloading videos every single day.

  • @yussefleon4904
    @yussefleon4904 Před rokem

    Hello, instead of doing the first 512 tokens, aren't you just taking the first 512 characters? Lov your videos btw :)

  • @RedCloudServices
    @RedCloudServices Před rokem

    Love mito but had them on a zoom call - it does not work with streamlit app. Perhaps it does not work with any app outside of a Jupyter notebook not sure 🤷‍♂️

  • @squadgang1678
    @squadgang1678 Před rokem

    Can you do sentiment analysis using apache spark - pyspark mllib

  • @atharvagangil4860
    @atharvagangil4860 Před rokem

    Hey! When I change the website to another one (like Amazon), it doesn't go with it. Please help me with it