Content Sentiment Analysis: Explore the emotion score of your content with Google API
Tags: actionshackathon, github, googlecloud, showdev
Published: 2020-08-22 16:32:22

### My Workflow

I spent a few nights wrapping Google's [analyzeSentiment API](https://cloud.google.com/natural-language/docs/analyzing-sentiment#language-sentiment-string-protocol) into a GitHub Action. The Action runs Sentiment Analysis over the content of HTML files and provides an overview of the overall emotion of all (the selected) pages in your project.

The API returns values from -1 to 1, indicating how strong a certain emotion – positive or negative – is. After running the Action, a table with the score per each page is printed in its logs. Read more about [Interpreting sentiment analysis values](https://cloud.google.com/natural-language/docs/basics#interpreting_sentiment_analysis_values).

Along with other content analysis tools, it might come in handy to maintainers who want to understand the text that is pushed to the project every day. See it in action 🚀

![Usage demo](https://dev-to-uploads.s3.amazonaws.com/i/bc2b8c3f99o4w8jm6fxd.gif)

⚠️ Now I got really excited about this and will continue developing along with other automation ideas that I have. This being an early release of the Action, please take a look at the [roadmap](https://github.com/BogDAAAMN/copy-sentiment-analysis#-known-issues-and-limitations) and submit issues with what kind of features you would like to see in future releases.  

### Submission Category: 

Maintainer Must-Haves

### Yaml File or Link to Code

Here is an example of how to use the Action on public `.html` files. 

```yaml
name: Sentiment analysis on public

on: push

jobs:
  analysis:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2 #Be sure you checkout the files beforehand
    - name: Run sentiment analysis on HTML files
      uses: bogdaaamn/copy-sentiment-analysis@v0.6.1
      with: 
        gcp_key: ${{ secrets.GCP_KEY }} #Google Cloud Platform API key. Read the README for instructions 
```

Along with the code – more [examples](https://github.com/BogDAAAMN/copy-sentiment-analysis#-usage), [requirements](https://github.com/BogDAAAMN/copy-sentiment-analysis#-usage) and a [known issues roadmap](https://github.com/BogDAAAMN/copy-sentiment-analysis#-known-issues-and-limitations) are available in the [bogdaaamn/copy-sentiment-analysis](https://github.com/BogDAAAMN/copy-sentiment-analysis) repository (view it on [Marketplace](https://github.com/marketplace/actions/content-sentiment-analysis)). 

{% github https://github.com/BogDAAAMN/copy-sentiment-analysis/ %}

### Additional Resources / Info

#### Open source use cases

At the moment, the overview table is printed in the Actions tab, after the code is running. But it seems counter-intuitive and having too much friction in between. 

I am curious about what the community thinks: **How would you see this Action printing the results? A comment to the PR? A table in Action's log? Failing if there are too many negative results?**

#### ⚠️ GCP's bias in sentiment analysis

A few years ago, Google API was criticized in the media for producing bias results towards race, gender, and religion. So I had mixed feelings about using a pre-trained model in this Action.

Now, it is hard to understand what is going on with Google's proprietary algorithm and how they fight unwanted bias, but more recent research (see [charlescearl, 2019](https://data.blog/2019/08/21/gender-and-racial-bias-in-cloud-nlp-sentiment-apis/)) concluded that GCP *seems to be less sensitive to the race or gender of participants* than other competitor platforms. The same article recommends that users should proceed with caution and conduct evaluations on their own. The tests that I've done had neutral results, but I am ready to expand my research and pull the plug if needed.

Moreover, there is extraordinary research done towards identifying, analyzing, and diminishing bias in data (see [Dixon et al., 2018](https://research.google/pubs/pub46743/) from Google Research or [Caliskan et al., 2016](https://arxiv.org/abs/1608.07187) and [May et al., 2019](https://arxiv.org/abs/1903.10561)) and all I hope is that Google (or really any cloud provider out there) is doing better and better. I believe it is really important to enable and support bias and fairness research – especially now, after the recent upbringing of GPT-3 (see [Burus, 2020](https://towardsdatascience.com/the-un-ethical-story-of-gpt-3-openais-million-dollar-model-213d7d06bbf1)) when the society gets exposed more and more to technology. 

#### Sources 

- [Vice: Google’s Sentiment Analyzer Thinks Being Gay Is Bad](https://www.vice.com/en_us/article/j5jmj8/google-artificial-intelligence-bias)

- [Engadget: Google's sentiment analysis API is just as biased as humans](https://www.engadget.com/2017-10-25-googles-sentiment-analysis-api-is-just-as-biased-as-humans.html)

- [Techleer: Google Sentiment Analysis API gives a biased output](https://www.techleer.com/articles/387-google-sentiment-analysis-api-gives-a-biased-output)

- [Gender and Racial Bias in Cloud NLP Sentiment APIs](https://data.blog/2019/08/21/gender-and-racial-bias-in-cloud-nlp-sentiment-apis)

- [Measuring and Mitigating Unintended Bias in Text Classification](https://research.google/pubs/pub46743)

- [Semantics derived automatically from language corpora contain human-like biases](https://arxiv.org/abs/1608.07187)

- [On Measuring Social Biases in Sentence Encoders](https://arxiv.org/abs/1903.10561)

- [The (Un)ethical Story of GPT-3: OpenAI’s Million Dollar Model](https://towardsdatascience.com/the-un-ethical-story-of-gpt-3-openais-million-dollar-model-213d7d06bbf1)