Spaces:
Runtime error
Runtime error
Commit
·
af2c220
1
Parent(s):
17fc7b7
Update scripts/sentiment.py
Browse files- scripts/sentiment.py +6 -8
scripts/sentiment.py
CHANGED
|
@@ -6,6 +6,11 @@ from tqdm import tqdm
|
|
| 6 |
import numpy as np
|
| 7 |
import numpy as np
|
| 8 |
import scipy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def tweet_cleaner(tweet: str) -> str:
|
| 11 |
# words = set(nltk.corpus.words.words())
|
|
@@ -93,13 +98,6 @@ def twitter_sentiment_api_score(
|
|
| 93 |
}
|
| 94 |
)
|
| 95 |
else:
|
| 96 |
-
|
| 97 |
-
from transformers import AutoModelForSequenceClassification
|
| 98 |
-
from transformers import TFAutoModelForSequenceClassification
|
| 99 |
-
from transformers import AutoTokenizer
|
| 100 |
-
from scipy.special import softmax
|
| 101 |
-
import os
|
| 102 |
-
|
| 103 |
task = "sentiment"
|
| 104 |
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"
|
| 105 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
|
@@ -124,7 +122,7 @@ def twitter_sentiment_api_score(
|
|
| 124 |
results["argmax"] = max_key
|
| 125 |
return results
|
| 126 |
|
| 127 |
-
return [get_sentimet(t) for t in tweet_list]
|
| 128 |
|
| 129 |
# Loop through the list of sentiment scores and replace the sentiment labels with more intuitive labels
|
| 130 |
result = []
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import numpy as np
|
| 8 |
import scipy
|
| 9 |
+
from transformers import AutoModelForSequenceClassification
|
| 10 |
+
from transformers import TFAutoModelForSequenceClassification
|
| 11 |
+
from transformers import AutoTokenizer
|
| 12 |
+
from scipy.special import softmax
|
| 13 |
+
import os
|
| 14 |
|
| 15 |
def tweet_cleaner(tweet: str) -> str:
|
| 16 |
# words = set(nltk.corpus.words.words())
|
|
|
|
| 98 |
}
|
| 99 |
)
|
| 100 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
task = "sentiment"
|
| 102 |
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"
|
| 103 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
|
|
|
| 122 |
results["argmax"] = max_key
|
| 123 |
return results
|
| 124 |
|
| 125 |
+
return [get_sentimet(t) for t in tqdm(tweet_list)]
|
| 126 |
|
| 127 |
# Loop through the list of sentiment scores and replace the sentiment labels with more intuitive labels
|
| 128 |
result = []
|