-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathal_sentiment_analysis.py
32 lines (20 loc) · 1.01 KB
/
al_sentiment_analysis.py
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
from opinions.learn import get_scraped_tweets, compute_uncertainty, TwitterModel, read_true_label, write_predicted_tweets, get_filename, compute_total_sentiment
from opinions import parse_twitter_active_learning_sentiment_args
args = parse_twitter_active_learning_sentiment_args()
filename = get_filename(args.path)
model = TwitterModel("cardiffnlp/twitter-roberta-base-sentiment", args.learning)
tweets = get_scraped_tweets(args.path)
while True:
uncertainty_indexes = compute_uncertainty(tweets)
tweets, X, y = read_true_label(tweets, uncertainty_indexes, args.topic, args.batch, model.config.id2label)
model.training_step(X, y)
tweets = model.predict_multiple(tweets, topic=args.topic)
write_predicted_tweets(filename, tweets)
key = input("Press q to quit or any other key to continue: ")
if key == "q":
break
if args.weight:
print("Weighted sentiment score:")
else:
print("Non weighted sentiment score:")
print(compute_total_sentiment(tweets, model.config, weighted=args.weight))