Analyze sentiment of open-ended feedback
Analyze text data, such as open-ended feedback, at scale by performing entity and sentiment analysis directly in Google Sheets.
Last updated: August, 2019
There are many formulas in Google Sheets for analyzing quantitative data, but spreadsheets often capture valuable text data as well. Text data in Google Sheets can come from many sources: Google Form responses, notes columns, descriptions, and more. As humans we can make sense of this data by reading it, but this becomes difficult as your data grows into hundreds or thousands of rows.
The Cloud Natural Language API takes the machine learning technology used by Google Search and Google Assistant and makes it possible for anyone to perform sentiment and entity analysis on their own data.
This solution uses Apps Script in a Google Sheet to perform entity and sentiment analysis on vacation rental reviews using the Cloud Natural Language API.
- Uses the Cloud Natural Language API to perform entity and sentiment analysis on text.
- Uses the
URL Fetchservices to programmatically send multiple rows of text data to the Cloud Natural Language API service and paste response data into a spreadsheet.
- Adds a custom menu to Google Sheets using the
Set up a Google Cloud Platform project
- Sign in to your Google Account. If you don't already have one, sign up for a new account.
- In the GCP Console, on the project selector page, select or create a GCP project.
- Make sure that billing is enabled for your Google Cloud Platform project.
- Enable the Google Natural Language API for your project.
- Create an API key following these instructions.
Set up a spreadsheet
- Make of copy of the spreadsheet here.
- From the spreadsheet, open the script editor by selecting Tools > Script editor.
- Copy and paste your API key into line 1 of
YOUR_API_KEY_HEREand maintaining the quotes.
- Save the changes by navigating to File > Save.
Add text data
- Return to the sheet, and reload your browser.
- Add sample text data to columns A-F. Sample vacation property reviews with a matching schema to the template are available on Kaggle and can be copied and pasted directly from the data preview pane. Alternatively, you may add your own data. Keep in mind that the script requires data in column B (id) and column F (comments) at a minimum in order to execute successfully.
- Ensure that columns G and H, which use built-in Sheets functions to detect the comment language and provide an English translation, are properly populated using the formula provided in row 2 of the template.
Run the script
- To run the script, navigate to the custom menu Sentiment tools > Mark entities and sentiment. If the menu is not present, reload your browser window.
- When prompted, click the Review permissions button.
- Select your Google Workspace account from the list.
- Click the Allow button.
- As the script executes, you will see response data populating the Entity Sentiment Data sheet and a completion flag in each row of the Review Data sheet.
Analyze the results
- When the script finishes execution, navigate to the Pivot Table tab to see a pivot table summarizing the average sentiment score for each entity mentioned across all rows of text data.
- More information on interpreting sentiment scores can be found in the Cloud Natural Language API documentation.
To learn more about how it was built, check out this blog post.
A video of a talk stepping through a similar solution can be found on YouTube.
Were you able to get the solution up and running?
If you have an idea for another solution you'd like to see featured in our gallery submit a request on the GitHub issue tracker.