---
url: 'http://workflows-of-ai.com/blog/sentiment-analysis'
title: 'Sentiment Analysis'
author:
  name: 'Marcus Johansson'
  url: 'http://workflows-of-ai.com/about/marcus-johansson'
date: '2023-10-12T13:24:54+02:00'
updated: '2026-10-10T12:14:04+02:00'
type: article
summary: 'Rate the sentiment of reviews on a 1 to 5 scale in Drupal with a list field and the AI Interpolator OpenAI module.'
tags:
  - 'Marcus Johansson'
  - Workflows
  - 'Drupal AI'
image: 'http://workflows-of-ai.com/sites/default/files/previews/0613e2a3cd375e3e.jpg'
published: true
og:
  site_name: 'Workflows of AI'
  'image:width': '1280'
  'image:height': '720'
  'image:alt': 'Sentiment Analysis'
---
Drupal AI

# Sentiment Analysis

Let OpenAI read a review and set a 1 to 5 rating field on its own, in under five minutes of setup.

  Marcus Johansson

October 12, 2023 · 2 min read

 ## About this video

Having developed the AI Interpolator OpenAI module, I wanted to ensure that tasks such as sentiment analysis are intuitive and user-friendly. In this specific case, the implementation process is streamlined; a user merely needs to incorporate an HTML text field where the raw textual content will be inputted. Adjacently, a ratings field is added, which is designed to display the analyzed sentiment score post-processing. The integration is straightforward, void of complexities, enabling users to set it up in less than five minutes.

When a user inputs text into the HTML field, the intricately designed algorithms of the OpenAI module are invoked, meticulously examining and evaluating the sentiment embedded in the text. The module parses the nuances, context, and lexical choices within the content, deducing the prevailing emotion or sentiment. This processed sentiment score or category is then instantaneously populated in the ratings field, offering users immediate, actionable insights without delay. Every element and line of code is meticulously optimized for speed and accuracy, ensuring an efficient and responsive user experience.

*This video is from before the AI Interpolator module became AI Automators, part of the [AI module](https://www.drupal.org/project/ai). Module and menu names have changed since, and some steps look different today.*

## Watch the video

[Watch on YouTube: Sentiment Analysis](https://www.youtube.com/watch?v=HBxqzhhOtG0)

### Video chapters

- 0:00 Why rate reviews with AI
- 2:01 Adding the rating list field
- 2:49 The sentiment prompt
- 4:18 Rating Gollum and Zelda
- 4:57 Using ratings in views and APIs

## Transcript

YouTube's automatic captions, lightly corrected. Click a line to jump to that moment in the video.

### Transcript

- 0:01 hi there uh Marcus here again this time uh we're going to create a workflow that creates a sentiment analysis um so the idea behind that is basically that uh you might for instance have a large
- 0:18 database of reviews of something uh but you want to have some actual metad data on a scale what this review means right so it's typical for review site to set 1
- 0:31 to 10 in in h rating or maybe 1 to five right so what I have done here is I've set up two articles I just copied the verdict from The Legend of Zelda: Ocarina of Time so that's one of the greatest
- 0:43 games ever right uh and I also copied the Lord of the Rings Gollum which uh not to beat on a dead horse but didn't get the best reviews and no one really liked it um so
- 0:59 the idea is here here to set up a a structure field that's uh rating basically where we let the AI set the rating so um before I start with this this is running Drupal it has the AI
- 1:14 interpolator modules running uh if you want to know more about what Drupal is and how to set it up and also how to set up the AI interpolator Suite please look at the
- 1:26 description uh of the video there's link there there's also links that explain what the in AI interpolator module is doing in the background and why it was built and so on uh and also everything
- 1:41 is open source it's free to use what I show here you can just download and do yourself so we start by logging in as a admin so we have rights to change structures and things we have a
- 1:55 content type it's called article it should probably be a review I just reviewed something here here uh and now we want to set our rating right and we're going to use a list integer in
- 2:05 this case so I mean we could have a normal integer or float so it basically just sets a number but in this case we want the number to actually mean something in a human readable form so we
- 2:17 set our rating and here you say the allowed values list right so one is the worst two is bad three is neutral four is good five wa five is great right we're just going to set
- 2:37 one review uh if you're using Drupal by the way you can of course use the rate module or something where you see stars and stuff and have it really cool but uh in this case I'm just going to show it
- 2:49 as a in a text form we enable the AI interpolator uh in this case we're going to use the integer field uh because we're creating an integer from in this case from a text
- 3:01 field right uh and we're going to base it on the article in this case there is actually uh in the placeholder a pretty good uh um text that we can use so we're just
- 3:18 going to copy this oh W yeah I'm going to mouse pad here so let's see there we copy up with the keyboard instead so based on the content text add a sentiment rating from the sentiment
- 3:36 list where Min so that's the minimum numeric value and Max is the max numeric value uh means positive uh in this case uh no there's going to be a Min and a Max uh ratings is just a comma
- 3:56 separated list of options and the context is the article then uh we can probably use GPT 3.5 uh in this case and we write you are a game reviewer review H you're game reviewer
- 4:13 that's enough right we can do direct because GPT-3.5 is fast we don't need to see any progress now if we go back to our content so in this tab we have Gollum there is no rating right now right so we
- 4:26 could manually set that rating and then the AI doesn't kick in but as long as we leave this empty it's going to set the rating now so it put it to bad which is probably
- 4:38 right it doesn't say that it's quite horrible right but the Legend of Zelda I hope uh if I reload so I get the edit here because I was logged out and now I'm logged in click save it should be
- 4:52 great I hope yes so it is great uh so there we have it we have a sentiment analysis since this is now saved as structure data in Drupal in this case we could easily create a view as it's
- 5:06 called in Drupal where you can create a filter like just show me the five star reviews or yeah search for something whatever it's it's very easy to build up it's a Content management framework
- 5:18 create very nice uh content Management Systems around it but as always also the chains that you set up or the the work uh flows that you set set up can be available as API JSON:API GraphQL or
- 5:34 something as well from Drupal so you could use your own application but just use this for the AI part uh so that's it uh workflows of AI there's more so workflows-of-ai.com
- 5:46 there's more videos of workflows if you're interested and yeah thanks for watching

  Filed under [Workflows](/blog?category=6) [Drupal AI](/blog?category=2)

Parts of this content were produced by AI.

This site has not assessed whether a label is required for this content.

  How was AI used?The video and the introduction are Marcus's own, first published on workflows-of-ai.com. AI wrote the subtitle, the summary and the video chapters from the transcript, and corrected misheard names in YouTube's automatic captions.

   Marcus Johansson

Tinkers with AI and Drupal

 [About Marcus](/about/marcus-johansson)[Drupal.org profile](https://www.drupal.org/u/marcus_johansson)[Drupal AI](https://www.drupal.org/project/ai)

## The post in three sentences

A list (integer) field holds the rating, with labels from worst to great for the values 1 to 5. The AI Interpolator reads the article text with GPT-3.5 and picks a value whenever the field is empty. A Gollum review gets bad and Zelda: Ocarina of Time gets great, and the stored ratings can be filtered in Views or used over an API.