File size: 7,320 Bytes
dee531a 0fdb914 1b0223b 0fdb914 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
---
license: mit
language:
- en
pipeline_tag: text-classification
library_name: fasttext
tags:
- math
---
## Math classifier
We use `math-classifier` to retrieve math-related content from `fineweb-edu`, `dclm`, ... to upsample math-related content
```python
import json
import os
import time
from concurrent.futures import ProcessPoolExecutor, wait, ALL_COMPLETED
from time import sleep
import fasttext
import numpy as np
import pandas as pd
import pyarrow.parquet as pq
from tqdm import tqdm
def print_error(value):
print("error: ", value)
def data_process(index, file, saved_dir):
try:
model_path = "math_score.bin"
model = fasttext.load_model(model_path)
# saved_dir: fineweb-edu/data/CC...-math/
filename = file.split('/')[-1].replace('.parquet', '.jsonl')
path90 = os.path.join(saved_dir, "09_10", filename)
if os.path.exists(path90):
print("exist", path90, flush=True)
return
sleep(index * 3)
os.makedirs(saved_dir, exist_ok=True)
label_list = []
s67_list = []
s78_list = []
s89_list = []
s90_list = []
st = time.time()
print("reading parquet", file, flush=True)
df = pd.read_parquet(file)
ed = time.time()
print("read parquet time: ", ed - st, flush=True)
for _, row_orginal in tqdm(
df.iterrows(),
total=len(df),
position=index,
desc=filename,
):
row = row_orginal.to_dict()
text = row['text'].replace('\n', ' ')
pred = model.predict(text)
label, score = pred[0][0], pred[1][0]
label_list.append(pred)
if label == '__label__positive':
if 0.6 <= score < 0.7:
s67_list.append(row)
if 0.7 <= score < 0.8:
s78_list.append(row)
elif 0.8 <= score < 0.9:
s89_list.append(row)
elif 0.9 <= score <= 1.0:
s90_list.append(row)
else:
continue
except Exception as e:
print_error(e)
return None
os.makedirs(os.path.join(saved_dir, "labeled"), exist_ok=True)
print("writing to file", flush=True)
with open(
os.path.join(saved_dir, "labeled",
filename.replace('.jsonl', '.txt')), 'w') as f:
f.write("\n".join(str(pred) for pred in label_list))
for dir_name in [ "07_08", "08_09", "09_10"]:
os.makedirs(os.path.join(saved_dir, dir_name), exist_ok=True)
with open(os.path.join(saved_dir, "06_07", filename), 'w') as f:
f.write("\n".join(json.dumps(line_now) for line_now in s67_list))
with open(os.path.join(saved_dir, "07_08", filename), 'w') as f:
f.write("\n".join(json.dumps(line_now) for line_now in s78_list))
with open(os.path.join(saved_dir, "08_09", filename), 'w') as f:
f.write("\n".join(json.dumps(line_now) for line_now in s89_list))
with open(os.path.join(saved_dir, "09_10", filename), 'w') as f:
f.write("\n".join(json.dumps(line_now) for line_now in s90_list))
return None
if __name__ == '__main__':
num_process = 5
start_time = time.time()
file_paths = []
base = "fineweb-edu/data/"
coun=0
for file_name in [
'CC-MAIN-2017-04','CC-MAIN-2017-09','CC-MAIN-2017-13',
'CC-MAIN-2017-17','CC-MAIN-2017-22','CC-MAIN-2017-26',
'CC-MAIN-2017-30','CC-MAIN-2017-34','CC-MAIN-2017-39',
'CC-MAIN-2017-43','CC-MAIN-2017-47','CC-MAIN-2017-51',
"CC-MAIN-2018-05","CC-MAIN-2018-09","CC-MAIN-2018-13",
"CC-MAIN-2018-17","CC-MAIN-2018-22","CC-MAIN-2018-26",
"CC-MAIN-2018-30","CC-MAIN-2018-34","CC-MAIN-2018-39",
"CC-MAIN-2018-43","CC-MAIN-2018-47","CC-MAIN-2018-51",
"CC-MAIN-2019-04","CC-MAIN-2019-09","CC-MAIN-2019-13",
"CC-MAIN-2019-18","CC-MAIN-2019-22","CC-MAIN-2019-26",
"CC-MAIN-2019-30","CC-MAIN-2019-35","CC-MAIN-2019-39",
"CC-MAIN-2019-43","CC-MAIN-2019-47","CC-MAIN-2019-51",
]:
print("Walking:", file_name)
original_file_path = base + file_name
math_dir = original_file_path + "-math"
print(math_dir)
for root, dirs, files in os.walk(original_file_path):
for file in files:
if file.endswith(".parquet"): # 只处理Parquet文件
file_path = os.path.abspath(os.path.join(root, file))
coun+=1
saved_dir = math_dir + "/" + file_path.split("/")[-1][:-8]
print(saved_dir)
file_paths.append((file_path, saved_dir))
print(coun)
print(len(lines))
print("total file paths", len(file_paths))
num_process = min(num_process, len(file_paths))
print("num_process", num_process)
futures = []
with ProcessPoolExecutor(num_process) as executor:
for index, (file_path, saved_dir) in enumerate(file_paths):
futures.append(
executor.submit(data_process, index % num_process, file_path,
saved_dir))
done, not_done = wait(futures, return_when=ALL_COMPLETED)
end_time = time.time()
# 计算并打印所用时间
elapsed_time = end_time - start_time
print(f"Time taken: {elapsed_time} seconds")
print("=" * 100)
```
## Related resources
- [Math classifier](https://huggingface.co/yulan-team/math-classifier)
- [Code classifier](https://huggingface.co/yulan-team/code-classifier)
- [Reasoning classifier](https://huggingface.co/yulan-team/reasoning-classifier)
---
## Contributing
We welcome any form of contribution, including feedback on model bad cases, feature suggestions, and example contributions. You can do so by submitting an [issue](https://github.com/RUC-GSAI/YuLan-Mini/issues).
## The Team
YuLan-Mini is developed and maintained by [AI Box, Renmin University of China](http://aibox.ruc.edu.cn/).
## License
- The code in this repository, the model weights, and optimizer states are released under the [MIT License](./LICENSE).
- Policies regarding the use of model weights, intermediate optimizer states, and training data will be announced in future updates.
- Limitations: Despite our efforts to mitigate safety concerns and encourage the generation of ethical and lawful text, the probabilistic nature of language models may still lead to unexpected outputs. For instance, responses might contain bias, discrimination, or other harmful content. Please refrain from disseminating such content. We are not liable for any consequences arising from the spread of harmful information.
## Citation
If you find YuLan-Mini helpful for your research or development, please cite [our technical report](https://arxiv.org/abs/2412.17743):
```
@article{hu2024yulan,
title={YuLan-Mini: An Open Data-efficient Language Model},
author={Hu, Yiwen and Song, Huatong and Deng, Jia and Wang, Jiapeng and Chen, Jie and Zhou, Kun and Zhu, Yutao and Jiang, Jinhao and Dong, Zican and Zhao, Wayne Xin and others},
journal={arXiv preprint arXiv:2412.17743},
year={2024}
}
```
|