Skip to content
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

Add --no_balance flag to not balance datasets #287

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
flag
  • Loading branch information
AlexTMallen committed Aug 22, 2023
commit 4ea0c4004913c6b68273eb99d5b29db110b5bbaf
4 changes: 4 additions & 0 deletions elk/extraction/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class Extract(Serializable):
binarize: bool = False
"""Whether to binarize the dataset labels for multi-class datasets."""

no_balance: bool = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just make it
balance: bool = True ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That would also avoid having that:
balance=not cfg.no_balance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it would be unclear how to use the flag to disable balancing from the CLA. --balance False or something is weirder than --no_balance

Copy link
Collaborator

Choose a reason for hiding this comment

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

--balance False does not seem weirder than --no_balance True to me.
But okay, it's fine for me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I think I agree with you now

"""Whether to disable balancing the dataset by label."""

int8: bool = False
"""Whether to perform inference in mixed int8 precision with `bitsandbytes`."""

Expand Down Expand Up @@ -189,6 +192,7 @@ def extract_hiddens(
num_shots=cfg.num_shots,
split_type=split_type,
template_path=cfg.template_path,
balance=not cfg.no_balance,
rank=rank,
world_size=world_size,
seed=cfg.seed,
Expand Down
5 changes: 3 additions & 2 deletions elk/extraction/prompt_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def load_prompts(
seed: int = 42,
split_type: Literal["train", "val"] = "train",
template_path: str | None = None,
balance: bool = True,
rank: int = 0,
world_size: int = 1,
) -> Iterator[dict]:
Expand Down Expand Up @@ -89,14 +90,14 @@ def load_prompts(
else:
fewshot_iter = None

if label_column in ds.features:
if label_column in ds.features and balance:
ds = BalancedSampler(
ds.to_iterable_dataset(),
set(label_choices),
label_col=label_column,
)
else:
if rank == 0:
if rank == 0 and balance:
print("No label column found, not balancing")
ds = ds.to_iterable_dataset()

Expand Down