Skip to content

Conversation

tastelikefeet
Copy link
Collaborator

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Write the detail information belongs to this PR.

Experiment results

Paste your experiment result here(if needed).

Copy link
Contributor

Summary of Changes

Hello @tastelikefeet, 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 addresses a critical bug within the embedding encoding process, specifically concerning the handling of negative samples. The fix ensures that the necessary data structures (lists associated with negative_{key} in the _encoded dictionary) are correctly initialized before any data is appended, thereby preventing potential KeyError exceptions and ensuring the stable and accurate generation of embeddings.

Highlights

  • Bug Fix: Resolved an issue in the _embedding_encode method where negative_{key} lists were not properly initialized before attempting to append encoded negative samples, which could lead to runtime errors.
  • Code Robustness: Improved the robustness of the embedding encoding logic by ensuring dictionary keys for negative samples are present before data manipulation.
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

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 fixes a potential KeyError in the _embedding_encode method. The original code did not ensure that a list was initialized for negative_{key} before attempting to append to it, which could happen if a key was present in a negative sample's encoding but not in the positive sample's. The fix adds a check to initialize the list if it doesn't exist. The change is correct and improves the robustness of the embedding encoding process. I've suggested a minor refactoring to make the code more concise using dict.setdefault.

Comment on lines +405 to 407
if f'negative_{key}' not in _encoded:
_encoded[f'negative_{key}'] = []
_encoded[f'negative_{key}'].append(negative_encoded[key])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This correctly fixes a potential KeyError. For conciseness, you could use dict.setdefault to achieve the same result in a single line.

                    _encoded.setdefault(f'negative_{key}', []).append(negative_encoded[key])

@tastelikefeet tastelikefeet merged commit e6c0a4d into modelscope:main Sep 21, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants