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

Update datasets #309

Merged
merged 5 commits into from
Dec 20, 2022
Merged

Update datasets #309

merged 5 commits into from
Dec 20, 2022

Conversation

gabegma
Copy link
Contributor

@gabegma gabegma commented Nov 30, 2022

Resolve #267

Description:

Checklist:

You should check all boxes before the PR is ready. If a box does not apply, check it to acknowledge it.

  • ISSUE NUMBER. You linked the issue number (Ex: Resolve #XXX).
  • PRE-COMMIT. You ran pre-commit on all commits, or else, you
    ran pre-commit run --all-files at the end.
  • USER CHANGES. The changes are added to CHANGELOG.md and the documentation, if they impact
    our users.
  • DEV CHANGES.
    • Update the documentation if this PR changes how to develop/launch on the app.
    • Update the README files and our wiki for any big design decisions, if relevant.
    • Add unit tests, docstrings, typing and comments for complex sections.

@gabegma
Copy link
Contributor Author

gabegma commented Dec 1, 2022

@Dref360 do you think my fixes for updating datasets make sense?

@gabegma gabegma marked this pull request as ready for review December 1, 2022 22:00
@Dref360
Copy link
Contributor

Dref360 commented Dec 1, 2022

looks good. We never run anything on the DatasetDict themselves so there is nothing to worry about if they don't have the same features.

Comment on lines 93 to 98
eval_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
train_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to instantiate only one ClassLabel object and pass it to both dataset managers?

Suggested change
eval_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
train_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
eval_dm._base_dataset_split.features["label"] = train_dm._base_dataset_split.features[
"label"
] = ClassLabel(num_classes=3, names=existing_classes + ["NO_INTENT"])

Or with a temporary variable:

Suggested change
eval_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
train_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
class_label = ClassLabel(num_classes=3, names=existing_classes + ["NO_INTENT"])
eval_dm._base_dataset_split.features["label"] = class_label
train_dm._base_dataset_split.features["label"] = class_label

Or if we move the creation of dms before that, we can loop on it:

Suggested change
eval_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
train_dm._base_dataset_split.features["label"] = ClassLabel(
num_classes=3, names=existing_classes + ["NO_INTENT"]
)
class_label = ClassLabel(num_classes=3, names=existing_classes + ["NO_INTENT"])
for dm in dms.values():
dm._base_dataset_split.features["label"] = class_label

Here is a complete diff of the last idea, in case it was not clear:

     # Adding a rejection class
     eval_dm: DatasetSplitManager = mod.get_dataset_split_manager(DatasetSplitName.eval)
     train_dm: DatasetSplitManager = mod.get_dataset_split_manager(DatasetSplitName.train)
-    existing_classes = eval_dm.get_class_names(labels_only=True)
-    eval_dm._base_dataset_split.features["label"] = ClassLabel(
-        num_classes=3, names=existing_classes + ["NO_INTENT"]
-    )
-    train_dm._base_dataset_split.features["label"] = ClassLabel(
-        num_classes=3, names=existing_classes + ["NO_INTENT"]
-    )
-    eval_dm._base_dataset_split = eval_dm._base_dataset_split.map(
-        lambda u, i: {"label": 2 if i % 10 == 0 else u["label"]}, with_indices=True
-    )
     dms = {
         DatasetSplitName.eval: eval_dm,
         DatasetSplitName.train: train_dm,
     }
+    existing_classes = eval_dm.get_class_names(labels_only=True)
+    class_label = ClassLabel(num_classes=3, names=existing_classes + ["NO_INTENT"])
+    for dm in dms.values():
+        dm._base_dataset_split.features["label"] = class_label
+    eval_dm._base_dataset_split = eval_dm._base_dataset_split.map(
+        lambda u, i: {"label": 2 if i % 10 == 0 else u["label"]}, with_indices=True
+    )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the recommendation! I further cleaned it up, because I think it was hard to read, given that sometimes we would edit the values in the Dict, and sometimes, directly eval_dm. LMK what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha! I had done the exact same change locally while reviewing, but I thought I was asking too much. That's perfect! 👍

Copy link
Contributor

@JosephMarinier JosephMarinier left a comment

Choose a reason for hiding this comment

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

That's a relief! Thank you! I have some minor comments, but that's good to go!

@gabegma gabegma merged commit 7afbd5c into main Dec 20, 2022
@gabegma gabegma deleted the ggm/update-datasets branch December 20, 2022 00:18
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.

Update datasets to v2.1.0
3 participants