donfu
commited on
Commit
·
fc31cfb
1
Parent(s):
c665373
Add an upload to HF script
Browse files- process.py +0 -12
- upload.py +22 -0
process.py
CHANGED
|
@@ -18,7 +18,6 @@ SOURCE = "stackexchange-{0}"
|
|
| 18 |
MAX_ANSWERS = 10
|
| 19 |
QUESTION_SCORE_TRESHOLD = 0
|
| 20 |
ANSWER_SCORE_TRESHOLD = 0
|
| 21 |
-
HF_DATASET = "donfu/oa-stackexchange"
|
| 22 |
PARQUET_FILE = "{0}.parquet"
|
| 23 |
MAX_LENGTH = 1000 # max length of question or answer
|
| 24 |
|
|
@@ -45,7 +44,6 @@ def process_dataset(dataset):
|
|
| 45 |
elif not os.path.exists(parquet_file):
|
| 46 |
df = parse_and_convert(xml_file, source)
|
| 47 |
save_parquet(df, dataset)
|
| 48 |
-
# upload_hf(dataset)
|
| 49 |
else:
|
| 50 |
print(f"File already converted {xml_file}. Skipping...")
|
| 51 |
|
|
@@ -149,16 +147,6 @@ def save_parquet(df, dataset):
|
|
| 149 |
print(f"Converted {len(df)} instructions into {parquet_file}")
|
| 150 |
|
| 151 |
|
| 152 |
-
def upload_hf(dataset):
|
| 153 |
-
"""
|
| 154 |
-
Upload to Hugging Face
|
| 155 |
-
"""
|
| 156 |
-
parquet_file = PARQUET_FILE.format(dataset)
|
| 157 |
-
dataset = load_dataset("parquet", data_files=parquet_file, name=dataset)
|
| 158 |
-
dataset.push_to_hub(HF_DATASET, max_shard_size="500MB")
|
| 159 |
-
print("Uploaded to Hugging Face: " + HF_DATASET)
|
| 160 |
-
|
| 161 |
-
|
| 162 |
remove_markdown_links_pattern = r"\[([^\]]+)\]\(([^\)]+)\)"
|
| 163 |
remove_remaining_links = r"https?:\/\/[^\s]+"
|
| 164 |
|
|
|
|
| 18 |
MAX_ANSWERS = 10
|
| 19 |
QUESTION_SCORE_TRESHOLD = 0
|
| 20 |
ANSWER_SCORE_TRESHOLD = 0
|
|
|
|
| 21 |
PARQUET_FILE = "{0}.parquet"
|
| 22 |
MAX_LENGTH = 1000 # max length of question or answer
|
| 23 |
|
|
|
|
| 44 |
elif not os.path.exists(parquet_file):
|
| 45 |
df = parse_and_convert(xml_file, source)
|
| 46 |
save_parquet(df, dataset)
|
|
|
|
| 47 |
else:
|
| 48 |
print(f"File already converted {xml_file}. Skipping...")
|
| 49 |
|
|
|
|
| 147 |
print(f"Converted {len(df)} instructions into {parquet_file}")
|
| 148 |
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
remove_markdown_links_pattern = r"\[([^\]]+)\]\(([^\)]+)\)"
|
| 151 |
remove_remaining_links = r"https?:\/\/[^\s]+"
|
| 152 |
|
upload.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# Simple script to convert StackExchange XML to Open Assistant format
|
| 3 |
+
# Original code by https://github.com/b-mc2
|
| 4 |
+
|
| 5 |
+
from datasets import load_dataset
|
| 6 |
+
|
| 7 |
+
PARQUET_FILE = "stackexchange.parquet"
|
| 8 |
+
HF_DATASET = "donfu/oa-stackexchange"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def upload_hf():
|
| 12 |
+
"""
|
| 13 |
+
Upload to Hugging Face
|
| 14 |
+
"""
|
| 15 |
+
parquet_file = PARQUET_FILE
|
| 16 |
+
dataset = load_dataset("parquet", data_files=parquet_file, name="oa-stackexchange")
|
| 17 |
+
dataset.push_to_hub(HF_DATASET, max_shard_size="500MB")
|
| 18 |
+
print("Uploaded to Hugging Face: " + HF_DATASET)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
upload_hf()
|