Skip to content

fix(eval): fix embedding averaging in privacy metrics#81

Open
nina-xu wants to merge 6 commits intomainfrom
ninaxu/fix-privacy-metrics
Open

fix(eval): fix embedding averaging in privacy metrics#81
nina-xu wants to merge 6 commits intomainfrom
ninaxu/fix-privacy-metrics

Conversation

@nina-xu
Copy link
Copy Markdown
Contributor

@nina-xu nina-xu commented Feb 20, 2026

Summary

Per this GitLab issue, we are averaging column embeddings incorrectly in the two privacy metrics, AIP and MIP. Later columns get a higher weight in the averaging. Taking Aaron's suggestion in the ticket for an equal weighting.

In addition, I DRY'ed up the code, taking common methods out into privacy_metric_utils.py, because both metrics utilize the same way of averaging text column embeddings.

I also added some tests to illustrate that the new way of averaging gives each column equal weight.

Pre-Review Checklist

Ensure that the following pass:

  • make format && make lint or via prek validation.
  • make test passes locally
  • make test-e2e passes locally
  • make test-ci-container passes locally (recommended)

Pre-Merge Checklist

  • New or updated tests for any fix or new behavior
  • Updated documentation for new features and behaviors, including docstrings for API docs.

Testing Plan

  • Add unit tests
  • Take one dataset, shuffle around columns and calculate privacy scores to show the effect before & after
  • Run slurm experiments to compare the scores before & after, so that we are aware of the new baseline
  • We hardly have datasets with 3 or more text columns, so it's hard to demonstrate the change in action. Ran the "short" dataset group; plus dolly (3 text columns) to demonstrate that things are not breaking (wandb). More specifically, dolly has 10 MIA and 10 for AIA for the 3 text columns, so we wouldn't be able to observe the difference from this dataset; patient_events also has 3 text columns, but it also has an AIA of 10

Note

Closes #203

@nina-xu nina-xu force-pushed the ninaxu/fix-privacy-metrics branch from 5a28c52 to b8c5c29 Compare March 31, 2026 14:56
@nina-xu nina-xu marked this pull request as ready for review March 31, 2026 20:58
@nina-xu nina-xu requested a review from a team as a code owner March 31, 2026 20:58
Copilot AI review requested due to automatic review settings March 31, 2026 20:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect column-embedding averaging in the AIP (attribute inference) and MIP (membership inference) privacy metrics by switching from sequential pairwise averaging (which overweighted later columns) to an equal-weight mean across all text columns, and factors shared logic into a new utility module.

Changes:

  • Introduce privacy_metric_utils.py with shared helpers for identifying text fields, splitting tabular/text columns, and embedding+averaging text columns via np.stack/np.mean.
  • Update AIP/MIP components to use the shared helpers and to reuse a single SentenceTransformer instance per metric invocation.
  • Add unit tests covering the corrected equal-weight embedding averaging behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/evaluation/components/test_privacy_metric_utils.py Adds regression/unit tests validating equal-weight embedding averaging and dataframe splitting.
src/nemo_safe_synthesizer/evaluation/components/privacy_metric_utils.py New shared utilities for text-field detection and embedding aggregation.
src/nemo_safe_synthesizer/evaluation/components/membership_inference_protection.py Replaces local helpers with shared utilities; fixes embedding averaging logic in MIP path.
src/nemo_safe_synthesizer/evaluation/components/attribute_inference_protection.py Replaces local helpers with shared utilities; fixes embedding averaging logic in AIP path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Nina Xu and others added 5 commits April 1, 2026 06:04
Signed-off-by: Nina Xu <ninaxu@cs-oci-ord-vscode-01.cm.cluster>
Signed-off-by: Nina Xu <ninaxu@cs-oci-ord-vscode-01.cm.cluster>
Signed-off-by: Nina Xu <19981858+nina-xu@users.noreply.github.com>
Signed-off-by: Nina Xu <19981858+nina-xu@users.noreply.github.com>
Signed-off-by: Nina Xu <19981858+nina-xu@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 1, 2026 13:07
@nina-xu nina-xu force-pushed the ninaxu/fix-privacy-metrics branch from c40b5f2 to d6ed8be Compare April 1, 2026 13:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nina-xu nina-xu requested a review from asteier2026 April 1, 2026 13:20
Signed-off-by: nina-xu <19981858+nina-xu@users.noreply.github.com>
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.

NSS privacy scores do not compute average correctly when 3 or more text columns

3 participants