Skip to content

Migrated ctc_asr from keras2 to keras3#2262

Merged
sachinprasadhs merged 7 commits intokeras-team:masterfrom
kharshith-k:asr_using_ctc_keras2_to_keras3_migration
Feb 12, 2026
Merged

Migrated ctc_asr from keras2 to keras3#2262
sachinprasadhs merged 7 commits intokeras-team:masterfrom
kharshith-k:asr_using_ctc_keras2_to_keras3_migration

Conversation

@kharshith-k
Copy link
Member

@kharshith-k kharshith-k commented Jan 22, 2026

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kharshith-k, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the Automatic Speech Recognition (ASR) example, specifically the ctc_asr implementation, to be fully compatible with Keras 3. The migration involved adapting the loss and decoding mechanisms to the new Keras API, which now leverages keras.ops and direct TensorFlow functions for certain operations. Additionally, it addresses an issue with data path resolution for the LJSpeech dataset, ensuring the example runs correctly.

Highlights

  • Keras 3 Migration: The ctc_asr example has been fully migrated from Keras 2 to Keras 3 API, ensuring compatibility with the latest Keras features and backend-agnostic operations.
  • API Updates for CTC Loss: The CTCLoss function was refactored to utilize tf.nn.ctc_loss instead of keras.backend.ctc_batch_cost, along with necessary adjustments to tensor types and shapes for Keras 3 compatibility.
  • API Updates for CTC Decoding: The decode_batch_predictions function was updated to use tf.nn.ctc_greedy_decoder, including transposing the input predictions and handling the SparseTensor output by converting it to a dense tensor and masking padding values.
  • Data Path Correction: Corrected the metadata_path and wavs_path definitions to accurately point to the LJSpeech dataset's subdirectories, resolving a potential data loading issue.
  • Dataset Re-initialization: The training and validation datasets are now re-initialized after the data path correction to ensure that the tf.data.Dataset objects correctly reference the updated file locations.
  • Notebook Metadata Updates: The ctc_asr.ipynb notebook's metadata has been updated, including the 'Last modified' date, resetting execution counts, and adjusting the kernel specification to reflect the Keras 3 environment.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the CTC ASR example from Keras 2 to Keras 3. The changes correctly update the imports and replace deprecated Keras 2 APIs like keras.backend.ctc_decode with their Keras 3 / TensorFlow equivalents.

My review includes several suggestions for improvement:

  • Correcting placeholder metadata at the top of the script.
  • Removing duplicated markdown links.
  • Refactoring a path correction for wavs_path to be defined correctly at the beginning of the script, which simplifies the code by removing redundant dataset re-creation.
  • A minor suggestion to use more idiomatic tensor indexing.

Overall, the migration is well-done, and with these changes, the code will be cleaner and more maintainable.

Copy link
Collaborator

@sachinprasadhs sachinprasadhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed only .py file as the source of truth, please address the comments and there are still many places where tf ops are used, try. to reduce the dependency, I have added my suggestions to few.

Copy link
Collaborator

@sachinprasadhs sachinprasadhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This looks good.
Just one change and also make the necessary changes to the "conclusion" part with the colab T4 GPU instance and update the training time accordingly.

Copy link
Collaborator

@sachinprasadhs sachinprasadhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sachinprasadhs sachinprasadhs merged commit 4d5893f into keras-team:master Feb 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants