Skip to content

Conversation

@fctb12
Copy link
Collaborator

@fctb12 fctb12 commented Jan 15, 2026

This draft PR is a reference for the inverse task benchmark: top-k accuracy.

Screenshot 2025-12-03 at 12 09 51 AM

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fctb12, 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 draft pull request introduces a new top_k_accuracy metric designed for the inverse evaluation of perturbation profiles. It provides a mechanism to assess how well predicted perturbation vectors match real ones within a specified top-k range, enhancing the benchmark capabilities for cellular evaluation tasks. Users can now control the 'k' parameter directly via a command-line argument.

Highlights

  • New Metric: Top-K Accuracy: A new top_k_accuracy metric has been introduced for evaluating inverse tasks, specifically designed for pseudo-bulked perturbation profiles. This metric assesses how well predicted perturbation vectors match real ones within a specified top-k range.
  • Command-Line Argument for K: A new command-line argument --topk (or -k) has been added to allow users to specify the k parameter for the top_k_accuracy metric, with a default value of 10. This provides flexibility in defining the neighborhood size for accuracy calculation.
  • Metric Integration: The top_k_accuracy metric is fully integrated into the evaluation framework, including its import, export, and registration in the metrics registry, making it available for use in evaluations.

🧠 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 introduces a new top-k_accuracy metric for inverse evaluation. The changes are well-structured, including a new command-line argument for k, the core metric implementation, and its registration within the framework. The logic is generally sound. I've provided a few suggestions to enhance code quality and clarity by adding a missing type hint, simplifying a calculation, and removing a redundant type conversion.

return norm_ranks

def top_k_accuracy(
data,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The data parameter is missing a type hint. For consistency with other metric functions in this file and for better code clarity, please add the type hint PerturbationAnndataPair.

Suggested change
data,
data: PerturbationAnndataPair,

D = skm.pairwise_distances(pred_mat, real_mat, metric=dist_metric)

n_real = D.shape[1]
k_eff = int(min(max(1, k), n_real))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The max(1, k) check is redundant because there's already a validation on line 219 that ensures k is a positive integer. You can simplify this line to improve clarity.

Suggested change
k_eff = int(min(max(1, k), n_real))
k_eff = int(min(k, n_real))

for i, pert in enumerate(perts_order):
# indices of k smallest distances
idx = np.argpartition(D[i], k_eff - 1)[:k_eff]
scores[str(pert)] = 1.0 if i in idx else 0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The pert variable is already a string, as it comes from perts_order which is a list[str]. The call to str(pert) is redundant and can be removed.

Suggested change
scores[str(pert)] = 1.0 if i in idx else 0.0
scores[pert] = 1.0 if i in idx else 0.0

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.

2 participants