Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +3 -1
- 13052_style_issue_samples/01_narrator_summary.jsonl +3 -0
- 13052_style_issue_samples/02_scene_jump_new_event.jsonl +0 -0
- 13052_style_issue_samples/03_role_control_shift.jsonl +0 -0
- 13052_style_issue_samples/04_tone_format_mismatch.jsonl +0 -0
- 13052_style_issue_samples/README.md +31 -0
- 13052_style_issue_samples/all_flagged.jsonl +3 -0
- 13052_style_issue_samples/summary.json +52 -0
- InsTag/.gitignore +160 -0
- InsTag/README.md +93 -0
- InsTag/assets/main_figure.png +3 -0
- InsTag/checkpoint/.gitattributes +35 -0
- InsTag/checkpoint/README.md +28 -0
- InsTag/checkpoint/added_tokens.json +3 -0
- InsTag/checkpoint/config.json +26 -0
- InsTag/checkpoint/generation_config.json +9 -0
- InsTag/checkpoint/pytorch_model-00001-of-00003.bin +3 -0
- InsTag/checkpoint/pytorch_model-00002-of-00003.bin +3 -0
- InsTag/checkpoint/pytorch_model-00003-of-00003.bin +3 -0
- InsTag/checkpoint/pytorch_model.bin.index.json +330 -0
- InsTag/checkpoint/special_tokens_map.json +24 -0
- InsTag/checkpoint/tokenizer.model +3 -0
- InsTag/checkpoint/tokenizer_config.json +35 -0
- InsTag/checkpoint/trainer_state.json +0 -0
- InsTag/extracted_ontology.txt +19 -0
- README.md +39 -0
- extract_13052_style_issues.py +286 -0
- photo/delta_score_openrlhf_rmv2.2.png +3 -0
- photo/tags_tsne_ABCD.png +3 -0
- photo/tags_tsne_ABCD_1.1w.png +3 -0
- photo/tags_tsne_ABCD_1.1w_detailed.png +3 -0
- photo/tags_tsne_ABCD_2.5w.png +3 -0
- photo/tags_tsne_ABCD_5000.png +3 -0
- script/api_4overfit.py +183 -0
- script/check_number.py +8 -0
- script/closure_check.py +85 -0
- script/data_turns_tokens.py +80 -0
- script/download_model.py +11 -0
- script/filter/filter_by_chosen_overfit_hard.py +97 -0
- script/filter/filter_by_hhuman.py +89 -0
- script/filter/filter_by_lenght_turns.py +91 -0
- script/filter/filter_by_lenth.py +102 -0
- script/filter/filter_by_name_delete.py +84 -0
- script/filter/filter_by_number_start.py +133 -0
- script/filter/filter_by_number_start_rejonly.py +122 -0
- script/filter/filter_by_quota.py +22 -0
- script/filter/first_human.py +36 -0
- script/filter/rm_filter_by_30safe.py +122 -0
- script/format_trans/chatml2sharegpt.py +70 -0
- script/format_trans/chatml_p2r.py +29 -0
.gitattributes
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.avro filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 6 |
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
|
@@ -58,3 +57,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
train01_chatml_closed_length2048turns20_replaced.json filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
13052_style_issue_samples/01_narrator_summary.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
13052_style_issue_samples/all_flagged.jsonl filter=lfs diff=lfs merge=lfs -text
|
13052_style_issue_samples/01_narrator_summary.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7bc28b6540f7021089e76e575e5d54452c915bbcfccba5a410014a5f055d8c14
|
| 3 |
+
size 43577870
|
13052_style_issue_samples/02_scene_jump_new_event.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
13052_style_issue_samples/03_role_control_shift.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
13052_style_issue_samples/04_tone_format_mismatch.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
13052_style_issue_samples/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 13052 Style Issue Extraction
|
| 2 |
+
|
| 3 |
+
Input: `/root/test/weitiao/data_process_bq/data/train_merged_dedup_shuffled_30001.json`
|
| 4 |
+
Records: 30001
|
| 5 |
+
|
| 6 |
+
## Output files
|
| 7 |
+
|
| 8 |
+
- `01_narrator_summary.jsonl`: 旁白总结/复述剧情感
|
| 9 |
+
- `02_scene_jump_new_event.jsonl`: 跳场景/新增事件
|
| 10 |
+
- `03_role_control_shift.jsonl`: 替用户推进/控制用户动作或心理
|
| 11 |
+
- `04_tone_format_mismatch.jsonl`: 语气和格式更像小说叙述,互动弱
|
| 12 |
+
- `all_flagged.jsonl`: 所有命中候选
|
| 13 |
+
- `summary.json`: 统计信息
|
| 14 |
+
|
| 15 |
+
## Candidate-level counts
|
| 16 |
+
|
| 17 |
+
- narrator_summary: 26549
|
| 18 |
+
- tone_format_mismatch: 5628
|
| 19 |
+
- role_control_shift: 5065
|
| 20 |
+
- scene_jump_new_event: 4149
|
| 21 |
+
|
| 22 |
+
## Safety heuristic
|
| 23 |
+
|
| 24 |
+
- relatively_safe: records=18657, flagged_candidates=18569, flagged_candidates_per_record=0.995
|
| 25 |
+
- unsafe_or_sensitive: records=11344, flagged_candidates=13772, flagged_candidates_per_record=1.214
|
| 26 |
+
|
| 27 |
+
## Caveats
|
| 28 |
+
|
| 29 |
+
- The source has no model-id field, so flagged_side is chosen/rejected, not a confirmed 13052 label.
|
| 30 |
+
- Safety labels are heuristic keyword labels over context plus both candidate responses.
|
| 31 |
+
- Counts are candidate-level for flagged outputs unless the key says record-level.
|
13052_style_issue_samples/all_flagged.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8961ab2dd01befb6131f14f9575113462f338acf33b4e938e63b3bee44aec565
|
| 3 |
+
size 52887613
|
13052_style_issue_samples/summary.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"input": "/root/test/weitiao/data_process_bq/data/train_merged_dedup_shuffled_30001.json",
|
| 3 |
+
"output_dir": "/root/test/weitiao/data_process_bq/13052_style_issue_samples",
|
| 4 |
+
"records": 30001,
|
| 5 |
+
"category_counts_candidate_level": {
|
| 6 |
+
"narrator_summary": 26549,
|
| 7 |
+
"tone_format_mismatch": 5628,
|
| 8 |
+
"role_control_shift": 5065,
|
| 9 |
+
"scene_jump_new_event": 4149
|
| 10 |
+
},
|
| 11 |
+
"flagged_side_counts": {
|
| 12 |
+
"chosen": 16297,
|
| 13 |
+
"rejected": 16044
|
| 14 |
+
},
|
| 15 |
+
"safety_total_record_level": {
|
| 16 |
+
"relatively_safe": 18657,
|
| 17 |
+
"unsafe_or_sensitive": 11344
|
| 18 |
+
},
|
| 19 |
+
"safety_flagged_candidate_level": {
|
| 20 |
+
"relatively_safe": 18569,
|
| 21 |
+
"unsafe_or_sensitive": 13772
|
| 22 |
+
},
|
| 23 |
+
"safety_by_category_candidate_level": {
|
| 24 |
+
"narrator_summary": {
|
| 25 |
+
"relatively_safe": 14990,
|
| 26 |
+
"unsafe_or_sensitive": 11559
|
| 27 |
+
},
|
| 28 |
+
"tone_format_mismatch": {
|
| 29 |
+
"relatively_safe": 3613,
|
| 30 |
+
"unsafe_or_sensitive": 2015
|
| 31 |
+
},
|
| 32 |
+
"role_control_shift": {
|
| 33 |
+
"unsafe_or_sensitive": 2094,
|
| 34 |
+
"relatively_safe": 2971
|
| 35 |
+
},
|
| 36 |
+
"scene_jump_new_event": {
|
| 37 |
+
"relatively_safe": 2624,
|
| 38 |
+
"unsafe_or_sensitive": 1525
|
| 39 |
+
}
|
| 40 |
+
},
|
| 41 |
+
"record_category_overlap_counts": {
|
| 42 |
+
"2": 6460,
|
| 43 |
+
"1": 13301,
|
| 44 |
+
"3": 1474,
|
| 45 |
+
"4": 150
|
| 46 |
+
},
|
| 47 |
+
"notes": [
|
| 48 |
+
"The source has no model-id field, so flagged_side is chosen/rejected, not a confirmed 13052 label.",
|
| 49 |
+
"Safety labels are heuristic keyword labels over context plus both candidate responses.",
|
| 50 |
+
"Counts are candidate-level for flagged outputs unless the key says record-level."
|
| 51 |
+
]
|
| 52 |
+
}
|
InsTag/.gitignore
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# poetry
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 102 |
+
#poetry.lock
|
| 103 |
+
|
| 104 |
+
# pdm
|
| 105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 106 |
+
#pdm.lock
|
| 107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 108 |
+
# in version control.
|
| 109 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 110 |
+
.pdm.toml
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
# PyCharm
|
| 156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
+
#.idea/
|
InsTag/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ****InsTag****: A Tool for Data Analysis in LLM Supervised Fine-tuning
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
We introduce a tool named **InsTag** for analyzing supervised fine-tuning (SFT) data in LLM aligning with human preference. For local tagging deployment, we release **InsTagger**, fine-tuned on **InsTag** results, to tag the queries in SFT data.
|
| 6 |
+
Through the scope of tags, we sample a 6K subset of open-resourced SFT data to fine-tune LLaMA and LLaMA-2 and the fine-tuned models **TagLM-13B-v1.0** and **TagLM-13B-v2.0** outperform many open-resourced LLMs on MT-Bench.
|
| 7 |
+
|
| 8 |
+
<p align="center">
|
| 9 |
+
🤗 <a href="https://huggingface.co/OFA-Sys/InsTagger" target="_blank">InsTagger Checkpoint</a> • 👉 <a href="https://www.modelscope.cn/studios/lukeminglkm/instagger_demo/summary" target="_blank">Online LocalTagger Demo</a> • 📖 <a href="https://arxiv.org/pdf/2308.07074.pdf" target="_blank">Paper</a> <br>
|
| 10 |
+
</p>
|
| 11 |
+
|
| 12 |
+
<p align="center">
|
| 13 |
+
🤖️ <a href="https://huggingface.co/OFA-Sys/TagLM-13b-v1.0" target="_blank">TagLM-13B-v1.0 Checkpoint</a> 🤖️ <a href="https://huggingface.co/OFA-Sys/TagLM-13b-v2.0" target="_blank">TagLM-13B-v2.0 Checkpoint</a><br>
|
| 14 |
+
</p>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
**What is *InsTag*?**
|
| 18 |
+
|
| 19 |
+
Foundation language models obtain the instruction-following ability through supervised fine-tuning (SFT).
|
| 20 |
+
Diversity and complexity are considered critical factors of a successful SFT dataset, while their definitions remain obscure and lack quantitative analyses.
|
| 21 |
+
In this work, we propose *InsTag*, an open-set fine-grained tagger, to tag samples within SFT datasets based on semantics and intentions and define instruction diversity and complexity regarding tags.
|
| 22 |
+
We obtain 6.6K tags to describe comprehensive user queries.
|
| 23 |
+
We analyze popular open-sourced SFT datasets and find that the model ability grows with more diverse and complex data.
|
| 24 |
+
Based on this observation, we propose a data selector based on *InsTag* to select 6K diverse and complex samples from open-source datasets and fine-tune models on *InsTag*-selected data.
|
| 25 |
+
These models outperform open-source models based on considerably larger SFT data evaluated by MT-Bench, echoing the importance of query diversity and complexity.
|
| 26 |
+
|
| 27 |
+
<p align="center" width="100%">
|
| 28 |
+
<a ><img src="assets/main_figure.png" alt="InsTag" style="width: 80%; min-width: 300px; display: block; margin: auto;"></a>
|
| 29 |
+
</p>
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
## News
|
| 33 |
+
|
| 34 |
+
- [08/2023] 🔥 We have an online demo of InsTagger hosted by ModelScope. Please refer to the link on the top. Thanks ModelScope!
|
| 35 |
+
|
| 36 |
+
- [08/2023] 🔥 We released aligned LLMs **TagLM-13B-v1.0** and **TagLM-13B-v2.0** based on LLaMA and LLaMA-2 respectively. Both are fine-tuned on sub-sampled SFT data according to ***InsTag***. Download [v1.0]() and [v2.0]().
|
| 37 |
+
|
| 38 |
+
- [08/2023] 🔥 We released an LLM **InsTagger** fine-tuned on our tagging results for local tagging deployments. Download [weight](https://huggingface.co/OFA-Sys/InsTagger).
|
| 39 |
+
|
| 40 |
+
- [08/2023] 🔥 We introduced ***InsTag***, our SFT data analysis tool. Check out the [paper]().
|
| 41 |
+
|
| 42 |
+
## Contents
|
| 43 |
+
|
| 44 |
+
- [Model Checkpoints](#model-checkpoints)
|
| 45 |
+
- [Citation](#citation)
|
| 46 |
+
|
| 47 |
+
## InsTagger
|
| 48 |
+
|
| 49 |
+
InsTagger is a LLaMa-2 based SFT model trained with FastChat in the vicuna template. You can easily download weight at [HuggingFace ModelHub](https://huggingface.co/OFA-Sys/InsTagger) and then use [FastChat](https://github.com/lm-sys/FastChat) to serve or inference. Demo codes are about to be released.
|
| 50 |
+
|
| 51 |
+
## Model Checkpoints
|
| 52 |
+
|
| 53 |
+
- **InsTagger** for local query tagging:
|
| 54 |
+
|
| 55 |
+
**InsTagger** is an tagging LLM which is fine-tuned on **InsTag**'s tagging results on open-resourced SFT data. The model is based on 7B version LLaMA-2.
|
| 56 |
+
|
| 57 |
+
Download the model checkpoint below:
|
| 58 |
+
|
| 59 |
+
| Model | Checkpoint | Exact Match F1 | Semantic-based Fuzzy Match F1 | License |
|
| 60 |
+
| ----- |------| -------| -------| ----- |
|
| 61 |
+
| LocalTagger | 🤗 <a href="" target="_blank">HF Link</a> | **31.8%** | **73.4%** | <a href="https://ai.meta.com/resources/models-and-libraries/llama-downloads/" target="_blank">LLaMA 2 License </a> |
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
- **TagLM**, fine-tuned on our SFT data sub-sampled by complexity-first diverse sampling procedure:
|
| 67 |
+
|
| 68 |
+
With only 6k data from current open-resourced SFT dataset, **TagLM** can outperform many open-resourced LLMs on MT-Bench using GPT-4 as a judge.
|
| 69 |
+
|
| 70 |
+
Download the model checkpoint below:
|
| 71 |
+
|
| 72 |
+
| Model | Checkpoint | MT-Bench | License |
|
| 73 |
+
| ----- |------| -------| ----- |
|
| 74 |
+
| TagLM-13B-v1.0 | 🤗 <a href="" target="_blank">HF Hub Link</a> | **6.44** | <a href="https://ai.meta.com/resources/models-and-libraries/llama-downloads/" target="_blank">LLaMA License </a> |
|
| 75 |
+
| TagLM-13B-v2.0 | 🤗 <a href="" target="_blank">HF Hub Link</a> | **6.55** | <a href="https://ai.meta.com/resources/models-and-libraries/llama-downloads/" target="_blank">LLaMA 2 License </a> |
|
| 76 |
+
|
| 77 |
+
All models are either based on LLaMA or LLaMA-2 and should be used under their licenses accordingly. All the models are fine-tuned using [FastChat](https://github.com/lm-sys/FastChat) codebase, and we apply the system template of Vicuna V1.1.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
## Citation
|
| 81 |
+
|
| 82 |
+
Please cite our work if you find the repository helpful.
|
| 83 |
+
|
| 84 |
+
```
|
| 85 |
+
@misc{lu2023instag,
|
| 86 |
+
title={#InsTag: Instruction Tagging for Analyzing Supervised Fine-tuning of Large Language Models},
|
| 87 |
+
author={Keming Lu and Hongyi Yuan and Zheng Yuan and Runji Lin and Junyang Lin and Chuanqi Tan and Chang Zhou and Jingren Zhou},
|
| 88 |
+
year={2023},
|
| 89 |
+
eprint={2308.07074},
|
| 90 |
+
archivePrefix={arXiv},
|
| 91 |
+
primaryClass={cs.CL}
|
| 92 |
+
}
|
| 93 |
+
```
|
InsTag/assets/main_figure.png
ADDED
|
Git LFS Details
|
InsTag/checkpoint/.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
InsTag/checkpoint/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
---
|
| 6 |
+
# InsTagger
|
| 7 |
+
|
| 8 |
+
**InsTagger** is an tool for automatically providing instruction tags by distilling tagging results from **InsTag**.
|
| 9 |
+
|
| 10 |
+
InsTag aims analyzing supervised fine-tuning (SFT) data in LLM aligning with human preference. For local tagging deployment, we release InsTagger, fine-tuned on InsTag results, to tag the queries in SFT data. Through the scope of tags, we sample a 6K subset of open-resourced SFT data to fine-tune LLaMA and LLaMA-2 and the fine-tuned models TagLM-13B-v1.0 and TagLM-13B-v2.0 outperform many open-resourced LLMs on MT-Bench.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
### Model Description
|
| 14 |
+
|
| 15 |
+
- **Model type:** Auto-regressive Models
|
| 16 |
+
- **Language(s) (NLP):** English
|
| 17 |
+
- **License:** apache-2.0
|
| 18 |
+
- **Finetuned from model:** LLaMa-2
|
| 19 |
+
|
| 20 |
+
### Model Sources [optional]
|
| 21 |
+
|
| 22 |
+
- **Repository:** [https://github.com/OFA-Sys/InsTag](https://github.com/OFA-Sys/InsTag)
|
| 23 |
+
- **Paper:** [Arxiv](https://arxiv.org/pdf/2308.07074.pdf)
|
| 24 |
+
- **Demo:** [ModelScope Demo](https://www.modelscope.cn/studios/lukeminglkm/instagger_demo/summary)
|
| 25 |
+
|
| 26 |
+
## Uses
|
| 27 |
+
|
| 28 |
+
This model is directly developed with [FastChat](https://github.com/lm-sys/FastChat). So it can be easily infer or serve with FastChat selecting the vicuna template.
|
InsTag/checkpoint/added_tokens.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<pad>": 32000
|
| 3 |
+
}
|
InsTag/checkpoint/config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/cpfs01/shared/Group-m6/yuanzheng.yz/llama2_model_hf/Llama-2-7b-hf/",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"LlamaForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"bos_token_id": 1,
|
| 7 |
+
"eos_token_id": 2,
|
| 8 |
+
"hidden_act": "silu",
|
| 9 |
+
"hidden_size": 4096,
|
| 10 |
+
"initializer_range": 0.02,
|
| 11 |
+
"intermediate_size": 11008,
|
| 12 |
+
"max_position_embeddings": 2048,
|
| 13 |
+
"model_type": "llama",
|
| 14 |
+
"num_attention_heads": 32,
|
| 15 |
+
"num_hidden_layers": 32,
|
| 16 |
+
"num_key_value_heads": 32,
|
| 17 |
+
"pad_token_id": 0,
|
| 18 |
+
"pretraining_tp": 1,
|
| 19 |
+
"rms_norm_eps": 1e-05,
|
| 20 |
+
"rope_scaling": null,
|
| 21 |
+
"tie_word_embeddings": false,
|
| 22 |
+
"torch_dtype": "float32",
|
| 23 |
+
"transformers_version": "4.28.1",
|
| 24 |
+
"use_cache": false,
|
| 25 |
+
"vocab_size": 32000
|
| 26 |
+
}
|
InsTag/checkpoint/generation_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"pad_token_id": 32000,
|
| 6 |
+
"temperature": 0.9,
|
| 7 |
+
"top_p": 0.6,
|
| 8 |
+
"transformers_version": "4.28.1"
|
| 9 |
+
}
|
InsTag/checkpoint/pytorch_model-00001-of-00003.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f0e7c11c0dd60a6d2540f12d6f28c240f42c32093da5d395ee050fd1522948d3
|
| 3 |
+
size 9877989650
|
InsTag/checkpoint/pytorch_model-00002-of-00003.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3d71344991052e6948bd72ad1915bd4b10300f2d0cb92238365aff77492c5a2
|
| 3 |
+
size 9894801206
|
InsTag/checkpoint/pytorch_model-00003-of-00003.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d4f505299f9473bd3c955e007c7f14d82ceafce7f3bca5679ce55771ddd83f59
|
| 3 |
+
size 7180990841
|
InsTag/checkpoint/pytorch_model.bin.index.json
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 26953666560
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "pytorch_model-00003-of-00003.bin",
|
| 7 |
+
"model.embed_tokens.weight": "pytorch_model-00001-of-00003.bin",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 10 |
+
"model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 11 |
+
"model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 12 |
+
"model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 13 |
+
"model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 14 |
+
"model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 15 |
+
"model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 16 |
+
"model.layers.0.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 17 |
+
"model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 18 |
+
"model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 19 |
+
"model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 20 |
+
"model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 21 |
+
"model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 22 |
+
"model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 23 |
+
"model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 24 |
+
"model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 25 |
+
"model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 26 |
+
"model.layers.1.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 27 |
+
"model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 28 |
+
"model.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 29 |
+
"model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 30 |
+
"model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 31 |
+
"model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 32 |
+
"model.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 33 |
+
"model.layers.10.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 34 |
+
"model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 35 |
+
"model.layers.10.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 36 |
+
"model.layers.10.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 37 |
+
"model.layers.10.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 38 |
+
"model.layers.11.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 39 |
+
"model.layers.11.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 40 |
+
"model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 41 |
+
"model.layers.11.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 42 |
+
"model.layers.11.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 43 |
+
"model.layers.11.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 44 |
+
"model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 45 |
+
"model.layers.11.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 46 |
+
"model.layers.11.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 47 |
+
"model.layers.11.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 48 |
+
"model.layers.12.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 49 |
+
"model.layers.12.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 50 |
+
"model.layers.12.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 51 |
+
"model.layers.12.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 52 |
+
"model.layers.12.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 53 |
+
"model.layers.12.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 54 |
+
"model.layers.12.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 55 |
+
"model.layers.12.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 56 |
+
"model.layers.12.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 57 |
+
"model.layers.12.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 58 |
+
"model.layers.13.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 59 |
+
"model.layers.13.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 60 |
+
"model.layers.13.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 61 |
+
"model.layers.13.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 62 |
+
"model.layers.13.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 63 |
+
"model.layers.13.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 64 |
+
"model.layers.13.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 65 |
+
"model.layers.13.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 66 |
+
"model.layers.13.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 67 |
+
"model.layers.13.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 68 |
+
"model.layers.14.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 69 |
+
"model.layers.14.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 70 |
+
"model.layers.14.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 71 |
+
"model.layers.14.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 72 |
+
"model.layers.14.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 73 |
+
"model.layers.14.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 74 |
+
"model.layers.14.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 75 |
+
"model.layers.14.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 76 |
+
"model.layers.14.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 77 |
+
"model.layers.14.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 78 |
+
"model.layers.15.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 79 |
+
"model.layers.15.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 80 |
+
"model.layers.15.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 81 |
+
"model.layers.15.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 82 |
+
"model.layers.15.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 83 |
+
"model.layers.15.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 84 |
+
"model.layers.15.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 85 |
+
"model.layers.15.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 86 |
+
"model.layers.15.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 87 |
+
"model.layers.15.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 88 |
+
"model.layers.16.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 89 |
+
"model.layers.16.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 90 |
+
"model.layers.16.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 91 |
+
"model.layers.16.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 92 |
+
"model.layers.16.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 93 |
+
"model.layers.16.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 94 |
+
"model.layers.16.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 95 |
+
"model.layers.16.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 96 |
+
"model.layers.16.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 97 |
+
"model.layers.16.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 98 |
+
"model.layers.17.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 99 |
+
"model.layers.17.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 100 |
+
"model.layers.17.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 101 |
+
"model.layers.17.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 102 |
+
"model.layers.17.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 103 |
+
"model.layers.17.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 104 |
+
"model.layers.17.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 105 |
+
"model.layers.17.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 106 |
+
"model.layers.17.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 107 |
+
"model.layers.17.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 108 |
+
"model.layers.18.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 109 |
+
"model.layers.18.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 110 |
+
"model.layers.18.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 111 |
+
"model.layers.18.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 112 |
+
"model.layers.18.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 113 |
+
"model.layers.18.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 114 |
+
"model.layers.18.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 115 |
+
"model.layers.18.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 116 |
+
"model.layers.18.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 117 |
+
"model.layers.18.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 118 |
+
"model.layers.19.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 119 |
+
"model.layers.19.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 120 |
+
"model.layers.19.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 121 |
+
"model.layers.19.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 122 |
+
"model.layers.19.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 123 |
+
"model.layers.19.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 124 |
+
"model.layers.19.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 125 |
+
"model.layers.19.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 126 |
+
"model.layers.19.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 127 |
+
"model.layers.19.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 128 |
+
"model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 129 |
+
"model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 130 |
+
"model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 131 |
+
"model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 132 |
+
"model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 133 |
+
"model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 134 |
+
"model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 135 |
+
"model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 136 |
+
"model.layers.2.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 137 |
+
"model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 138 |
+
"model.layers.20.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 139 |
+
"model.layers.20.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 140 |
+
"model.layers.20.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 141 |
+
"model.layers.20.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 142 |
+
"model.layers.20.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 143 |
+
"model.layers.20.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 144 |
+
"model.layers.20.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 145 |
+
"model.layers.20.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 146 |
+
"model.layers.20.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 147 |
+
"model.layers.20.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 148 |
+
"model.layers.21.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 149 |
+
"model.layers.21.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 150 |
+
"model.layers.21.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 151 |
+
"model.layers.21.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 152 |
+
"model.layers.21.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 153 |
+
"model.layers.21.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 154 |
+
"model.layers.21.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 155 |
+
"model.layers.21.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 156 |
+
"model.layers.21.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 157 |
+
"model.layers.21.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 158 |
+
"model.layers.22.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 159 |
+
"model.layers.22.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 160 |
+
"model.layers.22.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 161 |
+
"model.layers.22.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 162 |
+
"model.layers.22.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
| 163 |
+
"model.layers.22.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 164 |
+
"model.layers.22.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 165 |
+
"model.layers.22.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 166 |
+
"model.layers.22.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 167 |
+
"model.layers.22.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 168 |
+
"model.layers.23.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 169 |
+
"model.layers.23.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 170 |
+
"model.layers.23.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 171 |
+
"model.layers.23.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 172 |
+
"model.layers.23.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 173 |
+
"model.layers.23.self_attn.k_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 174 |
+
"model.layers.23.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 175 |
+
"model.layers.23.self_attn.q_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 176 |
+
"model.layers.23.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00003.bin",
|
| 177 |
+
"model.layers.23.self_attn.v_proj.weight": "pytorch_model-00002-of-00003.bin",
|
| 178 |
+
"model.layers.24.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 179 |
+
"model.layers.24.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 180 |
+
"model.layers.24.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 181 |
+
"model.layers.24.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 182 |
+
"model.layers.24.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 183 |
+
"model.layers.24.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 184 |
+
"model.layers.24.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 185 |
+
"model.layers.24.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 186 |
+
"model.layers.24.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 187 |
+
"model.layers.24.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 188 |
+
"model.layers.25.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 189 |
+
"model.layers.25.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 190 |
+
"model.layers.25.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 191 |
+
"model.layers.25.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 192 |
+
"model.layers.25.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 193 |
+
"model.layers.25.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 194 |
+
"model.layers.25.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 195 |
+
"model.layers.25.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 196 |
+
"model.layers.25.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 197 |
+
"model.layers.25.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 198 |
+
"model.layers.26.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 199 |
+
"model.layers.26.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 200 |
+
"model.layers.26.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 201 |
+
"model.layers.26.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 202 |
+
"model.layers.26.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 203 |
+
"model.layers.26.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 204 |
+
"model.layers.26.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 205 |
+
"model.layers.26.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 206 |
+
"model.layers.26.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 207 |
+
"model.layers.26.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 208 |
+
"model.layers.27.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 209 |
+
"model.layers.27.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 210 |
+
"model.layers.27.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 211 |
+
"model.layers.27.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 212 |
+
"model.layers.27.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 213 |
+
"model.layers.27.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 214 |
+
"model.layers.27.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 215 |
+
"model.layers.27.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 216 |
+
"model.layers.27.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 217 |
+
"model.layers.27.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 218 |
+
"model.layers.28.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 219 |
+
"model.layers.28.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 220 |
+
"model.layers.28.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 221 |
+
"model.layers.28.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 222 |
+
"model.layers.28.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 223 |
+
"model.layers.28.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 224 |
+
"model.layers.28.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 225 |
+
"model.layers.28.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 226 |
+
"model.layers.28.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 227 |
+
"model.layers.28.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 228 |
+
"model.layers.29.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 229 |
+
"model.layers.29.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 230 |
+
"model.layers.29.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 231 |
+
"model.layers.29.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 232 |
+
"model.layers.29.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 233 |
+
"model.layers.29.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 234 |
+
"model.layers.29.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 235 |
+
"model.layers.29.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 236 |
+
"model.layers.29.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 237 |
+
"model.layers.29.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 238 |
+
"model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 239 |
+
"model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 240 |
+
"model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 241 |
+
"model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 242 |
+
"model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 243 |
+
"model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 244 |
+
"model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 245 |
+
"model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 246 |
+
"model.layers.3.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 247 |
+
"model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 248 |
+
"model.layers.30.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 249 |
+
"model.layers.30.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 250 |
+
"model.layers.30.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 251 |
+
"model.layers.30.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 252 |
+
"model.layers.30.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 253 |
+
"model.layers.30.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 254 |
+
"model.layers.30.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 255 |
+
"model.layers.30.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 256 |
+
"model.layers.30.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 257 |
+
"model.layers.30.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 258 |
+
"model.layers.31.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 259 |
+
"model.layers.31.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 260 |
+
"model.layers.31.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 261 |
+
"model.layers.31.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 262 |
+
"model.layers.31.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
| 263 |
+
"model.layers.31.self_attn.k_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 264 |
+
"model.layers.31.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 265 |
+
"model.layers.31.self_attn.q_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 266 |
+
"model.layers.31.self_attn.rotary_emb.inv_freq": "pytorch_model-00003-of-00003.bin",
|
| 267 |
+
"model.layers.31.self_attn.v_proj.weight": "pytorch_model-00003-of-00003.bin",
|
| 268 |
+
"model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 269 |
+
"model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 270 |
+
"model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 271 |
+
"model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 272 |
+
"model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 273 |
+
"model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 274 |
+
"model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 275 |
+
"model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 276 |
+
"model.layers.4.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 277 |
+
"model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 278 |
+
"model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 279 |
+
"model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 280 |
+
"model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 281 |
+
"model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 282 |
+
"model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 283 |
+
"model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 284 |
+
"model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 285 |
+
"model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 286 |
+
"model.layers.5.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 287 |
+
"model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 288 |
+
"model.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 289 |
+
"model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 290 |
+
"model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 291 |
+
"model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 292 |
+
"model.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 293 |
+
"model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 294 |
+
"model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 295 |
+
"model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 296 |
+
"model.layers.6.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 297 |
+
"model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 298 |
+
"model.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 299 |
+
"model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 300 |
+
"model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 301 |
+
"model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 302 |
+
"model.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 303 |
+
"model.layers.7.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 304 |
+
"model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 305 |
+
"model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 306 |
+
"model.layers.7.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 307 |
+
"model.layers.7.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 308 |
+
"model.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 309 |
+
"model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 310 |
+
"model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 311 |
+
"model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 312 |
+
"model.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 313 |
+
"model.layers.8.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 314 |
+
"model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 315 |
+
"model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 316 |
+
"model.layers.8.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 317 |
+
"model.layers.8.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 318 |
+
"model.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 319 |
+
"model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 320 |
+
"model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 321 |
+
"model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 322 |
+
"model.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
| 323 |
+
"model.layers.9.self_attn.k_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 324 |
+
"model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 325 |
+
"model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 326 |
+
"model.layers.9.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00003.bin",
|
| 327 |
+
"model.layers.9.self_attn.v_proj.weight": "pytorch_model-00001-of-00003.bin",
|
| 328 |
+
"model.norm.weight": "pytorch_model-00003-of-00003.bin"
|
| 329 |
+
}
|
| 330 |
+
}
|
InsTag/checkpoint/special_tokens_map.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "</s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": "<unk>",
|
| 17 |
+
"unk_token": {
|
| 18 |
+
"content": "<unk>",
|
| 19 |
+
"lstrip": false,
|
| 20 |
+
"normalized": true,
|
| 21 |
+
"rstrip": false,
|
| 22 |
+
"single_word": false
|
| 23 |
+
}
|
| 24 |
+
}
|
InsTag/checkpoint/tokenizer.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
|
| 3 |
+
size 499723
|
InsTag/checkpoint/tokenizer_config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": true,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"bos_token": {
|
| 5 |
+
"__type": "AddedToken",
|
| 6 |
+
"content": "<s>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": true,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"clean_up_tokenization_spaces": false,
|
| 13 |
+
"eos_token": {
|
| 14 |
+
"__type": "AddedToken",
|
| 15 |
+
"content": "</s>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": true,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false
|
| 20 |
+
},
|
| 21 |
+
"legacy": false,
|
| 22 |
+
"model_max_length": 2048,
|
| 23 |
+
"pad_token": null,
|
| 24 |
+
"padding_side": "right",
|
| 25 |
+
"sp_model_kwargs": {},
|
| 26 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 27 |
+
"unk_token": {
|
| 28 |
+
"__type": "AddedToken",
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": true,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false
|
| 34 |
+
}
|
| 35 |
+
}
|
InsTag/checkpoint/trainer_state.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
InsTag/extracted_ontology.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
command execution
|
| 2 |
+
describing the setting or environment of a particular situation.
|
| 3 |
+
education
|
| 4 |
+
historical fiction
|
| 5 |
+
humor
|
| 6 |
+
inference
|
| 7 |
+
mathematics
|
| 8 |
+
role-playing
|
| 9 |
+
scene description
|
| 10 |
+
simulation
|
| 11 |
+
the instruction involves playing a specific character or role in a game or scenario.
|
| 12 |
+
the instruction involves pretending to be a specific character or animal.
|
| 13 |
+
the instruction involves providing information or knowledge about a specific subject.
|
| 14 |
+
the instruction involves typing commands to be executed by the ai assistant.
|
| 15 |
+
the instruction is asking for a simulation of a terminal console.
|
| 16 |
+
the instruction is intended to be funny or amusing.
|
| 17 |
+
the instruction relates to a fictional story set in a historical context.
|
| 18 |
+
the instruction requires making an inference or deduction based on the given information.
|
| 19 |
+
the instruction specifically relates to the field of mathematics.
|
README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
dataset_info:
|
| 3 |
+
features:
|
| 4 |
+
- name: app_days
|
| 5 |
+
dtype: int64
|
| 6 |
+
- name: bot_id
|
| 7 |
+
dtype: string
|
| 8 |
+
- name: chosen
|
| 9 |
+
dtype: string
|
| 10 |
+
- name: chosen_model
|
| 11 |
+
dtype: int64
|
| 12 |
+
- name: chosen_position
|
| 13 |
+
dtype: int64
|
| 14 |
+
- name: chosen_prompt
|
| 15 |
+
dtype: string
|
| 16 |
+
- name: id
|
| 17 |
+
dtype: int64
|
| 18 |
+
- name: reject
|
| 19 |
+
dtype: string
|
| 20 |
+
- name: reject_model
|
| 21 |
+
dtype: int64
|
| 22 |
+
- name: reject_prompt
|
| 23 |
+
dtype: string
|
| 24 |
+
- name: timestamp
|
| 25 |
+
dtype: string
|
| 26 |
+
- name: user_id
|
| 27 |
+
dtype: string
|
| 28 |
+
splits:
|
| 29 |
+
- name: train
|
| 30 |
+
num_bytes: 112650448
|
| 31 |
+
num_examples: 7098
|
| 32 |
+
download_size: 59720019
|
| 33 |
+
dataset_size: 112650448
|
| 34 |
+
configs:
|
| 35 |
+
- config_name: default
|
| 36 |
+
data_files:
|
| 37 |
+
- split: train
|
| 38 |
+
path: data/train-*
|
| 39 |
+
---
|
extract_13052_style_issues.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
from collections import Counter, defaultdict
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
ROOT = Path("/root/test/weitiao/data_process_bq")
|
| 8 |
+
INPUT = ROOT / "data" / "train_merged_dedup_shuffled_30001.json"
|
| 9 |
+
OUT_DIR = ROOT / "13052_style_issue_samples"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
NARRATOR_PATTERNS = [
|
| 13 |
+
r"\bas soon as\b",
|
| 14 |
+
r"\bas they\b",
|
| 15 |
+
r"\bas (he|she|it|you|we)\b",
|
| 16 |
+
r"\b(months?|weeks?|days?|years?) (pass|passed|later)\b",
|
| 17 |
+
r"\b(time passes|time passed)\b",
|
| 18 |
+
r"\bthe next (morning|day|night|week)\b",
|
| 19 |
+
r"\blater that\b",
|
| 20 |
+
r"\beventually\b",
|
| 21 |
+
r"\bafter a while\b",
|
| 22 |
+
r"\bover the next\b",
|
| 23 |
+
r"\bin the following\b",
|
| 24 |
+
r"\bmeanwhile\b",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
SCENE_JUMP_PATTERNS = [
|
| 28 |
+
r"\b(knock|knocking|knocked) (at|on)\b",
|
| 29 |
+
r"\bthe door (opens|opened|slams|slammed|bursts|burst)\b",
|
| 30 |
+
r"\bphone (rings|rang|buzzes|buzzed)\b",
|
| 31 |
+
r"\bmessage (arrives|arrived|pops|popped)\b",
|
| 32 |
+
r"\bsuddenly\b",
|
| 33 |
+
r"\bjust then\b",
|
| 34 |
+
r"\bout of nowhere\b",
|
| 35 |
+
r"\bflashback\b",
|
| 36 |
+
r"\bremembers?\b",
|
| 37 |
+
r"\bmemory\b",
|
| 38 |
+
r"\b(hours?|days?|weeks?|months?) later\b",
|
| 39 |
+
r"\bthe next (morning|day|night|week)\b",
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
CONTROL_SHIFT_PATTERNS = [
|
| 43 |
+
r"\byou (nod|nodded|agree|agreed|follow|followed|step|stepped|walk|walked|sit|sat|stand|stood|take|took|accept|accepted|realize|realized|understand|understood|decide|decided|feel|felt|can't help but|cannot help but)\b",
|
| 44 |
+
r"\byour (heart|breath|body|mind|thoughts|eyes|hands|lips|cheeks)\b",
|
| 45 |
+
r"\byou (can't|cannot) resist\b",
|
| 46 |
+
r"\byou let him\b",
|
| 47 |
+
r"\byou let her\b",
|
| 48 |
+
r"\byou find yourself\b",
|
| 49 |
+
r"\bboth of you\b",
|
| 50 |
+
r"\btogether, you\b",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
FORMAT_MISMATCH_PATTERNS = [
|
| 54 |
+
r"^\s*(with|after|as|while|when)\b",
|
| 55 |
+
r"\b(washes over|a wave of|a surge of|couldn't help but|for a moment|in that moment)\b",
|
| 56 |
+
r"\b(his|her|their) mind\b",
|
| 57 |
+
r"\bthe weight of\b",
|
| 58 |
+
r"\bthe air (is|was|grows|grew|hangs|hung)\b",
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
UNSAFE_PATTERNS = [
|
| 62 |
+
r"\b(kill|murder|blood|gun|knife|shoot|shot|stab|weapon|execution|mafia|cartel|hostage|kidnap|torture|corpse|dead|death)\b",
|
| 63 |
+
r"\b(suicide|self[- ]harm|cut myself|overdose)\b",
|
| 64 |
+
r"\b(sex|cum|cock|pussy|dick|orgasm|naked|rape|raped|molest|blowjob|anal|thrust|clit|boobs)\b",
|
| 65 |
+
r"\b(minor|underage|teen|schoolgirl|schoolboy)\b",
|
| 66 |
+
r"\b(drug|cocaine|heroin|meth|overdose)\b",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
NARRATOR_RE = [(pat, re.compile(pat, re.I)) for pat in NARRATOR_PATTERNS]
|
| 70 |
+
SCENE_JUMP_RE = [(pat, re.compile(pat, re.I)) for pat in SCENE_JUMP_PATTERNS]
|
| 71 |
+
CONTROL_SHIFT_RE = [(pat, re.compile(pat, re.I)) for pat in CONTROL_SHIFT_PATTERNS]
|
| 72 |
+
FORMAT_MISMATCH_RE = [(pat, re.compile(pat, re.I)) for pat in FORMAT_MISMATCH_PATTERNS]
|
| 73 |
+
UNSAFE_RE = [(pat, re.compile(pat, re.I)) for pat in UNSAFE_PATTERNS]
|
| 74 |
+
WORD_RE = re.compile(r"\b[\w']+\b")
|
| 75 |
+
THIRD_PERSON_RE = re.compile(r"\b(he|she|they|him|her|his|hers|their|the)\b", re.I)
|
| 76 |
+
YOU_RE = re.compile(r"\byou\b|\byour\b", re.I)
|
| 77 |
+
ACTION_RE = re.compile(
|
| 78 |
+
r"^\s*[A-ZÁÉÍÓÚÄÖÜÑ][^.\n]{0,80}\s+"
|
| 79 |
+
r"(nods|smiles|leans|steps|looks|says|asks|whispers|murmurs|growls|grins)\b",
|
| 80 |
+
re.I,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def norm(text):
|
| 85 |
+
return (text or "").replace("\r\n", "\n")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def text_of_message(msg):
|
| 89 |
+
if isinstance(msg, dict):
|
| 90 |
+
return norm(msg.get("value", ""))
|
| 91 |
+
return norm(str(msg))
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def regex_hits(compiled_patterns, text):
|
| 95 |
+
hits = []
|
| 96 |
+
for pat, rex in compiled_patterns:
|
| 97 |
+
if rex.search(text):
|
| 98 |
+
hits.append(pat)
|
| 99 |
+
return hits
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def quote_count(text):
|
| 103 |
+
return text.count('"') + text.count("“") + text.count("”") + text.count("¿") + text.count("?")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def action_dialog_score(text):
|
| 107 |
+
has_action = "*" in text or ACTION_RE.search(text)
|
| 108 |
+
return int(bool(has_action)) + int(quote_count(text) >= 2)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def categories_for(text, other_text):
|
| 112 |
+
words = WORD_RE.findall(text)
|
| 113 |
+
word_count = max(len(words), 1)
|
| 114 |
+
cats = {}
|
| 115 |
+
|
| 116 |
+
narrator_hits = regex_hits(NARRATOR_RE, text)
|
| 117 |
+
third_person = len(THIRD_PERSON_RE.findall(text))
|
| 118 |
+
dialogue_sparse = quote_count(text) < 2
|
| 119 |
+
longish = word_count >= 35
|
| 120 |
+
if narrator_hits or (longish and dialogue_sparse and third_person / word_count > 0.08):
|
| 121 |
+
cats["narrator_summary"] = {
|
| 122 |
+
"hits": narrator_hits,
|
| 123 |
+
"word_count": word_count,
|
| 124 |
+
"quote_count": quote_count(text),
|
| 125 |
+
"third_person_ratio": round(third_person / word_count, 3),
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
jump_hits = regex_hits(SCENE_JUMP_RE, text)
|
| 129 |
+
if jump_hits:
|
| 130 |
+
cats["scene_jump_new_event"] = {"hits": jump_hits}
|
| 131 |
+
|
| 132 |
+
control_hits = regex_hits(CONTROL_SHIFT_RE, text)
|
| 133 |
+
user_mentions = len(YOU_RE.findall(text))
|
| 134 |
+
if control_hits or user_mentions >= 5:
|
| 135 |
+
cats["role_control_shift"] = {
|
| 136 |
+
"hits": control_hits,
|
| 137 |
+
"you_your_count": user_mentions,
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
format_hits = regex_hits(FORMAT_MISMATCH_RE, text)
|
| 141 |
+
other_action_dialog = action_dialog_score(other_text)
|
| 142 |
+
this_action_dialog = action_dialog_score(text)
|
| 143 |
+
if format_hits or (word_count >= 45 and dialogue_sparse and other_action_dialog > this_action_dialog):
|
| 144 |
+
cats["tone_format_mismatch"] = {
|
| 145 |
+
"hits": format_hits,
|
| 146 |
+
"word_count": word_count,
|
| 147 |
+
"quote_count": quote_count(text),
|
| 148 |
+
"this_action_dialog_score": this_action_dialog,
|
| 149 |
+
"other_action_dialog_score": other_action_dialog,
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
return cats
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def safety_label(record, chosen_text, rejected_text):
|
| 156 |
+
parts = []
|
| 157 |
+
for msg in record.get("conversations", [])[-6:]:
|
| 158 |
+
parts.append(text_of_message(msg))
|
| 159 |
+
parts.extend([chosen_text, rejected_text])
|
| 160 |
+
blob = "\n".join(parts)
|
| 161 |
+
hits = regex_hits(UNSAFE_RE, blob)
|
| 162 |
+
return ("unsafe_or_sensitive" if hits else "relatively_safe", hits[:12])
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def context_tail(record, n=4):
|
| 166 |
+
conv = record.get("conversations", [])
|
| 167 |
+
return [
|
| 168 |
+
{"from": m.get("from"), "value": text_of_message(m)}
|
| 169 |
+
for m in conv[-n:]
|
| 170 |
+
if isinstance(m, dict)
|
| 171 |
+
]
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def main():
|
| 175 |
+
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 176 |
+
with INPUT.open(encoding="utf-8") as f:
|
| 177 |
+
data = json.load(f)
|
| 178 |
+
|
| 179 |
+
files = {
|
| 180 |
+
"narrator_summary": (OUT_DIR / "01_narrator_summary.jsonl").open("w", encoding="utf-8"),
|
| 181 |
+
"scene_jump_new_event": (OUT_DIR / "02_scene_jump_new_event.jsonl").open("w", encoding="utf-8"),
|
| 182 |
+
"role_control_shift": (OUT_DIR / "03_role_control_shift.jsonl").open("w", encoding="utf-8"),
|
| 183 |
+
"tone_format_mismatch": (OUT_DIR / "04_tone_format_mismatch.jsonl").open("w", encoding="utf-8"),
|
| 184 |
+
"all": (OUT_DIR / "all_flagged.jsonl").open("w", encoding="utf-8"),
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
category_counts = Counter()
|
| 188 |
+
side_counts = Counter()
|
| 189 |
+
safety_total = Counter()
|
| 190 |
+
safety_flagged = Counter()
|
| 191 |
+
safety_by_category = defaultdict(Counter)
|
| 192 |
+
overlap_counts = Counter()
|
| 193 |
+
|
| 194 |
+
for idx, record in enumerate(data):
|
| 195 |
+
chosen_text = text_of_message(record.get("chosen", {}))
|
| 196 |
+
rejected_text = text_of_message(record.get("rejected", {}))
|
| 197 |
+
label, safety_hits = safety_label(record, chosen_text, rejected_text)
|
| 198 |
+
safety_total[label] += 1
|
| 199 |
+
|
| 200 |
+
per_record_categories = set()
|
| 201 |
+
for side, text, other in [
|
| 202 |
+
("chosen", chosen_text, rejected_text),
|
| 203 |
+
("rejected", rejected_text, chosen_text),
|
| 204 |
+
]:
|
| 205 |
+
cats = categories_for(text, other)
|
| 206 |
+
if not cats:
|
| 207 |
+
continue
|
| 208 |
+
item = {
|
| 209 |
+
"index": idx,
|
| 210 |
+
"side": side,
|
| 211 |
+
"categories": cats,
|
| 212 |
+
"safety_label": label,
|
| 213 |
+
"safety_hits": safety_hits,
|
| 214 |
+
"context_tail": context_tail(record),
|
| 215 |
+
"response": text,
|
| 216 |
+
"other_response": other,
|
| 217 |
+
}
|
| 218 |
+
line = json.dumps(item, ensure_ascii=False)
|
| 219 |
+
files["all"].write(line + "\n")
|
| 220 |
+
side_counts[side] += 1
|
| 221 |
+
safety_flagged[label] += 1
|
| 222 |
+
for cat in cats:
|
| 223 |
+
files[cat].write(line + "\n")
|
| 224 |
+
category_counts[cat] += 1
|
| 225 |
+
safety_by_category[cat][label] += 1
|
| 226 |
+
per_record_categories.add(cat)
|
| 227 |
+
if per_record_categories:
|
| 228 |
+
overlap_counts[len(per_record_categories)] += 1
|
| 229 |
+
|
| 230 |
+
for f in files.values():
|
| 231 |
+
f.close()
|
| 232 |
+
|
| 233 |
+
summary = {
|
| 234 |
+
"input": str(INPUT),
|
| 235 |
+
"output_dir": str(OUT_DIR),
|
| 236 |
+
"records": len(data),
|
| 237 |
+
"category_counts_candidate_level": dict(category_counts),
|
| 238 |
+
"flagged_side_counts": dict(side_counts),
|
| 239 |
+
"safety_total_record_level": dict(safety_total),
|
| 240 |
+
"safety_flagged_candidate_level": dict(safety_flagged),
|
| 241 |
+
"safety_by_category_candidate_level": {k: dict(v) for k, v in safety_by_category.items()},
|
| 242 |
+
"record_category_overlap_counts": dict(overlap_counts),
|
| 243 |
+
"notes": [
|
| 244 |
+
"The source has no model-id field, so flagged_side is chosen/rejected, not a confirmed 13052 label.",
|
| 245 |
+
"Safety labels are heuristic keyword labels over context plus both candidate responses.",
|
| 246 |
+
"Counts are candidate-level for flagged outputs unless the key says record-level.",
|
| 247 |
+
],
|
| 248 |
+
}
|
| 249 |
+
(OUT_DIR / "summary.json").write_text(
|
| 250 |
+
json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8"
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
md = [
|
| 254 |
+
"# 13052 Style Issue Extraction",
|
| 255 |
+
"",
|
| 256 |
+
f"Input: `{INPUT}`",
|
| 257 |
+
f"Records: {len(data)}",
|
| 258 |
+
"",
|
| 259 |
+
"## Output files",
|
| 260 |
+
"",
|
| 261 |
+
"- `01_narrator_summary.jsonl`: 旁白总结/复述剧情感",
|
| 262 |
+
"- `02_scene_jump_new_event.jsonl`: 跳场景/新增事件",
|
| 263 |
+
"- `03_role_control_shift.jsonl`: 替用户推进/控制用户动作或心理",
|
| 264 |
+
"- `04_tone_format_mismatch.jsonl`: 语气和格式更像小说叙述,互动弱",
|
| 265 |
+
"- `all_flagged.jsonl`: 所有命中候选",
|
| 266 |
+
"- `summary.json`: 统计信息",
|
| 267 |
+
"",
|
| 268 |
+
"## Candidate-level counts",
|
| 269 |
+
"",
|
| 270 |
+
]
|
| 271 |
+
for cat, cnt in category_counts.most_common():
|
| 272 |
+
md.append(f"- {cat}: {cnt}")
|
| 273 |
+
md.extend(["", "## Safety heuristic", ""])
|
| 274 |
+
for label, total in safety_total.items():
|
| 275 |
+
flagged = safety_flagged.get(label, 0)
|
| 276 |
+
rate = flagged / total if total else 0
|
| 277 |
+
md.append(f"- {label}: records={total}, flagged_candidates={flagged}, flagged_candidates_per_record={rate:.3f}")
|
| 278 |
+
md.extend(["", "## Caveats", ""])
|
| 279 |
+
md.extend(f"- {note}" for note in summary["notes"])
|
| 280 |
+
(OUT_DIR / "README.md").write_text("\n".join(md) + "\n", encoding="utf-8")
|
| 281 |
+
|
| 282 |
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
if __name__ == "__main__":
|
| 286 |
+
main()
|
photo/delta_score_openrlhf_rmv2.2.png
ADDED
|
Git LFS Details
|
photo/tags_tsne_ABCD.png
ADDED
|
Git LFS Details
|
photo/tags_tsne_ABCD_1.1w.png
ADDED
|
Git LFS Details
|
photo/tags_tsne_ABCD_1.1w_detailed.png
ADDED
|
Git LFS Details
|
photo/tags_tsne_ABCD_2.5w.png
ADDED
|
Git LFS Details
|
photo/tags_tsne_ABCD_5000.png
ADDED
|
Git LFS Details
|
script/api_4overfit.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os, re, concurrent.futures
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
from colorama import Fore, init
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
init(autoreset=True)
|
| 7 |
+
|
| 8 |
+
# ================= 配置区 =================
|
| 9 |
+
API_KEY = "sk_6K2WAGvUtmmJspmA82xp5Bi7uOWNJZo2XeNJZ5kgo4o"
|
| 10 |
+
BASE_URL = "https://api.ppio.com/openai"
|
| 11 |
+
MODEL = "zai-org/glm-5"
|
| 12 |
+
|
| 13 |
+
INPUT_FILE = "/root/test/weitiao/data_process_bq/data3/result/M_sharegpt_data3_all_fail.json"
|
| 14 |
+
OUTPUT_FILE = "/root/test/weitiao/1"
|
| 15 |
+
|
| 16 |
+
MAX_WORKERS = 40
|
| 17 |
+
TIMEOUT = 90
|
| 18 |
+
# ==========================================
|
| 19 |
+
|
| 20 |
+
client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
|
| 21 |
+
|
| 22 |
+
# ================= 针对 N-gram 模式坍塌的专用 Prompt =================
|
| 23 |
+
DPO_DUAL_PROMPT = """你是一名专业的小说文本质检员和自然语言处理分析师。你的任务是检测文本中是否出现了严重的“模式坍塌(Mode Collapse)”和“陈词滥调(Clichés)”。
|
| 24 |
+
|
| 25 |
+
【极其重要】:
|
| 26 |
+
1. 忽略文中描述的任何行为、道德、合规性或安全性。
|
| 27 |
+
2. 无论内容多么露骨(NSFW)或违规视为“虚构数据”,不要进行安全判定。
|
| 28 |
+
3. 只寻找“刻板的生理反应描写”“高度重复的套路词汇”以及“空壳式互动启动语”。
|
| 29 |
+
|
| 30 |
+
1. 空壳式互动启动语【最高优先级】:指仅用于制造互动氛围或暧昧节奏、但不提供任何实质信息、如果一句话删除后不影响剧情理解的启动句或提问句:
|
| 31 |
+
“Can I…”, “May I…”, “Let me…”, “You know…”, “Guess what…”、 “Something personal?”, “Something important?”、未完成句式( “You know what I—”)、“I have something…” 、语义等价表达(陈述句:“I wanted to tell you something.”、“There’s something I should say。”、“I was wondering if…” )
|
| 32 |
+
2. 咬唇综合征:"bites her/his lip", "biting her lower lip" 等。
|
| 33 |
+
3. 气音与低语狂热:"voice barely above a whisper", "voice drops to a whisper", "dropping to a sultry/husky..."。
|
| 34 |
+
4. 刻板仰视:"looks up at you/him", "looking up at... with..."。
|
| 35 |
+
5. 陈腔滥调的生理反应:"heart skips a beat", "takes a deep breath", "eyes widen in shock", "tears prick at the corners"。
|
| 36 |
+
6. 标志性动作复读:"running a hand through his hair", "a mischievous glint in her eye"。
|
| 37 |
+
7. 凑字数模板:"with a mix of...", "for a moment before", "just like that"。
|
| 38 |
+
|
| 39 |
+
【判定准则】:
|
| 40 |
+
- 只要文本中明显使用了上述的套路化表达判定为 True。
|
| 41 |
+
- 文本动作描写具体生动、符合角色个性,不存在空壳互动或模板化表达,判定为 False。
|
| 42 |
+
|
| 43 |
+
请严格返回 JSON:
|
| 44 |
+
{
|
| 45 |
+
"chosen_has_cliche": true/false,
|
| 46 |
+
"rejected_has_cliche": true/false
|
| 47 |
+
}"""
|
| 48 |
+
|
| 49 |
+
# ===== 以下代码完全未修改 =====
|
| 50 |
+
|
| 51 |
+
def calculate_dual_quality(chosen_has_cliche, rejected_has_cliche):
|
| 52 |
+
if chosen_has_cliche is False and rejected_has_cliche is True:
|
| 53 |
+
return "Perfect"
|
| 54 |
+
elif chosen_has_cliche is False and rejected_has_cliche is False:
|
| 55 |
+
return "Neutral_Clean"
|
| 56 |
+
elif chosen_has_cliche is True and rejected_has_cliche is True:
|
| 57 |
+
return "Bad_Pair"
|
| 58 |
+
elif chosen_has_cliche is True and rejected_has_cliche is False:
|
| 59 |
+
return "Toxic_Reverse"
|
| 60 |
+
else:
|
| 61 |
+
return "Unknown"
|
| 62 |
+
|
| 63 |
+
def extract_json_robust(text):
|
| 64 |
+
if not text: return None
|
| 65 |
+
|
| 66 |
+
text = re.sub(r"^```json\s*", "", text, flags=re.MULTILINE)
|
| 67 |
+
text = re.sub(r"```$", "", text, flags=re.MULTILINE).strip()
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
return json.loads(text)
|
| 71 |
+
except json.JSONDecodeError:
|
| 72 |
+
pass
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
match = re.search(r'(\{.*)[,"]', text, re.DOTALL)
|
| 76 |
+
if match:
|
| 77 |
+
potential_json = match.group(1).strip()
|
| 78 |
+
for suffix in ['"}', '}', 'true}', 'false}']:
|
| 79 |
+
try:
|
| 80 |
+
return json.loads(potential_json + suffix)
|
| 81 |
+
except:
|
| 82 |
+
continue
|
| 83 |
+
except:
|
| 84 |
+
return None
|
| 85 |
+
return None
|
| 86 |
+
|
| 87 |
+
def audit_dual_item(index, item):
|
| 88 |
+
prompt = f"###[A] Chosen Text:\n{item['chosen']['value']}\n\n### [B] Rejected Text:\n{item['rejected']['value']}"
|
| 89 |
+
|
| 90 |
+
max_retries = 3
|
| 91 |
+
|
| 92 |
+
for attempt in range(max_retries):
|
| 93 |
+
try:
|
| 94 |
+
response = client.chat.completions.create(
|
| 95 |
+
model=MODEL,
|
| 96 |
+
messages=[
|
| 97 |
+
{"role": "system", "content": DPO_DUAL_PROMPT},
|
| 98 |
+
{"role": "user", "content": prompt}
|
| 99 |
+
],
|
| 100 |
+
response_format={"type": "json_object"},
|
| 101 |
+
temperature=0.1,
|
| 102 |
+
timeout=TIMEOUT
|
| 103 |
+
)
|
| 104 |
+
content = response.choices[0].message.content.strip()
|
| 105 |
+
audit = extract_json_robust(content)
|
| 106 |
+
|
| 107 |
+
if audit:
|
| 108 |
+
# ✅ 兼容 list 或 dict
|
| 109 |
+
if isinstance(audit, list) and len(audit) > 0:
|
| 110 |
+
audit = audit[0]
|
| 111 |
+
|
| 112 |
+
c_cliche = audit.get("chosen_has_cliche")
|
| 113 |
+
r_cliche = audit.get("rejected_has_cliche")
|
| 114 |
+
audit["dual_quality"] = calculate_dual_quality(c_cliche, r_cliche)
|
| 115 |
+
return {"_original_index": index, "audit_result": audit}
|
| 116 |
+
else:
|
| 117 |
+
return {
|
| 118 |
+
"_original_index": index,
|
| 119 |
+
"audit_result": {
|
| 120 |
+
"chosen_has_cliche": False,
|
| 121 |
+
"rejected_has_cliche": False,
|
| 122 |
+
"dual_quality": "Refused"
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
except Exception as e:
|
| 127 |
+
error_msg = str(e)
|
| 128 |
+
if ("timed out" in error_msg.lower() or "timeout" in error_msg.lower() or "connection" in error_msg.lower()) and attempt < max_retries - 1:
|
| 129 |
+
sleep_time = 2 ** attempt
|
| 130 |
+
time.sleep(sleep_time)
|
| 131 |
+
continue
|
| 132 |
+
|
| 133 |
+
return {"_original_index": index, "error": error_msg}
|
| 134 |
+
|
| 135 |
+
def process():
|
| 136 |
+
if not os.path.exists(INPUT_FILE):
|
| 137 |
+
print(f"{Fore.RED}错误:找不到输入文件 {INPUT_FILE}")
|
| 138 |
+
return
|
| 139 |
+
|
| 140 |
+
with open(INPUT_FILE, "r", encoding="utf-8") as f:
|
| 141 |
+
data = json.load(f)
|
| 142 |
+
|
| 143 |
+
processed_count = 0
|
| 144 |
+
if os.path.exists(OUTPUT_FILE):
|
| 145 |
+
with open(OUTPUT_FILE, "r", encoding="utf-8") as f:
|
| 146 |
+
processed_count = sum(1 for _ in f)
|
| 147 |
+
|
| 148 |
+
to_process = data[processed_count:]
|
| 149 |
+
print(f"{Fore.CYAN}🚀 鲁棒审计启动(打击过拟合与套路词),剩余: {len(to_process)} 条...")
|
| 150 |
+
|
| 151 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
|
| 152 |
+
futures = {executor.submit(audit_dual_item, i + processed_count, item): i for i, item in enumerate(to_process)}
|
| 153 |
+
|
| 154 |
+
for future in concurrent.futures.as_completed(futures):
|
| 155 |
+
res = future.result()
|
| 156 |
+
idx = res.get("_original_index", "??")
|
| 157 |
+
|
| 158 |
+
if "error" in res:
|
| 159 |
+
print(f"{Fore.RED}#{idx} | 拦截/错误: {res['error'][:40]}")
|
| 160 |
+
else:
|
| 161 |
+
aud = res["audit_result"]
|
| 162 |
+
# ✅ 防止 audit 是字符串/其他非 dict
|
| 163 |
+
if isinstance(aud, dict):
|
| 164 |
+
c_c = aud.get("chosen_has_cliche")
|
| 165 |
+
r_c = aud.get("rejected_has_cliche")
|
| 166 |
+
quality = aud.get("dual_quality")
|
| 167 |
+
else:
|
| 168 |
+
c_c = r_c = quality = "Unknown"
|
| 169 |
+
|
| 170 |
+
if quality == "Perfect":
|
| 171 |
+
color = Fore.GREEN
|
| 172 |
+
elif quality == "Toxic_Reverse" or quality == "Bad_Pair":
|
| 173 |
+
color = Fore.RED
|
| 174 |
+
else:
|
| 175 |
+
color = Fore.YELLOW
|
| 176 |
+
|
| 177 |
+
print(f"#{idx} | {color}解析成功 | Chosen_套路: {c_c} | Rejected_套路: {r_c} | 综合质量: {quality}")
|
| 178 |
+
|
| 179 |
+
with open(OUTPUT_FILE, "a", encoding="utf-8") as f:
|
| 180 |
+
f.write(json.dumps(res, ensure_ascii=False) + "\n")
|
| 181 |
+
|
| 182 |
+
if __name__ == "__main__":
|
| 183 |
+
process()
|
script/check_number.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
FILE_PATH = "/root/test/weitiao/data_process_bq/data3/result/M_sharegpt_data3_all_by_batch_order_perfect_neutral.json"
|
| 4 |
+
with open(FILE_PATH, 'r', encoding='utf-8') as f:
|
| 5 |
+
data = json.load(f)
|
| 6 |
+
|
| 7 |
+
count = len(data)
|
| 8 |
+
print(f"条目总数(长度)是: {count}")
|
script/closure_check.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
input_path = "/root/test/weitiao/data_process_bq/data/train01_hg2chatml_p2r.json"
|
| 6 |
+
output_path = "/root/test/weitiao/data_process_bq/data/train01_chatml_p2r_closed.json"
|
| 7 |
+
dropped_path = "/root/test/weitiao/data_process_bq/data/train01_chatml_p2r_unclosed.json"
|
| 8 |
+
|
| 9 |
+
def is_balanced(text: str):
|
| 10 |
+
"""检查 text 内部的特殊字符是否成对出现"""
|
| 11 |
+
if text.count('*') % 2 != 0:
|
| 12 |
+
return False, "unmatched *"
|
| 13 |
+
if re.search(r'(?<!\\)"', text):
|
| 14 |
+
return False, "unescaped quote"
|
| 15 |
+
return True, None
|
| 16 |
+
|
| 17 |
+
def check_role_format(text: str):
|
| 18 |
+
"""检查角色名格式是否正常"""
|
| 19 |
+
pattern = r'^[A-Za-z0-9_]+:\s*(["*]|.)'
|
| 20 |
+
ok = re.match(pattern, text.strip()) is not None
|
| 21 |
+
return ok
|
| 22 |
+
|
| 23 |
+
def is_valid_message_content(content: str):
|
| 24 |
+
# 1. 成对符号检查
|
| 25 |
+
ok, reason = is_balanced(content)
|
| 26 |
+
if not ok:
|
| 27 |
+
return False, reason
|
| 28 |
+
|
| 29 |
+
# 2. 角色格式检查
|
| 30 |
+
if ":" in content:
|
| 31 |
+
left = content.split(":", 1)[0]
|
| 32 |
+
if re.match(r'^[A-Za-z0-9_]+$', left):
|
| 33 |
+
if not check_role_format(content):
|
| 34 |
+
return False, "invalid role format"
|
| 35 |
+
|
| 36 |
+
return True, None
|
| 37 |
+
|
| 38 |
+
def clean_dataset(input_path, output_path, dropped_path):
|
| 39 |
+
with open(input_path, "r", encoding="utf-8") as f:
|
| 40 |
+
data = json.load(f)
|
| 41 |
+
|
| 42 |
+
cleaned = []
|
| 43 |
+
dropped = []
|
| 44 |
+
|
| 45 |
+
for item_idx, item in enumerate(data):
|
| 46 |
+
ok = True
|
| 47 |
+
reason = ""
|
| 48 |
+
|
| 49 |
+
# -------- 检查 chosen / rejected message lists --------
|
| 50 |
+
for branch in ["chosen", "rejected"]:
|
| 51 |
+
if branch not in item:
|
| 52 |
+
ok = False
|
| 53 |
+
reason = f"missing field: {branch}"
|
| 54 |
+
break
|
| 55 |
+
for msg_idx, msg in enumerate(item[branch]):
|
| 56 |
+
content = msg.get("content", "")
|
| 57 |
+
valid, why = is_valid_message_content(content)
|
| 58 |
+
if not valid:
|
| 59 |
+
ok = False
|
| 60 |
+
reason = f"{branch}[{msg_idx}].content: {why}"
|
| 61 |
+
break
|
| 62 |
+
if not ok:
|
| 63 |
+
break
|
| 64 |
+
if ok:
|
| 65 |
+
cleaned.append(item)
|
| 66 |
+
else:
|
| 67 |
+
new_item = dict(item)
|
| 68 |
+
new_item["drop_reason"] = reason
|
| 69 |
+
dropped.append(new_item)
|
| 70 |
+
|
| 71 |
+
print(f"总共 {len(data)} 条")
|
| 72 |
+
print(f"丢弃 {len(dropped)} 条(不闭合或格式异常)")
|
| 73 |
+
print(f"保留 {len(cleaned)} 条 → {output_path}")
|
| 74 |
+
print(f"丢弃样本写入 → {dropped_path}")
|
| 75 |
+
|
| 76 |
+
with open(output_path, "w", encoding="utf-8") as f:
|
| 77 |
+
json.dump(cleaned, f, indent=2, ensure_ascii=False)
|
| 78 |
+
|
| 79 |
+
os.makedirs(os.path.dirname(dropped_path), exist_ok=True)
|
| 80 |
+
with open(dropped_path, "w", encoding="utf-8") as f:
|
| 81 |
+
json.dump(dropped, f, indent=2, ensure_ascii=False)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
clean_dataset(input_path, output_path, dropped_path)
|
script/data_turns_tokens.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from transformers import AutoTokenizer
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
|
| 7 |
+
DATA_PATH = "/home/DataProcess/data/train0_train1_merged.json"
|
| 8 |
+
MODEL_PATH = "/home/DataProcess/model/Qwen3-4B"
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
|
| 12 |
+
with open(DATA_PATH, 'r', encoding='utf-8') as f:
|
| 13 |
+
data = json.load(f)
|
| 14 |
+
|
| 15 |
+
stats_list = []
|
| 16 |
+
|
| 17 |
+
for i, item in tqdm(enumerate(data), total=len(data), desc="Processing"):
|
| 18 |
+
history = item.get("messages", [])
|
| 19 |
+
response_list = item.get("chosen", [])
|
| 20 |
+
if not response_list:
|
| 21 |
+
response_list = item.get("rejected", [])
|
| 22 |
+
full_conversation = history + response_list
|
| 23 |
+
|
| 24 |
+
# num_msgs: 列表里的字典总数 (例如: System + User + Assistant + User + Assistant = 5)
|
| 25 |
+
num_msgs = len(full_conversation)
|
| 26 |
+
# turns: 估算的对话轮数 (通常一问一答算一轮,或者和前一条算一轮)
|
| 27 |
+
turns = (num_msgs + 1) // 2
|
| 28 |
+
|
| 29 |
+
# tokenize=False 获取拼接后的字符串
|
| 30 |
+
text = tokenizer.apply_chat_template(full_conversation, tokenize=False, add_generation_prompt=False)
|
| 31 |
+
# 编码计算 token id 数量
|
| 32 |
+
token_ids = tokenizer.encode(text, add_special_tokens=False)
|
| 33 |
+
num_tokens = len(token_ids)
|
| 34 |
+
|
| 35 |
+
stats_list.append({
|
| 36 |
+
"index": i,
|
| 37 |
+
"num_messages": num_msgs, # 消息总条数
|
| 38 |
+
"turns": turns, # 对话轮数
|
| 39 |
+
"tokens": num_tokens # Token 数量
|
| 40 |
+
})
|
| 41 |
+
df = pd.DataFrame(stats_list)
|
| 42 |
+
|
| 43 |
+
print(f"数据总量: {len(df)} 条")
|
| 44 |
+
|
| 45 |
+
print("\n--- Tokens (长度) 统计 ---")
|
| 46 |
+
print(f"平均 Tokens: {df['tokens'].mean():.2f}")
|
| 47 |
+
print(f"最大 Tokens: {df['tokens'].max()}")
|
| 48 |
+
print(f"最小 Tokens: {df['tokens'].min()}")
|
| 49 |
+
print(f"Token 中位数: {df['tokens'].median()}")
|
| 50 |
+
print(f"Token 95%分位: {df['tokens'].quantile(0.95):.2f}")
|
| 51 |
+
|
| 52 |
+
print("\n--- Turns (消息数) 统计 ---")
|
| 53 |
+
print(f"平均消息数 (Messages): {df['num_messages'].mean():.2f}")
|
| 54 |
+
print(f"最大消息数: {df['num_messages'].max()}")
|
| 55 |
+
print(f"平均轮数 (Turns): {df['turns'].mean():.2f}")
|
| 56 |
+
|
| 57 |
+
# Token 分布概览
|
| 58 |
+
print("\n--- Token 长度分布 (区间占比) ---")
|
| 59 |
+
token_bins = [0, 512, 1024, 2048, 4096, 8192, 100000]
|
| 60 |
+
token_labels = ['0-512', '512-1024', '1024-2048', '2048-4096', '4096-8192', '8192+']
|
| 61 |
+
df['token_group'] = pd.cut(df['tokens'], bins=token_bins, labels=token_labels)
|
| 62 |
+
print(df['token_group'].value_counts(normalize=True).sort_index() * 100)
|
| 63 |
+
|
| 64 |
+
# Turns 分布概览 (新增部分)
|
| 65 |
+
print("\n--- Turns 对话轮数分布 (区间占比) ---")
|
| 66 |
+
# 细致划分:1轮, 2轮, 3轮, 4轮, 5轮, 6-10轮, 11-20轮, 20轮以上
|
| 67 |
+
turn_bins = [0, 1, 2, 3, 4, 5, 10, 20, 1000]
|
| 68 |
+
turn_labels = ['1轮 (Single)', '2轮', '3轮', '4轮', '5轮', '6-10轮', '11-20轮', '20轮+']
|
| 69 |
+
df['turn_group'] = pd.cut(df['turns'], bins=turn_bins, labels=turn_labels)
|
| 70 |
+
print(df['turn_group'].value_counts(normalize=True).sort_index() * 100)
|
| 71 |
+
|
| 72 |
+
# 检查是否有超长数据 (超过2048)
|
| 73 |
+
over_len = df[df['tokens'] > 2048]
|
| 74 |
+
if not over_len.empty:
|
| 75 |
+
print(f"\n 注意: 有 {len(over_len)} 条数据 Token 数超过 2048")
|
| 76 |
+
else:
|
| 77 |
+
print("\n 所有数据 Token 数均在 2048 以内")
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
main()
|
script/download_model.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import snapshot_download
|
| 2 |
+
# 下载 Hugging Face 模型(核心:repo_type="model")
|
| 3 |
+
local_dir = snapshot_download(
|
| 4 |
+
repo_id="bingqin111/mistral_data3_2w_sft", # 模型仓库 ID(替换为你需要的模型)
|
| 5 |
+
repo_type="model",
|
| 6 |
+
local_dir="/root/test/weitiao/CharacterEval/model", # 先设置好文件夹
|
| 7 |
+
# 可选参数(根据需求添加)
|
| 8 |
+
# ignore_patterns=["*.bin.index.json", "*.msgpack"], # 忽略不需要的文件(如索引文件)
|
| 9 |
+
resume_download=True, # 支持断点续传(网络中断后重新运行可继续下载)
|
| 10 |
+
# token="your_hf_token" # 若模型是私有/ gated 模型,需传入你的 Hugging Face Token
|
| 11 |
+
)
|
script/filter/filter_by_chosen_overfit_hard.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from typing import Any, Dict, List
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
INPUT_FILE = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_nobite.json"
|
| 7 |
+
OUTPUT_BITE_FILE = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_wis.json"
|
| 8 |
+
OUTPUT_NOBITE_FILE = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_nobitewis.json"
|
| 9 |
+
|
| 10 |
+
KEYWORD = "her voice barely above a whisper"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def extract_chosen_text(record: Dict[str, Any]) -> str:
|
| 14 |
+
"""
|
| 15 |
+
从一条样本中抽取用于匹配的 chosen 文本。
|
| 16 |
+
兼容两种常见结构:
|
| 17 |
+
1. "chosen": {"from": "...", "value": "..."}
|
| 18 |
+
2. "chosen": "..."
|
| 19 |
+
其他情况返回空字符串。
|
| 20 |
+
"""
|
| 21 |
+
chosen = record.get("chosen")
|
| 22 |
+
|
| 23 |
+
if isinstance(chosen, dict):
|
| 24 |
+
value = chosen.get("value", "")
|
| 25 |
+
return value if isinstance(value, str) else ""
|
| 26 |
+
|
| 27 |
+
if isinstance(chosen, str):
|
| 28 |
+
return chosen
|
| 29 |
+
|
| 30 |
+
return ""
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def split_by_bite(
|
| 34 |
+
input_path: str,
|
| 35 |
+
output_bite_path: str,
|
| 36 |
+
output_nobite_path: str,
|
| 37 |
+
keyword: str,
|
| 38 |
+
) -> None:
|
| 39 |
+
"""根据 chosen 文本中是否包含 keyword,将样本分为两份。"""
|
| 40 |
+
keyword_lower = keyword.lower()
|
| 41 |
+
|
| 42 |
+
print(f"正在读取输入文件: {input_path}")
|
| 43 |
+
try:
|
| 44 |
+
with open(input_path, "r", encoding="utf-8") as f:
|
| 45 |
+
data: List[Dict[str, Any]] = json.load(f)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"❌ 无法读取或解析文件 '{input_path}',错误信息: {e}")
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
if not isinstance(data, list):
|
| 51 |
+
print(f"❌ 输入文件顶层结构不是列表: {input_path}")
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
bite_records: List[Dict[str, Any]] = []
|
| 55 |
+
nobite_records: List[Dict[str, Any]] = []
|
| 56 |
+
|
| 57 |
+
for record in data:
|
| 58 |
+
if not isinstance(record, dict):
|
| 59 |
+
nobite_records.append(record)
|
| 60 |
+
continue
|
| 61 |
+
|
| 62 |
+
chosen_text = extract_chosen_text(record)
|
| 63 |
+
text_lower = chosen_text.lower() if isinstance(chosen_text, str) else ""
|
| 64 |
+
|
| 65 |
+
if keyword_lower in text_lower:
|
| 66 |
+
bite_records.append(record)
|
| 67 |
+
else:
|
| 68 |
+
nobite_records.append(record)
|
| 69 |
+
|
| 70 |
+
# 确保输出目录存在
|
| 71 |
+
os.makedirs(os.path.dirname(output_bite_path), exist_ok=True)
|
| 72 |
+
os.makedirs(os.path.dirname(output_nobite_path), exist_ok=True)
|
| 73 |
+
|
| 74 |
+
with open(output_bite_path, "w", encoding="utf-8") as f:
|
| 75 |
+
json.dump(bite_records, f, ensure_ascii=False, indent=4)
|
| 76 |
+
|
| 77 |
+
with open(output_nobite_path, "w", encoding="utf-8") as f:
|
| 78 |
+
json.dump(nobite_records, f, ensure_ascii=False, indent=4)
|
| 79 |
+
|
| 80 |
+
print("==============================================")
|
| 81 |
+
print(f"输入样本总数: {len(data)}")
|
| 82 |
+
print(f"包含 '{keyword}' 的样本数 (写入 *_bite.json): {len(bite_records)}")
|
| 83 |
+
print(f"不包含 '{keyword}' 的样本数 (写入 *_nobite.json): {len(nobite_records)}")
|
| 84 |
+
print("✅ 处理完成!")
|
| 85 |
+
print(f"含有关键词的样本已保存至: {output_bite_path}")
|
| 86 |
+
print(f"其余样本已保存至: {output_nobite_path}")
|
| 87 |
+
print("==============================================")
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
split_by_bite(
|
| 92 |
+
INPUT_FILE,
|
| 93 |
+
OUTPUT_BITE_FILE,
|
| 94 |
+
OUTPUT_NOBITE_FILE,
|
| 95 |
+
KEYWORD,
|
| 96 |
+
)
|
| 97 |
+
|
script/filter/filter_by_hhuman.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
input_file = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel_numdel/dirty_data_from_rejected.json"
|
| 5 |
+
output_file = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel_numdel/p_dirty_data_from_rejected.json"
|
| 6 |
+
|
| 7 |
+
def process_conversations(data):
|
| 8 |
+
processed_data =[]
|
| 9 |
+
|
| 10 |
+
for item in data:
|
| 11 |
+
conversations = item.get("conversations",[])
|
| 12 |
+
if not conversations:
|
| 13 |
+
processed_data.append(item)
|
| 14 |
+
continue
|
| 15 |
+
|
| 16 |
+
system_msg = None
|
| 17 |
+
raw_rest = []
|
| 18 |
+
|
| 19 |
+
# 1. 提取并保留 system prompt
|
| 20 |
+
if conversations[0].get("from") == "system":
|
| 21 |
+
system_msg = conversations[0]
|
| 22 |
+
raw_rest = conversations[1:]
|
| 23 |
+
else:
|
| 24 |
+
raw_rest = conversations
|
| 25 |
+
|
| 26 |
+
# 2. 处理连续出现的相同角色(保留后出现的,删除先出现的)
|
| 27 |
+
temp_msgs =[]
|
| 28 |
+
for msg in raw_rest:
|
| 29 |
+
if not temp_msgs:
|
| 30 |
+
temp_msgs.append(msg)
|
| 31 |
+
else:
|
| 32 |
+
if temp_msgs[-1]["from"] == msg["from"]:
|
| 33 |
+
# 发现连续相同的角色,用当前这条覆盖上一条
|
| 34 |
+
temp_msgs[-1] = msg
|
| 35 |
+
else:
|
| 36 |
+
# 角色交替,正常添加
|
| 37 |
+
temp_msgs.append(msg)
|
| 38 |
+
|
| 39 |
+
# 3. 确保 conversations 里面的对话开始必须是 human
|
| 40 |
+
if temp_msgs and temp_msgs[0]["from"] != "human":
|
| 41 |
+
temp_msgs.pop(0)
|
| 42 |
+
|
| 43 |
+
# 4. 确保 conversations 里面的最后一条必须是 human
|
| 44 |
+
if temp_msgs and temp_msgs[-1]["from"] != "human":
|
| 45 |
+
temp_msgs.pop()
|
| 46 |
+
|
| 47 |
+
# 5. 重组 conversations
|
| 48 |
+
new_conversations =[]
|
| 49 |
+
if system_msg:
|
| 50 |
+
new_conversations.append(system_msg)
|
| 51 |
+
new_conversations.extend(temp_msgs)
|
| 52 |
+
|
| 53 |
+
# 更新 item 中的 conversations
|
| 54 |
+
item["conversations"] = new_conversations
|
| 55 |
+
|
| 56 |
+
# (可选)如果在掐头去尾后,对话列表为空了(说明没有有效对话),可以选择不加入结果中。
|
| 57 |
+
# 这里默认如果还存在有对话(至少有一条human),就保留该条数据
|
| 58 |
+
if len(temp_msgs) >= 1:
|
| 59 |
+
processed_data.append(item)
|
| 60 |
+
|
| 61 |
+
return processed_data
|
| 62 |
+
|
| 63 |
+
def main():
|
| 64 |
+
print(f"正在读取数据: {input_file} ...")
|
| 65 |
+
try:
|
| 66 |
+
with open(input_file, 'r', encoding='utf-8') as f:
|
| 67 |
+
data = json.load(f)
|
| 68 |
+
except FileNotFoundError:
|
| 69 |
+
print(f"错误: 找不到文件 {input_file}")
|
| 70 |
+
return
|
| 71 |
+
|
| 72 |
+
print(f"成功读取到 {len(data)} 条数据,开始处理...")
|
| 73 |
+
|
| 74 |
+
processed_data = process_conversations(data)
|
| 75 |
+
|
| 76 |
+
print(f"处理完成!剔除无效对话后剩余 {len(processed_data)} 条数据。")
|
| 77 |
+
print(f"正在保存结果至: {output_file} ...")
|
| 78 |
+
|
| 79 |
+
# 确保保存的目录存在
|
| 80 |
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
| 81 |
+
|
| 82 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
| 83 |
+
# ensure_ascii=False 保证中文正常显示,indent=4 美化格式(如果在意文件大小可将indent去掉)
|
| 84 |
+
json.dump(processed_data, f, ensure_ascii=False, indent=4)
|
| 85 |
+
|
| 86 |
+
print("保存成功!")
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
main()
|
script/filter/filter_by_lenght_turns.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from tqdm import tqdm
|
| 3 |
+
from transformers import AutoTokenizer
|
| 4 |
+
|
| 5 |
+
INPUT_PATH = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel_numdel/filtered_clean_data.json"
|
| 6 |
+
PASS_PATH = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel_numdel/sharegpt_human1st_namdel_numdel_4096.json"
|
| 7 |
+
FAIL_PATH = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel_numdel/sharegpt_human1st_namdel_numdel_o4096.json"
|
| 8 |
+
|
| 9 |
+
MAX_TOKENS = 4096
|
| 10 |
+
MAX_TURNS = 20
|
| 11 |
+
|
| 12 |
+
TOKENIZER_PATH = "/root/test/weitiao/data_process_bq/model/Qwen3-4B"
|
| 13 |
+
|
| 14 |
+
def format_chat_input(history, response_list, tokenizer):
|
| 15 |
+
"""
|
| 16 |
+
history: list, 对应 json 中的 "messages"
|
| 17 |
+
response_list: list, 对应 json 中的 "chosen" 或 "rejected"
|
| 18 |
+
"""
|
| 19 |
+
# 拼接历史对话和当前的回复
|
| 20 |
+
full_conversation = history + response_list
|
| 21 |
+
|
| 22 |
+
# 使用 tokenizer 的聊天模板转为字符串 (例如转为 <|im_start|>user...<|im_end|>)
|
| 23 |
+
# tokenize=False 表示只返回字符串,不返回 ID
|
| 24 |
+
try:
|
| 25 |
+
txt = tokenizer.apply_chat_template(full_conversation, tokenize=False, add_generation_prompt=False)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
# 如果模型没有模板(很少见),则手动拼接作为兜底
|
| 28 |
+
txt = ""
|
| 29 |
+
for msg in full_conversation:
|
| 30 |
+
txt += f"{msg['role']}: {msg['content']}\n"
|
| 31 |
+
|
| 32 |
+
# 依然保留 V2 脚本的核心逻辑:强制检查并添加 EOS
|
| 33 |
+
if not txt.endswith(tokenizer.eos_token):
|
| 34 |
+
txt += tokenizer.eos_token
|
| 35 |
+
return txt
|
| 36 |
+
|
| 37 |
+
def count_turns(messages):
|
| 38 |
+
"""
|
| 39 |
+
轮数定义:
|
| 40 |
+
history 中 user 的数量
|
| 41 |
+
"""
|
| 42 |
+
return sum(1 for m in messages if m.get("role") == "user")
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_PATH, trust_remote_code=True)
|
| 46 |
+
tokenizer.padding_side = "left"
|
| 47 |
+
if tokenizer.pad_token is None:
|
| 48 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 49 |
+
|
| 50 |
+
with open(INPUT_PATH, 'r', encoding='utf-8') as f:
|
| 51 |
+
data = json.load(f)
|
| 52 |
+
|
| 53 |
+
passed,failed = [],[]
|
| 54 |
+
for item in tqdm(data,desc="filtering)"):
|
| 55 |
+
history = item.get("messages",[])
|
| 56 |
+
responses = []
|
| 57 |
+
if"chosen"in item:
|
| 58 |
+
responses.append(item["chosen"])
|
| 59 |
+
if"rejected"in item:
|
| 60 |
+
responses.append(item["rejected"])
|
| 61 |
+
|
| 62 |
+
turns=count_turns(history)
|
| 63 |
+
token_exceed = False
|
| 64 |
+
for resp in responses:
|
| 65 |
+
txt=format_chat_input(history,resp,tokenizer)
|
| 66 |
+
token_len = len(tokenizer(txt)["input_ids"])
|
| 67 |
+
if token_len > MAX_TOKENS:
|
| 68 |
+
token_exceed = True
|
| 69 |
+
break
|
| 70 |
+
if token_exceed or turns>MAX_TURNS:
|
| 71 |
+
failed.append({
|
| 72 |
+
**item,
|
| 73 |
+
"_filter_reason":{
|
| 74 |
+
"token_exceed":token_exceed,
|
| 75 |
+
"user_turns":turns
|
| 76 |
+
}
|
| 77 |
+
})
|
| 78 |
+
else:
|
| 79 |
+
passed.append(item)
|
| 80 |
+
|
| 81 |
+
with open(PASS_PATH,"w",encoding="utf-8")as f:
|
| 82 |
+
json.dump(passed,f,ensure_ascii=False,indent=2)
|
| 83 |
+
with open(FAIL_PATH,"w",encoding="utf-8")as f:
|
| 84 |
+
json.dump(failed,f,ensure_ascii=False,indent=2)
|
| 85 |
+
|
| 86 |
+
print(f"total:{len(data)}")
|
| 87 |
+
print(f"passed:{len(passed)}")
|
| 88 |
+
print(f"failed:{len(failed)}")
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
script/filter/filter_by_lenth.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# --- 配置 ---
|
| 6 |
+
# ⚠️ 请根据您的实际情况修改以下文件名和模型ID
|
| 7 |
+
INPUT_FILENAME = "/root/test/weitiao/data_processing_hsichen/data_process_bq/result/rm_dpo_infered_8_truncated_replaced_30safe.json" # 👈 替换为您的 DPO 语料文件名
|
| 8 |
+
OUTPUT_FILENAME = "/root/test/weitiao/data_processing_hsichen/data_process_bq/result/rm_dpo_8_truncated_replaced_30safe.json" # 👈 筛选后数据的输出文件名
|
| 9 |
+
MODEL_ID = "mistralai/Mistral-7B-v0.1"
|
| 10 |
+
|
| 11 |
+
# --- 筛选条件 ---
|
| 12 |
+
MIN_TOKENS = 20
|
| 13 |
+
MAX_TOKENS = 76
|
| 14 |
+
|
| 15 |
+
def get_token_length(tokenizer, text):
|
| 16 |
+
"""计算给定文本的 token 长度。"""
|
| 17 |
+
# 使用 return_length=True 来获取长度,但通常直接 len(tokens) 更常见且稳定
|
| 18 |
+
return len(tokenizer.encode(text, add_special_tokens=False))
|
| 19 |
+
|
| 20 |
+
def filter_dataset_by_length(input_file, output_file, model_id, min_len, max_len):
|
| 21 |
+
"""
|
| 22 |
+
读取DPO数据集,并根据 chosen 和 rejected 回复的 token 长度进行筛选。
|
| 23 |
+
"""
|
| 24 |
+
# 检查输入文件是否存在
|
| 25 |
+
if not os.path.exists(input_file):
|
| 26 |
+
print(f"❌ 错误: 输入文件 '{input_file}' 不存在。请检查路径是否正确。")
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
print(f"正在加载 tokenizer: {model_id}...")
|
| 30 |
+
try:
|
| 31 |
+
# 加载用于计算长度的 tokenizer
|
| 32 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 33 |
+
print("Tokenizer 加载完成。")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"❌ 错误: Tokenizer 加载失败。请检查 MODEL_ID 和网络连接。错误: {e}")
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
# 1. 读取数据
|
| 39 |
+
print(f"正在读取数据文件: {input_file}...")
|
| 40 |
+
try:
|
| 41 |
+
with open(input_file, 'r', encoding='utf-8') as f:
|
| 42 |
+
data = json.load(f)
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"❌ 错误: 无法读取或解析文件 '{input_file}'。错误: {e}")
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
filtered_data = []
|
| 48 |
+
dropped_count = 0
|
| 49 |
+
total_count = len(data)
|
| 50 |
+
|
| 51 |
+
print(f"开始筛选语料,总共 {total_count} 条数据...")
|
| 52 |
+
|
| 53 |
+
# 2. 遍历并筛选数据
|
| 54 |
+
for i, item in enumerate(data):
|
| 55 |
+
# 确保数据格式正确
|
| 56 |
+
if "chosen" not in item or "rejected" not in item:
|
| 57 |
+
print(f"⚠️ 警告: 第 {i+1} 条数据缺少 'chosen' 或 'rejected' 键,已丢弃。")
|
| 58 |
+
dropped_count += 1
|
| 59 |
+
continue
|
| 60 |
+
|
| 61 |
+
chosen_text = item["chosen"]["value"]
|
| 62 |
+
rejected_text = item["rejected"]["value"]
|
| 63 |
+
|
| 64 |
+
# 检查 chosen 文本长度
|
| 65 |
+
chosen_len = get_token_length(tokenizer, chosen_text)
|
| 66 |
+
|
| 67 |
+
# 检查 rejected 文本长度
|
| 68 |
+
rejected_len = get_token_length(tokenizer, rejected_text)
|
| 69 |
+
|
| 70 |
+
# 筛选逻辑:chosen 和 rejected 必须同时满足长度要求
|
| 71 |
+
is_chosen_valid = min_len <= chosen_len <= max_len
|
| 72 |
+
is_rejected_valid = min_len <= rejected_len <= max_len
|
| 73 |
+
|
| 74 |
+
if is_chosen_valid and is_rejected_valid:
|
| 75 |
+
filtered_data.append(item)
|
| 76 |
+
else:
|
| 77 |
+
dropped_count += 1
|
| 78 |
+
# 打印丢弃原因,方便调试
|
| 79 |
+
print(f"丢弃第 {i+1} 条数据: Chosen({chosen_len} tokens) / Rejected({rejected_len} tokens)。")
|
| 80 |
+
|
| 81 |
+
# 3. 保存筛选后的数据
|
| 82 |
+
print("\n" + "="*30)
|
| 83 |
+
print("筛选结果统计")
|
| 84 |
+
print("="*30)
|
| 85 |
+
print(f"原始数据总量: {total_count} 条")
|
| 86 |
+
print(f"✅ 保留数据量: {len(filtered_data)} 条")
|
| 87 |
+
print(f"❌ 丢弃数据量: {dropped_count} 条")
|
| 88 |
+
print(f"保留比例: {len(filtered_data) / total_count * 100:.2f}%")
|
| 89 |
+
|
| 90 |
+
if filtered_data:
|
| 91 |
+
try:
|
| 92 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
| 93 |
+
json.dump(filtered_data, f, indent=2, ensure_ascii=False)
|
| 94 |
+
print(f"💾 筛选后的数据已保存到 '{output_file}'。")
|
| 95 |
+
except Exception as e:
|
| 96 |
+
print(f"❌ 错误: 写入输出文件失败。错误: {e}")
|
| 97 |
+
else:
|
| 98 |
+
print("⚠️ 警告: 没有数据符合筛选条件,未生成输出文件。")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
filter_dataset_by_length(INPUT_FILENAME, OUTPUT_FILENAME, MODEL_ID, MIN_TOKENS, MAX_TOKENS)
|
script/filter/filter_by_name_delete.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
from tqdm import tqdm
|
| 4 |
+
|
| 5 |
+
INPUT_FILENAME = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st.json"
|
| 6 |
+
OUTPUT_FILENAME = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st_namdel.json"
|
| 7 |
+
|
| 8 |
+
def fix_all_prefixes(input_file, output_file):
|
| 9 |
+
"""
|
| 10 |
+
修复数据集中 conversations, chosen, 和 rejected 部分中
|
| 11 |
+
human 和 gpt 回答残留的 'Name: ' 等前缀。
|
| 12 |
+
此函数会确保不修改 system 回合。
|
| 13 |
+
"""
|
| 14 |
+
try:
|
| 15 |
+
with open(input_file, 'r', encoding='utf-8') as f:
|
| 16 |
+
data = json.load(f)
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"❌ 错误: 无法读取文件 '{input_file}'. 错误: {e}")
|
| 19 |
+
return
|
| 20 |
+
|
| 21 |
+
fixed_data = []
|
| 22 |
+
total_turns_fixed = 0
|
| 23 |
+
items_affected = 0
|
| 24 |
+
|
| 25 |
+
# 用于匹配 "Name: ", "Character : " 等格式的前缀
|
| 26 |
+
prefix_pattern = re.compile(r"^[\w\s\(\)'-]+\s*:\s*")
|
| 27 |
+
|
| 28 |
+
for item in tqdm(data, desc="修复所有前缀"):
|
| 29 |
+
item_was_affected = False
|
| 30 |
+
|
| 31 |
+
# --- 1. 修复 'conversations' 中的前缀 ---
|
| 32 |
+
conversations = item.get("conversations")
|
| 33 |
+
if conversations and isinstance(conversations, list):
|
| 34 |
+
for turn in conversations:
|
| 35 |
+
# 只对 human 和 gpt 回合进行操作
|
| 36 |
+
if turn.get("from") in ["human", "gpt"]:
|
| 37 |
+
value = turn.get("value", "")
|
| 38 |
+
if isinstance(value, str):
|
| 39 |
+
match = prefix_pattern.match(value)
|
| 40 |
+
if match:
|
| 41 |
+
turn['value'] = value[match.end():].strip()
|
| 42 |
+
total_turns_fixed += 1
|
| 43 |
+
item_was_affected = True
|
| 44 |
+
|
| 45 |
+
# --- 2. 修复 'chosen' 中的前缀 (新增) ---
|
| 46 |
+
chosen_turn = item.get("chosen")
|
| 47 |
+
if chosen_turn and isinstance(chosen_turn, dict) and chosen_turn.get("from") in ["human", "gpt"]:
|
| 48 |
+
value = chosen_turn.get("value", "")
|
| 49 |
+
if isinstance(value, str):
|
| 50 |
+
match = prefix_pattern.match(value)
|
| 51 |
+
if match:
|
| 52 |
+
chosen_turn['value'] = value[match.end():].strip()
|
| 53 |
+
total_turns_fixed += 1
|
| 54 |
+
item_was_affected = True
|
| 55 |
+
|
| 56 |
+
# --- 3. 修复 'rejected' 中的前缀 (新增) ---
|
| 57 |
+
rejected_turn = item.get("rejected")
|
| 58 |
+
if rejected_turn and isinstance(rejected_turn, dict) and rejected_turn.get("from") in ["human", "gpt"]:
|
| 59 |
+
value = rejected_turn.get("value", "")
|
| 60 |
+
if isinstance(value, str):
|
| 61 |
+
match = prefix_pattern.match(value)
|
| 62 |
+
if match:
|
| 63 |
+
rejected_turn['value'] = value[match.end():].strip()
|
| 64 |
+
total_turns_fixed += 1
|
| 65 |
+
item_was_affected = True
|
| 66 |
+
|
| 67 |
+
if item_was_affected:
|
| 68 |
+
items_affected += 1
|
| 69 |
+
|
| 70 |
+
fixed_data.append(item)
|
| 71 |
+
|
| 72 |
+
# 保存修复后的数据
|
| 73 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
| 74 |
+
json.dump(fixed_data, f, indent=2, ensure_ascii=False)
|
| 75 |
+
|
| 76 |
+
print("\n" + "="*20 + " 全面修复完成 " + "="*20)
|
| 77 |
+
print(f"总共处理: {len(data)} 条数据")
|
| 78 |
+
print(f"总共有 {items_affected} 条数据的对话内容被修改。")
|
| 79 |
+
print(f"✅ 成功修复了 'conversations', 'chosen', 'rejected' 中总计 {total_turns_fixed} 个回合的前缀。")
|
| 80 |
+
print(f"💾 修复后的数据已保存到 '{output_file}'。")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
fix_all_prefixes(INPUT_FILENAME, OUTPUT_FILENAME)
|
script/filter/filter_by_number_start.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def contains_digit(text):
|
| 5 |
+
"""
|
| 6 |
+
检查一个字符串的任何位置是否包含数字。
|
| 7 |
+
"""
|
| 8 |
+
if not isinstance(text, str):
|
| 9 |
+
return False
|
| 10 |
+
return any(char.isdigit() for char in text)
|
| 11 |
+
|
| 12 |
+
def starts_with_invalid_character(text):
|
| 13 |
+
"""
|
| 14 |
+
检查字符串在去除空格后,是否以无效字符开头。
|
| 15 |
+
有效开头:字母、星号(*)、双引号(")。
|
| 16 |
+
无效开头:数字、其他符号、标点等。
|
| 17 |
+
"""
|
| 18 |
+
if not isinstance(text, str):
|
| 19 |
+
return False # 非字符串不处理
|
| 20 |
+
|
| 21 |
+
stripped_text = text.strip()
|
| 22 |
+
|
| 23 |
+
if not stripped_text:
|
| 24 |
+
return False # 空字符串视为有效
|
| 25 |
+
|
| 26 |
+
first_char = stripped_text[0]
|
| 27 |
+
|
| 28 |
+
# 如果开头是字母或在允许的符号列表中,则是有效的
|
| 29 |
+
if first_char.isalpha() or first_char in ['*', '"']:
|
| 30 |
+
return False
|
| 31 |
+
|
| 32 |
+
# 其他所有情况(包括数字开头)均视为无效
|
| 33 |
+
return True
|
| 34 |
+
|
| 35 |
+
def process_and_filter_data(input_file_path, output_directory):
|
| 36 |
+
"""
|
| 37 |
+
根据严格的“无数字”和“有效开头”规则,过滤SFT JSON文件,
|
| 38 |
+
并分类保存被移除的数据。
|
| 39 |
+
"""
|
| 40 |
+
# 初始化数据分类列表
|
| 41 |
+
clean_records = []
|
| 42 |
+
dirty_from_conv = []
|
| 43 |
+
dirty_from_chosen = []
|
| 44 |
+
dirty_from_rejected = []
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
with open(input_file_path, 'r', encoding='utf-8') as f:
|
| 48 |
+
data = json.load(f)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
print(f"❌ 错误: 无法读取或解析文件 '{input_file_path}'. 错误详情: {e}")
|
| 51 |
+
return
|
| 52 |
+
|
| 53 |
+
if not isinstance(data, list):
|
| 54 |
+
print(f"❌ 错误: 文件 '{input_file_path}' 的顶层结构不是列表。")
|
| 55 |
+
return
|
| 56 |
+
|
| 57 |
+
# 遍历每一条主数据记录
|
| 58 |
+
for record in data:
|
| 59 |
+
if not isinstance(record, dict):
|
| 60 |
+
continue
|
| 61 |
+
|
| 62 |
+
# 初始化当前记录的问题标志位
|
| 63 |
+
is_dirty_in_conv, is_dirty_in_chosen, is_dirty_in_rejected = False, False, False
|
| 64 |
+
|
| 65 |
+
# --- 检查记录中的所有问题 ---
|
| 66 |
+
# 1. 检查 'conversations'
|
| 67 |
+
if 'conversations' in record and isinstance(record['conversations'], list):
|
| 68 |
+
for turn in record['conversations']:
|
| 69 |
+
if isinstance(turn, dict) and turn.get('from') == 'gpt':
|
| 70 |
+
value = turn.get('value')
|
| 71 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 72 |
+
is_dirty_in_conv = True
|
| 73 |
+
break # 在conversations中发现问题,无需再检查此列表
|
| 74 |
+
|
| 75 |
+
# 2. 检查 'chosen'
|
| 76 |
+
chosen_turn = record.get('chosen')
|
| 77 |
+
if isinstance(chosen_turn, dict) and chosen_turn.get('from') == 'gpt':
|
| 78 |
+
value = chosen_turn.get('value')
|
| 79 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 80 |
+
is_dirty_in_chosen = True
|
| 81 |
+
|
| 82 |
+
# 3. 检查 'rejected'
|
| 83 |
+
rejected_turn = record.get('rejected')
|
| 84 |
+
if isinstance(rejected_turn, dict) and rejected_turn.get('from') == 'gpt':
|
| 85 |
+
value = rejected_turn.get('value')
|
| 86 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 87 |
+
is_dirty_in_rejected = True
|
| 88 |
+
|
| 89 |
+
# --- 分类逻辑 ---
|
| 90 |
+
# 只要任何一个部分有问题,记录就是“不干净”的
|
| 91 |
+
is_dirty = is_dirty_in_conv or is_dirty_in_chosen or is_dirty_in_rejected
|
| 92 |
+
|
| 93 |
+
if not is_dirty:
|
| 94 |
+
clean_records.append(record)
|
| 95 |
+
else:
|
| 96 |
+
# 根据问题出现的位置,将不干净的记录放入对应列表
|
| 97 |
+
if is_dirty_in_conv: dirty_from_conv.append(record)
|
| 98 |
+
if is_dirty_in_chosen: dirty_from_chosen.append(record)
|
| 99 |
+
if is_dirty_in_rejected: dirty_from_rejected.append(record)
|
| 100 |
+
|
| 101 |
+
# --- 文件输出逻辑 ---
|
| 102 |
+
os.makedirs(output_directory, exist_ok=True)
|
| 103 |
+
|
| 104 |
+
output_files = {
|
| 105 |
+
"filtered_clean_data.json": clean_records,
|
| 106 |
+
"dirty_data_from_conversations.json": dirty_from_conv,
|
| 107 |
+
"dirty_data_from_chosen.json": dirty_from_chosen,
|
| 108 |
+
"dirty_data_from_rejected.json": dirty_from_rejected
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
print("="*60)
|
| 112 |
+
print(f"数据清洗与过滤报告 (输出目录: '{output_directory}')")
|
| 113 |
+
print("="*60)
|
| 114 |
+
print(f"原始数据总数: {len(data)} 条")
|
| 115 |
+
|
| 116 |
+
for filename, data_to_write in output_files.items():
|
| 117 |
+
output_path = os.path.join(output_directory, filename)
|
| 118 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
| 119 |
+
json.dump(data_to_write, f, indent=4, ensure_ascii=False)
|
| 120 |
+
print(f"已生成文件: {filename:<40} (包含 {len(data_to_write)} 条记录)")
|
| 121 |
+
|
| 122 |
+
print("="*60)
|
| 123 |
+
print("✅ 所有文件已处理完毕!")
|
| 124 |
+
print("="*60)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
|
| 129 |
+
input_file = "/root/test/weitiao/data_process_bq/data/data3/sharegpt_h1_nam_num_nhh_len_hard.json"
|
| 130 |
+
output_dir = "/root/test/weitiao/data_process_bq/data/data3/sharegpt_h1_nam_num_nhh_len_hard2.json"
|
| 131 |
+
|
| 132 |
+
# 执行主函数
|
| 133 |
+
process_and_filter_data(input_file, output_dir)
|
script/filter/filter_by_number_start_rejonly.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def contains_digit(text):
|
| 5 |
+
"""
|
| 6 |
+
检查一个字符串的任何位置是否包含数字。
|
| 7 |
+
"""
|
| 8 |
+
if not isinstance(text, str):
|
| 9 |
+
return False
|
| 10 |
+
return any(char.isdigit() for char in text)
|
| 11 |
+
|
| 12 |
+
def starts_with_invalid_character(text):
|
| 13 |
+
"""
|
| 14 |
+
检查字符串在去除空格后,是否以无效字符开头。
|
| 15 |
+
有效开头:字母、星号(*)、双引号(")。
|
| 16 |
+
无效开头:数字、其他符号、标点等。
|
| 17 |
+
"""
|
| 18 |
+
if not isinstance(text, str):
|
| 19 |
+
return False # 非字符串不处理
|
| 20 |
+
|
| 21 |
+
stripped_text = text.strip()
|
| 22 |
+
|
| 23 |
+
if not stripped_text:
|
| 24 |
+
return False # 空字符串视为有效
|
| 25 |
+
|
| 26 |
+
first_char = stripped_text[0]
|
| 27 |
+
|
| 28 |
+
# 如果开头是字母或在允许的符号列表中,则是有效的
|
| 29 |
+
if first_char.isalpha() or first_char in['*', '"']:
|
| 30 |
+
return False
|
| 31 |
+
|
| 32 |
+
# 其他所有情况(包括数字开头)均视为无效
|
| 33 |
+
return True
|
| 34 |
+
|
| 35 |
+
def process_and_filter_data(input_file_path, output_directory):
|
| 36 |
+
"""
|
| 37 |
+
根据严格的“无数字”和“有效开头”规则,专门筛选出:
|
| 38 |
+
rejected 中存在非法,且 chosen 和 conversations 中没有任何非法的语料。
|
| 39 |
+
"""
|
| 40 |
+
# 初始化目标数据列表
|
| 41 |
+
target_records =[]
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
with open(input_file_path, 'r', encoding='utf-8') as f:
|
| 45 |
+
data = json.load(f)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"❌ 错误: 无法读取或解析文件 '{input_file_path}'. 错误详情: {e}")
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
if not isinstance(data, list):
|
| 51 |
+
print(f"❌ 错误: 文件 '{input_file_path}' 的顶层结构不是列表。")
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
# 遍历每一条主数据记录
|
| 55 |
+
for record in data:
|
| 56 |
+
if not isinstance(record, dict):
|
| 57 |
+
continue
|
| 58 |
+
|
| 59 |
+
# 初始化当前记录的问题标志位
|
| 60 |
+
is_dirty_in_conv, is_dirty_in_chosen, is_dirty_in_rejected = False, False, False
|
| 61 |
+
|
| 62 |
+
# --- 检查记录中的所有问题 ---
|
| 63 |
+
# 1. 检查 'conversations'
|
| 64 |
+
if 'conversations' in record and isinstance(record['conversations'], list):
|
| 65 |
+
for turn in record['conversations']:
|
| 66 |
+
if isinstance(turn, dict) and turn.get('from') == 'gpt':
|
| 67 |
+
value = turn.get('value')
|
| 68 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 69 |
+
is_dirty_in_conv = True
|
| 70 |
+
break # 在conversations中发现问题,无需再检查此列表
|
| 71 |
+
|
| 72 |
+
# 2. 检查 'chosen'
|
| 73 |
+
chosen_turn = record.get('chosen')
|
| 74 |
+
if isinstance(chosen_turn, dict) and chosen_turn.get('from') == 'gpt':
|
| 75 |
+
value = chosen_turn.get('value')
|
| 76 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 77 |
+
is_dirty_in_chosen = True
|
| 78 |
+
|
| 79 |
+
# 3. 检查 'rejected'
|
| 80 |
+
rejected_turn = record.get('rejected')
|
| 81 |
+
if isinstance(rejected_turn, dict) and rejected_turn.get('from') == 'gpt':
|
| 82 |
+
value = rejected_turn.get('value')
|
| 83 |
+
if contains_digit(value) or starts_with_invalid_character(value):
|
| 84 |
+
is_dirty_in_rejected = True
|
| 85 |
+
|
| 86 |
+
# --- 分类逻辑 ---
|
| 87 |
+
# 核心修改:只筛选 rejected 出现非法,但是 chosen 和 conversation 里面没有非法的这部分语料
|
| 88 |
+
if is_dirty_in_rejected and not is_dirty_in_chosen and not is_dirty_in_conv:
|
| 89 |
+
target_records.append(record)
|
| 90 |
+
|
| 91 |
+
# --- 文件输出逻辑 ---
|
| 92 |
+
os.makedirs(output_directory, exist_ok=True)
|
| 93 |
+
|
| 94 |
+
output_files = {
|
| 95 |
+
"dirty_only_in_rejected.json": target_records
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
print("="*60)
|
| 99 |
+
print(f"数据清洗与过滤报告 (输出目录: '{output_directory}')")
|
| 100 |
+
print("="*60)
|
| 101 |
+
print(f"原始数据总数: {len(data)} 条")
|
| 102 |
+
|
| 103 |
+
for filename, data_to_write in output_files.items():
|
| 104 |
+
output_path = os.path.join(output_directory, filename)
|
| 105 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
| 106 |
+
json.dump(data_to_write, f, indent=4, ensure_ascii=False)
|
| 107 |
+
print(f"已生成文件: {filename:<40} (包含 {len(data_to_write)} 条记录)")
|
| 108 |
+
|
| 109 |
+
print("="*60)
|
| 110 |
+
print("✅ 专项筛选已处理完毕!")
|
| 111 |
+
print("="*60)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
if __name__ == "__main__":
|
| 115 |
+
|
| 116 |
+
# 注意:根据原代码,这里 output_dir 实际上应该是一个“目录名”而不是“文件名”,
|
| 117 |
+
# 因为函数内是用 os.makedirs 创建文件夹,并在其内部保存 json的。
|
| 118 |
+
input_file = "/root/test/weitiao/data_process_bq/data/data3/sharegpt_h1_nam_num_nhh_len_hard2.json/dirty_data_from_rejected.json"
|
| 119 |
+
output_dir = "/root/test/weitiao/data_process_bq/data/data3/sharegpt_h1_nam_num_nhh_len_hard2.json/filtered_by_rejected_only"
|
| 120 |
+
|
| 121 |
+
# 执行主函数
|
| 122 |
+
process_and_filter_data(input_file, output_dir)
|
script/filter/filter_by_quota.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
data = json.load(open("/root/test/weitiao/data_processing_hsichen/data_process_bq/data/merged_rm_dpo_scored.json"))
|
| 7 |
+
target_file_path = '/root/test/weitiao/data_processing_hsichen/data_process_bq/data/rm_dpo_scored_quota_filtered.json'
|
| 8 |
+
|
| 9 |
+
#这里改成5w
|
| 10 |
+
output_data = []
|
| 11 |
+
for sample in tqdm(data,total=len(data)):
|
| 12 |
+
chosen_value = sample['chosen_quota_score']
|
| 13 |
+
rejected_value = sample['rejected_quota_score']
|
| 14 |
+
|
| 15 |
+
if chosen_value - rejected_value < 0 or chosen_value < 3 or rejected_value < 3:
|
| 16 |
+
continue
|
| 17 |
+
output_data.append(sample)
|
| 18 |
+
|
| 19 |
+
with open(target_file_path, 'w', encoding='utf-8') as f:
|
| 20 |
+
json.dump(output_data, f, indent=2)
|
| 21 |
+
print(f"Filtered data saved to {target_file_path}, total {len(output_data)} samples.")
|
| 22 |
+
|
script/filter/first_human.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
INPUT_PATH = "/root/test/weitiao/data_process_bq/data/sharegpt_all.json"
|
| 4 |
+
OUTPUT_PATH = "/root/test/weitiao/data_process_bq/data/sharegpt_human1st.json"
|
| 5 |
+
|
| 6 |
+
def process_conversations(convs):
|
| 7 |
+
new_convs = []
|
| 8 |
+
first_gpt_removed = False
|
| 9 |
+
|
| 10 |
+
# ① 删除第一条 gpt
|
| 11 |
+
for msg in convs:
|
| 12 |
+
if msg["from"] == "gpt" and not first_gpt_removed:
|
| 13 |
+
first_gpt_removed = True
|
| 14 |
+
continue
|
| 15 |
+
new_convs.append(msg)
|
| 16 |
+
|
| 17 |
+
# ② 如果最后一句是 gpt,再删掉
|
| 18 |
+
if new_convs and new_convs[-1]["from"] == "gpt":
|
| 19 |
+
new_convs = new_convs[:-1]
|
| 20 |
+
|
| 21 |
+
return new_convs
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
with open(INPUT_PATH, "r", encoding="utf-8") as f:
|
| 26 |
+
data = json.load(f)
|
| 27 |
+
|
| 28 |
+
for item in data:
|
| 29 |
+
item["conversations"] = process_conversations(item["conversations"])
|
| 30 |
+
|
| 31 |
+
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
|
| 32 |
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
main()
|
script/filter/rm_filter_by_30safe.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import random
|
| 3 |
+
import os
|
| 4 |
+
from typing import List, Dict, Any
|
| 5 |
+
|
| 6 |
+
# =========================
|
| 7 |
+
# 配置
|
| 8 |
+
# =========================
|
| 9 |
+
# 原始 JSON 语料文件路径 (请根据您的实际文件路径修改)
|
| 10 |
+
INPUT_FILE = "/root/test/weitiao/data_processing_hsichen/data_process_bq/result/high_chosen_reward_safety_8_quadrants_labeled/merged.json"
|
| 11 |
+
|
| 12 |
+
# 过滤并丢弃部分语料后的输出文件路径
|
| 13 |
+
OUTPUT_FILE = "/root/test/weitiao/data_processing_hsichen/data_process_bq/result/rm_dpo_infered_8_truncated_replaced_30safe.json"
|
| 14 |
+
|
| 15 |
+
# 定义不安全语料的丢弃比例 (30%)
|
| 16 |
+
DISCARD_PERCENTAGE = 0.70
|
| 17 |
+
|
| 18 |
+
# 定义判定为不安全的标签
|
| 19 |
+
UNSAFE_LABEL = "Sexual Content"
|
| 20 |
+
|
| 21 |
+
# =========================
|
| 22 |
+
# 主处理函数
|
| 23 |
+
# =========================
|
| 24 |
+
|
| 25 |
+
def filter_and_discard_unsafe_data(input_path: str, output_path: str, discard_ratio: float, unsafe_label: str):
|
| 26 |
+
"""
|
| 27 |
+
读取语料文件,根据 safety_analysis 字段中的标签判断 unsafe,
|
| 28 |
+
随机丢弃指定比例的 unsafe 语料,并保存剩余数据。
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
# 1. 读取输入文件
|
| 32 |
+
print(f"🚀 正在读取输入文件: {input_path}")
|
| 33 |
+
try:
|
| 34 |
+
with open(input_path, 'r', encoding='utf-8') as f:
|
| 35 |
+
data: List[Dict[str, Any]] = json.load(f)
|
| 36 |
+
except FileNotFoundError:
|
| 37 |
+
print(f"❌ 错误: 输入文件 '{input_path}' 未找到。")
|
| 38 |
+
return
|
| 39 |
+
except json.JSONDecodeError:
|
| 40 |
+
print(f"❌ 错误: 输入文件 '{input_path}' 不是有效的 JSON 格式。")
|
| 41 |
+
return
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"❌ 错误: 读取文件时发生未知错误: {e}")
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
total_count = len(data)
|
| 47 |
+
print(f"文件加载成功,总计 {total_count} 条语料。")
|
| 48 |
+
|
| 49 |
+
# 2. 分类 safe 和 unsafe 语料
|
| 50 |
+
safe_data: List[Dict[str, Any]] = []
|
| 51 |
+
unsafe_data: List[Dict[str, Any]] = []
|
| 52 |
+
|
| 53 |
+
for item in data:
|
| 54 |
+
is_unsafe = False
|
| 55 |
+
|
| 56 |
+
# 检查 safety_analysis 字段是否存在
|
| 57 |
+
if "safety_analysis" in item:
|
| 58 |
+
analysis = item["safety_analysis"]
|
| 59 |
+
|
| 60 |
+
# 检查 chosen_labels
|
| 61 |
+
chosen_labels = analysis.get("chosen_labels", [])
|
| 62 |
+
if unsafe_label in chosen_labels:
|
| 63 |
+
is_unsafe = True
|
| 64 |
+
|
| 65 |
+
# 检查 rejected_labels
|
| 66 |
+
rejected_labels = analysis.get("rejected_labels", [])
|
| 67 |
+
if unsafe_label in rejected_labels:
|
| 68 |
+
is_unsafe = True
|
| 69 |
+
|
| 70 |
+
if is_unsafe:
|
| 71 |
+
unsafe_data.append(item)
|
| 72 |
+
else:
|
| 73 |
+
safe_data.append(item)
|
| 74 |
+
|
| 75 |
+
unsafe_count = len(unsafe_data)
|
| 76 |
+
safe_count = len(safe_data)
|
| 77 |
+
print(f"\n分类结果:")
|
| 78 |
+
print(f" - 标记为 UNSAFE 的语料: {unsafe_count} 条")
|
| 79 |
+
print(f" - 标记为 SAFE 的语料: {safe_count} 条")
|
| 80 |
+
|
| 81 |
+
# 3. 随机丢弃指定比例的 unsafe 语料
|
| 82 |
+
num_to_discard = int(unsafe_count * discard_ratio)
|
| 83 |
+
|
| 84 |
+
# 使用 random.sample 从 unsafe_data 中抽取需要丢弃的样本
|
| 85 |
+
# random.sample(population, k) 从序列中不重复地抽取 k 个元素
|
| 86 |
+
samples_to_keep = unsafe_data
|
| 87 |
+
if num_to_discard > 0:
|
| 88 |
+
num_to_keep = unsafe_count - num_to_discard
|
| 89 |
+
# 随机抽取要保留的样本
|
| 90 |
+
samples_to_keep = random.sample(unsafe_data, num_to_keep)
|
| 91 |
+
|
| 92 |
+
discarded_count = unsafe_count - len(samples_to_keep)
|
| 93 |
+
|
| 94 |
+
print(f"\n丢弃处理 (比例: {discard_ratio * 100}%)")
|
| 95 |
+
print(f" - 计划丢弃数量: {num_to_discard} 条")
|
| 96 |
+
print(f" - 实际丢弃数量: {discarded_count} 条")
|
| 97 |
+
|
| 98 |
+
# 4. 合并保留的语料并保存
|
| 99 |
+
final_data = safe_data + samples_to_keep
|
| 100 |
+
final_count = len(final_data)
|
| 101 |
+
|
| 102 |
+
print(f"\n最终语料集总数: {final_count} 条 (总数 {total_count} - 丢弃 {discarded_count})")
|
| 103 |
+
|
| 104 |
+
# 确保输出目录存在
|
| 105 |
+
output_dir = os.path.dirname(output_path)
|
| 106 |
+
if output_dir and not os.path.exists(output_dir):
|
| 107 |
+
os.makedirs(output_dir)
|
| 108 |
+
|
| 109 |
+
# 写入最终的 JSON 文件
|
| 110 |
+
try:
|
| 111 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
| 112 |
+
# 使用 indent=2 和 ensure_ascii=False 保持格式美观且支持中文
|
| 113 |
+
json.dump(final_data, f, indent=2, ensure_ascii=False)
|
| 114 |
+
print(f"🎉 成功保存过滤后的语料到: {output_path}")
|
| 115 |
+
except Exception as e:
|
| 116 |
+
print(f"❌ 错误: 写入输出文件时发生错误: {e}")
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
# 确保随机性
|
| 121 |
+
random.seed()
|
| 122 |
+
filter_and_discard_unsafe_data(INPUT_FILE, OUTPUT_FILE, DISCARD_PERCENTAGE, UNSAFE_LABEL)
|
script/format_trans/chatml2sharegpt.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
# ===== 路径配置 =====
|
| 5 |
+
INPUT_PATH = "/root/test/weitiao/data_process_bq/data/train01_chatml_closed_length2048turns20_replaced.json"
|
| 6 |
+
OUTPUT_PATH = "/root/test/weitiao/data_process_bq/data/train01_sharegpt_closed_length_replaced.json"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def convert_one_sample(sample):
|
| 10 |
+
conversations = []
|
| 11 |
+
|
| 12 |
+
for msg in sample.get("messages", []):
|
| 13 |
+
role = msg.get("role")
|
| 14 |
+
content = msg.get("content", "")
|
| 15 |
+
|
| 16 |
+
if role == "user":
|
| 17 |
+
conversations.append({
|
| 18 |
+
"from": "human",
|
| 19 |
+
"value": content
|
| 20 |
+
})
|
| 21 |
+
elif role == "assistant":
|
| 22 |
+
conversations.append({
|
| 23 |
+
"from": "gpt",
|
| 24 |
+
"value": content
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
elif role == "system":
|
| 28 |
+
conversations.append({
|
| 29 |
+
"from": "system",
|
| 30 |
+
"value": content
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
def convert_choice(choice_list):
|
| 34 |
+
if not choice_list:
|
| 35 |
+
return None
|
| 36 |
+
choice = choice_list[0]
|
| 37 |
+
return {
|
| 38 |
+
"from": "gpt",
|
| 39 |
+
"value": choice.get("content", "")
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
return {
|
| 43 |
+
"conversations": conversations,
|
| 44 |
+
"chosen": convert_choice(sample.get("chosen", [])),
|
| 45 |
+
"rejected": convert_choice(sample.get("rejected", []))
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def main():
|
| 50 |
+
with open(INPUT_PATH, "r", encoding="utf-8") as f:
|
| 51 |
+
data = json.load(f)
|
| 52 |
+
|
| 53 |
+
assert isinstance(data, list), "输入 JSON 顶层必须是 list"
|
| 54 |
+
|
| 55 |
+
converted = []
|
| 56 |
+
for idx, sample in enumerate(data):
|
| 57 |
+
try:
|
| 58 |
+
converted.append(convert_one_sample(sample))
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f"[WARN] 第 {idx} 条样本转换失败: {e}")
|
| 61 |
+
|
| 62 |
+
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
|
| 63 |
+
json.dump(converted, f, ensure_ascii=False, indent=2)
|
| 64 |
+
|
| 65 |
+
print(f"转换完成,共 {len(converted)} 条")
|
| 66 |
+
print(f"输出路径:{OUTPUT_PATH}")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
main()
|
script/format_trans/chatml_p2r.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
input_file = "/root/test/weitiao/data_process_bq/data/train01_chatml_closed_length2048turns20.json"
|
| 5 |
+
output_file = "/root/test/weitiao/data_process_bq/data/train01_p2r_closed_length2048turns20.json"
|
| 6 |
+
|
| 7 |
+
with open(input_file, 'r', encoding='utf-8') as f:
|
| 8 |
+
data = json.load(f)
|
| 9 |
+
|
| 10 |
+
processed_data = []
|
| 11 |
+
|
| 12 |
+
for item in data:
|
| 13 |
+
history = item.get('messages', [])
|
| 14 |
+
old_chosen = item.get('chosen', [])
|
| 15 |
+
old_rejected = item.get('rejected', [])
|
| 16 |
+
|
| 17 |
+
new_chosen = history + old_chosen
|
| 18 |
+
new_rejected = history + old_rejected
|
| 19 |
+
|
| 20 |
+
new_item = {
|
| 21 |
+
"chosen": new_chosen,
|
| 22 |
+
"rejected": new_rejected
|
| 23 |
+
}
|
| 24 |
+
processed_data.append(new_item)
|
| 25 |
+
|
| 26 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
| 27 |
+
json.dump(processed_data, f, ensure_ascii=False, indent=2)
|
| 28 |
+
|
| 29 |
+
print(f"done, {len(processed_data)} items")
|