Datasets:
added example, cleaned content
Browse files
README.md
CHANGED
|
@@ -39,11 +39,9 @@ extra_gated_fields:
|
|
| 39 |
- [Changelog](#changelog)
|
| 40 |
- [Dataset Summary](#dataset-summary)
|
| 41 |
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
| 42 |
-
- [Languages](#languages)
|
| 43 |
- [Dataset Structure](#dataset-structure)
|
| 44 |
-
- [Data Instances](#data-instances)
|
| 45 |
- [Data Fields](#data-fields)
|
| 46 |
-
- [
|
| 47 |
- [Dataset Creation](#dataset-creation)
|
| 48 |
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
| 49 |
- [Additional Information](#additional-information)
|
|
@@ -85,6 +83,74 @@ As na example of aggregation operation on The Stack, the image above shows conce
|
|
| 85 |
|
| 86 |
The meta data will allow you to reconstruct repository directory structures. For this, for each repository form `ri` tabele it is needed to take all its files from `fi` table, find them in The Stack by file's `hexsha` and save those files' content under its path for a repository from `fi` table. For speed it is preferable to index The Stack by hexsha first.
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
## Dataset Creation
|
| 90 |
|
|
|
|
| 39 |
- [Changelog](#changelog)
|
| 40 |
- [Dataset Summary](#dataset-summary)
|
| 41 |
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
|
|
|
| 42 |
- [Dataset Structure](#dataset-structure)
|
|
|
|
| 43 |
- [Data Fields](#data-fields)
|
| 44 |
+
- [Usage Example](#usage-example)
|
| 45 |
- [Dataset Creation](#dataset-creation)
|
| 46 |
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
| 47 |
- [Additional Information](#additional-information)
|
|
|
|
| 83 |
|
| 84 |
The meta data will allow you to reconstruct repository directory structures. For this, for each repository form `ri` tabele it is needed to take all its files from `fi` table, find them in The Stack by file's `hexsha` and save those files' content under its path for a repository from `fi` table. For speed it is preferable to index The Stack by hexsha first.
|
| 85 |
|
| 86 |
+
### Usage Example
|
| 87 |
+
|
| 88 |
+
Restore folder structure for python files in numpy repository
|
| 89 |
+
```
|
| 90 |
+
import datasets
|
| 91 |
+
from pathlib import Path
|
| 92 |
+
from tqdm.auto import tqdm
|
| 93 |
+
import pandas as pd
|
| 94 |
+
|
| 95 |
+
# assuming metadata is cloned into the local folder /data/hf_repos/the-stack-metadata
|
| 96 |
+
# the stack is cloned into the local folder /data/hf_repos/the-stack-v1.1
|
| 97 |
+
# destination folder is in /repo_workdir/numpy_restored
|
| 98 |
+
the_stack_meta_path = Path('/data/hf_repos/the-stack-metadata')
|
| 99 |
+
the_stack_path = Path('/data/hf_repos/the-stack-v1.1')
|
| 100 |
+
repo_dst_root = Path('/repo_workdir/numpy_restored')
|
| 101 |
+
repo_name = 'numpy/numpy'
|
| 102 |
+
|
| 103 |
+
# Get bucket with numpy repo info
|
| 104 |
+
# meta_bucket_path = None
|
| 105 |
+
#for fn in tqdm(list((the_stack_meta_path/'data').glob('*/ri.parquet'))):
|
| 106 |
+
# df = pd.read_parquet(fn)
|
| 107 |
+
# if any(df['name'] == repo_name):
|
| 108 |
+
# meta_bucket_path = fn
|
| 109 |
+
# break
|
| 110 |
+
meta_bucket_path = the_stack_meta_path / 'data/255_944'
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
# Get repository id from repo name
|
| 114 |
+
ri_id = pd.read_parquet(
|
| 115 |
+
meta_bucket_path / 'ri.parquet'
|
| 116 |
+
).query(
|
| 117 |
+
f'`name` == "{repo_name}"'
|
| 118 |
+
)['id'].to_list()[0]
|
| 119 |
+
|
| 120 |
+
# Get files information for the reopository
|
| 121 |
+
files_info = pd.read_parquet(
|
| 122 |
+
meta_bucket_path / 'fi.parquet'
|
| 123 |
+
).query(
|
| 124 |
+
f'`ri_id` == {ri_id} and `size` != 0 and `is_deleted` == False'
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
# Convert DF with files information to a dictionary by language and then file hexsha
|
| 128 |
+
# there can be more than one file with the same hexsha in the repo so we gather
|
| 129 |
+
# all instances per unique hexsha
|
| 130 |
+
files_info_dict = {
|
| 131 |
+
k: v[['hexsha', 'path']].groupby('hexsha').apply(lambda x: list(x['path'])).to_dict()
|
| 132 |
+
for k, v in files_info.groupby('lang_ex')
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
# Load Python part of The Stack
|
| 136 |
+
ds = datasets.load_dataset(
|
| 137 |
+
str(the_stack_path/'data/python'),
|
| 138 |
+
num_proc=10, ignore_verifications=True
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# Save file content of the python files in the numpy reposirotry in their appropriate locations
|
| 142 |
+
def save_file_content(example, files_info_dict, repo_dst_root):
|
| 143 |
+
if example['hexsha'] in files_info_dict:
|
| 144 |
+
for el in files_info_dict[example['hexsha']]:
|
| 145 |
+
path = repo_dst_root / el
|
| 146 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 147 |
+
path.write_text(example['content'])
|
| 148 |
+
ds.map(
|
| 149 |
+
save_file_content,
|
| 150 |
+
fn_kwargs={'files_info_dict': files_info_dict['Python'], 'repo_dst_root': repo_dst_root},
|
| 151 |
+
num_proc=10
|
| 152 |
+
)
|
| 153 |
+
```
|
| 154 |
|
| 155 |
## Dataset Creation
|
| 156 |
|