Repository navigation
Expand file tree
/
Copy pathrun_emotion.txt
More file actions
37 lines (25 loc) · 2.1 KB
/
Copy pathrun_emotion.txt
File metadata and controls
37 lines (25 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
this time performing Text Classification using a model specifically fine-tuned for Emotion Detection.
This task takes a piece of text and predicts the emotion expressed (e.g., joy, sadness, anger). We will use a specific model trained for this purpose.
Prerequisites:
Ensure you have the necessary libraries. The model we'll use is based on RoBERTa and likely requires sentencepiece.
Bash
pip install transformers sentencepiece torch
# Or: pip install transformers sentencepiece tensorflow
(Ensure your existing virtual environment is active).
Explicit Model Choice:
We will use j-hartmann/emotion-english-distilroberta-base. This model is a distilled (smaller, faster) version of RoBERTa that has been specifically fine-tuned on English datasets annotated with emotions (typically labels like anger, disgust, fear, joy, neutral, sadness, surprise).
How to Run:
Make sure you've run pip install transformers sentencepiece torch (or the tensorflow equivalent) in your activated virtual environment.
Save the code above into a file named run_emotion.py.
Open your Ubuntu terminal.
Make sure your virtual environment is activated (source .venv/bin/activate).
Run the script:
Bash
python run_emotion.py
What to Expect:
First Run: It will download the j-hartmann/emotion-english-distilroberta-base model files (DistilRoBERTa is smaller than base/large models) and cache them locally.
Classification Execution: The model will process each input sentence and predict the probability of it belonging to each of the emotion categories it was trained on (e.g., joy, sadness, anger, fear, surprise, disgust, neutral).
Output: For each input sentence, it will print:
The sentence itself.
A list of emotions ranked by their predicted score (highest probability first). You should see that the top prediction generally matches the expected emotion for each sentence (e.g., "joy" for the first sentence, "anger" or "disgust" for the traffic sentence, "fear" or "sadness" for the anxiety sentence, etc.).
This example demonstrates using a specific, pre-trained text classification model for a nuanced task like emotion detection, running entirely locally.