-
Notifications
You must be signed in to change notification settings - Fork 0
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
allow non-translation tasks #25
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
546925a
allow non-translation tasks
lannelin 7cfbc09
handle single lang case
lannelin 176b6b6
rm reqs file
lannelin a5d9395
drop empty rows
lannelin 5dd7e24
multieurlex tests
lannelin 03dd56a
rm cache files
lannelin 42b7a1d
ignore test caches
lannelin ae88310
fix quote mismatch
lannelin 5d35c90
rm hardcoded sample
lannelin ac6a292
rm commented code
lannelin 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 |
---|---|---|
|
@@ -164,3 +164,6 @@ slurm_scripts/slurm_logs* | |
temp | ||
.vscode | ||
local_notebooks | ||
|
||
# test caches | ||
tests/testdata/*/*/cache* |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import os | ||
import shutil | ||
|
||
import datasets | ||
from datasets import load_dataset | ||
|
||
from arc_spice.data import multieurlex_utils | ||
|
||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
TESTDATA_DIR = os.path.join(PROJECT_ROOT, "tests/testdata") | ||
BASE_DATASET_INFO_MULTILANG = os.path.join( | ||
TESTDATA_DIR, "base_testdata/dataset_info.json" | ||
) | ||
BASE_DATASET_INFO_EN = os.path.join(TESTDATA_DIR, "base_testdata/dataset_info_en.json") | ||
BASE_DATASET_METADATA_DIR = os.path.join(TESTDATA_DIR, "base_testdata/MultiEURLEX") | ||
|
||
# TODO | ||
CONTENT_MULTILANG: list[dict[str, str]] = [ | ||
{ | ||
"en": f"Some text before the marker 1 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 1", # noqa: E501 | ||
"fr": f"Some text before the marker 1 {multieurlex_utils.ARTICLE_1_MARKERS['fr']} Some text after the marker 1", # noqa: E501 | ||
"de": f"Some text before the marker 1 {multieurlex_utils.ARTICLE_1_MARKERS['de']} Some text after the marker 1", # noqa: E501 | ||
}, | ||
{ | ||
"en": f"Some text before the marker 2 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 2", # noqa: E501 | ||
"fr": f"Some text before the marker 2 {multieurlex_utils.ARTICLE_1_MARKERS['fr']} Some text after the marker 2", # noqa: E501 | ||
"de": f"Some text before the marker 2 {multieurlex_utils.ARTICLE_1_MARKERS['de']} Some text after the marker 2", # noqa: E501 | ||
}, | ||
{ | ||
"en": "Some text before the marker 3", # no marker, no text after marker | ||
"fr": "Some text before the marker 3", | ||
"de": "Some text before the marker 3", | ||
}, | ||
{ | ||
"en": f"Some text before the marker 4 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 4", # noqa: E501 | ||
"fr": f"Some text before the marker 4 {multieurlex_utils.ARTICLE_1_MARKERS['fr']} Some text after the marker 4", # noqa: E501 | ||
"de": f"Some text before the marker 4 {multieurlex_utils.ARTICLE_1_MARKERS['de']} Some text after the marker 4", # noqa: E501 | ||
}, | ||
{ | ||
"en": f"Some text before the marker 5 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 5", # noqa: E501 | ||
"fr": f"Some text before the marker 5 {multieurlex_utils.ARTICLE_1_MARKERS['fr']} Some text after the marker 5", # noqa: E501 | ||
"de": f"Some text before the marker 5 {multieurlex_utils.ARTICLE_1_MARKERS['de']} Some text after the marker 5", # noqa: E501 | ||
}, | ||
] | ||
CONTENT_EN: list[str] = [ | ||
f"Some text before the marker 1 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 1", # noqa: E501 | ||
f"Some text before the marker 2 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 2", # noqa: E501 | ||
"Some text before the marker 3", # no marker, no text after marker | ||
f"Some text before the marker 4 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 4", # noqa: E501 | ||
f"Some text before the marker 5 {multieurlex_utils.ARTICLE_1_MARKERS['en']} Some text after the marker 5", # noqa: E501 | ||
] | ||
|
||
|
||
def overwrite_text( | ||
_orig, | ||
i: int, | ||
content: list[dict[str, str]] | list[str], | ||
) -> dict[str, str | dict[str, str]]: | ||
return {"text": content[i]} | ||
|
||
|
||
def create_test_ds( | ||
testdata_dir: str, | ||
ds_name: str, | ||
content: list[dict[str, str]] | list[str], | ||
dataset_info_fpath: str, | ||
) -> None: | ||
dataset = load_dataset( | ||
"multi_eurlex", | ||
"all_languages", | ||
label_level="level_1", | ||
trust_remote_code=True, | ||
) | ||
|
||
dataset["train"] = dataset["train"].take(5) | ||
dataset["validation"] = dataset["validation"].take(5) | ||
dataset["test"] = dataset["test"].take(5) | ||
|
||
dataset = dataset.map( | ||
overwrite_text, | ||
with_indices=True, | ||
fn_kwargs={"content": content}, | ||
) | ||
|
||
dataset.save_to_disk(os.path.join(testdata_dir, ds_name)) | ||
|
||
shutil.copy( | ||
dataset_info_fpath, | ||
os.path.join(testdata_dir, ds_name, "train/dataset_info.json"), | ||
) | ||
shutil.copy( | ||
dataset_info_fpath, | ||
os.path.join(testdata_dir, ds_name, "validation/dataset_info.json"), | ||
) | ||
shutil.copy( | ||
dataset_info_fpath, | ||
os.path.join(testdata_dir, ds_name, "test/dataset_info.json"), | ||
) | ||
# metadata copy | ||
shutil.copytree( | ||
BASE_DATASET_METADATA_DIR, | ||
os.path.join(testdata_dir, ds_name, "MultiEURLEX"), | ||
) | ||
|
||
assert datasets.load_from_disk(os.path.join(testdata_dir, ds_name)) is not None | ||
|
||
|
||
if __name__ == "__main__": | ||
os.makedirs(TESTDATA_DIR, exist_ok=True) | ||
|
||
content = [ | ||
"Some text before the marker en Some text after the marker", | ||
"Some text before the marker fr Some text after the marker", | ||
] | ||
|
||
create_test_ds( | ||
testdata_dir=TESTDATA_DIR, | ||
ds_name="multieurlex_test", | ||
content=CONTENT_MULTILANG, | ||
dataset_info_fpath=BASE_DATASET_INFO_MULTILANG, | ||
) | ||
|
||
create_test_ds( | ||
testdata_dir=TESTDATA_DIR, | ||
ds_name="multieurlex_test_en", | ||
content=CONTENT_EN, | ||
dataset_info_fpath=BASE_DATASET_INFO_EN, | ||
) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
would it be appropriate to split these functionalities into two functions, or pass a
debug_flag
argument?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.
I've simply removed the manually entered data here. I assume this script will be superseded in time by something that goes over more than 1 sample