You know how when you become comfortable with someone, you sometimes may become a little more blunt?
Sometimes we may not notice if the tone of our emails is overly positive or negative. It's important to occasionally stop and reflect that we are treating the people around us with respect. The Unconscious Bias project is a Windows universal application allows you to use data to analyze the sentiment of your emails to a given email address.
On April 13-14, 2016, I participated in hack.nyc. I worked with James Sturtevant to develop “Unconscious Bias”. We created a Windows universal application in which the user can specify an email address. Then, we use the Office 365 APIs to access the user’s email and get messages that were sent to that email address. The emails are analyzed for positive/negative sentiment by the Microsoft Cognitive Services Text Analytics service. Then we display the average sentiment score of your emails to that email address, along with a chart of your sentiment over time.
Regarding the tech, Office graph development still has a huge startup cost with getting authentication configured correctly. After that, it is pretty straightforward, with both REST APIs or a client SDK. I like that they provided a “UniqueBody” which gave us the email body without all of the earlier replies if it is a long thread. The Microsoft Cognitive Services are amazing and very easy to use. We may add key phrase extraction later as well. Finally, in the Windows/XAML world, I love RelativePanel so much. So much easier to design a UI! You can specify that a certain control should be placed (for example) below another control, and then it behaves accordingly on different form factors at different resolutions.
Our work is available on GitHub at https://github.com/jsturtevant/UnconsciousBias.
Here’s a quick walkthrough of the app. The initial screen prompts you for the email address of the person with which to analyze your interactions.
After entering an email address and clicking the “Get Insights” button, you are prompted to enter your credentials to sign into your email account. We did not have to write this code; this user auth dialogue box is provided by the APIs.
Enter your own email address and password so that the application can access your email. Then, the text of the emails to that person are analyzed and your results are displayed. (I added the blur effect; you will be able to see the email address that you entered.)
We still need to make some improvements to the chart. But you can see the idea of providing both overall sentiment score and a graph of the sentiment over time.
At a high level, we knew that we needed the inputs of the username/password to sign into email and the person’s email address on which you want to test sentiment, and we wanted to output sentiment analysis. Our logic all lives in the Universal Windows Platform app (that calls out to several services); we could have instead hosted our logic in an Azure service.
As a Universal Windows Platform app, it runs on my Windows Phone too!
Here are a couple of quick thoughts in brain-dump format to help you get up and running with the Microsoft Graph:
- In the NuGet Package Manager, install Microsoft.Graph.
- To register our app and get a client ID: http://dev.office.com/app-registration
- The detailed descriptions of permissions are at http://graph.microsoft.io/en-us/docs/authorization/permission_scopes.
- The Graph Explorer documentation at https://graph.microsoft.io is pretty good, and the Graph Explorer is the absolute best for messing around and testing it out.
- We used query parameters to filter down messages to a certain user. We found that the “search” query parameter currently seems to work better than the “filter” query parameter (but I submitted a bug and this is being fixed).
- I used http://jsonlint.com/ to parse my JSON and test that it was formatted correctly.
- Find your Office 365 tenant ID: https://support.office.com/en-us/article/Find-your-Office-365-tenant-ID-6891b561-a52d-4ade-9f39-b492285e2c9b
Here is the snippet of code in which we get the emails to the given email address.
var emails = await graphClient.Me
We chose to use “UniqueBody” because it contains just your latest message to the email address. If you and the selected email address have a long thread back and forth, it will strip out all of the replies and only include the new, unique part of the message.
You need to explicitly select “UniqueBody” because it is duplicate information. Using a default get-messages call won’t return it by default because all of the message is also in the “body” content. The documentation of the parts of the message is at https://graph.microsoft.io/en-us/docs/api-reference/beta/resources/message.
Resources: Office Development
Office Developer Center: http://dev.office.com/
Get Started: http://dev.office.com/getting-started
Microsoft Graph: http://graph.microsoft.io
Graph Explorer: https://graph.microsoft.io/en-us/graph-explorer
Resources: Text Analytics from Microsoft Cognitive Services
Text Analytics Features: https://www.microsoft.com/cognitive-services/en-us/text-analytics-api
Let’s assume that you want to gain knowledge around any unconscious bias and positivity/negativity you are displaying towards your colleague Jason.
The Unconscious Bias application will prompt you (the user) for the permissions it needs to access your email, and proceed only after it has consent. Once you have authenticated to your email account, it will access your email account to get the latest 10 email messages that you have sent to Jason (only the unique last messages that you sent to him in the email thread, stripping out older back-and-forth responses between you and Jason). It will access the internet to send these messages to the Microsoft Cognitive Services for sentiment processing.
The image, voice, video or text understanding capabilities of the Unconscious Bias app uses Microsoft Cognitive Services. Microsoft will receive the images, audio, video, and other data that you upload (via this app) for service improvement purposes. To report abuse of the Microsoft Cognitive Services to Microsoft, please visit the Microsoft Cognitive Services website at https://www.microsoft.com/cognitive-services, and use the “Report Abuse” link at the bottom of the page to contact Microsoft. For more information about Microsoft privacy policies please see their privacy statement here: https://go.microsoft.com/fwlink/?LinkId=521839.