liveBook · Manning

Keyword

As explained in Starting Data Analytics with Generative AI and Python

A word or short phrase that represents a topic, property, or information need in text analysis or retrieval.

A keyword is a word or short phrase used to represent a topic, property, emotion, or information need in text. In review analysis, keywords turn a large reading task into a focused search for patterns such as delivery problems or positive opinions. section 5.5.2

Finding delivery problems

Suppose a restaurant chain wants to detect complaints about delivery timeliness. Useful starting keywords include “late delivery,” “long wait,” and “slow service.” Broader terms such as “cold food,” “soggy fries,” and “starving” may reveal related service failures that a narrow list would miss. section 5.5.2

Treat a generated keyword list as a starting point rather than a complete answer:

  • Check whether the terms match the business question and the language of the records. section 5.5.2
  • Look for missing terminology caused by changing language, market shifts, personal assumptions, or narrow framing. section 5.5.2
  • Inspect surrounding context and account for inflections, contractions, and other word-form variations before interpreting matches. section 5.5.3

Positive Portuguese reviews

A prompt can request Portuguese keywords indicating positive product opinions and English translations. Results may include “Excelente” (Excellent), “Confiável” (Reliable), “Rápido” (Fast), “Recomendo” (Recommend), and “Vale a pena” (Worth it). 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())

A Python function sends a keyword-generation prompt through the OpenAI ChatGPT API, controls temperature and token limits, and returns one result per line. section 5.5.3

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Explains selection risks, demonstrates multilingual examples, and notes context and word variations without developing a full matching method.
Examples
Uses restaurant-delivery complaints, Portuguese positive-review terms, translations, and a Python API function as examples.
What you can do after
Apply it via the OpenAI ChatGPT API to generate candidate review-search terms, then inspect context and language variations.
How it connects
Connects keywords with text mining, sentiment analysis, customer reviews, search tasks, and generative AI.

Also explained in

Compare how 3 books explain keyword →

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.