Close Menu
    Trending
    • What health care providers actually want from AI
    • Alibaba har lanserat Qwen-Image-Edit en AI-bildbehandlingsverktyg som öppenkällkod
    • Can an AI doppelgänger help me do my job?
    • Therapists are secretly using ChatGPT during sessions. Clients are triggered.
    • Anthropic testar ett AI-webbläsartillägg för Chrome
    • A Practical Blueprint for AI Document Classification
    • Top Priorities for Shared Services and GBS Leaders for 2026
    • The Generalist: The New All-Around Type of Data Professional?
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Unlocking Multimodal Video Transcription with Gemini
    Artificial Intelligence

    Unlocking Multimodal Video Transcription with Gemini

    ProfitlyAIBy ProfitlyAIAugust 29, 2025No Comments72 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email



    A fast heads-up earlier than we begin:

    • I’m a developer at Google Cloud. I’m glad to share this text and hope you’ll be taught a number of issues. Ideas and opinions are totally my very own.
    • The supply code for this text (and future updates) is on the market in this notebook (Apache License model 2.0).
    • You may experiment without cost with Gemini in Google AI Studio and get an API key to name Gemini programmatically.
    • All photographs, except in any other case famous, are by me.

    ✨ Overview

    Conventional machine studying (ML) notion fashions sometimes deal with particular options and single modalities, deriving insights solely from pure language, speech, or imaginative and prescient evaluation. Traditionally, extracting and consolidating info from a number of modalities has been difficult on account of siloed processing, advanced architectures, and the danger of information being “misplaced in translation.” Nevertheless, multimodal and long-context giant language fashions (LLMs) like Gemini can overcome these points by processing all modalities inside the similar context, opening new prospects.

    Transferring past speech-to-text, this pocket book explores obtain complete video transcriptions by leveraging all obtainable modalities. It covers the next subjects:

    • A strategy for addressing new or advanced issues with a multimodal LLM
    • A immediate method for decoupling knowledge and preserving consideration: tabular extraction
    • Methods for profiting from Gemini’s 1M-token context in a single request
    • Sensible examples of multimodal video transcriptions
    • Ideas & optimizations

    🔥 Problem

    To completely transcribe a video, we’re trying to reply the next questions:

    • 1️⃣ What was stated and when?
    • 2️⃣ Who’re the audio system?
    • 3️⃣ Who stated what?

    Can we remedy this downside in a simple and environment friendly means?


    🌟 State-of-the-art

    1️⃣ What was stated and when?

    This can be a recognized downside with an present answer:

    • Speech-to-Textual content (STT) is a course of that takes an audio enter and transforms speech into textual content. STT can present timestamps on the phrase stage. Additionally it is often known as computerized speech recognition (ASR).

    Within the final decade, task-specific ML fashions have most successfully addressed this.


    2️⃣ Who’re the audio system?

    We will retrieve speaker names in a video from two sources:

    • What’s written (e.g., audio system will be launched with on-screen info once they first communicate)
    • What’s spoken (e.g., “Good day Bob! Alice! How are you doing?”)

    Imaginative and prescient and Pure Language Processing (NLP) fashions might help with the next options:

    • Imaginative and prescient: Optical Character Recognition (OCR), additionally known as textual content detection, extracts the textual content seen in photographs.
    • Imaginative and prescient: Particular person Detection identifies if and the place individuals are in a picture.
    • NLP: Entity Extraction can determine named entities in textual content.

    3️⃣ Who stated what?

    That is one other recognized downside with a partial answer (complementary to Speech-to-Textual content):

    • Speaker Diarization (often known as speaker flip segmentation) is a course of that splits an audio stream into segments for the completely different detected audio system (“Speaker A”, “Speaker B”, and so forth.).

    Researchers have made vital progress on this subject for many years, notably with ML fashions in recent times, however that is nonetheless an energetic subject of analysis. Current options have shortcomings, reminiscent of requiring human supervision and hints (e.g., the minimal and most variety of audio system, the language spoken), and supporting a restricted set of languages.


    🏺 Conventional ML pipeline

    Fixing all of 1️⃣, 2️⃣, and three️⃣ isn’t easy. This could seemingly contain establishing an elaborate supervised processing pipeline, based mostly on a number of state-of-the-art ML fashions, reminiscent of the next:

    We would want days or even weeks to design and arrange such a pipeline. Moreover, on the time of writing, our multimodal-video-transcription problem will not be a solved downside, so there’s completely no certainty of reaching a viable answer.


    Gemini permits for speedy prompt-based downside fixing. With simply textual content directions, we will extract info and remodel it into new insights, by a simple and automatic workflow.

    🎬 Multimodal

    Gemini is natively multimodal, which suggests it may possibly course of various kinds of inputs:

    • textual content
    • picture
    • audio
    • video
    • doc

    🌐 Multilingual

    Gemini can also be multilingual:

    • It may course of inputs and generate outputs in 100+ languages
    • If we will remedy the video problem for one language, that answer ought to naturally prolong to all different languages

    🧰 A natural-language toolbox

    Multimodal and multilingual understanding in a single mannequin lets us shift from counting on task-specific ML fashions to utilizing a single versatile LLM.

    Our problem now appears to be like rather a lot easier:

    natural-language toolbox with gemini (L. Picard)

    In different phrases, let’s rephrase our problem: Can we absolutely transcribe a video with simply the next?

    • 1 video
    • 1 immediate
    • 1 request

    Let’s strive with Gemini…


    🏁 Setup

    🐍 Python packages

    We’ll use the next packages:

    • google-genai: the Google Gen AI Python SDK lets us name Gemini with a number of strains of code
    • pandas for knowledge visualization

    We’ll additionally use these packages (dependencies of google-genai):

    • pydantic for knowledge administration
    • tenacity for request administration
    pip set up --quiet "google-genai>=1.31.0" "pandas[output-formatting]"

    🔗 Gemini API

    We have now two most important choices to ship requests to Gemini:

    • Vertex AI: Construct enterprise-ready tasks on Google Cloud
    • Google AI Studio: Experiment, prototype, and deploy small tasks

    The Google Gen AI SDK gives a unified interface to those APIs and we will use setting variables for the configuration.

    Choice A – Gemini API by way of Vertex AI 🔽

    Requirement:

    • A Google Cloud mission
    • The Vertex AI API should be enabled for this mission

    Gen AI SDK setting variables:

    Study extra about setting up a project and a development environment.

    Choice B – Gemini API by way of Google AI Studio 🔽

    Requirement:

    Gen AI SDK setting variables:

    • GOOGLE_GENAI_USE_VERTEXAI="False"
    • GOOGLE_API_KEY="<API_KEY>"

    Study extra about getting a Gemini API key from Google AI Studio.

    💡 You may retailer your setting configuration outdoors of the supply code:

    Atmosphere Technique
    IDE .env file (or equal)
    Colab Colab Secrets and techniques (🗝️ icon in left panel, see code beneath)
    Colab Enterprise Google Cloud mission and site are mechanically outlined
    Vertex AI Workbench Google Cloud mission and site are mechanically outlined
    Outline the next setting detection capabilities. You can too outline your configuration manually if wanted. 🔽
    import os
    import sys
    from collections.abc import Callable
    
    from google import genai
    
    # Guide setup (depart unchanged if setup is environment-defined)
    
    # @markdown **Which API: Vertex AI or Google AI Studio?**
    GOOGLE_GENAI_USE_VERTEXAI = True  # @param {sort: "boolean"}
    
    # @markdown **Choice A - Google Cloud mission [+location]**
    GOOGLE_CLOUD_PROJECT = ""  # @param {sort: "string"}
    GOOGLE_CLOUD_LOCATION = "world"  # @param {sort: "string"}
    
    # @markdown **Choice B - Google AI Studio API key**
    GOOGLE_API_KEY = ""  # @param {sort: "string"}
    
    
    def check_environment() -> bool:
        check_colab_user_authentication()
        return check_manual_setup() or check_vertex_ai() or check_colab() or check_local()
    
    
    def check_manual_setup() -> bool:
        return check_define_env_vars(
            GOOGLE_GENAI_USE_VERTEXAI,
            GOOGLE_CLOUD_PROJECT.strip(),  # May need been pasted with line return
            GOOGLE_CLOUD_LOCATION,
            GOOGLE_API_KEY,
        )
    
    
    def check_vertex_ai() -> bool:
        # Workbench and Colab Enterprise
        match os.getenv("VERTEX_PRODUCT", ""):
            case "WORKBENCH_INSTANCE":
                go
            case "COLAB_ENTERPRISE":
                if not running_in_colab_env():
                    return False
            case _:
                return False
    
        return check_define_env_vars(
            True,
            os.getenv("GOOGLE_CLOUD_PROJECT", ""),
            os.getenv("GOOGLE_CLOUD_REGION", ""),
            "",
        )
    
    
    def check_colab() -> bool:
        if not running_in_colab_env():
            return False
    
        # Colab Enterprise was checked earlier than, so that is Colab solely
        from google.colab import auth as colab_auth  # sort: ignore
    
        colab_auth.authenticate_user()
    
        # Use Colab Secrets and techniques (🗝️ icon in left panel) to retailer the setting variables
        # Secrets and techniques are non-public, seen solely to you and the notebooks that you choose
        # - Vertex AI: Retailer your settings as secrets and techniques
        # - Google AI: Immediately import your Gemini API key from the UI
        vertexai, mission, location, api_key = get_vars(get_colab_secret)
    
        return check_define_env_vars(vertexai, mission, location, api_key)
    
    
    def check_local() -> bool:
        vertexai, mission, location, api_key = get_vars(os.getenv)
    
        return check_define_env_vars(vertexai, mission, location, api_key)
    
    
    def running_in_colab_env() -> bool:
        # Colab or Colab Enterprise
        return "google.colab" in sys.modules
    
    
    def check_colab_user_authentication() -> None:
        if running_in_colab_env():
            from google.colab import auth as colab_auth  # sort: ignore
    
            colab_auth.authenticate_user()
    
    
    def get_colab_secret(secret_name: str, default: str) -> str:
        from google.colab import userdata  # sort: ignore
    
        strive:
            return userdata.get(secret_name)
        besides Exception as e:
            return default
    
    
    def get_vars(getenv: Callable[[str, str], str]) -> tuple[bool, str, str, str]:
        # Restrict getenv calls to the minimal (might set off UI affirmation for secret entry)
        vertexai_str = getenv("GOOGLE_GENAI_USE_VERTEXAI", "")
        if vertexai_str:
            vertexai = vertexai_str.decrease() in ["true", "1"]
        else:
            vertexai = bool(getenv("GOOGLE_CLOUD_PROJECT", ""))
    
        mission = getenv("GOOGLE_CLOUD_PROJECT", "") if vertexai else ""
        location = getenv("GOOGLE_CLOUD_LOCATION", "") if mission else ""
        api_key = getenv("GOOGLE_API_KEY", "") if not mission else ""
    
        return vertexai, mission, location, api_key
    
    
    def check_define_env_vars(
        vertexai: bool,
        mission: str,
        location: str,
        api_key: str,
    ) -> bool:
        match (vertexai, bool(mission), bool(location), bool(api_key)):
            case (True, True, _, _):
                # Vertex AI - Google Cloud mission [+location]
                location = location or "world"
                define_env_vars(vertexai, mission, location, "")
            case (True, False, _, True):
                # Vertex AI - API key
                define_env_vars(vertexai, "", "", api_key)
            case (False, _, _, True):
                # Google AI Studio - API key
                define_env_vars(vertexai, "", "", api_key)
            case _:
                return False
    
        return True
    
    
    def define_env_vars(vertexai: bool, mission: str, location: str, api_key: str) -> None:
        os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = str(vertexai)
        os.environ["GOOGLE_CLOUD_PROJECT"] = mission
        os.environ["GOOGLE_CLOUD_LOCATION"] = location
        os.environ["GOOGLE_API_KEY"] = api_key
    
    
    def check_configuration(consumer: genai.Shopper) -> None:
        service = "Vertex AI" if consumer.vertexai else "Google AI Studio"
        print(f"Utilizing the {service} API", finish="")
    
        if consumer._api_client.mission:
            print(f' with mission "{consumer._api_client.mission[:7]}…"', finish="")
            print(f' in location "{consumer._api_client.location}"')
        elif consumer._api_client.api_key:
            api_key = consumer._api_client.api_key
            print(f' with API key "{api_key[:5]}…{api_key[-5:]}"', finish="")
            print(f" (in case of error, be certain it was created for {service})")

    🤖 Gen AI SDK

    To ship Gemini requests, create a google.genai consumer:

    from google import genai
    
    check_environment()
    
    consumer = genai.Shopper()

    Test your configuration:

    check_configuration(consumer)
    Utilizing the Vertex AI API with mission "lpdemo-…" in location "europe-west9"

    🧠 Gemini mannequin

    Gemini is available in completely different versions.

    Let’s get began with Gemini 2.0 Flash, because it presents each excessive efficiency and low latency:

    • GEMINI_2_0_FLASH = "gemini-2.0-flash"

    💡 We choose Gemini 2.0 Flash deliberately. The Gemini 2.5 mannequin household is usually obtainable and much more succesful, however we wish to experiment and perceive Gemini’s core multimodal conduct. If we full our problem with 2.0, this also needs to work with newer fashions.


    ⚙️ Gemini configuration

    Gemini can be utilized in several methods, starting from factual to artistic mode. The issue we’re making an attempt to unravel is a knowledge extraction use case. We wish outcomes as factual and deterministic as potential. For this, we will change the content generation parameters.

    We’ll set the temperature, top_p, and seed parameters to reduce randomness:

    • temperature=0.0
    • top_p=0.0
    • seed=42 (arbitrary fastened worth)

    🎞️ Video sources

    Listed below are the primary video sources that Gemini can analyze:

    supply URI Vertex AI Google AI Studio
    Google Cloud Storage gs://bucket/path/to/video.* ✅
    Net URL https://path/to/video.* ✅
    YouTube https://www.youtube.com/watch?v=YOUTUBE_ID ✅ ✅

    ⚠️ Essential notes

    • Our video check suite primarily makes use of public YouTube movies. That is for simplicity.
    • When analyzing YouTube sources, Gemini receives uncooked audio/video streams with none further metadata, precisely as if processing the corresponding video recordsdata from Cloud Storage.
    • YouTube does supply caption/subtitle/transcript options (user-provided or auto-generated). Nevertheless, these options deal with word-level speech-to-text and are restricted to 40+ languages. Gemini doesn’t obtain any of this knowledge and also you’ll see {that a} multimodal transcription with Gemini gives further advantages.
    • Moreover, our problem additionally includes figuring out audio system and extracting speaker knowledge, a singular new functionality.

    🛠️ Helpers

    Outline our helper capabilities and knowledge 🔽
    import enum
    from dataclasses import dataclass
    from datetime import timedelta
    
    import IPython.show
    import tenacity
    from google.genai.errors import ClientError
    from google.genai.sorts import (
        FileData,
        FinishReason,
        GenerateContentConfig,
        GenerateContentResponse,
        Half,
        VideoMetadata,
    )
    
    
    class Mannequin(enum.Enum):
        # Usually Obtainable (GA)
        GEMINI_2_0_FLASH = "gemini-2.0-flash"
        GEMINI_2_5_FLASH = "gemini-2.5-flash"
        GEMINI_2_5_PRO = "gemini-2.5-pro"
        # Default mannequin
        DEFAULT = GEMINI_2_0_FLASH
    
    
    # Default configuration for extra deterministic outputs
    DEFAULT_CONFIG = GenerateContentConfig(
        temperature=0.0,
        top_p=0.0,
        seed=42,  # Arbitrary fastened worth
    )
    
    YOUTUBE_URL_PREFIX = "https://www.youtube.com/watch?v="
    CLOUD_STORAGE_URI_PREFIX = "gs://"
    
    
    def url_for_youtube_id(youtube_id: str) -> str:
        return f"{YOUTUBE_URL_PREFIX}{youtube_id}"
    
    
    class Video(enum.Enum):
        go
    
    
    class TestVideo(Video):
        # For testing functions, video period is statically specified within the enum title
        # Suffix (ISO 8601 based mostly): _PT[<h>H][<m>M][<s>S]
    
        # Google DeepMind | The Podcast | Season 3 Trailer | 59s
        GDM_PODCAST_TRAILER_PT59S = url_for_youtube_id("0pJn3g8dfwk")
        # Google Maps | Stroll within the footsteps of Jane Goodall | 2min 42s
        JANE_GOODALL_PT2M42S = "gs://cloud-samples-data/video/JaneGoodall.mp4"
        # Google DeepMind | AlphaFold | The making of a scientific breakthrough | 7min 54s
        GDM_ALPHAFOLD_PT7M54S = url_for_youtube_id("gg7WjuFs8F4")
        # Brut | French reportage | 8min 28s
        BRUT_FR_DOGS_WATER_LEAK_PT8M28S = url_for_youtube_id("U_yYkb-ureI")
        # Google DeepMind | The Podcast | AI for science | 54min 23s
        GDM_AI_FOR_SCIENCE_FRONTIER_PT54M23S = url_for_youtube_id("nQKmVhLIGcs")
        # Google I/O 2025 | Developer Keynote | 1h 10min 03s
        GOOGLE_IO_DEV_KEYNOTE_PT1H10M03S = url_for_youtube_id("GjvgtwSOCao")
        # Google Cloud | Subsequent 2025 | Opening Keynote | 1h 40min 03s
        GOOGLE_CLOUD_NEXT_PT1H40M03S = url_for_youtube_id("Md4Fs-Zc3tg")
        # Google I/O 2025 | Keynote | 1h 56min 35s
        GOOGLE_IO_KEYNOTE_PT1H56M35S = url_for_youtube_id("o8NiE3XMPrM")
    
    
    class ShowAs(enum.Enum):
        DONT_SHOW = enum.auto()
        TEXT = enum.auto()
        MARKDOWN = enum.auto()
    
    
    @dataclass
    class VideoSegment:
        begin: timedelta
        finish: timedelta
    
    
    def generate_content(
        immediate: str,
        video: Video | None = None,
        video_segment: VideoSegment | None = None,
        mannequin: Mannequin | None = None,
        config: GenerateContentConfig | None = None,
        show_as: ShowAs = ShowAs.TEXT,
    ) -> None:
        immediate = immediate.strip()
        mannequin = mannequin or Mannequin.DEFAULT
        config = config or DEFAULT_CONFIG
    
        model_id = mannequin.worth
        if video:
            if not (video_part := get_video_part(video, video_segment)):
                return
            contents = [video_part, prompt]
            caption = f"{video.title} / {model_id}"
        else:
            contents = immediate
            caption = f"{model_id}"
        print(f" {caption} ".heart(80, "-"))
    
        for try in get_retrier():
            with try:
                response = consumer.fashions.generate_content(
                    mannequin=model_id,
                    contents=contents,
                    config=config,
                )
                display_response_info(response)
                display_response(response, show_as)
    
    
    def get_video_part(
        video: Video,
        video_segment: VideoSegment | None = None,
        fps: float | None = None,
    ) -> Half | None:
        video_uri: str = video.worth
    
        if not consumer.vertexai:
            video_uri = convert_to_https_url_if_cloud_storage_uri(video_uri)
            if not video_uri.startswith(YOUTUBE_URL_PREFIX):
                print("Google AI Studio API: Solely YouTube URLs are presently supported")
                return None
    
        file_data = FileData(file_uri=video_uri, mime_type="video/*")
        video_metadata = get_video_part_metadata(video_segment, fps)
    
        return Half(file_data=file_data, video_metadata=video_metadata)
    
    
    def get_video_part_metadata(
        video_segment: VideoSegment | None = None,
        fps: float | None = None,
    ) -> VideoMetadata:
        def offset_as_str(offset: timedelta) -> str:
            return f"{offset.total_seconds()}s"
    
        if video_segment:
            start_offset = offset_as_str(video_segment.begin)
            end_offset = offset_as_str(video_segment.finish)
        else:
            start_offset = None
            end_offset = None
    
        return VideoMetadata(start_offset=start_offset, end_offset=end_offset, fps=fps)
    
    
    def convert_to_https_url_if_cloud_storage_uri(uri: str) -> str:
        if uri.startswith(CLOUD_STORAGE_URI_PREFIX):
            return f"https://storage.googleapis.com/{uri.removeprefix(CLOUD_STORAGE_URI_PREFIX)}"
        else:
            return uri
    
    
    def get_retrier() -> tenacity.Retrying:
        return tenacity.Retrying(
            cease=tenacity.stop_after_attempt(7),
            wait=tenacity.wait_incrementing(begin=10, increment=1),
            retry=should_retry_request,
            reraise=True,
        )
    
    
    def should_retry_request(retry_state: tenacity.RetryCallState) -> bool:
        if not retry_state.end result:
            return False
        err = retry_state.end result.exception()
        if not isinstance(err, ClientError):
            return False
        print(f"❌ ClientError {err.code}: {err.message}")
    
        retry = False
        match err.code:
            case 400 if err.message will not be None and " strive once more " in err.message:
                # Workshop: mission accessing Cloud Storage for the primary time (service agent provisioning)
                retry = True
            case 429:
                # Workshop: momentary mission with 1 QPM quota
                retry = True
        print(f"🔄 Retry: {retry}")
    
        return retry
    
    
    def display_response_info(response: GenerateContentResponse) -> None:
        if usage_metadata := response.usage_metadata:
            if usage_metadata.prompt_token_count:
                print(f"Enter tokens   : {usage_metadata.prompt_token_count:9,d}")
            if usage_metadata.candidates_token_count:
                print(f"Output tokens  : {usage_metadata.candidates_token_count:9,d}")
            if usage_metadata.thoughts_token_count:
                print(f"Ideas tokens: {usage_metadata.thoughts_token_count:9,d}")
        if not response.candidates:
            print("❌ No `response.candidates`")
            return
        if (finish_reason := response.candidates[0].finish_reason) != FinishReason.STOP:
            print(f"❌ {finish_reason = }")
        if not response.textual content:
            print("❌ No `response.textual content`")
            return
    
    
    def display_response(
        response: GenerateContentResponse,
        show_as: ShowAs,
    ) -> None:
        if show_as == ShowAs.DONT_SHOW:
            return
        if not (response_text := response.textual content):
            return
        response_text = response.textual content.strip()
    
        print(" begin of response ".heart(80, "-"))
        match show_as:
            case ShowAs.TEXT:
                print(response_text)
            case ShowAs.MARKDOWN:
                display_markdown(response_text)
        print(" finish of response ".heart(80, "-"))
    
    
    def display_markdown(markdown: str) -> None:
        IPython.show.show(IPython.show.Markdown(markdown))
    
    
    def display_video(video: Video) -> None:
        video_url = convert_to_https_url_if_cloud_storage_uri(video.worth)
        assert video_url.startswith("https://")
    
        video_width = 600
        if video_url.startswith(YOUTUBE_URL_PREFIX):
            youtube_id = video_url.removeprefix(YOUTUBE_URL_PREFIX)
            ipython_video = IPython.show.YouTubeVideo(youtube_id, width=video_width)
        else:
            ipython_video = IPython.show.Video(video_url, width=video_width)
    
        display_markdown(f"### Video ([source]({video_url}))")
        IPython.show.show(ipython_video)

    🧪 Prototyping

    🌱 Pure conduct

    Earlier than diving any deeper, it’s fascinating to see how Gemini responds to easy directions, to develop some instinct about its pure conduct.

    Let’s first see what we get with minimalistic prompts and a brief English video.

    video = TestVideo.GDM_PODCAST_TRAILER_PT59S
    display_video(video)
    
    immediate = "Transcribe the video's audio with time info."
    generate_content(immediate, video)
    

    Video (source)

    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,708
    Output tokens  :       421
    ------------------------------ begin of response -------------------------------
    [00:00:00] Do I've to name you Sir Demis now?
    [00:00:01] Oh, you do not.
    [00:00:02] Completely not.
    [00:00:04] Welcome to Google DeepMind the podcast with me, your host Professor Hannah Fry.
    [00:00:06] We wish to take you to the center of the place these concepts are coming from.
    [00:00:12] We wish to introduce you to the people who find themselves main the design of our collective future.
    [00:00:19] Getting the security proper might be, I would say, probably the most vital challenges of our time.
    [00:00:25] I would like secure and succesful.
    [00:00:27] I desire a bridge that won't collapse.
    [00:00:30] simply give these scientists a superpower that they'd not imagined earlier.
    [00:00:34] autonomous automobiles.
    [00:00:35] It is onerous to fathom that while you're engaged on a search engine.
    [00:00:38] We may even see totally new style or totally new types of artwork come up.
    [00:00:42] There could also be a brand new phrase that's not music, portray, pictures, film making, and that AI could have helped us create it.
    [00:00:48] You actually need AGI to have the ability to peer into the mysteries of the universe.
    [00:00:51] Sure, quantum mechanics, string idea, properly, and the character of actuality.
    [00:00:55] Ow.
    [00:00:57] the magic of AI.
    ------------------------------- finish of response --------------------------------

    Outcomes:

    • Gemini naturally outputs a listing of [time] transcript strains.
    • That’s Speech-to-Textual content in a single line!
    • It appears to be like like we will reply “1️⃣ What was stated and when?”.

    Now, what about “2️⃣ Who’re the audio system?”

    immediate = "Record the audio system identifiable within the video."
    generate_content(immediate, video)
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,705
    Output tokens  :        46
    ------------------------------ begin of response -------------------------------
    Listed below are the audio system identifiable within the video:
    
    *   Professor Hannah Fry
    *   Demis Hassabis
    *   Anca Dragan
    *   Pushmeet Kohli
    *   Jeff Dean
    *   Douglas Eck
    ------------------------------- finish of response --------------------------------

    Outcomes:

    • Gemini can consolidate the names seen on title playing cards throughout the video.
    • That’s OCR + entity extraction in a single line!
    • “2️⃣ Who’re the audio system?” appears to be like solved too!

    ⏩ Not so quick!

    The pure subsequent step is to leap to the ultimate directions, to unravel our downside as soon as and for all.

    immediate = """
    Transcribe the video's audio together with speaker names (use "?" if not discovered).
    
    Format instance:
    [00:02] John Doe - Good day Alice!
    """
    generate_content(immediate, video)
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,732
    Output tokens  :       378
    ------------------------------ begin of response -------------------------------
    Right here is the audio transcription of the video:
    
    [00:00] ? - Do I've to name you Sir Demis now?
    [00:01] Demis Hassabis - Oh, you do not. Completely not.
    [00:04] Professor Hannah Fry - Welcome to Google DeepMind the podcast with me, your host, Professor Hannah Fry.
    [00:06] Professor Hannah Fry - We wish to take you to the center of the place these concepts are coming from. We wish to introduce you to the people who find themselves main the design of our collective future.
    [00:19] Anca Dragan - Getting the security proper might be, I would say, probably the most vital challenges of our time. I would like secure and succesful. I desire a bridge that won't collapse.
    [00:29] Pushmeet Kohli - Simply give these scientists a superpower that they'd not imagined earlier.
    [00:34] Jeff Dean - Autonomous automobiles. It is onerous to fathom that while you're engaged on a search engine.
    [00:38] Douglas Eck - We may even see totally new style or totally new types of artwork come up. There could also be a brand new phrase that's not music, portray, pictures, film making, and that AI could have helped us create it.
    [00:48] Professor Hannah Fry - You actually need AGI to have the ability to peer into the mysteries of the universe.
    [00:51] Demis Hassabis - Sure, quantum mechanics, string idea, properly, and the character of actuality.
    [00:55] Professor Hannah Fry - Ow!
    [00:57] Douglas Eck - The magic of AI.
    ------------------------------- finish of response --------------------------------

    That is nearly appropriate. The primary phase isn’t attributed to the host (who is just launched a bit later), however every part else appears to be like appropriate.

    Nonetheless, these will not be real-world situations:

    • The video could be very brief (lower than a minute)
    • The video can also be somewhat easy (audio system are clearly launched with on-screen title playing cards)

    Let’s strive with this 8-minute (and extra advanced) video:

    generate_content(immediate, TestVideo.GDM_ALPHAFOLD_PT7M54S)
    Output 🔽
    ------------------- GDM_ALPHAFOLD_PT7M54S / gemini-2.0-flash -------------------
    Enter tokens   :   134,177
    Output tokens  :     2,689
    ------------------------------ begin of response -------------------------------
    [00:02] ? - We have found extra concerning the world than every other civilization earlier than us.
    [00:08] ? - However now we have been caught on this one downside.
    [00:11] ? - How do proteins fold up?
    [00:13] ? - How do proteins go from a string of amino acids to a compact form that acts as a machine and drives life?
    [00:22] ? - Once you discover out about proteins, it is extremely thrilling.
    [00:25] ? - You can consider them as little organic nano machines.
    [00:28] ? - They're basically the basic constructing blocks that energy every part dwelling on this planet.
    [00:34] ? - If we will reliably predict protein constructions utilizing AI, that would change the way in which we perceive the pure world.
    [00:46] ? - Protein folding is one in all these holy grail sort issues in biology.
    [00:50] Demis Hassabis - We have all the time hypothesized that AI must be useful to make these varieties of massive scientific breakthroughs extra rapidly.
    [00:58] ? - After which I will in all probability be  little tunings which may make a distinction.
    [01:02] ? - It must be making a histogram on and a background ability.
    [01:04] ? - We have been engaged on our system AlphaFold actually onerous now for over two years.
    [01:08] ? - Quite than having to do painstaking experiments, sooner or later biologists may be capable of as an alternative depend on AI strategies to immediately predict constructions rapidly and effectively.
    [01:17] Kathryn Tunyasuvunakool - Usually talking, biologists are usually fairly skeptical of computational work, and I feel that skepticism is wholesome and I respect it, however I really feel very enthusiastic about what AlphaFold can obtain.
    [01:28] Andrew Senior - CASP is once we, we are saying, look, DeepMind is doing protein folding.
    [01:31] Andrew Senior - That is how good we're, and possibly it is higher than everyone else, possibly it is not.
    [01:37] ? - We determined to enter CASP competitors as a result of it represented the Olympics of protein folding.
    [01:44] John Moult - CASP, we began to try to velocity up the answer to the protein folding downside.
    [01:50] John Moult - Once we began CASP in 1994, I actually was naive about how onerous this was going to be.
    [01:58] ? - It was very cumbersome to try this as a result of it took a very long time.
    [02:01] ? - Let's examine what, what, what are we doing nonetheless to enhance?
    [02:03] ? - Sometimes 100 completely different teams from around the globe take part in CASP, and we take a set of 100 proteins and we ask the teams to ship us what they suppose the constructions appear like.
    [02:15] ? - We will attain 57.9 GDT on CASP 12 floor fact.
    [02:19] John Jumper - CASP has a metric on which you may be scored, which is that this GDT metric.
    [02:25] John Jumper - On a scale of zero to 100, you'll count on a GDT over 90 to be an answer to the issue.
    [02:33] ? - If we do obtain this, this has unbelievable medical relevance.
    [02:37] Pushmeet Kohli - The implications are immense, from how illnesses progress, how one can uncover new medication.
    [02:45] Pushmeet Kohli - It is limitless.
    [02:46] ? - I needed to make a, a extremely easy system and the outcomes have been surprisingly good.
    [02:50] ? - The crew acquired some outcomes with a brand new method, not solely is it extra correct, but it surely's a lot quicker than the outdated system.
    [02:56] ? - I feel we'll considerably exceed what we're doing proper now.
    [02:59] ? - This can be a sport, sport changer, I feel.
    [03:01] John Moult - In CASP 13, one thing very vital had occurred.
    [03:06] John Moult - For the primary time, we noticed the efficient software of synthetic intelligence.
    [03:11] ? - We have superior the cutting-edge within the subject, in order that's incredible, however we nonetheless acquired a protracted option to go earlier than we have solved it.
    [03:18] ? - The shapes had been now roughly appropriate for most of the proteins, however the particulars, precisely the place every atom sits, which is basically what we'd name an answer, we're not but there.
    [03:29] ? - It does not assist when you have the tallest ladder when you are going to the moon.
    [03:33] ? - We hit slightly little bit of a brick wall, um, since we received CASP, then it was again to the drafting board and like what are our new concepts?
    [03:41] ? - Um, after which it is taken a short while, I might say, for them to get again to the place they had been, however with the brand new concepts.
    [03:51] ? - They will go additional, proper?
    [03:52] ? - So, um, in order that's a extremely vital second.
    [03:55] ? - I've seen that second so many occasions now, however I do know what meaning now, and I do know that is the time now to press.
    [04:02] ? - We have to double down and go as quick as potential from right here.
    [04:05] ? - I feel we have no time to lose.
    [04:07] ? - So the intention is to enter CASP once more.
    [04:09] ? - CASP is deeply anxious.
    [04:12] ? - There's one thing bizarre occurring with, um, the training as a result of it's studying one thing that is correlated with GDT, but it surely's not calibrated.
    [04:18] ? - I really feel barely uncomfortable.
    [04:20] ? - We must be studying this, you understand, within the blink of an eye fixed.
    [04:23] ? - The know-how advancing outdoors DeepMind can also be doing unbelievable work.
    [04:27] Richard Evans - And there is all the time the likelihood one other crew has come someplace on the market subject that we do not even learn about.
    [04:32] ? - Somebody requested me, properly, ought to we panic now?
    [04:33] ? - After all, we must always have been panicking earlier than.
    [04:35] ? - It does appear to do higher, however nonetheless does not do fairly in addition to the perfect mannequin.
    [04:39] ? - Um, so it appears to be like like there's room for enchancment.
    [04:42] ? - There's all the time a threat that you've got missed one thing, and that is why blind assessments like CASP are so vital to validate whether or not our outcomes are actual.
    [04:49] ? - Clearly, I am excited to see how CASP 14 goes.
    [04:51] ? - My expectation is we get our heads down, we deal with the complete objective, which is to unravel the entire downside.
    [05:14] ? - We had been ready for CASP to begin on April fifteenth as a result of that is when it was initially scheduled to begin, and it has been delayed by a month on account of coronavirus.
    [05:24] ? - I actually miss everybody.
    [05:25] ? - No, I struggled slightly bit simply sort of getting right into a routine, particularly, uh, my spouse, she got here down with the, the virus.
    [05:32] ? - I imply, fortunately it did not end up too critical.
    [05:34] ? - CASP began on Monday.
    [05:37] Demis Hassabis - Can I simply verify this diagram you have acquired right here, John, this one the place we ask floor fact.
    [05:40] Demis Hassabis - Is that this one we have finished badly on?
    [05:42] ? - We're really fairly good on this area.
    [05:43] ? - If you happen to think about that we hadn't have stated it got here round this manner, however had put it in.
    [05:47] ? - Yeah, and that as an alternative.
    [05:48] ? - Yeah.
    [05:49] ? - One of many hardest proteins we have gotten in CASP so far is a SARS-CoV-2 protein, uh, known as Orf8.
    [05:55] ? - Orf8 is a coronavirus protein.
    [05:57] ? - We tried actually onerous to enhance our prediction, like actually, actually onerous, in all probability probably the most time that now we have ever spent on a single goal.
    [06:05] ? - So we're about two-thirds of the way in which by CASP, and we have gotten three solutions again.
    [06:11] ? - We now have a floor fact for Orf8, which is among the coronavirus proteins.
    [06:17] ? - And it seems we did very well in predicting that.
    [06:20] Demis Hassabis - Wonderful job, everybody, the entire crew.
    [06:23] Demis Hassabis - It has been an unbelievable effort.
    [06:24] John Moult - Right here what we noticed in CASP 14 was a gaggle delivering atomic accuracy off the bat, basically fixing what in our world is 2 issues.
    [06:34] John Moult - How do you look to search out the suitable answer, after which how do you acknowledge you have acquired the suitable answer while you're there?
    [06:41] ? - All proper, are we, are we principally right here?
    [06:46] ? - I'll learn an e-mail.
    [06:48] ? - Uh, I acquired this from John Moult.
    [06:50] ? - Now I will simply learn it.
    [06:51] ? - It says, John, as I count on you understand, your group has carried out amazingly properly in CASP 14, each relative to different teams and in absolute mannequin accuracy.
    [07:02] ? - Congratulations on this work.
    [07:05] ? - It's actually excellent.
    [07:07] Demis Hassabis - AlphaFold represents an enormous leap ahead that I hope will actually speed up drug discovery and assist us to higher perceive illness.
    [07:13] John Moult - It is fairly mind-blowing.
    [07:16] John Moult - You recognize, these outcomes had been, for me, having labored on this downside so lengthy, after many, many stops and begins and can this ever get there, immediately this can be a answer.
    [07:28] John Moult - We have solved the issue.
    [07:29] John Moult - This offers you such pleasure about the way in which science works, about how one can by no means see precisely and even roughly what is going on to occur subsequent.
    [07:37] John Moult - There are all the time these surprises, and that basically, as a scientist, is what retains you going.
    [07:41] John Moult - What is going on to be the subsequent shock?
    ------------------------------- finish of response --------------------------------

    This falls aside: Most segments haven’t any recognized speaker!

    As we are attempting to unravel a brand new advanced downside, LLMs haven’t been educated on any recognized answer. That is seemingly why direct directions don’t yield the anticipated reply.

    At this stage:

    • We would conclude that we will’t remedy the issue with real-world movies.
    • Persevering by making an attempt an increasing number of elaborate prompts for this unsolved downside may lead to a waste of time.

    Let’s take a step again and take into consideration what occurs underneath the hood…


    ⚛️ Below the hood

    Trendy LLMs are principally constructed upon the Transformer structure, a brand new neural community design detailed in a 2017 paper by Google researchers titled Attention Is All You Need. The paper launched the self-attention mechanism, a key innovation that essentially modified the way in which machines course of language.

    🪙 Tokens

    Tokens are the LLM constructing blocks. We will take into account a token to signify a chunk of knowledge.

    Examples of Gemini multimodal tokens (with default parameters):

    content material tokens particulars
    howdy 1 1 token for widespread phrases/sequences
    passionately 2 ardour•ately
    passionnément 3 ardour•né•ment (similar adverb in French)
    picture 258 per picture (or per tile relying on picture decision)
    audio with out timecodes 25 / second dealt with by the audio tokenizer
    video with out audio 258 / body dealt with by the video tokenizer at 1 body per second
    MM:SS timecode 5 audio chunk or video body temporal reference
    H:MM:SS timecode 7 equally, for content material longer than 1 hour

    🎞️ Sampling body charge

    By default, video frames are sampled at 1 body per second (1 FPS). These frames are included within the context with their corresponding timecodes.

    You need to use a customized sampling body charge with the Half.video_metadata.fps parameter:

    video sort change fps vary
    static, sluggish lower the body charge 0.0 < fps < 1.0
    dynamic, quick improve the body charge 1.0 < fps <= 24.0

    💡 For 1.0 < fps, Gemini was educated to know MM:SS.sss and H:MM:SS.sss timecodes.


    🔍 Media decision

    By default, every sampled body is represented with 258 tokens.

    You may specify a medium or low media decision with the GenerateContentConfig.media_resolution parameter:

    media_resolution for video inputs tokens/ body profit
    MEDIA_RESOLUTION_MEDIUM (default) 258 greater precision, permits extra detailed understanding
    MEDIA_RESOLUTION_LOW 66 quicker and cheaper inference, permits longer movies

    💡 The “media decision” will be seen because the “picture token decision”: the variety of tokens used to signify a picture.


    🧮 Possibilities all the way in which down

    The power of LLMs to speak in flawless pure language could be very spectacular, but it surely’s simple to get carried away and make incorrect assumptions.

    Be mindful how LLMs work:

    • An LLM is educated on an enormous tokenized dataset, which represents its data (its long-term reminiscence)
    • Throughout the coaching, its neural community learns token patterns
    • Once you ship a request to an LLM, your inputs are remodeled into tokens (tokenization)
    • To reply your request, the LLM predicts, token by token, the subsequent seemingly tokens
    • Total, LLMs are distinctive statistical token prediction machines that appear to imitate how some components of our mind work

    This has a number of penalties:

    • LLM outputs are simply statistically seemingly follow-ups to your inputs
    • LLMs present some types of reasoning: they will match advanced patterns however haven’t any precise deep understanding
    • LLMs haven’t any consciousness: they’re designed to generate tokens and can accomplish that based mostly in your directions
    • Order issues: Tokens which can be generated first will affect tokens which can be generated subsequent

    For the subsequent step, some methodical immediate crafting may assist…


    🏗️ Immediate crafting

    🪜 Methodology

    Immediate crafting, additionally known as immediate engineering, is a comparatively new subject. It includes designing and refining textual content directions to information LLMs in direction of producing desired outputs. Like writing, it’s each an artwork and a science, a ability that everybody can develop with apply.

    We will discover numerous reference supplies about immediate crafting. Some prompts will be very lengthy, advanced, and even scary. Crafting prompts with a high-performing LLM like Gemini is far easier. Listed below are three key adjectives to bear in mind:

    • iterative
    • exact
    • concise

    Iterative

    Immediate crafting is usually an iterative course of. Listed below are some suggestions:

    • Craft your immediate step-by-step
    • Hold monitor of your successive iterations
    • At each iteration, be certain to measure what’s working versus what’s not
    • If you happen to attain a regression, backtrack to a profitable iteration

    Exact

    Precision is essential:

    • Use phrases as particular as potential
    • Phrases with a number of meanings can introduce variability, so use exact expressions
    • Precision will affect possibilities in your favor

    Concise

    Concision has further benefits:

    • A brief immediate is simpler for us builders to know (and keep!)
    • The longer your immediate is, the extra seemingly you’re to introduce inconsistencies and even contradictions, which leads to variable interpretations of your directions
    • Check and belief the LLM’s data: this information acts as an implicit context and may make your immediate shorter and clearer

    Total, although this will likely appear contradictory, if you happen to take the time to be iterative, exact, and concise, you’re more likely to save a variety of time.

    💡 If you wish to discover this matter, try Prompting strategies (Google Cloud reference) and Prompt engineering (68-page PDF by Lee Boonstra).


    📚 Terminology

    We’re not consultants in video transcription (but!) however we wish Gemini to behave as one. Consequently, we’d like to put in writing prompts as particular as potential for this use case. Whereas LLMs course of directions based mostly on their coaching data, they will additionally share this information with us.

    We will be taught rather a lot by immediately asking Gemini:

    immediate = """
    What's the terminology used for video transcriptions?
    Please present a typical output instance.
    """
    generate_content(immediate, show_as=ShowAs.MARKDOWN)
    Output 🔽
    ------------------------------- gemini-2.0-flash -------------------------------
    Enter tokens   :        18
    Output tokens  :     1,814
    ------------------------------ begin of response -------------------------------
    ## Terminology Used for Video Transcriptions
    
    Here is a breakdown of widespread terminology used when discussing video transcriptions:
    
    *   **Transcription:** The final time period for changing audio or video content material into textual content.
    *   **Video Transcription:** Particularly refers to transcribing the audio portion of a video.
    *   **Verbatim Transcription:** A transcription that features each spoken phrase, together with filler phrases ("um," "ah"), false begins, stutters, and background noises (if related).  It goals for a extremely correct illustration of the spoken phrase.
    *   **Clear Verbatim Transcription (or Edited Transcription):** A transcription that removes filler phrases, false begins, and stutters to create a extra readable and polished textual content. It focuses on conveying the which means clearly.
    *   **Clever Verbatim Transcription:** A center floor between verbatim and clear verbatim. It removes some filler phrases and stutters however retains components that contribute to the speaker's fashion or the context of the dialog.
    *   **Abstract Transcription:** A quick overview of the video's content material, highlighting the details.
    *   **Timecoding (or Timestamping):** Including timestamps to the transcription to point when every part of textual content was spoken within the video.  That is essential for accessibility and navigation.
    *   **Speaker Identification:** Figuring out and labeling completely different audio system within the video.
    *   **Captioning (or Subtitling):** Creating textual content variations of the video's audio which can be displayed on the display, normally synchronized with the video.  Captions are sometimes used for accessibility (for deaf or hard-of-hearing viewers) and for viewers preferring to learn alongside.
    *   **Closed Captions:** Captions that may be turned on or off by the viewer.
    *   **Open Captions:** Captions which can be completely embedded within the video and can't be turned off.
    *   **SRT (SubRip Subtitle):** A standard file format for storing captions and subtitles.
    *   **VTT (Video Textual content Tracks):** A extra fashionable file format for captions and subtitles, typically used with HTML5 video.
    *   **Burned-in Captions:** Captions which can be completely embedded into the video file.
    *   **Transcriber:** The particular person or software program that performs the transcription.
    *   **Accuracy Charge:** The proportion of phrases transcribed accurately.
    *   **Turnaround Time:** The time it takes to finish the transcription.
    
    ## Typical Output Instance
    
    As an instance now we have a brief video clip of an interview. Here is how various kinds of transcriptions may look:
    
    **Situation:** A brief clip of an interview with a chef discussing their new restaurant.
    
    **1. Verbatim Transcription (with Timecoding):**
    
    ```
    00:00:00 --> 00:00:03 Interviewer: So, Chef, welcome to the present!
    00:00:03 --> 00:00:06 Chef: Thanks for having me. It is, uh, nice to be right here.
    00:00:06 --> 00:00:12 Interviewer: So, inform us slightly bit about your new restaurant, "The Golden Spoon."
    00:00:12 --> 00:00:20 Chef: Properly, um, it is, it has been a dream of mine for, like, years, you understand?  To, like, open a spot that basically focuses on, um, seasonal elements.
    00:00:20 --> 00:00:25 Interviewer: And what sort of delicacies can individuals count on?
    00:00:25 --> 00:00:32 Chef: We're doing, uh, fashionable American, however with, like, an actual emphasis on, uh, native farms and, you understand, sustainable practices.
    ```
    
    **2. Clear Verbatim Transcription (with Timecoding):**
    
    ```
    00:00:00 --> 00:00:03 Interviewer: So, Chef, welcome to the present!
    00:00:03 --> 00:00:06 Chef: Thanks for having me. It is nice to be right here.
    00:00:06 --> 00:00:12 Interviewer: So, inform us slightly bit about your new restaurant, "The Golden Spoon."
    00:00:12 --> 00:00:20 Chef: Properly, it has been a dream of mine for years to open a spot that basically focuses on seasonal elements.
    00:00:20 --> 00:00:25 Interviewer: And what sort of delicacies can individuals count on?
    00:00:25 --> 00:00:32 Chef: We're doing fashionable American, however with an actual emphasis on native farms and sustainable practices.
    ```
    
    **3. Clever Verbatim Transcription (with Timecoding):**
    
    ```
    00:00:00 --> 00:00:03 Interviewer: So, Chef, welcome to the present!
    00:00:03 --> 00:00:06 Chef: Thanks for having me. It is nice to be right here.
    00:00:06 --> 00:00:12 Interviewer: So, inform us slightly bit about your new restaurant, "The Golden Spoon."
    00:00:12 --> 00:00:20 Chef: Properly, it has been a dream of mine for, like, years, you understand? To open a spot that basically focuses on seasonal elements.
    00:00:20 --> 00:00:25 Interviewer: And what sort of delicacies can individuals count on?
    00:00:25 --> 00:00:32 Chef: We're doing fashionable American, however with, like, an actual emphasis on native farms and, you understand, sustainable practices.
    ```
    
    **4. Abstract Transcription:**
    
    ```
    Chef discusses their new restaurant, "The Golden Spoon," which focuses on seasonal elements and fashionable American delicacies with an emphasis on native farms and sustainable practices.
    ```
    
    **5. SRT File (for Captions):**
    
    ```
    1
    00:00:00,000 --> 00:00:03,000
    Interviewer: So, Chef, welcome to the present!
    
    2
    00:00:03,000 --> 00:00:06,000
    Chef: Thanks for having me. It is nice to be right here.
    
    3
    00:00:06,000 --> 00:00:12,000
    Interviewer: So, inform us slightly bit about your new restaurant, "The Golden Spoon."
    
    4
    00:00:12,000 --> 00:00:20,000
    Chef: Properly, it has been a dream of mine for years to open a spot that basically focuses on seasonal elements.
    
    5
    00:00:20,000 --> 00:00:25,000
    Interviewer: And what sort of delicacies can individuals count on?
    
    6
    00:00:25,000 --> 00:00:32,000
    Chef: We're doing fashionable American, however with an actual emphasis on native farms and sustainable practices.
    ```
    
    **Key Variations:**
    
    *   **Verbatim:** Captures each element, together with imperfections in speech.
    *   **Clear Verbatim:**  Focuses on readability and readability by eradicating pointless components.
    *   **Clever Verbatim:** A stability between accuracy and readability.
    *   **Abstract:** Gives a concise overview.
    *   **SRT:**  A structured file format for displaying captions synchronized with the video.
    
    The perfect sort of transcription depends upon the particular wants of the mission.  For authorized or analysis functions, a verbatim transcription could be crucial. For normal accessibility or advertising functions, a clear verbatim or clever verbatim transcription is commonly most well-liked.  Abstract transcriptions are helpful for rapidly understanding the content material of a video.  SRT recordsdata are important for including captions to movies.
    ------------------------------- finish of response --------------------------------

    Up to now, we’ve seen the next:

    • We didn’t handle to get the complete transcription with recognized audio system suddenly
    • Order issues (as a result of a generated token influences the possibilities for subsequent tokens)

    To deal with our problem, we want Gemini to deduce from the next multimodal info:

    • textual content (our directions + what could also be written within the video)
    • audio cues (every part stated or audible within the video’s audio)
    • visible cues (every part seen within the video)
    • time (when issues occur)

    That’s fairly a mix of knowledge sorts!

    As video transcription is an information extraction use case, if we take into consideration the ultimate consequence as a database, our last objective will be seen because the technology of two associated tables (transcripts and audio system). If we write it down, our preliminary three sub-problems now look decoupled:

    transcripts and speakers tables (L. Picard)

    💡 In laptop science, knowledge decoupling enhances knowledge locality, typically yielding improved efficiency throughout areas reminiscent of cache utilization, knowledge entry, semantic understanding, or system upkeep. Inside the LLM Transformer structure, core efficiency depends closely on the eye mechanism. Nonetheless, the eye pool is finite and tokens compete for consideration. Researchers generally seek advice from “consideration dilution” for long-context, million-token-scale benchmarks. Whereas we can’t immediately debug LLMs as customers, intuitively, knowledge decoupling might enhance the mannequin’s focus, resulting in a greater consideration span.

    Since Gemini is extraordinarily good with patterns, it may possibly mechanically generate identifiers to hyperlink our tables. As well as, since we finally need an automatic workflow, we will begin reasoning when it comes to knowledge and fields:

    transcripts and speakers tables with id (L. Picard)

    Let’s name this method “tabular extraction”, cut up our directions into two duties (tables), nonetheless in a single request, and prepare them in a significant order…


    💬 Transcripts

    Initially, let’s deal with getting the audio transcripts:

    • Gemini has confirmed to be natively good at audio transcription
    • This requires much less inference than picture evaluation
    • It’s central and unbiased info

    💡 Producing an output that begins with appropriate solutions ought to assist to realize an general appropriate output.

    We’ve additionally seen what a typical transcription entry can appear like:

    00:02 speaker_1: Welcome!

    However, instantly, there will be some ambiguities in our multimodal use case:

    • What’s a speaker?
    • Is it somebody we see/hear?
    • What if the particular person seen within the video will not be the one talking?
    • What if the particular person talking is rarely seen within the video?

    How will we unconsciously determine who’s talking in a video?

    • First, in all probability by figuring out the completely different voices on the fly?
    • Then, in all probability by consolidating further audio and visible cues?

    Can Gemini perceive voice traits?

    immediate = """
    Utilizing solely the video's audio, listing the next audible traits:
    - Voice tones
    - Voice pitches
    - Languages
    - Accents
    - Talking types
    """
    video = TestVideo.GDM_PODCAST_TRAILER_PT59S
    
    generate_content(immediate, video, show_as=ShowAs.MARKDOWN)
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,730
    Output tokens  :       168
    ------------------------------ begin of response -------------------------------
    Okay, this is a breakdown of the audible traits within the video's audio:
    
    - **Voice Tones:** The tones vary from conversational and pleasant to extra critical and considerate. There are additionally moments of pleasure and humor.
    - **Voice Pitches:** There's a mixture of excessive and low pitches, relying on the speaker. The feminine audio system are inclined to have greater pitches, whereas the male audio system have decrease pitches.
    - **Languages:** The first language is English.
    - **Accents:** There are a number of accents, together with British, American, and presumably others which can be more durable to pinpoint with out extra context.
    - **Talking Types:** The talking types differ from formal {and professional} (like in an interview setting) to extra informal and conversational. Some audio system are extra articulate and exact, whereas others are extra relaxed.
    ------------------------------- finish of response --------------------------------

    What a couple of French video?

    video = TestVideo.BRUT_FR_DOGS_WATER_LEAK_PT8M28S
    
    generate_content(immediate, video, show_as=ShowAs.MARKDOWN)
    -------------- BRUT_FR_DOGS_WATER_LEAK_PT8M28S / gemini-2.0-flash --------------
    Enter tokens   :   144,055
    Output tokens  :       147
    ------------------------------ begin of response -------------------------------
    Here is a breakdown of the audible traits within the video, based mostly on the audio:
    
    *   **Languages:** Primarily French.
    *   **Accents:** French accents are current, with some variations relying on the speaker.
    *   **Voice Tones:** The voice tones differ relying on the speaker and the context. Some are conversational and informative, whereas others are extra enthusiastic and inspiring, particularly when interacting with the canines.
    *   **Voice Pitches:** The voice pitches differ relying on the speaker and the context.
    *   **Talking Types:** The talking types differ relying on the speaker and the context. Some are conversational and informative, whereas others are extra enthusiastic and inspiring, particularly when interacting with the canines.
    ------------------------------- finish of response --------------------------------

    ⚠️ We have now to be cautious right here: responses can consolidate multimodal info and even normal data. For instance, if an individual is legendary, their title is most probably a part of the LLM’s data. If they’re recognized to be from the UK, a potential inference is that they’ve a British accent. That is why we made our immediate extra particular by together with “utilizing solely the video’s audio”.

    💡 If you happen to conduct extra exams, for instance on non-public audio recordsdata (i.e., not a part of widespread data and with no further visible cues), you’ll see that Gemini’s audio tokenizer performs exceptionally properly and extracts semantic speech info!

    After a number of iterations, we will arrive at a transcription immediate specializing in the audio and voices:

    immediate = """
    Process:
    - Watch the video and hear fastidiously to the audio.
    - Determine every distinctive voice utilizing a `voice` ID (1, 2, 3, and so forth.).
    - Transcribe the video's audio verbatim with voice diarization.
    - Embody the `begin` timecode (MM:SS) for every speech phase.
    - Output a JSON array the place every object has the next fields:
      - `begin`
      - `textual content`
      - `voice`
    """
    video = TestVideo.GDM_PODCAST_TRAILER_PT59S
    
    generate_content(immediate, video, show_as=ShowAs.MARKDOWN)
    Output 🔽
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,800
    Output tokens  :       635
    ------------------------------ begin of response -------------------------------
    [
      {
        "start": "00:00",
        "text": "Do I have to call you Sir Demis now?",
        "voice": 1
      },
      {
        "start": "00:01",
        "text": "Oh, you don't. Absolutely not.",
        "voice": 2
      },
      {
        "start": "00:03",
        "text": "Welcome to Google Deep Mind the podcast with me, your host Professor Hannah Fry.",
        "voice": 1
      },
      {
        "start": "00:06",
        "text": "We want to take you to the heart of where these ideas are coming from. We want to introduce you to the people who are leading the design of our collective future.",
        "voice": 1
      },
      {
        "start": "00:19",
        "text": "Getting the safety right is probably, I'd say, one of the most important challenges of our time. I want safe and capable.",
        "voice": 3
      },
      {
        "start": "00:26",
        "text": "I want a bridge that will not collapse.",
        "voice": 3
      },
      {
        "start": "00:30",
        "text": "just give these scientists a superpower that they had not imagined earlier.",
        "voice": 4
      },
      {
        "start": "00:34",
        "text": "autonomous vehicles. It's hard to fathom that when you're working on a search engine.",
        "voice": 5
      },
      {
        "start": "00:38",
        "text": "We may see entirely new genre or entirely new forms of art come up. There may be a new word that is not music, painting, photography, movie making, and that AI will have helped us create it.",
        "voice": 6
      },
      {
        "start": "00:48",
        "text": "You really want AGI to be able to peer into the mysteries of the universe.",
        "voice": 1
      },
      {
        "start": "00:51",
        "text": "Yes, quantum mechanics, string theory, well, and the nature of reality.",
        "voice": 2
      },
      {
        "start": "00:55",
        "text": "Ow.",
        "voice": 1
      },
      {
        "start": "00:56",
        "text": "the magic of AI.",
        "voice": 6
      }
    ]
    ------------------------------- finish of response --------------------------------

    That is wanting good! And if you happen to check these directions on extra advanced movies, you’ll get equally promising outcomes.

    Discover how the immediate reuses cherry-picked phrases from the terminology beforehand offered by Gemini, whereas aiming for precision and concision:

    • verbatim is unambiguous (not like “spoken phrases”)
    • 1, 2, 3, and so forth. is an ellipsis (Gemini can infer the sample)
    • timecode is restricted (timestamp has extra meanings)
    • MM:SS clarifies the timecode format

    💡 Gemini 2.0 was educated to know the particular MM:SS timecode format. Gemini 2.5 additionally helps the H:MM:SS format for longer movies. For the newest updates, seek advice from the video understanding documentation.

    We’re midway there. Let’s full our database technology with a second process…


    🧑 Audio system

    The second process is fairly easy: we wish to extract speaker info right into a second desk. The 2 tables are logically linked by the voice ID.

    After a number of iterations, we will attain a two-task immediate like the next:

    immediate = """
    Generate a JSON object with keys `task1_transcripts` and `task2_speakers` for the next duties.
    
    **Process 1 - Transcripts**
    
    - Watch the video and hear fastidiously to the audio.
    - Determine every distinctive voice utilizing a `voice` ID (1, 2, 3, and so forth.).
    - Transcribe the video's audio verbatim with voice diarization.
    - Embody the `begin` timecode (MM:SS) for every speech phase.
    - Output a JSON array the place every object has the next fields:
      - `begin`
      - `textual content`
      - `voice`
    
    **Process 2 - Audio system**
    
    - For every `voice` ID from Process 1, extract details about the corresponding speaker.
    - Use visible and audio cues.
    - If a speaker's title can't be discovered, use a query mark (`?`) as the worth.
    - Output a JSON array the place every object has the next fields:
      - `voice`
      - `title`
    
    JSON:
    """
    video = TestVideo.GDM_PODCAST_TRAILER_PT59S
    
    generate_content(immediate, video, show_as=ShowAs.MARKDOWN)
    Output 🔽
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,920
    Output tokens  :       806
    ------------------------------ begin of response -------------------------------
    {
      "task1_transcripts": [
        {
          "start": "00:00",
          "text": "Do I have to call you Sir Demis now?",
          "voice": 1
        },
        {
          "start": "00:01",
          "text": "Oh, you don't. Absolutely not.",
          "voice": 2
        },
        {
          "start": "00:04",
          "text": "Welcome to Google Deep Mind the podcast with me, your host Professor Hannah Fry.",
          "voice": 1
        },
        {
          "start": "00:06",
          "text": "We want to take you to the heart of where these ideas are coming from. We want to introduce you to the people who are leading the design of our collective future.",
          "voice": 1
        },
        {
          "start": "00:19",
          "text": "Getting the safety right is probably, I'd say, one of the most important challenges of our time. I want safe and capable.",
          "voice": 3
        },
        {
          "start": "00:26",
          "text": "I want a bridge that will not collapse.",
          "voice": 3
        },
        {
          "start": "00:30",
          "text": "That just give these scientists a superpower that they had not imagined earlier.",
          "voice": 4
        },
        {
          "start": "00:34",
          "text": "autonomous vehicles. It's hard to fathom that when you're working on a search engine.",
          "voice": 5
        },
        {
          "start": "00:38",
          "text": "We may see entirely new genre or entirely new forms of art come up. There may be a new word that is not music, painting, photography, movie making, and that AI will have helped us create it.",
          "voice": 6
        },
        {
          "start": "00:48",
          "text": "You really want AGI to be able to peer into the mysteries of the universe.",
          "voice": 1
        },
        {
          "start": "00:51",
          "text": "Yes, quantum mechanics, string theory, well, and the nature of reality.",
          "voice": 2
        },
        {
          "start": "00:55",
          "text": "Ow.",
          "voice": 1
        },
        {
          "start": "00:56",
          "text": "the magic of AI.",
          "voice": 6
        }
      ],
      "task2_speakers": [
        {
          "voice": 1,
          "name": "Professor Hannah Fry"
        },
        {
          "voice": 2,
          "name": "Demis Hassabis"
        },
        {
          "voice": 3,
          "name": "Anca Dragan"
        },
        {
          "voice": 4,
          "name": "Pushmeet Kohli"
        },
        {
          "voice": 5,
          "name": "Jeff Dean"
        },
        {
          "voice": 6,
          "name": "Douglas Eck"
        }
      ]
    }
    ------------------------------- finish of response --------------------------------

    Check this immediate on extra advanced movies: it’s nonetheless wanting good!


    🚀 Finalization

    🧩 Structured output

    We’ve iterated in direction of a exact and concise immediate. Now, we will deal with Gemini’s response:

    • The response is apparent textual content containing fenced code blocks
    • As an alternative, we’d like a structured output, to obtain constantly formatted responses
    • Ideally, we’d additionally prefer to keep away from having to parse the response, which could be a upkeep burden

    Getting structured outputs is an LLM characteristic additionally known as “managed technology”. Since we’ve already crafted our immediate when it comes to knowledge tables and JSON fields, that is now a formality.

    In our request, we will add the next parameters:

    • response_mime_type="software/json"
    • response_schema="YOUR_JSON_SCHEMA" (docs)

    In Python, this will get even simpler:

    • Use the pydantic library
    • Replicate your output construction with courses derived from pydantic.BaseModel

    We will simplify the immediate by eradicating the output specification components:

    Generate a JSON object with keys `task1_transcripts` and `task2_speakers` for the next duties.
    …
    - Output a JSON array the place every object has the next fields:
      - `begin`
      - `textual content`
      - `voice`
    …
    - Output a JSON array the place every object has the next fields:
      - `voice`
      - `title`

    … to maneuver them to matching Python courses as an alternative:

    import pydantic
    
    class Transcript(pydantic.BaseModel):
        begin: str
        textual content: str
        voice: int
    
    class Speaker(pydantic.BaseModel):
        voice: int
        title: str
    
    class VideoTranscription(pydantic.BaseModel):
        task1_transcripts: listing[Transcript] = pydantic.Area(default_factory=listing)
        task2_speakers: listing[Speaker] = pydantic.Area(default_factory=listing)

    … and request a structured response:

    response = consumer.fashions.generate_content(
        # …
        config=GenerateContentConfig(
            # …
            response_mime_type="software/json",
            response_schema=VideoTranscription,
            # …
        ),
    )

    Lastly, retrieving the objects from the response can also be direct:

    if isinstance(response.parsed, VideoTranscription):
        video_transcription = response.parsed
    else:
        video_transcription = VideoTranscription()  # Empty transcription

    The fascinating features of this method are the next:

    • The immediate focuses on the logic and the courses deal with the output
    • It’s simpler to replace and keep typed courses
    • The JSON schema is mechanically generated by the Gen AI SDK from the category offered in response_schema and dispatched to Gemini
    • The response is mechanically parsed by the Gen AI SDK and deserialized into the corresponding Python objects

    ⚠️ If you happen to hold output specs in your immediate, guarantee there aren’t any contradictions between the immediate and the schema (e.g., similar subject names and order), as this will negatively affect the standard of the responses.

    💡 It’s potential to have extra structural info immediately within the schema (e.g., detailed subject definitions). See Controlled generation.


    ✨ Implementation

    Let’s finalize our code. As well as, now that now we have a secure immediate, we will even enrich our answer to extract every speaker’s firm, place, and role_in_video:

    Remaining code 🔽
    import re
    
    import pydantic
    from google.genai.sorts import MediaResolution, ThinkingConfig
    
    SamplingFrameRate = float
    
    VIDEO_TRANSCRIPTION_PROMPT = """
    **Process 1 - Transcripts**
    
    - Watch the video and hear fastidiously to the audio.
    - Determine every distinctive voice utilizing a `voice` ID (1, 2, 3, and so forth.).
    - Transcribe the video's audio verbatim with voice diarization.
    - Embody the `begin` timecode ({timecode_spec}) for every speech phase.
    
    **Process 2 - Audio system**
    
    - For every `voice` ID from Process 1, extract details about the corresponding speaker.
    - Use visible and audio cues.
    - If a chunk of knowledge can't be discovered, use a query mark (`?`) as the worth.
    """
    NOT_FOUND = "?"
    
    
    class Transcript(pydantic.BaseModel):
        begin: str
        textual content: str
        voice: int
    
    
    class Speaker(pydantic.BaseModel):
        voice: int
        title: str
        firm: str
        place: str
        role_in_video: str
    
    
    class VideoTranscription(pydantic.BaseModel):
        task1_transcripts: listing[Transcript] = pydantic.Area(default_factory=listing)
        task2_speakers: listing[Speaker] = pydantic.Area(default_factory=listing)
    
    
    def get_generate_content_config(mannequin: Mannequin, video: Video) -> GenerateContentConfig:
        media_resolution = get_media_resolution_for_video(video)
        thinking_config = get_thinking_config(mannequin)
    
        return GenerateContentConfig(
            temperature=DEFAULT_CONFIG.temperature,
            top_p=DEFAULT_CONFIG.top_p,
            seed=DEFAULT_CONFIG.seed,
            response_mime_type="software/json",
            response_schema=VideoTranscription,
            media_resolution=media_resolution,
            thinking_config=thinking_config,
        )
    
    
    def get_video_duration(video: Video) -> timedelta | None:
        # For testing functions, video period is statically specified within the enum title
        # Suffix (ISO 8601 based mostly): _PT[<h>H][<m>M][<s>S]
        # For manufacturing,
        # - fetch durations dynamically or retailer them individually
        # - bear in mind video VideoMetadata.start_offset & VideoMetadata.end_offset
        regex = r"_PT(?:(d+)H)?(?:(d+)M)?(?:(d+)S)?$"
        if not (match := re.search(regex, video.title)):
            print(f"⚠️ No period data in {video.title}. Will use defaults.")
            return None
    
        h_str, m_str, s_str = match.teams()
        return timedelta(
            hours=int(h_str) if h_str will not be None else 0,
            minutes=int(m_str) if m_str will not be None else 0,
            seconds=int(s_str) if s_str will not be None else 0,
        )
    
    
    def get_media_resolution_for_video(video: Video) -> MediaResolution | None:
        if not (video_duration := get_video_duration(video)):
            return None  # Default
    
        # For testing functions, that is based mostly on video period, as our brief movies are usually extra detailed
        less_than_five_minutes = video_duration < timedelta(minutes=5)
        if less_than_five_minutes:
            media_resolution = MediaResolution.MEDIA_RESOLUTION_MEDIUM
        else:
            media_resolution = MediaResolution.MEDIA_RESOLUTION_LOW
    
        return media_resolution
    
    
    def get_sampling_frame_rate_for_video(video: Video) -> SamplingFrameRate | None:
        sampling_frame_rate = None  # Default (1 FPS for present fashions)
    
        # [Optional] Outline a customized FPS: 0.0 < sampling_frame_rate <= 24.0
    
        return sampling_frame_rate
    
    
    def get_timecode_spec_for_model_and_video(mannequin: Mannequin, video: Video) -> str:
        timecode_spec = "MM:SS"  # Default
    
        match mannequin:
            case Mannequin.GEMINI_2_0_FLASH:  # Helps MM:SS
                go
            case Mannequin.GEMINI_2_5_FLASH | Mannequin.GEMINI_2_5_PRO:  # Assist MM:SS and H:MM:SS
                period = get_video_duration(video)
                one_hour_or_more = period will not be None and timedelta(hours=1) <= period
                if one_hour_or_more:
                    timecode_spec = "MM:SS or H:MM:SS"
            case _:
                assert False, "Add timecode format for brand spanking new mannequin"
    
        return timecode_spec
    
    
    def get_thinking_config(mannequin: Mannequin) -> ThinkingConfig | None:
        # Examples of considering configurations (Gemini 2.5 fashions)
        match mannequin:
            case Mannequin.GEMINI_2_5_FLASH:  # Pondering disabled
                return ThinkingConfig(thinking_budget=0, include_thoughts=False)
            case Mannequin.GEMINI_2_5_PRO:  # Minimal considering funds and no summarized ideas
                return ThinkingConfig(thinking_budget=128, include_thoughts=False)
            case _:
                return None  # Default
    
    
    def get_video_transcription_from_response(
        response: GenerateContentResponse,
    ) -> VideoTranscription:
        if not isinstance(response.parsed, VideoTranscription):
            print("❌ Couldn't parse the JSON response")
            return VideoTranscription()  # Empty transcription
    
        return response.parsed
    
    
    def get_video_transcription(
        video: Video,
        video_segment: VideoSegment | None = None,
        fps: float | None = None,
        immediate: str | None = None,
        mannequin: Mannequin | None = None,
    ) -> VideoTranscription:
        mannequin = mannequin or Mannequin.DEFAULT
        model_id = mannequin.worth
    
        fps = fps or get_sampling_frame_rate_for_video(video)
        video_part = get_video_part(video, video_segment, fps)
        if not video_part:  # Unsupported supply, return an empty transcription
            return VideoTranscription()
        if immediate is None:
            timecode_spec = get_timecode_spec_for_model_and_video(mannequin, video)
            immediate = VIDEO_TRANSCRIPTION_PROMPT.format(timecode_spec=timecode_spec)
        contents = [video_part, prompt.strip()]
    
        config = get_generate_content_config(mannequin, video)
    
        print(f" {video.title} / {model_id} ".heart(80, "-"))
        response = None
        for try in get_retrier():
            with try:
                response = consumer.fashions.generate_content(
                    mannequin=model_id,
                    contents=contents,
                    config=config,
                )
                display_response_info(response)
    
        assert isinstance(response, GenerateContentResponse)
        return get_video_transcription_from_response(response)

    Check it:

    def test_structured_video_transcription(video: Video) -> None:
        transcription = get_video_transcription(video)
    
        print("-" * 80)
        print(f"Transcripts : {len(transcription.task1_transcripts):3d}")
        print(f"Audio system    : {len(transcription.task2_speakers):3d}")
        for speaker in transcription.task2_speakers:
            print(f"- {speaker}")
    
    
    test_structured_video_transcription(TestVideo.GDM_PODCAST_TRAILER_PT59S)
    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,917
    Output tokens  :       989
    --------------------------------------------------------------------------------
    Transcripts :  13
    Audio system    :   6
    - voice=1 title='Professor Hannah Fry' firm='Google DeepMind' place='Host' role_in_video='Host'
    - voice=2 title='Demis Hassabis' firm='Google DeepMind' place='Co-Founder & CEO' role_in_video='Interviewee'
    - voice=3 title='Anca Dragan' firm='?' place='Director, AI Security & Alignment' role_in_video='Interviewee'
    - voice=4 title='Pushmeet Kohli' firm='?' place='VP Science & Strategic Initiatives' role_in_video='Interviewee'
    - voice=5 title='Jeff Dean' firm='?' place='Chief Scientist' role_in_video='Interviewee'
    - voice=6 title='Douglas Eck' firm='?' place='Senior Analysis Director' role_in_video='Interviewee'

    📊 Knowledge visualization

    We began prototyping in pure language, crafted a immediate, and generated a structured output. Since studying uncooked knowledge will be cumbersome, we will now current video transcriptions in a extra visually interesting means.

    Right here’s a potential orchestrator operate:

    def transcribe_video(video: Video, …) -> None:
        display_video(video)
        transcription = get_video_transcription(video, …)
        display_speakers(transcription)
        display_transcripts(transcription)
    Let’s add some knowledge visualization capabilities 🔽
    import itertools
    from collections.abc import Callable, Iterator
    
    from pandas import DataFrame, Collection
    from pandas.io.codecs.fashion import Styler
    from pandas.io.codecs.style_render import CSSDict
    
    BGCOLOR_COLUMN = "bg_color"  # Hidden column to retailer row background colours
    
    
    def yield_known_speaker_color() -> Iterator[str]:
        PAL_40 = ("#669DF6", "#EE675C", "#FCC934", "#5BB974")
        PAL_30 = ("#8AB4F8", "#F28B82", "#FDD663", "#81C995")
        PAL_20 = ("#AECBFA", "#F6AEA9", "#FDE293", "#A8DAB5")
        PAL_10 = ("#D2E3FC", "#FAD2CF", "#FEEFC3", "#CEEAD6")
        PAL_05 = ("#E8F0FE", "#FCE8E6", "#FEF7E0", "#E6F4EA")
        return itertools.cycle([*PAL_40, *PAL_30, *PAL_20, *PAL_10, *PAL_05])
    
    
    def yield_unknown_speaker_color() -> Iterator[str]:
        GRAYS = ["#80868B", "#9AA0A6", "#BDC1C6", "#DADCE0", "#E8EAED", "#F1F3F4"]
        return itertools.cycle(GRAYS)
    
    
    def get_color_for_voice_mapping(audio system: listing[Speaker]) -> dict[int, str]:
        known_speaker_color = yield_known_speaker_color()
        unknown_speaker_color = yield_unknown_speaker_color()
    
        mapping: dict[int, str] = {}
        for speaker in audio system:
            if speaker.title != NOT_FOUND:
                coloration = subsequent(known_speaker_color)
            else:
                coloration = subsequent(unknown_speaker_color)
            mapping[speaker.voice] = coloration
    
        return mapping
    
    
    def get_table_styler(df: DataFrame) -> Styler:
        def join_styles(types: listing[str]) -> str:
            return ";".be a part of(types)
    
        table_css = [
            "color: #202124",
            "background-color: #BDC1C6",
            "border: 0",
            "border-radius: 0.5rem",
            "border-spacing: 0px",
            "outline: 0.5rem solid #BDC1C6",
            "margin: 1rem 0.5rem",
        ]
        th_css = ["background-color: #E8EAED"]
        th_td_css = ["text-align:left", "padding: 0.25rem 1rem"]
        table_styles = [
            CSSDict(selector="", props=join_styles(table_css)),
            CSSDict(selector="th", props=join_styles(th_css)),
            CSSDict(selector="th,td", props=join_styles(th_td_css)),
        ]
    
        return df.fashion.set_table_styles(table_styles).conceal()
    
    
    def change_row_bgcolor(row: Collection) -> listing[str]:
        fashion = f"background-color:{row[BGCOLOR_COLUMN]}"
        return [style] * len(row)
    
    
    def display_table(yield_rows: Callable[[], Iterator[list[str]]]) -> None:
        knowledge = yield_rows()
        df = DataFrame(columns=subsequent(knowledge), knowledge=knowledge)
        styler = get_table_styler(df)
        styler.apply(change_row_bgcolor, axis=1)
        styler.conceal([BGCOLOR_COLUMN], axis="columns")
    
        html = styler.to_html()
        IPython.show.show(IPython.show.HTML(html))
    
    
    def display_speakers(transcription: VideoTranscription) -> None:
        def sanitize_field(s: str, symbol_if_unknown: str) -> str:
            return symbol_if_unknown if s == NOT_FOUND else s
    
        def yield_rows() -> Iterator[list[str]]:
            yield ["voice", "name", "company", "position", "role_in_video", BGCOLOR_COLUMN]
    
            color_for_voice = get_color_for_voice_mapping(transcription.task2_speakers)
            for speaker in transcription.task2_speakers:
                yield [
                    str(speaker.voice),
                    sanitize_field(speaker.name, NOT_FOUND),
                    sanitize_field(speaker.company, NOT_FOUND),
                    sanitize_field(speaker.position, NOT_FOUND),
                    sanitize_field(speaker.role_in_video, NOT_FOUND),
                    color_for_voice.get(speaker.voice, "red"),
                ]
    
        display_markdown(f"### Audio system ({len(transcription.task2_speakers)})")
        display_table(yield_rows)
    
    
    def display_transcripts(transcription: VideoTranscription) -> None:
        def yield_rows() -> Iterator[list[str]]:
            yield ["start", "speaker", "transcript", BGCOLOR_COLUMN]
    
            color_for_voice = get_color_for_voice_mapping(transcription.task2_speakers)
            speaker_for_voice = {
                speaker.voice: speaker for speaker in transcription.task2_speakers
            }
            previous_voice = None
            for transcript in transcription.task1_transcripts:
                current_voice = transcript.voice
                speaker_label = ""
                if speaker := speaker_for_voice.get(current_voice, None):
                    if speaker.title != NOT_FOUND:
                        speaker_label = speaker.title
                    elif speaker.place != NOT_FOUND:
                        speaker_label = f"[voice {current_voice}][{speaker.position}]"
                    elif speaker.role_in_video != NOT_FOUND:
                        speaker_label = f"[voice {current_voice}][{speaker.role_in_video}]"
                if not speaker_label:
                    speaker_label = f"[voice {current_voice}]"
                yield [
                    transcript.start,
                    speaker_label if current_voice != previous_voice else '"',
                    transcript.text,
                    color_for_voice.get(current_voice, "red"),
                ]
                previous_voice = current_voice
    
        display_markdown(f"### Transcripts ({len(transcription.task1_transcripts)})")
        display_table(yield_rows)
    
    
    def transcribe_video(
        video: Video,
        video_segment: VideoSegment | None = None,
        fps: float | None = None,
        immediate: str | None = None,
        mannequin: Mannequin | None = None,
    ) -> None:
        display_video(video)
        transcription = get_video_transcription(video, video_segment, fps, immediate, mannequin)
        display_speakers(transcription)
        display_transcripts(transcription)

    ✅ Problem accomplished

    🎬 Quick video

    This video is a trailer for the Google DeepMind podcast. It contains a fast-paced montage of 6 interviews. The multimodal transcription is great:

    transcribe_video(TestVideo.GDM_PODCAST_TRAILER_PT59S)

    Video (source)

    ----------------- GDM_PODCAST_TRAILER_PT59S / gemini-2.0-flash -----------------
    Enter tokens   :    16,917
    Output tokens  :       989

    Audio system (6)

    Transcripts (13)


    🎬 Narrator-only video

    This video is a documentary that takes viewers on a digital tour of the Gombe Nationwide Park in Tanzania. There’s no seen speaker. Jane Goodall is accurately detected because the narrator, her title is extracted from the credit:

    transcribe_video(TestVideo.JANE_GOODALL_PT2M42S)

    Video (source)

    ------------------- JANE_GOODALL_PT2M42S / gemini-2.0-flash --------------------
    Enter tokens   :    46,324
    Output tokens  :       717

    Audio system (1)

    Transcripts (14)

    💡 Over the previous few years, I’ve frequently used this video to check specialised ML fashions and it constantly resulted in numerous varieties of errors. Gemini’s transcription, together with punctuation, is ideal.


    🎬 French video

    This French reportage combines on-the-ground footage of a specialised crew that makes use of educated canines to detect leaks in underground consuming water pipes. The recording takes place totally open air in a rural setting. The interviewed employees are launched with on-screen textual content overlays. The audio, captured stay on location, consists of ambient noise. There are additionally some off-screen or unidentified audio system. This video is somewhat advanced. The multimodal transcription gives wonderful outcomes with no false positives:

    transcribe_video(TestVideo.BRUT_FR_DOGS_WATER_LEAK_PT8M28S)

    Video (source)

    -------------- BRUT_FR_DOGS_WATER_LEAK_PT8M28S / gemini-2.0-flash --------------
    Enter tokens   :    46,514
    Output tokens  :     4,924

    Audio system (14)

    Transcripts (61)

    💡 Our immediate was crafted and examined with English movies, however works with out modification with this French video. It also needs to work for movies in these 100+ different languages.

    💡 In a multilingual answer, we would ask to translate our transcriptions into any of these 100+ languages and even carry out textual content cleanup. This may be finished in a second request, because the multimodal transcription is advanced sufficient by itself.

    💡 Gemini’s audio tokenizer detects greater than speech. If you happen to attempt to listing non-speech sounds on audio tracks solely (to make sure the response doesn’t profit from any visible cues), you’ll see it may possibly detect sounds reminiscent of “canine bark”, “music”, “sound impact”, “footsteps”, “laughter”, “applause”…

    💡 In our knowledge visualization tables, coloured rows are inference positives (audio system recognized by the mannequin), whereas grey rows correspond to negatives (unidentified audio system). This makes it simpler to know the outcomes. Because the immediate we crafted favors accuracy over recall, coloured rows are typically appropriate, and grey rows correspond both to unnamed/unidentifiable audio system (true negatives) or to audio system that ought to have been recognized (false negatives).


    🎬 Complicated video

    This Google DeepMind video is kind of advanced:

    • It’s extremely edited and really dynamic
    • Audio system are sometimes off-screen and different individuals will be seen as an alternative
    • The researchers are sometimes in teams and it’s not all the time apparent who’s talking
    • Some video pictures had been taken 2 years aside: the identical audio system can sound and look completely different!

    Gemini 2.0 Flash generates a superb transcription regardless of the complexity. Nevertheless, it’s more likely to listing duplicate audio system because of the video sort. Gemini 2.5 Professional gives a deeper inference and manages to consolidate the audio system:

    transcribe_video(
        TestVideo.GDM_ALPHAFOLD_PT7M54S,
        mannequin=Mannequin.GEMINI_2_5_PRO,
    )

    Video (source)

    -------------------- GDM_ALPHAFOLD_PT7M54S / gemini-2.5-pro --------------------
    Enter tokens   :    43,354
    Output tokens  :     4,861
    Ideas tokens:        80

    Audio system (11)

    Transcripts (81)


    🎬 Lengthy transcription

    The whole size of the transcribed textual content can rapidly attain the utmost variety of output tokens. With our present JSON response schema, we will attain 8,192 output tokens (supported by Gemini 2.0) with transcriptions of ~25min movies. Gemini 2.5 fashions help as much as 65,536 output tokens (8x extra) and allow us to transcribe longer movies.

    For this 54-minute panel dialogue, Gemini 2.5 Professional makes use of solely ~30-35% of the enter/output token limits:

    transcribe_video(
        TestVideo.GDM_AI_FOR_SCIENCE_FRONTIER_PT54M23S,
        mannequin=Mannequin.GEMINI_2_5_PRO,
    )

    Video (source)

    ------------ GDM_AI_FOR_SCIENCE_FRONTIER_PT54M23S / gemini-2.5-pro -------------
    Enter tokens   :   297,153
    Output tokens  :    22,896
    Ideas tokens:        65

    Audio system (14)

    Transcripts (593)

    💡 On this lengthy video, the 5 panelists are accurately transcribed, diarized, and recognized. Within the second half of the video, unseen attendees ask inquiries to the panel. They’re accurately recognized as viewers members and, although their names and corporations are by no means written on the display, Gemini accurately extracts and even consolidates the knowledge from the audio cues.


    🎬 1h+ video

    Within the newest Google I/O keynote video (1h 10min):

    • ~30-35%% of the token restrict is used (383k/1M in, 20/64k out)
    • The dozen audio system are properly recognized, together with the demo “AI Voices” (“Gemini” and “Casey”)
    • Speaker names are extracted from slanted textual content on the background display for the stay keynote audio system (e.g., Josh Woodward at 0:07) and from lower-third on-screen textual content within the DolphinGemma reportage (e.g., Dr. Denise Herzing at 1:05:28)
    transcribe_video(
        TestVideo.GOOGLE_IO_DEV_KEYNOTE_PT1H10M03S,
        mannequin=Mannequin.GEMINI_2_5_PRO,
    )

    Video (source)

    -------------- GOOGLE_IO_DEV_KEYNOTE_PT1H10M03S / gemini-2.5-pro ---------------
    Enter tokens   :   382,699
    Output tokens  :    19,772
    Ideas tokens:        75

    Audio system (14)

    Transcripts (201)


    🎬 40 speaker video

    On this 1h 40min Google Cloud Subsequent keynote video:

    • ~50-70% of the token restrict is used (547k/1M in, 45/64k out)
    • 40 distinct voices are diarized
    • 29 audio system are recognized, related to their 21 respective firms or divisions
    • The transcription takes as much as 8 minutes (roughly 4 minutes with video tokens cached), which is 13 to 23 occasions quicker than watching the complete video with out pauses.
    transcribe_video(
        TestVideo.GOOGLE_CLOUD_NEXT_PT1H40M03S,
        mannequin=Mannequin.GEMINI_2_5_PRO,
    )

    Video (source)

    ---------------- GOOGLE_CLOUD_NEXT_PT1H40M03S / gemini-2.5-pro -----------------
    Enter tokens   :   546,590
    Output tokens  :    45,398
    Ideas tokens:        74

    Audio system (40)

    Transcripts (853)


    ⚖️ Strengths & weaknesses

    👍 Strengths

    Total, Gemini is able to producing wonderful transcriptions that surpass human-generated ones in these features:

    • Consistency of the transcription
    • Good grammar and punctuation
    • Spectacular semantic understanding
    • No typos or transcription system errors
    • Exhaustivity (each audible phrase is transcribed)

    💡 As you understand, a single incorrect/lacking phrase (and even letter) can fully change the which means. These strengths assist guarantee high-quality transcriptions and cut back the danger of misunderstandings.

    If we evaluate YouTube’s user-provided transcriptions (generally by skilled caption distributors) to our auto-generated ones, we will observe some vital variations. Listed below are some examples from the final check:

     timecode ❌ user-provided ✅ our transcription
    9:47 analysis and fashions analysis and mannequin
    13:32 used by 100,000 companies used by over 100,000 companies
    18:19 infrastructure core layer infrastructure core for AI
    20:21 {hardware} system {hardware} technology
    23:42 I do deployed ML fashions Toyota deployed ML fashions
    34:17 Vertex video Vertex Media
    41:11 velocity up app improvement velocity up software coding and improvement
    42:15 efficiency and confirmed insights efficiency enchancment insights
    50:20 throughout the milt agent ecosystem throughout the multi-agent ecosystem
    52:50 Salesforce, and Dun Salesforce, or Dun
    1:22:28 please nearly Please welcome
    1:31:07 organizations, like I say Charles organizations like Charles
    1:33:23 a number of public LOMs a number of public LLMs
    1:33:54 Gemini’s Agent tech AI Gemini’s agentic AI
    1:34:24 mitigated outsider threat mitigated insider threat
    1:35:58 from finish level, viral, networks from endpoint, firewall, networks
    1:38:45 We at Google are We at Google Cloud are

    👎 Weaknesses

    The present immediate will not be good although. It focuses first on the audio for transcription after which on all cues for speaker knowledge extraction. Although Gemini natively ensures a really excessive consolidation from the context, the immediate can present these uncomfortable side effects:

    • Sensitivity to audio system’ pronunciation or accent
    • Misspellings for correct nouns
    • Inconsistencies between transcription and completely recognized speaker title

    Listed below are examples from the identical check:

    timecode ✅ user-provided ❌ our transcription
    3:31 Bosun Boson
    3:52 Imagen Think about
    3:52 Veo VO
    11:15 Berman Burman
    25:06 Huang Wang
    38:58 Allegiant Stadium Allegiance Stadium
    1:29:07 Snyk Sneak

    We’ll cease our exploration right here and depart it as an train, however listed here are potential methods to repair these errors, so as of simplicity/price:

    • Replace the immediate to make use of visible cues for correct nouns, reminiscent of “Guarantee all correct nouns (individuals, firms, merchandise, and so forth.) are spelled accurately and constantly. Prioritize on-screen textual content for reference.”
    • Enrich the immediate with a further preliminary desk to extract the right nouns and use them explicitly within the context
    • Add obtainable video context metadata within the immediate
    • Cut up the immediate into two successive requests

    📈 Ideas & optimizations

    🔧 Mannequin choice

    Every mannequin can differ when it comes to efficiency, velocity, and value.

    Right here’s a sensible abstract based mostly on the mannequin specs, our video check suite, and the present immediate:

    Mannequin Efficiency Pace Price Max. enter tokens Max. output tokens Video sort
    Gemini 2.0 Flash ⭐⭐ ⭐⭐⭐ ⭐⭐⭐ 1,048,576
    = 1M
    8,192
    = 8k
    Commonplace video, as much as 25min
    Gemini 2.5 Flash ⭐⭐ ⭐⭐ ⭐⭐ 1,048,576
    = 1M
    65,536
    = 64k
    Commonplace video, 25min+
    Gemini 2.5 Professional ⭐⭐⭐ ⭐ ⭐ 1,048,576
    = 1M
    65,536
    = 64k
    Complicated video or 1h+ video

    🔧 Video phase

    You don’t all the time want to research movies from begin to end. You may point out a video phase with begin and/or finish offsets within the VideoMetadata construction.

    On this instance, Gemini will solely analyze the 30:00-50:00 phase of the video:

    video_metadata = VideoMetadata(
        start_offset="1800.0s",
        end_offset="3000.0s",
        …
    )

    🔧 Media decision

    In our check suite, the movies are pretty commonplace. We acquired wonderful outcomes through the use of a “low” media decision (“medium” being the default), specified with the GenerateContentConfig.media_resolution parameter.

    💡 This gives quicker and cheaper inferences, whereas additionally enabling the evaluation of 3x longer movies.

    We used a easy heuristic based mostly on video period, however you may wish to make it dynamic on a per-video foundation:

    def get_media_resolution_for_video(video: Video) -> MediaResolution | None:
        if not (video_duration := get_video_duration(video)):
            return None  # Default
    
        # For testing functions, that is based mostly on video period, as our brief movies are usually extra detailed
        less_than_five_minutes = video_duration < timedelta(minutes=5)
        if less_than_five_minutes:
            media_resolution = MediaResolution.MEDIA_RESOLUTION_MEDIUM
        else:
            media_resolution = MediaResolution.MEDIA_RESOLUTION_LOW
    
        return media_resolution

    ⚠️ If you choose a “low” media decision and expertise an obvious lack of understanding, you could be dropping vital particulars within the sampled video frames. That is simple to repair: swap again to the default media decision.


    🔧 Sampling body charge

    The default sampling body charge of 1 FPS labored nice in our exams. You may wish to customise it for every video:

    SamplingFrameRate = float
    
    def get_sampling_frame_rate_for_video(video: Video) -> SamplingFrameRate | None:
        sampling_frame_rate = None  # Default (1 FPS for present fashions)
    
        # [Optional] Outline a customized FPS: 0.0 < sampling_frame_rate <= 24.0
    
        return sampling_frame_rate

    💡 You may combine the parameters. On this excessive instance, assuming the enter video has a 24fps body charge, all frames can be sampled for a 10s phase:

    video_metadata = VideoMetadata(
        start_offset="42.0s",
        end_offset="52.0s",
        fps=24.0,
    )

    ⚠️ If you happen to use a better sampling charge, this multiplies the variety of frames (and tokens) accordingly, rising latency and value. As 10s × 24fps = 240 frames = 4×60s × 1fps, this 10-second evaluation at 24 FPS is equal to a 4-minute default evaluation at 1 FPS.


    🎯 Precision vs recall

    The immediate can affect the precision and recall of our knowledge extractions, particularly when utilizing express versus implicit wording. If you’d like extra qualitative outcomes, favor precision utilizing express wording; if you need extra quantitative outcomes, favor recall utilizing implicit wording:

    wording favors generates much less LLM conduct
    express precision false positives depends extra (or solely) on the offered context
    implicit recall false negatives depends on the general context, infers extra, and may use its coaching data

    Listed below are examples that may result in subtly completely different outcomes:

    wording verbs qualifiers
    express “extract”, “quote” “said”, “direct”, “precise”, “verbatim”
    implicit “determine”, “deduce” “discovered”, “oblique”, “potential”, “potential”

    💡 Completely different fashions can even behave in a different way for a similar immediate. Particularly, extra performant fashions may appear extra “assured” and make extra implicit inferences or consolidations.

    💡 For instance, on this AlphaFold video, on the 04:57 timecode, “Spring 2020” is first displayed as context. Then, a brief declaration from “The Prime Minister” is heard within the background (“You will need to keep at house”) with out every other hints. When requested to “determine” (somewhat than “extract”) the speaker, Gemini is more likely to infer extra and attribute the voice to “Boris Johnson”. There’s completely no express point out of Boris Johnson; his identification is accurately inferred from the context (“UK”, “Spring 2020”, and “The Prime Minister”).


    🏷️ Metadata

    In our present exams, Gemini solely makes use of audio and body tokens, tokenized from sources on Google Cloud Storage or YouTube. When you have further video metadata, this could be a goldmine; attempt to add it to your immediate and enrich the video context for higher outcomes upfront.

    Doubtlessly useful metadata:

    • Video description: This will present a greater understanding of the place and when the video was shot.
    • Speaker data: This might help auto-correct names which can be solely heard and never apparent to spell.
    • Entity data: Total, this might help get higher transcriptions for customized or non-public knowledge.

    💡 For YouTube movies, no further metadata or transcript is fetched. Gemini solely receives the uncooked audio and video streams. You may verify this your self by evaluating your outcomes with YouTube’s computerized captioning (no punctuation, audio solely) or user-provided transcripts (cleaned up), when obtainable.

    💡 If you understand your video considerations a crew or an organization, including inner knowledge within the context might help appropriate or full the requested speaker names (offered there aren’t any homonyms in the identical context), firms, and job titles.

    💡 On this French reportage, within the 06:16-06:31 video shot, there are two canines: Arnold and Rio. “Arnold” is clearly audible, repeated thrice, and accurately transcribed. “Rio” is named solely as soon as, audible for a fraction of a second in a loud setting, and the audio transcription can differ. Offering the names of the entire crew (homeowners & canines, even when they don’t seem to be all within the video) might help in transcribing this brief title constantly.

    💡 It also needs to be potential to floor the outcomes with Google Search, Google Maps, or your individual RAG system. See Grounding overview.


    🔬 Debugging & proof

    Iterating by successive prompts and debugging LLM outputs will be difficult, particularly when making an attempt to know the explanations for the outcomes.

    It’s potential to ask Gemini to supply proof within the response. In our video transcription answer, we may request a timecoded “proof” for every speaker’s recognized title, firm, or position. This permits linking outcomes to their sources, discovering and understanding sudden insights, checking potential false positives…

    💡 Within the examined movies, when making an attempt to know the place the insights got here from, requesting proof yielded very insightful explanations, for instance:

    • Particular person names could possibly be extracted from numerous sources (video convention captions, badges, unseen contributors introducing themselves when asking questions in a convention panel…)
    • Firm names could possibly be discovered from textual content on uniforms, backpacks, automobiles…

    💡 In a doc knowledge extraction answer, we may request to supply an “excerpt” as proof, together with web page quantity, chapter quantity, or every other related location info.


    🐘 Verbose JSON

    The JSON format is presently the commonest option to generate structured outputs with LLMs. Nevertheless, JSON is a somewhat verbose knowledge format, as subject names are repeated for every object. For instance, an output can appear like the next, with many repeated underlying tokens:

    {
      "task1_transcripts": [
        { "start": "00:02", "text": "We've…", "voice": 1 },
        { "start": "00:07", "text": "But we…", "voice": 1 }
        // …
      ],
      "task2_speakers": [
        {
          "voice": 1,
          "name": "John Moult",
          "company": "University of Maryland",
          "position": "Co-Founder, CASP",
          "role_in_video": "Expert"
        },
        // …
        {
          "voice": 3,
          "name": "Demis Hassabis",
          "company": "DeepMind",
          "position": "Founder and CEO",
          "role_in_video": "Team Leader"
        }
        // …
      ]
    }

    To optimize output dimension, an fascinating risk is to ask Gemini to generate an XML block containing a CSV for every of your tabular extractions. The sector names are specified as soon as within the header, and through the use of tab separators, for instance, we will obtain extra compact outputs like the next:

    <TASK1_TRANSCRIPT_CSV>
    begin  textual content     voice
    00:02  We have…   1
    00:07  However we…  1
    …
    </TASK1_TRANSCRIPT_CSV>
    <TASK2_SPEAKER_CSV>
    voice  title            firm                 place          role_in_video
    1      John Moult      College of Maryland  Co-Founder, CASP  Professional
    …
    3      Demis Hassabis  DeepMind                Founder and CEO   Group Chief
    …
    </TASK2_SPEAKER_CSV>

    💡 Gemini excels at patterns and codecs. Relying in your wants, be at liberty to experiment with JSON, XML, CSV, YAML, and any customized structured codecs. It’s seemingly that the business will evolve to permit much more elaborate structured outputs.


    🐿️ Context caching

    Context caching optimizes the price and the latency of repeated requests utilizing the identical base inputs.

    There are two methods requests can profit from context caching:

    • Implicit caching: By default, upon the primary request, enter tokens are cached, to speed up responses for subsequent requests with the identical base inputs. That is absolutely automated and no code change is required.
    • Specific caching: You place particular inputs into the cache and reuse this cached content material as a base on your requests. This gives full management however requires managing the cache manually.
    Instance of implicit caching 🔽
    model_id = "gemini-2.0-flash"
    video_file_data = FileData(
        file_uri="gs://bucket/path/to/my-video.mp4",
        mime_type="video/mp4",
    )
    video = Half(file_data=video_file_data)
    prompt_1 = "Record the individuals seen within the video."
    prompt_2 = "Summarize what occurs to John Smith."
    
    # ✅ Request A1: static knowledge (video) positioned first
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents=,
    )
    
    # ✅ Request A2: seemingly cache hit for the video tokens
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents=,
    )

    💡 Implicit caching will be disabled on the mission stage (see data governance).

    Implicit caching is prefix-based, so it solely works if you happen to put static knowledge first and variable knowledge final.

    Instance of requests stopping implicit caching 🔽
    # ❌ Request B1: variable enter positioned first
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents=[prompt_1, video],
    )
    
    # ❌ Request B2: no cache hit
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents=[prompt_2, video],
    )

    💡 This explains why the data-plus-instructions enter order is most well-liked, for efficiency (not LLM-related) causes.

    Price-wise, the enter tokens retrieved with a cache hit profit from a 75% low cost within the following circumstances:

    • Implicit caching: With all Gemini fashions, cache hits are mechanically discounted (with none management on the cache).
    • Specific caching: With all Gemini fashions and supported fashions in Mannequin Backyard, you management your cached inputs and their lifespans to make sure cache hits.
    Instance of express caching 🔽
    from google.genai.sorts import (
        Content material,
        CreateCachedContentConfig,
        FileData,
        GenerateContentConfig,
        Half,
    )
    
    model_id = "gemini-2.0-flash-001"
    
    # Enter video
    video_file_data = FileData(
        file_uri="gs://cloud-samples-data/video/JaneGoodall.mp4",
        mime_type="video/mp4",
    )
    video_part = Half(file_data=video_file_data)
    video_contents = [Content(role="user", parts=[video_part])]
    
    # Video explicitly put in cache, with time-to-live (TTL) earlier than computerized deletion
    cached_content = consumer.caches.create(
        mannequin=model_id,
        config=CreateCachedContentConfig(
            ttl="1800s",
            display_name="video-cache",
            contents=video_contents,
        ),
    )
    if cached_content.usage_metadata:
        print(f"Cached tokens: {cached_content.usage_metadata.total_token_count or 0:,}")
        # Cached tokens: 46,171
        # ✅ Video tokens are cached (commonplace tokenization charge + storage price for TTL period)
    
    cache_config = GenerateContentConfig(cached_content=cached_content.title)
    
    # Request #1
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents="Record the individuals talked about within the video.",
        config=cache_config,
    )
    if response.usage_metadata:
        print(f"Enter tokens : {response.usage_metadata.prompt_token_count or 0:,}")
        print(f"Cached tokens: {response.usage_metadata.cached_content_token_count or 0:,}")
        # Enter tokens : 46,178
        # Cached tokens: 46,171
        # ✅ Cache hit (75% low cost)
    
    # Request #i (inside the TTL interval)
    # …
    
    # Request #n (inside the TTL interval)
    response = consumer.fashions.generate_content(
        mannequin=model_id,
        contents="Record all of the timecodes when Jane Goodall is talked about.",
        config=cache_config,
    )
    if response.usage_metadata:
        print(f"Enter tokens : {response.usage_metadata.prompt_token_count or 0:,}")
        print(f"Cached tokens: {response.usage_metadata.cached_content_token_count or 0:,}")
        # Enter tokens : 46,182
        # Cached tokens: 46,171
        # ✅ Cache hit (75% low cost)

    💡 Specific caching wants a selected mannequin model (like …-001 on this instance) to make sure the cache stays legitimate and isn’t affected by a mannequin replace.

    ℹ️ Study extra about Context caching.


    ⏳ Batch prediction

    If you have to course of a big quantity of movies and don’t want synchronous responses, you need to use a single batch request and cut back your price.

    💡 Batch requests for Gemini fashions get a 50% low cost in comparison with commonplace requests.

    ℹ️ Study extra about Batch prediction.


    ♾️ To manufacturing… and past

    A couple of further notes:

    • The present immediate will not be good and will be improved. It has been preserved in its present state for instance its improvement beginning with Gemini 2.0 Flash and a easy video check suite.
    • The Gemini 2.5 fashions are extra succesful and intrinsically present a greater video understanding. Nevertheless, the present immediate has not been optimized for them. Writing optimum prompts for various fashions is one other problem.
    • If you happen to check transcribing your individual movies, particularly various kinds of movies, it’s possible you’ll run into new or particular points. They will in all probability be addressed by enriching the immediate.
    • Future fashions will seemingly help extra output options. This could enable for richer structured outputs and for easier prompts.
    • As fashions continue learning, it’s additionally potential that multimodal video transcription will develop into a one-liner immediate.
    • Gemini’s picture and audio tokenizers are really spectacular and allow many different use circumstances. To completely grasp the extent of the probabilities, you may run unit exams on photographs or audio recordsdata.
    • We constrained our problem to utilizing a single request, which may dilute the LLM’s consideration in such wealthy multimodal contexts. For optimum leads to a large-scale answer, splitting the processing into two steps (i.e., requests) ought to assist Gemini’s consideration focus even additional. In step one, we’d extract and diarize the audio stream solely, which ought to lead to probably the most exact speech-to-text transcription (possibly with extra voice identifiers than precise audio system, however with a minimal variety of false positives). Within the second step, we’d reinject the transcription to deal with extracting and consolidating speaker knowledge from the video frames. This could even be an answer to course of very lengthy movies, even these a number of hours in period.

    🏁 Conclusion

    Multimodal video transcription, which requires the advanced synthesis of audio and visible knowledge, is a real problem for ML practitioners, with out mainstream options. A standard method, involving an elaborate pipeline of specialised fashions, can be engineering-intensive with none assure of success. In distinction, Gemini proved to be a flexible toolbox for reaching a robust and easy answer based mostly on a single immediate:

    multimodal video transcription solution (L. Picard)

    We managed to handle this advanced downside with the next methods:

    • Prototyping with open prompts to develop instinct about Gemini’s pure strengths
    • Taking into consideration how LLMs work underneath the hood
    • Crafting more and more particular prompts utilizing a tabular extraction technique
    • Producing structured outputs to maneuver in direction of production-ready code
    • Including knowledge visualization for simpler interpretation of responses and smoother iterations
    • Adapting default parameters to optimize the outcomes
    • Conducting extra exams, iterating, and even enriching the extracted knowledge

    These ideas ought to apply to many different knowledge extraction domains and assist you to remedy your individual advanced issues. Have enjoyable and glad fixing!


    ➕ Extra!



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow to Import Pre-Annotated Data into Label Studio and Run the Full Stack with Docker
    Next Article Marginal Effect of Hyperparameter Tuning with XGBoost
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    The Generalist: The New All-Around Type of Data Professional?

    September 1, 2025
    Artificial Intelligence

    How to Develop a Bilingual Voice Assistant

    August 31, 2025
    Artificial Intelligence

    The Machine Learning Lessons I’ve Learned This Month

    August 31, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Att säga ”Snälla” och ”Tack” till ChatGPT kostar OpenAI miljontals dollar i datorkraft

    April 21, 2025

    Five things you need to know about AI right now

    July 22, 2025

    BBC Uses AI to Resurrect Agatha Christie as Your Personal Writing Coach

    May 1, 2025

    From Equal Weights to Smart Weights: OTPO’s Approach to Better LLM Alignment

    July 15, 2025

    The Free AI Tutor That Never Sleeps

    August 5, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    ChatGPT’s New Image Generator Is Melting GPUs and Redefining Creativity

    April 11, 2025

    Personal Skill Development & Career Advancement

    April 10, 2025

    Overcoming Challenges to Realize Benefits

    April 3, 2025
    Our Picks

    What health care providers actually want from AI

    September 2, 2025

    Alibaba har lanserat Qwen-Image-Edit en AI-bildbehandlingsverktyg som öppenkällkod

    September 2, 2025

    Can an AI doppelgänger help me do my job?

    September 2, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.