Migrating GNN node classification tutorial to Keras3#2304
Migrating GNN node classification tutorial to Keras3#2304LakshmiKalaKadali wants to merge 3 commits intokeras-team:masterfrom
Conversation
Summary of ChangesHello, 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 undertakes a comprehensive migration of the GNN node classification tutorial to Keras 3, ensuring compatibility with the latest Keras API and enabling multi-backend support. Beyond the API update, significant architectural improvements were introduced to enhance the numerical stability of the GNN model, particularly concerning message passing and aggregation. The data preparation pipeline was also refined to include a dedicated validation set, leading to more robust model evaluation and training practices. Highlights
🧠 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. Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the GNN node classification tutorial to Keras 3, making it backend-agnostic by using keras.ops. Beyond the migration, you've introduced several excellent improvements that enhance the model's stability and the example's robustness, including adding self-loops, degree normalization, and a more rigorous data splitting and evaluation setup. My review includes a few minor suggestions to improve reproducibility by consistently using the seeded random number generator and to ensure the generated plots are saved correctly.
| ax2.legend(["train", "test"], loc="upper right") | ||
| ax2.legend(["train", "val"], loc="upper right") | ||
| ax2.set_xlabel("Epochs") | ||
| ax2.set_ylabel("Accuracy") |
There was a problem hiding this comment.
With the switch to the 'Agg' backend for matplotlib, the learning curve plots are generated but not displayed or saved. To make them useful, you should save them to a file. This can be done by adding a plt.savefig() call at the end of the function.
ax2.set_ylabel("Accuracy")
if title:
filename = f"{title.lower().replace(' ', '_')}_learning_curves.png"
plt.savefig(filename)
plt.close(fig)| token_probability = x_train_base.mean(axis=0) | ||
| instances = [] | ||
| for _ in range(num_instances): | ||
| probabilities = np.random.uniform(size=len(token_probability)) |
There was a problem hiding this comment.
| selected_paper_indices1 = np.random.choice(subject_papers, 5, replace=False) | ||
|
|
||
| selected_paper_indices2 = np.random.choice( | ||
| papers.paper_id.to_numpy(), 2, replace=False | ||
| ) |
There was a problem hiding this comment.
For reproducibility, it's better to use the rng object that was initialized with a fixed seed, instead of np.random.choice. This will ensure that the generated citations for new nodes are the same across runs.
selected_paper_indices1 = rng.choice(subject_papers, 5, replace=False)
selected_paper_indices2 = rng.choice(
papers.paper_id.to_numpy(), 2, replace=False
)There was a problem hiding this comment.
Thanks! Can you generate the ipynb and md files?
https://github.com/keras-team/keras-io?tab=readme-ov-file#creating-a-new-example-starting-from-a-python-script
[Edit] and update formatting so black passes
Removing review - needs extra files and reformat
The PR migrates the GNN tutorial to Keras3. The changes included to make the network numerically stable are
Self-Loops: Integrated automatic addition of self-loops in the GNNNodeClassifier constructor to ensure nodes retain their own identity during message passing.
Degree Normalization: Implemented manual segment-based mean pooling (Sum / Degree) in the GraphConvLayer. This prevents feature explosion in high-degree nodes and stabilizes the validation loss.
Input Feature Normalization: Added row-normalization for binary word vectors in the model's initialization to ensure consistent feature scales.colab ref notebook
Thank You