-
Notifications
You must be signed in to change notification settings - Fork 5
Delta based relevance for comp reg alignment to multi-attribute targets #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
eveenhuis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, I'd be fine with merging as is. Just a couple of nits/sanity checks
| # Two or more attributes -> keep the one with largest delta | ||
| else: | ||
| if len(attribute_prediction_scores.keys()) > 2: | ||
| raise RuntimeError("Relevance filtering not implemented for more than two choices.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: David recommended I raise NotImplementedError for a similar check
| alignment_target): | ||
| # If there are two non-medical attributes, removes the one with smaller delta | ||
|
|
||
| attributes = list({key for inner in attribute_prediction_scores.values() for key in inner}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we're looping all choice predictions in case different choices have different predictions? Do we think that'll actually happen?
| choiceA, choiceB = list(attribute_prediction_scores.keys()) | ||
| max_delta = -np.inf | ||
| for attr in attributes: | ||
| delta = abs(np.array(attribute_prediction_scores[choiceA][attr]).mean() - np.array(attribute_prediction_scores[choiceB][attr]).mean()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know at one point we potentially had to handle both a single prediction and a list of predictions. Do we still need to do that? (If not yayyyyy simpler code :))
| max_delta = -np.inf | ||
| for attr in attributes: | ||
| delta = abs(np.array(attribute_prediction_scores[choiceA][attr]).mean() - np.array(attribute_prediction_scores[choiceB][attr]).mean()) | ||
| if delta > max_delta: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only keep the first one if there's a tie. I think that's fine because I don't know what we'd actually do if there was a tie (plus that seems unlikely), but just double checking you didn't have a different set of assumptions
| # Update predicted scores to only have more relevant attribute | ||
| filtered_attribute_prediction_scores = {choiceA:{}, choiceB:{}} | ||
| for keep_attr in keep_attributes: | ||
| filtered_attribute_prediction_scores[choiceA][keep_attr] = attribute_prediction_scores[choiceA][keep_attr] | ||
| filtered_attribute_prediction_scores[choiceB][keep_attr] = attribute_prediction_scores[choiceB][keep_attr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit)
| # Update predicted scores to only have more relevant attribute | |
| filtered_attribute_prediction_scores = {choiceA:{}, choiceB:{}} | |
| for keep_attr in keep_attributes: | |
| filtered_attribute_prediction_scores[choiceA][keep_attr] = attribute_prediction_scores[choiceA][keep_attr] | |
| filtered_attribute_prediction_scores[choiceB][keep_attr] = attribute_prediction_scores[choiceB][keep_attr] | |
| # Update predicted scores to only have more relevant attribute | |
| filtered_attribute_prediction_scores = { | |
| choice: { | |
| keep_attr: predictions[choice][keep_attr] | |
| for keep_attr in keep_attributes | |
| } | |
| for choice in attribute_prediction_scores.keys() | |
| } |
Enables comp. reg. alignment to multi-attribute targets by adding a component step that for each probe:
Example call to run zeroshot:
Example call to run fewshot: