liveBook · Manning

Gemini

As explained in Starting Data Analytics with Generative AI and Python

A family of Google's generative AI models capable of processing and generating text and, in some variants, other modalities.

Gemini is a family of Google generative AI models that can assist with data analysis through a chat interface or an API. A practical question is whether it can help turn a request such as “find positive Portuguese customer reviews” into keywords and working Python code. It can propose both, but the results still need testing against the data. section 1.3.1 section 5.5.3

Choose an access route that fits the task:

  • Use the Gemini web interface to enter a prompt and inspect its answer. Do not paste confidential data into a public service. section 1.3.1
  • Use Google Vertex AI for programmatic requests. The illustrated Python setup installs google-cloud-aiplatform, identifies a Cloud project and location, and selects gemini-1.0-pro for text generation. The example also sets output and safety parameters; gemini-1.0-pro-vision is identified for multimodal requests. section 1.3.3
Listing 1.4 Example code to call Vertex AI on Google Cloud
import vertexai
from vertexai.generative_models import GenerativeModel, ChatSession, 
HarmCategory, HarmBlockThreshold
# Replace PROJECT_ID with the ID of your Google Cloud project.
my_id = "PROJECT_ID"
# Replace with your Google Cloud location
my_location = "us-central1"
def generate_text(project_id: str, location: str, prompt: str) -> str:
    # Initialize Vertex AI
    vertexai.init(project=project_id, location=location)
    # Load the model
    model = GenerativeModel("gemini-1.0-pro")
    # Generation config
    config = {"max_output_tokens": 2048, "temperature": 0.4, "top_p": 1,
    "top_k": 32}
    # Safety config
    safety_config = {
        HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT:
        HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
        HarmCategory.HARM_CATEGORY_HARASSMENT:
        HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
    }
    # Generate content
    responses = model.generate_content(
        [prompt],
        generation_config=config,
        stream=True,
        safety_settings=safety_config,
    )
    text_responses = []
    for response in responses:
        text_responses.append(response.text)
    return "".join(text_responses)
prompt = "What are all the colors in a rainbow?"
print(generate_text(my_id, my_location, prompt))

Inspect the Vertex AI Python listing for model selection, generation settings, and safety configuration before adapting it to a project. section 1.3.3

Check a proposed review filter

Prompt Gemini for Python code to extract positive Portuguese reviews from a dataframe column named review_comment_message. Its proposed approach combined keyword search with NLTK stopword removal and VADER sentiment scoring. That extra machinery is not automatically an improvement: stopword removal adds little to a single-word search, and the cited sentiment package was not designed for languages other than English. Run the code, inspect selected and rejected raw reviews, and revise the method or ask a more targeted question. section 5.5.6

Gemini Advanced can also suggest possible explanations for differences in delivery times between Brazilian states, including geography, carrier performance, and warehouse location. Treat these as hypotheses to investigate, not findings established by the model. Likewise, check generated keyword formats and API code: response formatting may vary, and a model may be unaware of API changes. For web research, compare its synthesis with the underlying sources rather than accepting a fluent answer on trust. section 4.5 section 5.5.3 section 5.7

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Shows web access, a configured Vertex AI Python call, and a critique of generated review-filtering code; does not examine model internals.
Examples
Tests Portuguese positive-review extraction and uses interstate delivery-time disparities to elicit possible operational explanations.
What it assumes
Assumes familiarity with Python dataframes for the review-code comparison; spells out the Cloud installation and configuration used in the API example.
What you can do after
Apply it via Gemini’s web interface or Vertex AI, then inspect generated code and verify analytical suggestions against data.
How it connects
Connects Gemini to Vertex AI, prompt engineering, keyword search, sentiment analysis, and data validation.

Also explained in

Compare how 7 books explain Gemini →

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.