liveBook · Manning

Positive sentiment

As explained in Starting Data Analytics with Generative AI and Python

Positive sentiment is a favorable emotional or evaluative attitude expressed toward a product, service, or experience.

Positive sentiment signals favorable emotions or opinions about a product, service, or experience. In customer reviews, it helps surface what people value and support decisions about products, marketing, and delivery. section 5.5.3 section 6.2.1

Portuguese review terms that can indicate positive sentiment include:

  • Excelente, ótimo, maravilhoso, incrível, fantástico, and perfeito. section 5.5.3
  • Bom, eficiente, durável, confiável, rápido, and custo-benefício. section 5.5.3
  • Recomendo, satisfeito, confortável, fácil de usar, funcional, melhor, and vale a pena. section 5.5.3

Generate a searchable keyword set

Ask an AI assistant to generate 20 keywords indicating positive sentiment for Portuguese customer reviews, optionally requesting English translations. Inspect the returned list before using it: words can change meaning with context, inflections, and contractions. section 5.5.3

Listing 5.5 Generating keywords via ChatGPT API
from openai import OpenAI

def generate_keywords(temperature=0.5, max_tokens=150):
    client = OpenAI(
        api_key="your_api_key", # Make sure to use your actual API key here
    )

    prompt = """Generate a list of 20 keywords indicating positive 
    sentiment to be used for searching customer reviews in Portuguese."""

    try:
        response = client.chat.completions.create(
            messages=[
                {
                    "role": "user",
                    "content": prompt,
                }
            ],
            model="gpt-4-0125-preview", # Replace with the model you have 
            access to
            temperature=temperature,
            max_tokens=max_tokens,
        )
        return(response.choices[0].message.content.split("\n"))

    except Exception as e:
        print(f"An error occurred: {str(e)}")

# Example usage
print("Generated Keywords:")
print(generate_keywords())

Use the Python example to request positive-sentiment keywords through the OpenAI client, then split the response into searchable lines and check failures. section 5.5.3

Treat keyword matching as a practical starting point rather than complete analysis: simple sentiment analysis commonly separates positive, negative, and neutral text, while emotion or aspect-based analysis can provide finer detail. section 5.5.3 section 6.2.1

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Explains keyword-based identification and basic positive-negative-neutral classification, while stopping short of detailed contextual or aspect-level analysis.
Examples
Uses Portuguese keywords such as excelente, recomendo, satisfeito, and vale a pena, plus a generated keyword-list prompt.
What you can do after
Apply it via the OpenAI client to generate candidate Portuguese search terms, then inspect and validate the returned keywords.
How it connects
Connects positive sentiment with sentiment analysis, customer reviews, emotion detection, and aspect-based sentiment analysis.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.