This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
add CC100 #1562
Merged
Merged
add CC100 #1562
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4515a34
WIP: add CC100
erip 1794b82
add split following EnWiki9's train-only split convention
erip f641e6d
add default args to satisfy _wrap_split_argument_with_fn
erip ee478df
incorporate feedback from review.
erip 0775e78
fix issue with consistent tuple return.
erip 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 hidden or 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
This file contains hidden or 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,56 @@ | ||
| import os.path | ||
|
|
||
| from typing import Union, Tuple | ||
|
|
||
| from torchtext._internal.module_utils import is_module_available | ||
|
|
||
| if is_module_available("torchdata"): | ||
| from torchdata.datapipes.iter import FileOpener, HttpReader, IterableWrapper | ||
|
|
||
| from torchtext.data.datasets_utils import ( | ||
| _create_dataset_directory, | ||
| _wrap_split_argument | ||
| ) | ||
|
|
||
| URL = "http://data.statmt.org/cc-100/%s.txt.xz" | ||
|
|
||
| VALID_CODES = { | ||
| "am", "ar", "as", "az", "be", "bg", "bn", "bn_rom", "br", "bs", "ca", "cs", "cy", "da", "de", | ||
| "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fr", "fy", "ga", "gd", "gl", "gn", "gu", | ||
| "ha", "he", "hi", "hi_rom", "hr", "ht", "hu", "hy", "id", "ig", "is", "it", "ja", "jv", "ka", | ||
| "kk", "km", "kn", "ko", "ku", "ky", "la", "lg", "li", "ln", "lo", "lt", "lv", "mg", "mk", "ml", | ||
| "mn", "mr", "ms", "my", "my_zaw", "ne", "nl", "no", "ns", "om", "or", "pa", "pl", "ps", "pt", | ||
| "qu", "rm", "ro", "ru", "sa", "si", "sc", "sd", "sk", "sl", "so", "sq", "sr", "ss", "su", "sv", | ||
| "sw", "ta", "ta_rom", "te", "te_rom", "th", "tl", "tn", "tr", "ug", "uk", "ur", "ur_rom", "uz", | ||
| "vi", "wo", "xh", "yi", "yo", "zh-Hans", "zh-Hant", "zu", | ||
| } | ||
|
|
||
| NUM_LINES = None | ||
| MD5 = None | ||
|
|
||
| DATASET_NAME = "CC100" | ||
|
|
||
|
|
||
| @_create_dataset_directory(dataset_name=DATASET_NAME) | ||
| @_wrap_split_argument(("train",)) | ||
| def CC100(root: str, split: Union[Tuple[str], str], language_code: str = "en"): | ||
| if language_code not in VALID_CODES: | ||
| raise ValueError(f"Invalid language code {language_code}") | ||
|
|
||
| url = URL % language_code | ||
| url_dp = IterableWrapper([url]) | ||
| cache_compressed_dp = url_dp.on_disk_cache( | ||
| filepath_fn=lambda x: os.path.join(root, os.path.basename(url)) | ||
| ) | ||
|
|
||
| cache_compressed_dp = HttpReader(cache_compressed_dp) | ||
| cache_compressed_dp = cache_compressed_dp.end_caching(mode="wb", same_filepath_fn=True) | ||
|
|
||
| cache_decompressed_dp = cache_compressed_dp.on_disk_cache( | ||
| filepath_fn=lambda x: os.path.join(root, os.path.basename(x).rstrip(".xz")) | ||
| ) | ||
| cache_decompressed_dp = FileOpener(cache_decompressed_dp, mode="b").read_from_xz() | ||
| cache_decompressed_dp = cache_decompressed_dp.end_caching(mode="wb") | ||
|
|
||
| data_dp = FileOpener(cache_decompressed_dp, mode="r").readlines(return_path=False) | ||
| return data_dp.map(lambda x: (language_code, x)) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.