Are there many positive people on Vtuber? Are there many negative people? This time, I analyzed Vtuber's tweets and measured their positiveness.
As a result, Sana Natori was found to be positive.
[('Neutral', 31), ('Positive', 12), ('Negative', 7)]
1.7142857142857142
A little positive
We also analyzed tweets from DWU and Machinery Tomoko.
This time, we will analyze emotions with COTOHA API. COTOHA API is an API developed by NTT Communications and uses the results of 40 years of research on Japanese language technology. You can easily perform annoying sentiment analysis just by sending a text. In addition to the sentiment analysis API used this time, there are also syntax analysis and keyword extraction APIs.
As a basic policy, we will first analyze about 50 emotions. Of the 50 tweets, if there are more positive tweets than negative tweets, it is considered positive. If the opposite is true, it will be judged as negative. After that, I tried to sort out pretty positive and a little positive by the sense value.
This time, I implemented it with google colaboratory. Please see here for the detailed implementation. By rewriting the API key of twitter and the API key of COTOHA API, you can measure the positiveness of your favorite user.
BASE_URL = "https://api.ce-cotoha.com/api/dev/nlp/"
CLIENT_ID = "hogehoge"
CLIENT_SECRET = "hogehoge"
def auth(client_id, client_secret):
token_url = "https://api.ce-cotoha.com/v1/oauth/accesstokens"
headers = {
"Content-Type": "application/json",
"charset": "UTF-8"
}
data = {
"grantType": "client_credentials",
"clientId": client_id,
"clientSecret": client_secret
}
r = requests.post(token_url,
headers=headers,
data=json.dumps(data))
return r.json()["access_token"]
def sentiment(sentence, access_token):
base_url = BASE_URL
headers = {
"Content-Type": "application/json",
"charset": "UTF-8",
"Authorization": "Bearer {}".format(access_token)
}
data = {
"sentence": sentence,
"type": "kuzure"
}
r = requests.post(base_url + "v1/sentiment",
headers=headers,
data=json.dumps(data))
return r
def cleansing_tweet(tweet):
clean_tweets = []
for line in tweet:
temp = line.text
temp = re.sub('RT .*', '', temp)
temp = re.sub('@.*', '', temp)
temp = re.sub('http.*', '', temp)
temp = re.sub('\n.*', '', temp)
temp = re.sub('\u3000.*', '', temp)
if len(temp) != 0:
clean_tweets.append(temp)
if len(clean_tweets) >= 50:
break
return clean_tweets
def check_positive(result):
counter = Counter(result)
print(counter.most_common())
positive_negative = counter["Positive"]/counter["Negative"]
print(positive_negative)
if positive_negative > 1:
if positive_negative > 4:
print("Very positive")
elif positive_negative > 2:
print("Positive")
elif positive_negative > 1:
print("A little positive")
elif positive_negative < 1:
if positive_negative < 0.25:
print("Very negative")
elif positive_negative < 0.5:
print("Is negative")
elif positive_negative < 1:
print("A little negative")
elif counter["Positive"] == 0 and counter["Negative"] == 0:
print("Losing emotions")
First of all, let's analyze the tweets of Sunshine Ikezaki to check if the positive judgment is made correctly.
Analysis results of Sunshine Ikezaki
[('Neutral', 32), ('Positive', 16), ('Negative', 2)]
8.0
Very positive
It seems that you can judge correctly. Let's analyze Vtuber.
Analysis result of Sana Natori
[('Neutral', 31), ('Positive', 12), ('Negative', 7)]
1.7142857142857142
A little positive
Analysis result of DWU
[('Neutral', 28), ('Negative', 15), ('Positive', 7)]
0.4666666666666667
Is negative
Analysis result of Machinery Tomoko
[('Neutral', 27), ('Positive', 16), ('Negative', 7)]
2.2857142857142856
Positive
This time, we acquired tweets, performed sentiment analysis, and judged the degree of positive and negative. As for the future outlook, it would be interesting to judge not only the emotions of the whole sentence but also the emotional words.