-
Couldn't load subscription status.
- Fork 57
fix: create single source of truth for dataset column names #171
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
Conversation
…e in saved outputs
…amatically, thus ensuring it contains all column names
src/fmeval/constants.py
Outdated
|
|
||
| COLUMN_NAMES = [e.value for e in ColumnNames] | ||
|
|
||
| # These constants are included so that eval algorithm code doesn't need |
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.
Subjective:
I think we should remove these, it's fine being verbose in the code: ColumnName.MODEL_INPUT_COLUMN_NAME.value. It keeps the code readable, ensures in readers mind that ColumnNames enum is the source of truth.
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.
Makes sense; will update
Issue #, if available:
Description of changes:
Current state of affairs
Problem 1
Currently, we define the schema for what gets written to the saved output file (generated by
util.save_dataset) in theEvalOutputRecordclass. This class has attributes likemodel_input,sent_less_output, etc. that correspond to columns in the Ray Dataset produced by an EvalAlgorithm'sevaluatemethod.However, the column names in the produced Ray Dataset are governed by the
*_COLUMN_NAMEconstants inconstants.py. Thus, we need to ensure parity between these column name constants and the attributes ofEvalOutputRecord. Specifically, this code inEvalOutputRecord.from_rowrequires that the attribute names inEvalOutputRecordexactly match their corresponding*_COLUMN_NAMEstrings.Currently, there is no mechanism for ensuring such parity. There is simply a comment in the docstring of the
EvalOutputRecordclass. Even if the comment is acknowledged by an engineer, there is still room for manual error, like typos.Problem 2
Currently,
EvalOutputRecordlooks to the setCOLUMN_NAMESas the source of truth regarding Ray Dataset column names, but not every*_COLUMN_NAMEconstant is included in this set. Since there's nothing enforcing that we include every new*_COLUMN_NAMEconstant inCOLUMN_NAMES, it is very easy to accidentally skip the step of updatingCOLUMN_NAMES.This problem has already resulted in a bug. In this PR, the attributes
prompt,sent_more_prompt, andsent_less_promptwere added toEvalOutputRecord. While the corresponding constantsSENT_MORE_PROMPT_COLUMN_NAME = "sent_more_prompt"andSENT_LESS_PROMPT_COLUMN_NAME = "sent_less_prompt"exist inconstants.py(note thatPROMPT_COLUMN_NAME = "prompt"is currently being defined in each eval algo's code, which I have changed in this PR), they aren't included inCOLUMN_NAMES, which means that this snippet will not "pick up" the prompt, sent_more_prompt, and sent_less_prompt columns when constructing theEvalOutputRecordobject.Proposed changes
Fix for Problem 1
I propose that we get rid of the attributes in
EvalOutputRecordthat correspond to the non-score columns (ex:model_input,sent_less_output, etc), and instead use a single attribute,non_score_columns, which is aDict, to encode the same information content. The keys to this dict will be validated inEvalOutputRecord's__post_init__method by comparing them toconstants.COLUMN_NAMES.Fix for Problem 2
I have added a new Enum,
ColumnNames, which encapsulates all of the*_COLUMN_NAMEconstants. The setCOLUMN_NAMESis now defined automatically, using the values inColumnNames. BecauseCOLUMN_NAMESis created fromColumnNames, we will never run into the issue where we add a new*_COLUMN_NAMEconstant butCOLUMN_NAMESdoesn't get updated accordingly.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.