-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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 run_glue for do_predict with local test data (#9442) #9486
Merged
sgugger
merged 5 commits into
huggingface:master
from
forest1988:forest1988-fix-run_glue-own_regression_dataset
Jan 13, 2021
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dba9600
Update run_glue for do_predict with local test data (#9442)
forest1988 a77675e
Update run_glue (#9442): fix comments ('files' to 'a file')
forest1988 b1e10ac
Update run_glue (#9442): reflect the code review
forest1988 b2936c3
Update run_glue (#9442): auto format
forest1988 37531ab
Update run_glue (#9442): reflect the code review
forest1988 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 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 |
---|---|---|
|
@@ -93,6 +93,7 @@ class DataTrainingArguments: | |
validation_file: Optional[str] = field( | ||
default=None, metadata={"help": "A csv or a json file containing the validation data."} | ||
) | ||
test_file: Optional[str] = field(default=None, metadata={"help": "A csv or a json file containing the test data."}) | ||
|
||
def __post_init__(self): | ||
if self.task_name is not None: | ||
|
@@ -205,16 +206,30 @@ def main(): | |
if data_args.task_name is not None: | ||
# Downloading and loading a dataset from the hub. | ||
datasets = load_dataset("glue", data_args.task_name) | ||
elif data_args.train_file.endswith(".csv"): | ||
# Loading a dataset from local csv files | ||
datasets = load_dataset( | ||
"csv", data_files={"train": data_args.train_file, "validation": data_args.validation_file} | ||
) | ||
else: | ||
# Loading a dataset from local json files | ||
datasets = load_dataset( | ||
"json", data_files={"train": data_args.train_file, "validation": data_args.validation_file} | ||
) | ||
# Loading a dataset from your local files. | ||
# CSV/JSON training and evaluation files are needed. | ||
data_files = {"train": data_args.train_file, "validation": data_args.validation_file} | ||
|
||
# Get the test dataset: you can provide your own CSV/JSON test file (see below) | ||
# when you use `do_predict` without specifying a GLUE benchmark task. | ||
if training_args.do_predict: | ||
if data_args.test_file is not None: | ||
extension = data_args.test_file.split(".")[-1] | ||
assert extension in ["csv", "json"], "`test_file` should be a csv or a json file." | ||
data_files["test"] = data_args.test_file | ||
else: | ||
raise ValueError("Need either a GLUE task or a test file for `do_predict`.") | ||
|
||
for key in data_files.keys(): | ||
logger.info(f"load a local file for {key}: {data_files[key]}") | ||
Comment on lines
+229
to
+230
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. This could info to log, thanks for adding! |
||
|
||
if data_args.train_file.endswith(".csv"): | ||
# Loading a dataset from local csv files | ||
datasets = load_dataset("csv", data_files=data_files) | ||
else: | ||
# Loading a dataset from local json files | ||
datasets = load_dataset("json", data_files=data_files) | ||
# See more about loading any type of standard or custom dataset at | ||
# https://huggingface.co/docs/datasets/loading_datasets.html. | ||
|
||
|
@@ -325,7 +340,7 @@ def preprocess_function(examples): | |
|
||
train_dataset = datasets["train"] | ||
eval_dataset = datasets["validation_matched" if data_args.task_name == "mnli" else "validation"] | ||
if data_args.task_name is not None: | ||
if data_args.task_name is not None or data_args.test_file is not None: | ||
test_dataset = datasets["test_matched" if data_args.task_name == "mnli" else "test"] | ||
|
||
# Log a few random samples from the training set: | ||
|
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.
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.
The extension will need to be the same one as for the training and validation file, so we should adapt this assert to test that.
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.
Reflecting the comments, assert now checks that the
test file
has the same extension as thetrain file
.Also, I thought there was no check if the
validation file
has the same extension as thetrain file
, so I modified that. Is this change OK?