Predicting customer behavior with sentiment analysis
In this section, we will run a sentiment analysis task on several Hugging Face transformer models to see which ones produce the best results and the ones we simply like the best.
We will begin this by using a Hugging Face DistilBERT model.
Sentiment analysis with DistilBERT
Let's run a sentiment analysis task with DistilBERT and see how we can use the result to predict customer behavior.
Open SentimentAnalysis.ipynb
and the transformer installation and import cells:
!pip install -q transformers
from transformers import pipeline
We will now create a function named classify
, which will run the model with the sequences we send to it:
def classify(sequence,M):
#DistilBertForSequenceClassification(default model)
nlp_cls = pipeline('sentiment-analysis')
if M==1:
print(nlp_cls.model.config)
return nlp_cls(sequence)
Note that if you send M=1
to the function, it will display...