liveBook · Manning

Post-processing

As explained in Starting Data Analytics with Generative AI and Python

Post-processing is the transformation, validation, or cleanup of generated or computed output after its initial production.

A generated answer is not necessarily ready to use. Post-processing means inspecting and refining it after generation so that its format, content, and wording fit the task. A list for searching customer reviews, for example, needs to be usable as a list—not merely look convincing on screen. section 5.5.3 section 8.4.3

Check the output before passing it along:

  • Remove irrelevant comments or excessive explanation, and adjust the language for the intended audience without changing the message. section 8.4.3
  • Inspect structure and completeness. A prompt requesting 20 keywords may still return an inconsistently formatted or truncated list; max_tokens limits response tokens, not the number of keywords. section 5.5.3
  • Where bias matters, evaluate outputs before adjusting them. Fairness-based reranking, resampling, or reweighing can operate outside the model, but must not replace checking whether the model suits the use case. section 8.5.2

From response to keyword list

An API prompt asks for 20 positive-sentiment keywords for Portuguese customer reviews. Python splits the returned text at newlines. Inspect the resulting entries and count them: the response format can vary, and a low token limit can cut the list short. Revise the prompt if a more consistent format is needed. 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())

The API listing shows the newline split that turns generated text into a Python list—and why checking that list matters. section 5.5.3

For consequential outputs, cleanup is not a substitute for validation. Loan-underwriting advice, for instance, calls for examining possible disparities associated with historical training data before relying on an adjusted result. section 8.5.2

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Explains inspection, formatting, language cleanup, and possible fairness adjustments, but does not provide an implementation of fairness reranking.
Examples
Uses Portuguese review keywords, a pet-food business explanation, and residential-loan underwriting to show differing output checks.
What it assumes
Assumes familiarity with generating AI responses; the keyword workflow also uses a Python API call and newline splitting.
What you can do after
Practice/perform output inspection and cleanup, while evaluating whether fairness adjustments are justified rather than trusting them automatically.
How it connects
Links post-processing to prompt design, API token limits, audience adaptation, and bias detection.

Also explained in

Compare how 4 books explain post-processing →

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.