-
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
Open
jadie1
wants to merge
4
commits into
main
Choose a base branch
from
dev/ph2_delta_based_relevance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
26da5b0
Fix for ICL with multi-attribute targets
jadie1 73f5854
Adding step to remove less reevant attribute based on delta for multi…
jadie1 3700e31
Correcting Phase2RegressionRemoveIrrelevantAttributes
jadie1 7903e17
Small improvements to Phase2RegressionRemoveIrrelevantAttributes
jadie1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from rich.highlighter import JSONHighlighter | ||
| import numpy as np | ||
|
|
||
| from align_system.algorithms.abstracts import ADMComponent | ||
| from align_system.utils import adm_utils, logging | ||
|
|
@@ -162,3 +163,55 @@ def run_returns(self): | |
|
|
||
| def run(self): | ||
| return "Looked at scores." | ||
|
|
||
|
|
||
| class Phase2RegressionRemoveIrrelevantAttributes(ADMComponent): | ||
| def run_returns(self): | ||
| return ('attribute_prediction_scores', | ||
| 'alignment_target') | ||
|
|
||
| def run(self, | ||
| attribute_prediction_scores, | ||
| alignment_target | ||
| ): | ||
| # If there are two non-medical attributes, removes the one with smaller delta | ||
|
|
||
| attributes = list(next(iter(attribute_prediction_scores.values())).keys()) | ||
jadie1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Ignore / don't filter out medical | ||
| if 'medical' in attributes: | ||
| attributes.remove('medical') | ||
|
|
||
| # Only one attribute aside from medical -> filtering not needed | ||
| if len(attributes) == 1: | ||
| return attribute_prediction_scores, alignment_target | ||
|
|
||
| # Two attributes -> remove the one with smaller delta | ||
| elif len(attributes) == 2: | ||
jadie1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if len(attribute_prediction_scores.keys()) != 2: | ||
| raise RuntimeError("Relevance filtering not implemented for more than two choices.") | ||
jadie1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: David recommended I raise |
||
| else: | ||
| # Determine less relevant attribute | ||
| choiceA, choiceB = list(attribute_prediction_scores.keys()) | ||
| attr0, attr1 = attributes[0], attributes[1] | ||
| delta0 = abs(np.array(attribute_prediction_scores[choiceA][attr0]).mean() - np.array(attribute_prediction_scores[choiceB][attr0]).mean()) | ||
| delta1 = abs(np.array(attribute_prediction_scores[choiceA][attr1]).mean() - np.array(attribute_prediction_scores[choiceB][attr1]).mean()) | ||
| if delta0 >= delta1: | ||
| remove_attr = attr1 | ||
| else: | ||
| remove_attr = attr0 | ||
|
|
||
| # Remove less relevant attribute | ||
| del attribute_prediction_scores[choiceA][remove_attr] | ||
| del attribute_prediction_scores[choiceB][remove_attr] | ||
|
|
||
| log.info("[bold]*REMOVING THE LESS RELEVANT ATTRIBUTE: {}*[/bold]".format(remove_attr), extra={"markup": True}) | ||
|
|
||
| # Update target to not include less relevant attribute | ||
| alignment_target['kdma_values'] = [entry for entry in alignment_target['kdma_values'] if entry['kdma'] != remove_attr] | ||
| log.info("[bold]*ALIGNING TO TARGET*[/bold]", extra={"markup": True}) | ||
jadie1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log.info("{}".format(alignment_target), extra={"highlighter": JSON_HIGHLIGHTER}) | ||
|
|
||
| return attribute_prediction_scores, alignment_target | ||
|
|
||
| else: | ||
| raise RuntimeError("Relevance filtering not implemented for more than two attributes.") | ||
61 changes: 61 additions & 0 deletions
61
align_system/configs/adm/phase2_pipeline_fewshot_comparative_regression_delta_relevance.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: phase2_pipeline_zeroshot_comparative_regression_delta_relevance | ||
|
|
||
| defaults: | ||
| # Import defaults into this namspace (adm) as @name, for further | ||
| # customization | ||
|
|
||
| # Shared variables / components | ||
| - /attribute@mu: medical_urgency | ||
| - /attribute@af: affiliation_focus | ||
| - /attribute@mf: merit_focus | ||
| - /attribute@ss: search_or_stay | ||
| - /attribute@ps: personal_safety | ||
| - /inference_engine@structured_inference_engine: outlines_structured_greedy | ||
| - /template/scenario_description@scenario_description_template: phase2 | ||
| - /template/prompt@prompt_template: phase2_comparative_regression | ||
| - /template/output_schema@comparative_regression_choice_schema: phase2_comparative_regression_choice | ||
| # ADM components to be used in "steps" | ||
| - /adm_component/misc@step_definitions.format_choices: itm_format_choices | ||
| - /adm_component/icl@step_definitions.regression_icl: phase2_comparative | ||
| - /adm_component/regression@step_definitions.comparative_regression: phase2_comparative_no_template | ||
| - /adm_component/misc@step_definitions.regression_rule_based_correction: phase2_regression_rule_based_correction | ||
| - /adm_component/misc@step_definitions.remove_irrelevant_attributes: phase2_regression_remove_irrelevant_attributes | ||
| - /adm_component/alignment@step_definitions.scalar_alignment: medical_urgency_scalar | ||
| - /adm_component/misc@step_definitions.justification_from_reasonings: justification_from_reasonings | ||
| - /adm_component/misc@step_definitions.ensure_chosen_action: ensure_chosen_action | ||
| - /adm_component/misc@step_definitions.populate_choice_info: populate_choice_info | ||
| # Use definitions in this file to override defaults defined above | ||
| - _self_ | ||
|
|
||
| attribute_definitions: | ||
| medical: ${adm.mu} | ||
| affiliation: ${adm.af} | ||
| merit: ${adm.mf} | ||
| search: ${adm.ss} | ||
| personal_safety: ${adm.ps} | ||
|
|
||
| step_definitions: | ||
| regression_icl: | ||
| scenario_description_template: ${ref:adm.scenario_description_template} | ||
| attributes: ${adm.attribute_definitions} | ||
| prompt_template: ${ref:adm.prompt_template} | ||
|
|
||
| comparative_regression: | ||
| scenario_description_template: ${ref:adm.scenario_description_template} | ||
| prompt_template: ${ref:adm.prompt_template} | ||
| score_schema_template: ${adm.comparative_regression_choice_schema} | ||
|
|
||
| instance: | ||
| _target_: align_system.algorithms.pipeline_adm.PipelineADM | ||
|
|
||
| steps: | ||
| # Reference the step instances we want to use in order | ||
| - ${ref:adm.step_definitions.format_choices} | ||
| - ${ref:adm.step_definitions.regression_icl} | ||
| - ${ref:adm.step_definitions.comparative_regression} | ||
| - ${ref:adm.step_definitions.regression_rule_based_correction} | ||
| - ${ref:adm.step_definitions.remove_irrelevant_attributes} | ||
| - ${ref:adm.step_definitions.scalar_alignment} | ||
| - ${ref:adm.step_definitions.justification_from_reasonings} | ||
| - ${ref:adm.step_definitions.ensure_chosen_action} | ||
| - ${ref:adm.step_definitions.populate_choice_info} |
54 changes: 54 additions & 0 deletions
54
...n_system/configs/adm/phase2_pipeline_zeroshot_comparative_regression_delta_relevance.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: phase2_pipeline_zeroshot_comparative_regression_delta_relevance | ||
|
|
||
| defaults: | ||
| # Import defaults into this namspace (adm) as @name, for further | ||
| # customization | ||
|
|
||
| # Shared variables / components | ||
| - /attribute@mu: medical_urgency | ||
| - /attribute@af: affiliation_focus | ||
| - /attribute@mf: merit_focus | ||
| - /attribute@ss: search_or_stay | ||
| - /attribute@ps: personal_safety | ||
| - /inference_engine@structured_inference_engine: outlines_structured_greedy | ||
| - /template/scenario_description@scenario_description_template: phase2 | ||
| - /template/prompt@prompt_template: phase2_comparative_regression | ||
| - /template/output_schema@comparative_regression_choice_schema: phase2_comparative_regression_choice | ||
| # ADM components to be used in "steps" | ||
| - /adm_component/misc@step_definitions.format_choices: itm_format_choices | ||
| - /adm_component/regression@step_definitions.comparative_regression: phase2_comparative | ||
| - /adm_component/misc@step_definitions.regression_rule_based_correction: phase2_regression_rule_based_correction | ||
| - /adm_component/misc@step_definitions.remove_irrelevant_attributes: phase2_regression_remove_irrelevant_attributes | ||
| - /adm_component/alignment@step_definitions.scalar_alignment: medical_urgency_scalar | ||
| - /adm_component/misc@step_definitions.justification_from_reasonings: justification_from_reasonings | ||
| - /adm_component/misc@step_definitions.ensure_chosen_action: ensure_chosen_action | ||
| - /adm_component/misc@step_definitions.populate_choice_info: populate_choice_info | ||
| # Use definitions in this file to override defaults defined above | ||
| - _self_ | ||
|
|
||
| attribute_definitions: | ||
| medical: ${adm.mu} | ||
| affiliation: ${adm.af} | ||
| merit: ${adm.mf} | ||
| search: ${adm.ss} | ||
| personal_safety: ${adm.ps} | ||
|
|
||
| step_definitions: | ||
| comparative_regression: | ||
| scenario_description_template: ${ref:adm.scenario_description_template} | ||
| prompt_template: ${ref:adm.prompt_template} | ||
| score_schema_template: ${adm.comparative_regression_choice_schema} | ||
|
|
||
| instance: | ||
| _target_: align_system.algorithms.pipeline_adm.PipelineADM | ||
|
|
||
| steps: | ||
| # Reference the step instances we want to use in order | ||
| - ${ref:adm.step_definitions.format_choices} | ||
| - ${ref:adm.step_definitions.comparative_regression} | ||
| - ${ref:adm.step_definitions.regression_rule_based_correction} | ||
| - ${ref:adm.step_definitions.remove_irrelevant_attributes} | ||
| - ${ref:adm.step_definitions.scalar_alignment} | ||
| - ${ref:adm.step_definitions.justification_from_reasonings} | ||
| - ${ref:adm.step_definitions.ensure_chosen_action} | ||
| - ${ref:adm.step_definitions.populate_choice_info} |
1 change: 1 addition & 0 deletions
1
align_system/configs/adm_component/misc/phase2_regression_remove_irrelevant_attributes.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| _target_: align_system.algorithms.misc_itm_adm_components.Phase2RegressionRemoveIrrelevantAttributes |
25 changes: 25 additions & 0 deletions
25
...iment/phase2_june_collab/multi_attribute_pipeline_fewshot_comparative_regression_loo.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # @package _global_ | ||
| defaults: | ||
| - override /adm: phase2_pipeline_fewshot_comparative_regression_delta_relevance | ||
| - override /interface: ta3 | ||
|
|
||
| interface: | ||
| session_type: adept | ||
| training_session: full | ||
| username: "pipeline_fewshot_comp_reg_multi_attribute_test" | ||
| domain: "p2triage" | ||
| scenario_ids: | ||
| - June2025-AF-train | ||
| - June2025-MF-train | ||
|
|
||
| # LOO - Remove for eval | ||
| adm: | ||
| step_definitions: | ||
| regression_icl: | ||
| icl_generator_partial: | ||
| incontext_settings: | ||
| leave_one_out_strategy: 'scenario_description' | ||
|
|
||
| apply_action_filtering: false | ||
| force_determinism: true | ||
| align_to_target: true |
25 changes: 25 additions & 0 deletions
25
...periment/phase2_june_collab/multi_attribute_pipeline_zeroshot_comparative_regression.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # @package _global_ | ||
| defaults: | ||
| - override /adm: phase2_pipeline_zeroshot_comparative_regression_delta_relevance | ||
| - override /interface: ta3 | ||
|
|
||
| interface: | ||
| session_type: adept | ||
| training_session: full | ||
| username: "pipeline_zeroshot_comp_reg_multi_attribute_test" | ||
| domain: "p2triage" | ||
| scenario_ids: | ||
| - June2025-AF-train | ||
| - June2025-MF-train | ||
|
|
||
| # LOO - Remove for eval | ||
| adm: | ||
| step_definitions: | ||
| regression_icl: | ||
| icl_generator_partial: | ||
| incontext_settings: | ||
| leave_one_out_strategy: 'scenario_description' | ||
|
|
||
| apply_action_filtering: false | ||
| force_determinism: true | ||
| align_to_target: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.