arrow_back

Inspect Rich Documents with Gemini Multimodality and Multimodal RAG: Challenge Lab

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Inspect Rich Documents with Gemini Multimodality and Multimodal RAG: Challenge Lab

Lab 1 hour 30 minutes universal_currency_alt 5 Credits show_chart Intermediate
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

GSP520

Google Cloud self-paced labs logo

Overview

In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.

When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.

To score 100% you must successfully complete all tasks within the time period!

This lab is recommended for students who have enrolled in the Inspect Rich Documents with Gemini Multimodality and Multimodal RAG skill badge. Are you ready for the challenge?

Topics tested

  • Using multimodal prompts to extract information from text and visual data, generating a video description, and retrieving extra information beyond the video by using multimodality with Gemini
  • Building metadata of documents containing text and images, getting all relevant text chunks, and printing citations by using Multimodal Retrieval Augmented Generation (RAG) with Gemini

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

Open JupyterLab

  1. In the Google Cloud Console, on the Navigation menu, click Vertex AI > Workbench.

  2. On the Instances page, find the gemini-jupyterlab instance, and click on the Open JupyterLab button.

Clone the notebook from GitHub

  1. In JupyterLab, click the Terminal icon to open a new terminal.

  2. At the command-line prompt, type the following command and press ENTER:

git clone --depth=1 https://github.com/GoogleCloudPlatform/training-data-analyst

To verify the objective, click Check my progress. Clone the notebook from GitHub.

Run the cells in the Setup and requirements section of notebook

  1. Double-click on the training-data-analyst directory to see its contents.

  2. Within the training-data-analyst directory, navigate to self-paced-labs > gemini, and double-click on the notebook (.ipynb) file named inspect_rich_documents_w_gemini_multimodality_and_multimodal_rag to open it.

  3. Run the 4 cells in the Setup and requirements section of the notebook (before you get to Task 1).

  • Use the following information to initialize the Vertex AI SDK for Python for your project:
    • For Project ID, enter .
    • For Location, enter .

Challenge Scenario

You are a Marketing Campaign Coordinator at a media company, working closely with the Marketing Manager to plan, execute, and evaluate campaigns to meet sales targets. Recently, you secured an exciting new contract with Google. As a Marketing Campaign Coordinator, you’re eager to dive into the materials that will help you familiarize yourself with the Google brand and Google brand identity as quickly as possible. Therefore, you plan to review Google’s brand guidelines, previous campaigns, product ads, customer testimonials, and financial reports by leveraging Gemini’s innovative capabilities to gain deeper insights into Google more efficiently.

In this challenge, you begin with multimodal prompts to extract information from text and visual data, generating a video description, and retrieving extra information beyond the video by using multimodality with Gemini. You also build metadata of documents containing text and images, getting all relevant text chunks, and printing citations by using Multimodal Retrieval Augmented Generation (RAG) with Gemini.

Task 1. Generate Multimodal Insights with the Gemini Pro Vision model

In this task, you familiarize yourself with the Google brand and Google brand identity using Gemini Pro Vision (gemini-pro-vision), which is a multimodal model that supports multimodal prompts. You include text, image(s), and video in your prompt requests and get text or code responses.

To complete this task, follow the instructions in the notebook.

Task 1.1 Image understanding across multiple images

To verify the objective, click Check my progress. Image understanding across multiple images.

Task 1.2. Similarities/Differences between images

To verify the objective, click Check my progress. Similarities/Differences between images.

Task 1.3. Generate a video description

Complete this subtask using https://storage.googleapis.com/spls/gsp520/google-pixel-8-pro.mp4, and proceed to the next task.

Task 1.4. Extract tags of objects throughout the video

Complete this subtask using https://storage.googleapis.com/spls/gsp520/google-pixel-8-pro.mp4, and proceed to the next task.

Task 1.5. Ask more questions about a video

Complete this subtask using https://storage.googleapis.com/spls/gsp520/google-pixel-8-pro.mp4, and proceed to the next task.

Task 1.6. Retrieve extra information beyond the video

To verify the objective, click Check my progress. Generate a video description and retrieve extra information beyond the video.

Task 2. Retrieve and integrate knowledge with multimodal retrieval augmented generation (RAG)

To complete this task, follow the instructions in the notebook.

Available data and helper functions for Task 2

For this task, you use two different source data documents:

  1. The Terms of Service document for Google's services, defining the relationship between Google and its users. It covers what users can expect from Google, the rules for using the services, intellectual property rights related to content, and the procedures for resolving disputes or disagreements. This sample document contains only text.

  2. A modified version of Google-10K which provides a comprehensive overview of the company's financial performance, business operations, management, and risk factors. As the original document is rather large, you will be using a modified version with only 14 pages instead. Although it's truncated, this sample document still contains text along with images such as tables, charts, and graphs.

You also select from the following helper functions to complete the tasks (more information on these functions available on Github):

  • For Inspect the processed text metadata:

    • text: the original text from the page
    • text_embedding_page: the embedding of the original text from the page
    • chunk_text: the original text divided into smaller chunks
    • chunk_number: the index of each text chunk
    • text_embedding_chunk: the embedding of each text chunk
  • For Inspect the processed image metadata:

    • img_desc: Gemini-generated textual description of the image.
    • mm_embedding_from_text_desc_and_img: Combined embedding of image and its description, capturing both visual and textual information.
    • mm_embedding_from_img_only: Image embedding without description, for comparison with description-based analysis.
    • text_embedding_from_image_description: Separate text embedding of the generated description, enabling textual analysis and comparison.
  • For Import the helper functions to implement RAG:

    • get_similar_text_from_query(): Given a text query, finds text from the document which are relevant, using cosine similarity algorithm. It uses text embeddings from the metadata to compute and the results can be filtered by top score, page/chunk number, or embedding size.
    • print_text_to_text_citation(): Prints the source (citation) and details of the retrieved text from the get_similar_text_from_query() function.
    • get_similar_image_from_query(): Given an image path or an image, finds images from the document which are relevant. It uses image embeddings from the metadata.
    • print_text_to_image_citation(): Prints the source (citation) and the details of retrieved images from the `get_similar_image_from_query()`` function.
    • get_gemini_response(): Interacts with a Gemini model to answer questions based on a combination of text and image inputs.
    • display_images(): Displays a series of images provided as paths or PIL Image objects.

Task 2.1. Build metadata of documents containing text and images

Complete this subtask, and proceed to the next task.

Task 2.2. Create a user query

Complete this subtask, and proceed to the next task.

Task 2.3. Get all relevant text chunks

Complete this subtask, and proceed to the next task.

Task 2.4. Create context_text

Complete this subtask, and proceed to the next task.

Task 2.5. Pass context to Gemini

To verify the objective, click Check my progress. Retrieve and integrate knowledge with multimodal retrieval augmented generation (RAG).

Congratulations!

By completing this challenge lab, you have demonstrated your adeptness in leveraging Gemini APIs to generate text, create function calls, and describe video contents. Your work ensured that these features met the expected standards before deployment to production. Well done!

Inspect Rich Documents with Gemini Multimodality and Multimodal RAG badge

Next steps / Learn more

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated April 3, 2024

Lab Last Tested April 3, 2024

Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.