Human communication includes not only language but also a lot of nonverbal information such as facial expressions and gestures. When analyzing and interpreting human behavior mechanically and programmatically, more information can be obtained by adding meaning to such non-verbal information. These technologies are being researched and developed in various fields such as image processing, natural language processing, and voice recognition, and are expected to be applied in many fields such as marketing and interaction systems with robots. It will continue to grow significantly in the future.
In the previous article (a program that automatically corrects "Takenoko no Sato" to "Kinoko no Yama" and automatically corrects it), * I tried using a text-based emotion estimation API to correct * errors **. By utilizing such natural language processing technology, it becomes possible to estimate the emotions of the speaker and return different reactions depending on the emotions. For example, when a speaker is sad, the chatbot can estimate and comfort the emotions so that they can communicate properly.
On the other hand, there are a certain number of people in the world who claim that they have no feelings. For example, the following people.
"Don't talk ... I ... I have no emotions ..." "What is laughing ...?"
-Zero (33)-("Quotations that fall in love with women", 2011)
Specs I
Junior high school student, (14.6 years old)
Hobbies, nothing in particular (although I read newspapers and news to get the minimum information)
Emotions, none
From the sixth grade of elementary school, the surroundings feel stupid and emotions fade Almost no left now It's like a machine It makes me sad when I see myself cold
-ID: Qm9QaLSN0-("I'm a junior high school student, but honest feelings aren't there and everything seems ridiculous", 2013)
Since there are no emotions among these people, "I may not be able to communicate properly with others" "I may be different from other people" "Actually, I am a reincarnated ability person I think that some people may suffer from a lot of anxieties such as "Isn't it?"
Fortunately, however, many cutting-edge companies such as Google, Microsoft, and NTT have published their latest research results in the form of an emotion estimation API. You can use them to thoroughly analyze and compare emotions with these people to see if they are truly emotionless. If it is presumed to have emotions, "You also have emotions" "I'm not a special person, ** just an ordinary ordinary person " ** "I can't communicate There may be other causes as well. " I thought that I could give you a sense of security by gently telling you, so I decided to try various emotion estimation APIs this time.
Below, I will describe how to use each and the impressions I actually used.
Compare the results using the following four types of emotion estimation APIs. All of them are free to use, so I will explain how to use them.
Google Cloud Natural Language API
First, register with Google Cloud Platform. Also register your credit card. (There is a free period for one year.)
Select "Library" from the "APIs and Services" menu. Find and enable the "Cloud Natural Language API". Next, select "Credentials" from the "APIs and Services" menu, create an API key from "Create Credentials", and make a note of it.
At Google Colabratory "Create a new notebook".
"Add code" to write and execute the following code. (Execute is the triangle ▷ button on the left)
import getpass
APIKEY = getpass.getpass()
You will be asked for a pass, so enter the API KEY and press ENTER.
Next, do "Add Code", write the following code, and execute it to display the result of emotion estimation.
import requests
key = APIKEY
#Text you want to analyze emotions
text = "Don't talk to me ... I ... I don't have any emotions ..."
#API URL
url = 'https://language.googleapis.com/v1/documents:analyzeSentiment?key=' + key
#Basic information settings
header = {'Content-Type': 'application/json'}
body = {
"document": {
"type": "PLAIN_TEXT",
"language": "JA",
"content": text
},
"encodingType": "UTF8"
}
#Receive the result in json format.
response = requests.post(url, headers=header, json=body).json()
print(response)
#Display the analysis results on the console screen
print("Comprehensive magnitude:",response["documentSentiment"]["magnitude"])
print("Comprehensive score:",response["documentSentiment"]["score"])
for i in response["sentences"]:
print(i["text"]["content"],"magnitude:",i["sentiment"]["magnitude"],", score:",i["sentiment"]["score"])
Microsoft Azure Text Analytics API
If you want to use it easily, you can try the demo below. https://azure.microsoft.com/ja-jp/services/cognitive-services/text-analytics/
If you implement it as code, you can get a trial key that is valid for 7 days from the following. https://azure.microsoft.com/ja-jp/try/cognitive-services/#lang
Use the quick start below to create and execute code in Colaboratory. However, the emotion analysis version uses the latest v3.0-preview.1. (V2.1 in quick start) https://docs.microsoft.com/ja-jp/azure/cognitive-services/text-analytics/quickstarts/python
import requests
# pprint is used to format the JSON response
from pprint import pprint
import os
subscription_key = "<paste-your-text-analytics-key-here>"
endpoint = "<paste-your-text-analytics-endpoint-here>"
sentiment_url = endpoint + "/text/analytics/v3.0-preview.1/sentiment"
documents = {"documents": [
{"id": "1", "language": "ja",
"text": "Don't talk to me ... I ... I don't have any emotions ..."},
]}
headers = {"Ocp-Apim-Subscription-Key": subscription_key}
response = requests.post(sentiment_url, headers=headers, json=documents)
sentiments = response.json()
pprint(sentiments)
COTOHA API
Register as a Developer from the COTOHA API and obtain an ID and PASS. https://api.ce-cotoha.com/contents/index.html Each API can be used up to 1000 times a day, or up to 30,000 times a month.
You can execute it by writing the following in Colaboratory and rewriting the ID and PASS.
import requests
import json
import sys
from pprint import pprint
BASE_URL = "https://api.ce-cotoha.com/api/dev/"
CLIENT_ID = "ID obtained by COTOHA API"
CLIENT_SECRET = "PASS obtained with COTOHA API"
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,
}
r = requests.post(base_url + "nlp/v1/sentiment",
headers=headers,
data=json.dumps(data))
return r.json()
if __name__ == "__main__":
sentence = "Don't talk to me ... I ... I don't have any emotions ..."
access_token = auth(CLIENT_ID, CLIENT_SECRET)
sentiment_result = sentiment(sentence,access_token)
pprint(sentiment_result)
Since the free version is provided only on the Web, you can use it from the demo site below. https://emotion-ai.userlocal.jp/
Let's compare the results by applying each emotion estimator. Below, the result is long, so I'm folding it. Click to expand.
Google Cloud Natural Language API
Comprehensive magnitude: 0.7
Comprehensive score: 0.7
About Google's Sentiment score: -1.0 (negative) to 1.0 (positive) magnitude: 0.0 ~ + inf The emotion is expressed by. It seems that "sad" and "angry" are not distinguished and only the strength is expressed as negative or positive. Interpretation example "" score ": 0.8," magnitude ": 3.0" is clearly positive So this time it's weak and positive. ** Result: Slightly positive **
Microsoft Azure Text Analytics API
'sentenceScores': {'negative': 0.55,
'neutral': 0.37,
'positive': 0.08},
'sentiment': 'negative'
Microsoft's Sentiment is judged to have a total of 1 negative, neutral, and positive. This time, it seems that the negativeness was judged most strongly. If it is a demo site, it will be displayed as shown in the image below. ** Result: Slightly negative **
COTOHA API
'result': {'emotional_phrase': [],
'score': 0.36632366672980926,
'sentiment': 'Neutral'}
The COTOHA API seems to indicate either Positive, Negative, Neutral and its reliability. The characteristic is the section called emotional_phrase, which has not appeared this time, but since the terms related to emotions and the labels of those emotions are extracted, it seems that they can be used depending on the intended use. If it is a sample, the following is described.
"emotional_phrase":[
{
"form":"Song",
"emotion":"Rejoice,relief"
}
This time, the score is Neutral and the reliability is low, so it seems to be ** emotionless, but it may be different **. In a sense, it's close to the correct answer.
** Result: Emotionless (maybe) **
** Result: Angry and like **
Google Cloud Natural Language API
Comprehensive magnitude: 0.1
Comprehensive score: -0.1
** Result: Weak emotionlessness. What is weak emotionlessness ... **
Microsoft Azure Text Analytics API
'sentenceScores': {'negative': 0.91,
'neutral': 0.04,
'positive': 0.05},
'sentiment': 'negative'}
** Result: Negative **
COTOHA API
'result': {'emotional_phrase': [{'emotion': 'PN', 'form': 'laugh'}],
'score': 0.2729609019529442,
'sentiment': 'Neutral'},
This result is also ** emotionless but not confident **.
** Result: Emotionless (maybe) **
** Result: Like, anger and joy **
Google Cloud Natural Language API
Comprehensive magnitude: 1.8
Comprehensive score: 0.1
Strong emotionlessness. What is ...
** Result: Strong emotionless **
Microsoft Azure Text Analytics API
'documentScores': {'negative': 0.56,
'neutral': 0.28,
'positive': 0.16},
'sentiment': 'negative'}
** Result: Slightly negative **
COTOHA API
'result': {'emotional_phrase': [{'emotion': 'N', 'form': 'to become sad'},
{'emotion': 'PN', 'form': 'cold'},
{'emotion': 'sad', 'form': 'Stupid'},
{'emotion': 'PN', 'form': 'minimum'}],
'score': 0.6473423833981717,
'sentiment': 'Negative'}
** Result: Negative **
** Result: Somewhat afraid **
The results of positive and negative judgments are summarized in the table below.
Microsoft | COTOHA | User local | ||
---|---|---|---|---|
1.I have no emotions | Somewhat positive(+1) | Slightly negative(-1) | Emotionless(Low reliability) (0) | Angry and like(0) |
2.What is laughing | Weakened emotionless(0) | Negative(-1) | Emotionless(Low reliability)(0) | Like, anger, and joy(+1) |
3.Spec me | Strong emotionlessness(0) | Slightly negative(-1) | Negative(-1) | Somewhat afraid(-1) |
General comment | It is a mystery that a positive came out. I don't know the distinction between strong and weak | Overall negative. I feel like the correct answer. | Judged as nothing with low reliability->It seems to be a correct answer in a sense, but it may not be judged strongly unless there is a phrase that directly expresses emotions. | There are times when multiple emotions are mixed and I do not understand well |
That's why I've only tried 3 cases, but the results are quite different. Each company's individuality comes out. This time, the results of the four companies are totaled to judge the emotions, and Mr. Rei is emotionless with a total of 0, and the spec I am negative with -3. As expected, Rei (33) has a different age than the mystery of junior high school students.
I have tried using each of them, but I personally judged that Microsoft's ones were totally negative, and I felt that it was the most likely. From a practical point of view, I think it would be easier to use if the positive and negative scores were given. It seems that the COTOHA API judges as emotionless, which seems to be the correct answer, and it seems that the result is that there is no standard and it cannot be judged simply because there is no phrase expressing emotion. Should it be called no judgment rather than emotionless? It is convenient to extract phrases that express emotions, but there are many patterns that do not necessarily say emotional phrases, so it seems necessary to verify whether they are practical or not. I feel that Google's positive negatives and strengths are actually not very practical. I wasn't sure what to do with a weak negative or a strong emotionlessness. It seems that we need to think about implementation for a moment. User Local isn't quite sure because the conflicting emotions are too mixed up. I don't know where to use it ...
The above are the impressions of using each emotion analysis API. If there is someone near you who says, "I ... I don't have emotions ...", please verify that you really have no emotions and tell us the results gently.
Recommended Posts