Sentiment Analysis with BERT Neural Network and Python

Поделиться
HTML-код
  • Опубликовано: 19 июн 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!
  • НаукаНаука

Комментарии • 203

  • @abrh2793
    @abrh2793 2 года назад +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 2 года назад

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

  • @sebastianzapata9368
    @sebastianzapata9368 Год назад +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 Год назад

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

  • @satoshinakamoto5710
    @satoshinakamoto5710 Год назад

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

  • @sahilsmohanty2663
    @sahilsmohanty2663 3 года назад +17

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

    • @NicholasRenotte
      @NicholasRenotte  3 года назад +4

      Anytime, so glad you enjoyed it @Sahil!

    • @madhu1987ful
      @madhu1987ful 2 года назад

      @@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)

  • @seherkanwal245
    @seherkanwal245 Год назад

    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 2 года назад

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

  • @metinunlu_
    @metinunlu_ Год назад +1

    Incredible work, love your explanations. Thank you!

  • @bhavikdudhrejiya852
    @bhavikdudhrejiya852 Год назад

    Your channel is a treasure for Data Scientist.

  • @arjumann5480
    @arjumann5480 2 года назад +2

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

  • @superrelaxation508
    @superrelaxation508 2 года назад +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 6 месяцев назад

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

  • @francescue8128
    @francescue8128 2 года назад +1

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

  • @rolsondeleferme6825
    @rolsondeleferme6825 2 года назад +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..

  • @thaGkillah
    @thaGkillah 3 года назад +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  3 года назад +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 2 года назад +1

    An excellent tutorial. Thank you much for this.

  • @madhu1987ful
    @madhu1987ful 2 года назад +1

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

  • @shabirahmed6510
    @shabirahmed6510 Год назад

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

  • @stefan6825
    @stefan6825 2 года назад +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!

  • @pauliusjanuska4090
    @pauliusjanuska4090 2 года назад +4

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

  • @christophercrager1925
    @christophercrager1925 2 года назад +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 5 дней назад

    Awesome stuff man, helping me on my project

  • @luizkrein
    @luizkrein 2 года назад

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

  • @Michael-dl4sj
    @Michael-dl4sj 3 года назад +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  3 года назад +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 2 года назад

      @@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

  • @69nukeee
    @69nukeee 4 месяца назад

    Sweet video, loved it!

  • @GauravKumar-xg4sw
    @GauravKumar-xg4sw 2 года назад

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

  • @santiagobardelli5675
    @santiagobardelli5675 6 месяцев назад

    Great job, Nicholas!

  • @bertranddol
    @bertranddol 2 года назад

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

  • @celynraquel5982
    @celynraquel5982 2 года назад +1

    Amazing video!

  • @rizf800
    @rizf800 Год назад

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

  • @sagara5982
    @sagara5982 3 года назад +3

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

    • @NicholasRenotte
      @NicholasRenotte  3 года назад +1

      Thanks so much @First Attempt, welcome to the fam!

  • @Aynold
    @Aynold 3 года назад +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  3 года назад

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

  • @JohnM-ch4to
    @JohnM-ch4to 3 года назад +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  3 года назад

      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!

  • @PriteshRPatel-lr5uh
    @PriteshRPatel-lr5uh 3 месяца назад

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

  • @joe8ones
    @joe8ones 2 года назад +14

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

  • @morningstar618z8
    @morningstar618z8 2 года назад +1

    Great tutorial thanks

  • @kian69topgun1
    @kian69topgun1 2 года назад

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

  • @molmock
    @molmock Год назад

    Thank you so much !

  • @subratasaha8820
    @subratasaha8820 2 года назад +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?

  • @dheerajchoudhury
    @dheerajchoudhury 3 года назад +2

    Love your videos bro 😉
    Feel like lot to learn

    • @NicholasRenotte
      @NicholasRenotte  3 года назад +1

      Thanks a bunch @Dheeraj! Definitely always something new!

  • @rolandohernandez6627
    @rolandohernandez6627 Год назад

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

  • @fahnub
    @fahnub 10 месяцев назад

    Cool and informative.

  • @krishnamore2281
    @krishnamore2281 3 года назад +1

    Thank you for making a video on this

  • @muzammelmokhtar6498
    @muzammelmokhtar6498 3 года назад +1

    Very good explanation and content

    • @NicholasRenotte
      @NicholasRenotte  3 года назад

      Thanks so much @Muzammel! So glad you enjoyed it.

  • @ameerazam3269
    @ameerazam3269 3 года назад +1

    Appreciate your work sir

  • @owaisahmad8336
    @owaisahmad8336 Год назад

    Amazing!

  • @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!😃

  • @kashishrajput4934
    @kashishrajput4934 Год назад

    Great Thank you.

  • @yeast1103
    @yeast1103 Год назад

    Thank you

  • @nimishbansal4752
    @nimishbansal4752 3 года назад +1

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

  • @ameerazam3269
    @ameerazam3269 3 года назад +1

    Again best explanation

  • @peterkhoo9606
    @peterkhoo9606 3 года назад +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  3 года назад

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

  • @dec13666
    @dec13666 3 года назад +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  2 года назад

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

  • @ashaoluayanfe7474
    @ashaoluayanfe7474 2 года назад

    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?

  • @RS-vu5um
    @RS-vu5um 2 года назад

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

  • @owenhochwald506
    @owenhochwald506 Год назад

    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?

  • @nandankakadiya1494
    @nandankakadiya1494 3 года назад +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  3 года назад +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 3 года назад +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  3 года назад

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

  • @mamadoumoussabangoura2031
    @mamadoumoussabangoura2031 Год назад

    i like so much your cours

  • @JC-xl5ti
    @JC-xl5ti Год назад +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 Год назад

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

  • @diveshbhagooli6631
    @diveshbhagooli6631 3 года назад +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  3 года назад

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

  • @lowwwleechi
    @lowwwleechi 2 года назад +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  2 года назад +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 2 года назад

      @@NicholasRenotte Got it! Thanks a lot!

  • @ajithnaidu6978
    @ajithnaidu6978 Год назад

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

  • @wsr005
    @wsr005 2 года назад

    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

  • @leonvanpersi8044
    @leonvanpersi8044 Год назад

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

  • @rainymornings
    @rainymornings Год назад

    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.

  • @asrikinantifebriany6228
    @asrikinantifebriany6228 Год назад

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

  • @DeliHunV
    @DeliHunV 3 месяца назад

    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...

  • @jegadeeswarisridharan341
    @jegadeeswarisridharan341 2 года назад

    wonderful

  • @merakshitrading9216
    @merakshitrading9216 9 месяцев назад

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

  • @heisenbergwhite5845
    @heisenbergwhite5845 3 года назад +1

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

  • @naresh22081989
    @naresh22081989 2 года назад +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  2 года назад

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

  • @subhanbasha8813
    @subhanbasha8813 3 года назад +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  3 года назад

      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!

  • @melly-by8tm
    @melly-by8tm 8 месяцев назад

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

  • @shanthiathisayaraj7833
    @shanthiathisayaraj7833 3 года назад +1

    Awsome buddy

  • @ghost_assassinz1877
    @ghost_assassinz1877 Год назад

    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

  • @harryfeng4199
    @harryfeng4199 2 года назад

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

  • @user-or7ji5hv8y
    @user-or7ji5hv8y 3 года назад +1

    this is cool!

  • @ghpkishore
    @ghpkishore 3 года назад +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.

    • @NicholasRenotte
      @NicholasRenotte  3 года назад

      You got it! Got a ton more HF stuff coming as well.

  • @diegotestdireco3494
    @diegotestdireco3494 Год назад

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

  • @ey5722
    @ey5722 2 года назад +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  2 года назад

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

    • @ey5722
      @ey5722 2 года назад

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

    • @NicholasRenotte
      @NicholasRenotte  2 года назад

      @@ey5722 nope, not yet.

  • @interlightstudio1645
    @interlightstudio1645 2 года назад

    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

  • @akshatkhanna2517
    @akshatkhanna2517 Год назад

    Please make a video tutorial on Web scraping as well.

  • @yussefleon4904
    @yussefleon4904 Год назад

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

  • @pahadiasd5992
    @pahadiasd5992 2 года назад

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

  • @joaofmoura2
    @joaofmoura2 Год назад

    Very good !!!! IBM

  • @monicaaraneda7462
    @monicaaraneda7462 Год назад

    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'

  • @ariebenzadon6435
    @ariebenzadon6435 Год назад

    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 Год назад

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

  • @sitiauniamaram3422
    @sitiauniamaram3422 2 года назад +1

    How to validate the output of the sentiment?

  • @atharvagangil4860
    @atharvagangil4860 Год назад

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

  • @harikiran8182
    @harikiran8182 Год назад

    Is there any method to evaluate output ?

  • @chrisfig2387
    @chrisfig2387 3 года назад +2

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

    • @NicholasRenotte
      @NicholasRenotte  3 года назад

      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 3 года назад

      @@NicholasRenotte Thank you, love your work!

  • @ravikshdikola6089
    @ravikshdikola6089 2 года назад +1

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

    • @NicholasRenotte
      @NicholasRenotte  2 года назад

      Could probably pass through the logits to a subsequent layer!

  • @RedCloudServices
    @RedCloudServices Год назад

    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 🤷‍♂️

  • @henkhbit5748
    @henkhbit5748 3 года назад +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  3 года назад

      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 3 года назад

      @@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  3 года назад +1

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

    • @henkhbit5748
      @henkhbit5748 3 года назад

      @@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  3 года назад

      @@henkhbit5748 😂 😂 😂

  • @mysticallybeautiful2368
    @mysticallybeautiful2368 6 месяцев назад

    I am stuck as i want to add an input which will be predicted. So basically i want to add an input ( a user would write a line for which the sentiment should be predicted) but i am unable to write the code for it. Can anyone please help me.

  • @chiranshuadik9818
    @chiranshuadik9818 2 года назад +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  2 года назад

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

  • @squadgang1678
    @squadgang1678 Год назад

    Can you do sentiment analysis using apache spark - pyspark mllib

  • @casmirsunny7784
    @casmirsunny7784 Год назад

    I am interested in Data science web scraping. How do I go about it?

  • @andrewkariuki
    @andrewkariuki 2 года назад

    Hi Nick?
    Am currently pursuing a masters degree and seeking thesis ideas. Any ideas, ideally in ML, would be appreciated.