Add files using upload-large-folder tool
Browse files- README.md +200 -0
- data/OneReason_General/_SUCCESS +0 -0
- data/OneReason_Pid2Caption/_SUCCESS +0 -0
- data/OneReason_Pid2Sid/_SUCCESS +0 -0
- data/OneReason_Pid2Tag/_SUCCESS +0 -0
- data/OneReason_Pid2Tag/part-00000.parquet +3 -0
- data/OneReason_Pid2Tag/part-00001.parquet +3 -0
- data/OneReason_Pid2Tag/part-00002.parquet +3 -0
- data/OneReason_Pid2Tag/part-00004.parquet +3 -0
- data/OneReason_Pid2Tag/part-00005.parquet +3 -0
- data/OneReason_Pid2Tag/part-00008.parquet +3 -0
- data/OneReason_Pid2Tag/part-00009.parquet +3 -0
- data/OneReason_Pid2Tag/part-00010.parquet +3 -0
- data/OneReason_Pid2Tag/part-00011.parquet +3 -0
- data/OneReason_Pid2Tag/part-00012.parquet +3 -0
- data/OneReason_Pid2Tag/part-00013.parquet +3 -0
- data/OneReason_Pid2Tag/part-00014.parquet +3 -0
- data/OneReason_Pid2Tag/part-00015.parquet +3 -0
- data/OneReason_Pid2Tag/part-00016.parquet +3 -0
- data/OneReason_Pid2Tag/part-00017.parquet +3 -0
- data/OneReason_Pid2Tag/part-00018.parquet +3 -0
- data/OneReason_Pid2Tag/part-00019.parquet +3 -0
- data/OneReason_Pid2Tag/part-00020.parquet +3 -0
- data/OneReason_Pid2Tag/part-00021.parquet +3 -0
- data/OneReason_Pid2Tag/part-00024.parquet +3 -0
- data/OneReason_Pid2Tag/part-00025.parquet +3 -0
- data/OneReason_Pid2Tag/part-00026.parquet +3 -0
- data/OneReason_Pid2Tag/part-00027.parquet +3 -0
- data/OneReason_Pid2Tag/part-00028.parquet +3 -0
- data/OneReason_Pid2Tag/part-00029.parquet +3 -0
- data/OneReason_Pid2Tag/part-00030.parquet +3 -0
- data/OneReason_UserProfile/_SUCCESS +0 -0
- data/OneReason_UserProfile/part-00000.parquet +3 -0
- data/OneReason_UserProfile/part-00001.parquet +3 -0
- data/OneReason_UserProfile/part-00003.parquet +3 -0
- data/OneReason_UserProfile/part-00006.parquet +3 -0
- data/OneReason_UserProfile/part-00007.parquet +3 -0
- data/OneReason_UserProfile/part-00008.parquet +3 -0
- data/OneReason_UserProfile/part-00009.parquet +3 -0
- demo/README.md +69 -0
- demo/baseline-data/baseline_data/sampled/sampled.parquet +3 -0
- demo/config/demo.yaml +45 -0
- demo/convert_jsonl.py +106 -0
- demo/convertv2.py +411 -0
- demo/data/data_final.jsonl +10 -0
- demo/scripts/00_install.sh +74 -0
- demo/scripts/01_convert_data.sh +26 -0
- demo/scripts/02_register_dataset.py +30 -0
- demo/scripts/03_train.sh +21 -0
- demo/scripts/run_all.sh +8 -0
README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Explorer_LLM_Rec_Competition
|
| 2 |
+
|
| 3 |
+
This dataset contains user historical behaviors and content metadata, constructed from real user interaction histories. It covers behavior sequences across multiple domains for a single user and supports cross-domain recommendation, semantic-ID retrieval / generation, content understanding, and related tasks.
|
| 4 |
+
|
| 5 |
+
## Files
|
| 6 |
+
|
| 7 |
+
| File | Description |
|
| 8 |
+
|------|-------------|
|
| 9 |
+
| `OneReason_UserProfile/` | Per-user multi-domain behavior records (~500k rows) |
|
| 10 |
+
| `OneReason_Pid2Sid/` | Mapping from content PID to three-segment semantic ID |
|
| 11 |
+
| `OneReason_Pid2Caption/` | Mapping from content PID to text caption |
|
| 12 |
+
| `OneReason_Pid2Tag/` | Mapping from content PID to level-3 category tag |
|
| 13 |
+
| `OneReason_General/` | General knowledge data |
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Anonymization & Join Rules
|
| 18 |
+
|
| 19 |
+
- All `pid` / item id / author id / live id are hashed `int64` values.
|
| 20 |
+
- The user table contains no `uid`; each row is an anonymous user sample.
|
| 21 |
+
- Hashed item ids join the three item-metadata tables via `(domain, pid)`.
|
| 22 |
+
- Regular videos and ads both come from the video system, distinguished by `domain`:
|
| 23 |
+
- Regular video: `video/video`
|
| 24 |
+
- Ad: `video/ad`
|
| 25 |
+
- Some users' video-watch sequences also contain ads.
|
| 26 |
+
|
| 27 |
+
## Domain Values
|
| 28 |
+
|
| 29 |
+
| Domain | Meaning | Associated user fields | Token prefix |
|
| 30 |
+
|--------|---------|------------------------|--------------|
|
| 31 |
+
| `video/video` | Regular short videos | `video_*`, `video_history_*` | `<\|video_begin\|>` |
|
| 32 |
+
| `video/ad` | Ads / outer-loop content | `outer_loop_*` | `<\|ad_begin\|>` |
|
| 33 |
+
| `goods` | E-commerce products | `ec_*` | `<\|prod_begin\|>` |
|
| 34 |
+
| `live` | Live-streaming hosts | `live_hist_author_id_list` | `<\|living_begin\|>` |
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## OneReason_Pid2Sid
|
| 39 |
+
|
| 40 |
+
Semantic-ID mapping table. Converts a content ID into a three-segment semantic ID.
|
| 41 |
+
|
| 42 |
+
| Field | Type | Description |
|
| 43 |
+
|-------|------|-------------|
|
| 44 |
+
| `pid` | int64 | Hashed content / product / host ID |
|
| 45 |
+
| `domain` | string | Domain of the content (see Domain Values) |
|
| 46 |
+
| `sid_three` | list[float] | Three-segment semantic ID `[s_a, s_b, s_c]` |
|
| 47 |
+
|
| 48 |
+
Token concatenation example:
|
| 49 |
+
|
| 50 |
+
```text
|
| 51 |
+
video/video: <|video_begin|><s_a_123><s_b_456><s_c_789>
|
| 52 |
+
video/ad: <|ad_begin|><s_a_123><s_b_456><s_c_789>
|
| 53 |
+
goods: <|prod_begin|><s_a_123><s_b_456><s_c_789>
|
| 54 |
+
live: <|living_begin|><s_a_123><s_b_456><s_c_789>
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## OneReason_Pid2Caption
|
| 58 |
+
|
| 59 |
+
Lookup of a content's text description by hashed PID.
|
| 60 |
+
|
| 61 |
+
| Field | Type | Description |
|
| 62 |
+
|-------|------|-------------|
|
| 63 |
+
| `pid` | int64 | Hashed content / product / host ID |
|
| 64 |
+
| `domain` | string | Domain of the content (see Domain Values) |
|
| 65 |
+
| `caption` | string | Content description, or stringified list of description tags |
|
| 66 |
+
|
| 67 |
+
## OneReason_Pid2Tag
|
| 68 |
+
|
| 69 |
+
Level-3 category tag for video, ad, and live content.
|
| 70 |
+
|
| 71 |
+
| Field | Type | Description |
|
| 72 |
+
|-------|------|-------------|
|
| 73 |
+
| `pid` | int64 | Hashed content / host ID |
|
| 74 |
+
| `domain` | string | Domain; currently `video/video`, `video/ad`, `live` |
|
| 75 |
+
| `tag_lv3` | string | Level-3 category tag |
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## OneReason_UserProfile
|
| 80 |
+
|
| 81 |
+
Each row is an anonymous user-profile sample containing behavior sequences from e-commerce, short-video, live-streaming, and ad domains.
|
| 82 |
+
|
| 83 |
+
### Sequence Alignment Rules
|
| 84 |
+
|
| 85 |
+
`user_history` fields are grouped into 4 domains. Each domain has one or more **primary sequences (pid / ID sequences)**, and every primary sequence is paired with a set of **aligned feature sequences** of identical length. If both a primary sequence and its aligned feature sequences are `null`, the user has no behavior in that domain.
|
| 86 |
+
|
| 87 |
+
#### `video/video` (short video)
|
| 88 |
+
|
| 89 |
+
| Primary sequence | Aligned feature sequences |
|
| 90 |
+
|------------------|---------------------------|
|
| 91 |
+
| `video_sampled_pid_list` | `video_neg_feedback_list`, `video_like_list`, `video_comment_list`, `video_forward_list`, `video_collect_list`, `video_watch_time_list`, `video_play_done_list`, `video_duration_list`, `video_ts_list` |
|
| 92 |
+
| `video_history_sampled_pid_list` | `video_history_neg_feedback_list`, `video_history_like_list`, `video_history_comment_list`, `video_history_forward_list`, `video_history_collect_list`, `video_history_watch_time_list`, `video_history_play_done_list`, `video_history_duration_list`, `video_history_ts_list` |
|
| 93 |
+
|
| 94 |
+
#### `video/ad` (ads / outer-loop)
|
| 95 |
+
|
| 96 |
+
| Primary sequence | Aligned feature sequences |
|
| 97 |
+
|------------------|---------------------------|
|
| 98 |
+
| `outer_loop_history_action_pid_list_pos` | `outer_loop_history_action_pid_list_pos_ts` |
|
| 99 |
+
| `outer_loop_history_action_pid_list_click` | `outer_loop_history_action_pid_list_click_ts`, `outer_loop_history_action_pid_list_click_type`, `outer_loop_history_action_pid_list_click_industry` |
|
| 100 |
+
| `outer_loop_deep_target_pid` | `outer_loop_deep_target_pid_ts` |
|
| 101 |
+
|
| 102 |
+
#### `goods` (e-commerce)
|
| 103 |
+
|
| 104 |
+
| Primary sequence | Aligned feature sequences |
|
| 105 |
+
|------------------|---------------------------|
|
| 106 |
+
| `ec_item_id_list` | `ec_cvr_label_list`, `ec_time_ms_list` |
|
| 107 |
+
| `ec_good_click_item_id_list_extend` | `ec_trunc_clk_lag` |
|
| 108 |
+
| `ec_good_order_item_id_list_extend` | `ec_trunc_buy_lag` |
|
| 109 |
+
| `ec_colossus_rs_item_id_list` | `ec_colossus_rs_lagv1_list`, `ec_colossus_rs_lagv2_list`, `ec_colossus_rs_is_click_list`, `ec_colossus_rs_is_cart_list`, `ec_colossus_rs_is_buy_list` |
|
| 110 |
+
|
| 111 |
+
#### `live` (live-streaming)
|
| 112 |
+
|
| 113 |
+
| Primary sequence | Aligned feature sequences |
|
| 114 |
+
|------------------|---------------------------|
|
| 115 |
+
| `live_hist_author_id_list` | `live_hist_timestamp_list`, `live_hist_live_id_list`, `live_hist_show_cnt_list`, `live_hist_play_cnt_list`, `live_hist_valid_play_cnt_list`, `live_hist_play_duration_list`, `live_hist_valid_play_duration_list`, `live_hist_like_cnt_list`, `live_hist_comment_cnt_list`, `live_hist_reduce_similar_cnt_list`, `live_hist_report_live_cnt_list`, `live_hist_author_category_type_list`, `live_hist_author_type_list`, `live_hist_is_interactive_mp_live_list`, `live_hist_is_building_live_list`, `live_hist_is_local_life_live_list`, `live_hist_is_detect_game_live_list`, `live_hist_is_recruit_live_list`, `live_hist_follow_author_cnt_list` |
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
### E-commerce Fields
|
| 120 |
+
|
| 121 |
+
| Field | Type | Description |
|
| 122 |
+
|-------|------|-------------|
|
| 123 |
+
| `ec_item_id_list` | list[int64] | E-commerce item ID sequence |
|
| 124 |
+
| `ec_cvr_label_list` | list[int64] | Conversion label aligned with `ec_item_id_list` |
|
| 125 |
+
| `ec_time_ms_list` | list[int64] | Absolute timestamp (ms) aligned with `ec_item_id_list` |
|
| 126 |
+
| `ec_colossus_rs_item_id_list` | list[int64] | Recently shown e-commerce item ID sequence |
|
| 127 |
+
| `ec_colossus_rs_lagv1_list` | list[int64] | Hour-level lag of `ec_colossus_rs_item_id_list` relative to `ec_time_ms` |
|
| 128 |
+
| `ec_colossus_rs_lagv2_list` | list[int64] | Supplementary hour-level lag of `ec_colossus_rs_item_id_list` relative to `ec_time_ms` |
|
| 129 |
+
| `ec_colossus_rs_is_click_list` | list[int64] | Click flag for each recently shown item (0/1) |
|
| 130 |
+
| `ec_colossus_rs_is_cart_list` | list[int64] | Add-to-cart flag for each recently shown item (0/1) |
|
| 131 |
+
| `ec_colossus_rs_is_buy_list` | list[int64] | Purchase flag for each recently shown item (0/1) |
|
| 132 |
+
| `ec_good_click_item_id_list_extend` | list[int64] | Recently clicked e-commerce item ID sequence |
|
| 133 |
+
| `ec_trunc_clk_lag` | list[int64] | Hour-level lag of `ec_good_click_item_id_list_extend` relative to `ec_time_ms` |
|
| 134 |
+
| `ec_good_order_item_id_list_extend` | list[int64] | Recently purchased e-commerce item ID sequence |
|
| 135 |
+
| `ec_trunc_buy_lag` | list[int64] | Hour-level lag of `ec_good_order_item_id_list_extend` relative to `ec_time_ms` |
|
| 136 |
+
| `ec_time_ms` | int64 | Snapshot time when e-commerce features were captured |
|
| 137 |
+
|
| 138 |
+
### Short Video Fields
|
| 139 |
+
|
| 140 |
+
| Field | Type | Description |
|
| 141 |
+
|-------|------|-------------|
|
| 142 |
+
| `video_sampled_pid_list` | list[int64] | Currently clicked short-video ID sequence |
|
| 143 |
+
| `video_neg_feedback_list` | list[float] | Negative-feedback flag for currently clicked videos (0/1) |
|
| 144 |
+
| `video_like_list` | list[float] | Like flag for currently clicked videos (0/1) |
|
| 145 |
+
| `video_comment_list` | list[float] | Comment flag for currently clicked videos (0/1) |
|
| 146 |
+
| `video_forward_list` | list[float] | Forward / share flag for currently clicked videos (0/1) |
|
| 147 |
+
| `video_collect_list` | list[float] | Collect flag for currently clicked videos (0/1) |
|
| 148 |
+
| `video_watch_time_list` | list[float] | Watch time for currently clicked videos |
|
| 149 |
+
| `video_play_done_list` | list[float] | Play-done (full-watch) flag for currently clicked videos (0/1) |
|
| 150 |
+
| `video_duration_list` | list[float] | Duration of currently clicked videos |
|
| 151 |
+
| `video_ts_list` | list[int64] | Absolute timestamp of currently clicked videos |
|
| 152 |
+
| `video_history_sampled_pid_list` | list[int64] | Historical shown short-video ID sequence |
|
| 153 |
+
| `video_history_neg_feedback_list` | list[float] | Negative-feedback flag for historical videos (0/1) |
|
| 154 |
+
| `video_history_like_list` | list[float] | Like flag for historical videos (0/1) |
|
| 155 |
+
| `video_history_comment_list` | list[float] | Comment flag for historical videos (0/1) |
|
| 156 |
+
| `video_history_forward_list` | list[float] | Forward / share flag for historical videos (0/1) |
|
| 157 |
+
| `video_history_collect_list` | list[float] | Collect flag for historical videos (0/1) |
|
| 158 |
+
| `video_history_watch_time_list` | list[float] | Watch time for historical videos |
|
| 159 |
+
| `video_history_play_done_list` | list[float] | Play-done flag for historical videos (0/1) |
|
| 160 |
+
| `video_history_duration_list` | list[float] | Duration of historical videos |
|
| 161 |
+
| `video_history_ts_list` | list[int64] | Absolute timestamp of historical videos |
|
| 162 |
+
| `video_history_seq_len` | int64 | Length of the historical-video sequence |
|
| 163 |
+
|
| 164 |
+
### Live-streaming Fields
|
| 165 |
+
|
| 166 |
+
| Field | Type | Description |
|
| 167 |
+
|-------|------|-------------|
|
| 168 |
+
| `live_hist_timestamp_list` | list[string] | Date of watched live streams|
|
| 169 |
+
| `live_hist_author_id_list` | list[int64] | Host ID of watched live streams |
|
| 170 |
+
| `live_hist_live_id_list` | list[int64] | Live-room ID of watched live streams |
|
| 171 |
+
| `live_hist_show_cnt_list` | list[int64] | Impression count |
|
| 172 |
+
| `live_hist_play_cnt_list` | list[int64] | Play count |
|
| 173 |
+
| `live_hist_valid_play_cnt_list` | list[int64] | Valid-play count |
|
| 174 |
+
| `live_hist_play_duration_list` | list[int64] | Total play duration |
|
| 175 |
+
| `live_hist_valid_play_duration_list` | list[int64] | Valid-play duration |
|
| 176 |
+
| `live_hist_like_cnt_list` | list[int64] | Like count |
|
| 177 |
+
| `live_hist_comment_cnt_list` | list[int64] | Comment count |
|
| 178 |
+
| `live_hist_reduce_similar_cnt_list` | list[int64] | "Reduce similar" / "not interested" count |
|
| 179 |
+
| `live_hist_report_live_cnt_list` | list[int64] | Report count |
|
| 180 |
+
| `live_hist_author_category_type_list` | list[string] | Host category type |
|
| 181 |
+
| `live_hist_author_type_list` | list[string] | Host type |
|
| 182 |
+
| `live_hist_is_interactive_mp_live_list` | list[int64] | Interactive mini-program live flag (0/1) |
|
| 183 |
+
| `live_hist_is_building_live_list` | list[int64] | Real-estate live flag (0/1) |
|
| 184 |
+
| `live_hist_is_local_life_live_list` | list[int64] | Local-life live flag (0/1) |
|
| 185 |
+
| `live_hist_is_detect_game_live_list` | list[int64] | Gaming live flag (0/1) |
|
| 186 |
+
| `live_hist_is_recruit_live_list` | list[int64] | Recruitment live flag (0/1) |
|
| 187 |
+
| `live_hist_follow_author_cnt_list` | list[int64] | List of follow-author action counts |
|
| 188 |
+
|
| 189 |
+
### Ad / Outer-loop Fields
|
| 190 |
+
|
| 191 |
+
| Field | Type | Description |
|
| 192 |
+
|-------|------|-------------|
|
| 193 |
+
| `outer_loop_history_action_pid_list_pos` | list[int64] | Recently deep-converted outer-loop ad ID sequence |
|
| 194 |
+
| `outer_loop_history_action_pid_list_pos_ts` | list[int64] | Absolute timestamp aligned with `outer_loop_history_action_pid_list_pos` |
|
| 195 |
+
| `outer_loop_history_action_pid_list_click` | list[int64] | Recently clicked outer-loop ad ID sequence |
|
| 196 |
+
| `outer_loop_history_action_pid_list_click_ts` | list[int64] | Absolute timestamp aligned with `outer_loop_history_action_pid_list_click` |
|
| 197 |
+
| `outer_loop_history_action_pid_list_click_type` | list[string] | Click type aligned with `outer_loop_history_action_pid_list_click` |
|
| 198 |
+
| `outer_loop_history_action_pid_list_click_industry` | list[string] | Industry aligned with `outer_loop_history_action_pid_list_click` |
|
| 199 |
+
| `outer_loop_deep_target_pid` | list[int64] | Deep-conversion target ID sequence of recent outer-loop ads |
|
| 200 |
+
| `outer_loop_deep_target_pid_ts` | list[int64] | Absolute timestamp aligned with `outer_loop_deep_target_pid` |
|
data/OneReason_General/_SUCCESS
ADDED
|
File without changes
|
data/OneReason_Pid2Caption/_SUCCESS
ADDED
|
File without changes
|
data/OneReason_Pid2Sid/_SUCCESS
ADDED
|
File without changes
|
data/OneReason_Pid2Tag/_SUCCESS
ADDED
|
File without changes
|
data/OneReason_Pid2Tag/part-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98de2b6b8d77039c55092368fcbb622d3adcb11744f7cf1dc8e57066ab2f5a2a
|
| 3 |
+
size 2313395
|
data/OneReason_Pid2Tag/part-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c7593e8e941fec3988c2c7bf0568e0e76771b660eafd64d7875c4d692bf1f934
|
| 3 |
+
size 2287279
|
data/OneReason_Pid2Tag/part-00002.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c05d9659df91d4e29a8e6c5b1dd47fa40d57215c9f2debbec6f8c4891db97dbf
|
| 3 |
+
size 1709864
|
data/OneReason_Pid2Tag/part-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f1f0e05298bbfc9c4d88533f2f90089de2f4e993f5f5d1c36fe5ee8806c8c65
|
| 3 |
+
size 2289522
|
data/OneReason_Pid2Tag/part-00005.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff9bce7ba673e3356d58100378cfed3a4c2c144a8891801dc42f1f3bd32a0fe9
|
| 3 |
+
size 1727526
|
data/OneReason_Pid2Tag/part-00008.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0a771ac7464cdb110bff6e6015f5d0ffdad537835bc7e25a330b780341080c89
|
| 3 |
+
size 1713755
|
data/OneReason_Pid2Tag/part-00009.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71ea42e65ac88df100baba4ac6b081fbbcb25735cf44e8fdb9d9c9cb2bc23632
|
| 3 |
+
size 2307764
|
data/OneReason_Pid2Tag/part-00010.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a78b05a32c9509dbff2e778b118e91fdeed59800ebd9cf0fb2d9f0e5825f3ddb
|
| 3 |
+
size 2286973
|
data/OneReason_Pid2Tag/part-00011.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aee9cad2103590083efb4f70fa86dc77dcdc159006c11115d5eaf8693e67dfd3
|
| 3 |
+
size 1708813
|
data/OneReason_Pid2Tag/part-00012.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45face9c9b9ee2ef450c5d0f7752ab98c24889478c978777e1d93de00b2c1456
|
| 3 |
+
size 2308771
|
data/OneReason_Pid2Tag/part-00013.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:32a8a766a46cc54054eaa2ced466eeef87a1dfc91f93a9b3b6b7f798e225b399
|
| 3 |
+
size 2286751
|
data/OneReason_Pid2Tag/part-00014.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8b94881a53ff56aa96fcd448ccf48c043e43d6aacaba52de9b2635dcc822f61
|
| 3 |
+
size 1704678
|
data/OneReason_Pid2Tag/part-00015.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c3d1b4356b0c2532d56cc2f3dfb44061eee2fd4a088bb5d1fe6053484da0a4c
|
| 3 |
+
size 2313724
|
data/OneReason_Pid2Tag/part-00016.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:39d2d4442f631090558b0fa3eace6565cbcd33774d43c9fed2f22a07a8561500
|
| 3 |
+
size 2286780
|
data/OneReason_Pid2Tag/part-00017.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e59f6ed23fe6469bae97ed1d498cf9b3612bbba87fd0ebd635bb853957f1b0c0
|
| 3 |
+
size 1705941
|
data/OneReason_Pid2Tag/part-00018.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44f5b62d16c3499eb68733513f60ddb75b74d18a75b941f186fdf177c22fdba5
|
| 3 |
+
size 2311358
|
data/OneReason_Pid2Tag/part-00019.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f7d0fc4f6a0ab2f4a470ea2567c95f4643e8c2514c430e695bd7419ad60c6c0
|
| 3 |
+
size 2286951
|
data/OneReason_Pid2Tag/part-00020.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47b7645225503203341767be2c5397f25e1b37f2316e825c5273618201337172
|
| 3 |
+
size 1706938
|
data/OneReason_Pid2Tag/part-00021.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:36754b2255c3745da234a859aca944283f27f7b3d7e70112d81d5773c92eaf3a
|
| 3 |
+
size 2313558
|
data/OneReason_Pid2Tag/part-00024.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6206ef56d23fb0ce4ec6056ee34652fcfa3872f12c6eb92df1a2c2f10045b874
|
| 3 |
+
size 2313003
|
data/OneReason_Pid2Tag/part-00025.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7fc2f7653ecfa26ebfd3dcaef464f13eb12f0833f3bb99af6b23e3a20fd384cc
|
| 3 |
+
size 2286256
|
data/OneReason_Pid2Tag/part-00026.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:382f0e826689a25d1060e621ad962ffcb142c7b87f1a25e09ce2ca9820b48777
|
| 3 |
+
size 1709350
|
data/OneReason_Pid2Tag/part-00027.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b3743bd3a75b8a28c233d383b04832d13303705d3c11e557c716466479dd294
|
| 3 |
+
size 2315013
|
data/OneReason_Pid2Tag/part-00028.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87184471887c986364dd7a85a48805f78463dbe54fb7d826db42323cfa59c6d9
|
| 3 |
+
size 2286680
|
data/OneReason_Pid2Tag/part-00029.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a46786026a90095b1d48392723003c2b91e7c108eebd9a4e598245d2a04487c
|
| 3 |
+
size 1705279
|
data/OneReason_Pid2Tag/part-00030.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f9c80deefd23955b79700a5ba14a869713a0468578dbe01434112362d510034
|
| 3 |
+
size 94643
|
data/OneReason_UserProfile/_SUCCESS
ADDED
|
File without changes
|
data/OneReason_UserProfile/part-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d1f6205abc2f8f066ed5c59d47e4dc0beaab7410fd690db5c6b7c8a8e14818e8
|
| 3 |
+
size 852964129
|
data/OneReason_UserProfile/part-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:05db8ab2570d01cc2f9dcdaac789382f496e95aed266bd6d9248b28a54c9a01c
|
| 3 |
+
size 859223356
|
data/OneReason_UserProfile/part-00003.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1fab3f2467babea4d28828ee9f6dc2f6eb5d13c6affdf184030b5ddbf767cfe4
|
| 3 |
+
size 857073501
|
data/OneReason_UserProfile/part-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a9bacb5acb31876a6349b16f4b54e976b9ba188a4cc019c133641faa6c29d50
|
| 3 |
+
size 853816058
|
data/OneReason_UserProfile/part-00007.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:29a50169b7f52a1c2ab3fa5fd781b8a7a35bb61419290ce29fde6d9b5237574f
|
| 3 |
+
size 856775580
|
data/OneReason_UserProfile/part-00008.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34802225633825e4a22b86d6e214bdbea8dff4cf5ddc36bfe1207c90b3b0eaf0
|
| 3 |
+
size 853819368
|
data/OneReason_UserProfile/part-00009.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8651f876b35b42c2d8a98dc406e4faf35cbda810c32b0c2443692ccb754b324f
|
| 3 |
+
size 852743333
|
demo/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LLaMA-Factory 本地资源微调说明
|
| 2 |
+
|
| 3 |
+
> **demo**:仅含 10 条从原始 parquet 采样的未处理样本(`demo/baseline-data/baseline_data/sampled/sampled.parquet`),用于端到端跑通 pipeline。
|
| 4 |
+
|
| 5 |
+
## 1. 总览
|
| 6 |
+
|
| 7 |
+
| 项 | 值 |
|
| 8 |
+
|---|---|
|
| 9 |
+
| 基座模型 | `<YOUR_BASE_MODEL_PATH>` OneReason-0.8B-pretrain-competition |
|
| 10 |
+
| demo 数据 | `demo/baseline-data/baseline_data/sampled/sampled.parquet`|
|
| 11 |
+
| 训练框架 | LLaMA-Factory `0.9.6.dev0`|
|
| 12 |
+
| 微调方式 | 全量 SFT, bf16, packing+neat_packing, FlashAttention-2, Liger Kernel |
|
| 13 |
+
| 输出 | `demo/output/onereason_0.8b_sft/`|
|
| 14 |
+
|
| 15 |
+
## 2. 训练流程
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
bash demo/scripts/run_all.sh
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
`run_all.sh` 按顺序执行:
|
| 22 |
+
|
| 23 |
+
1. `00_install.sh` — 构建环境
|
| 24 |
+
2. `01_convert_data.sh` — `convertv2.py` 把 parquet → Alpaca JSONL
|
| 25 |
+
3. `02_register_dataset.py` — 注册数据
|
| 26 |
+
4. `03_train.sh` — `llamafactory-cli train demo/config/demo.yaml` 启动训练
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
万擎官网SFT数据集下载方式为:【模型服务】-【数据管理】-【数据集】-【下载比赛数据集】;
|
| 30 |
+
可解压到 demo/baseline-data/baseline_data/sampled下,对数据注册后完成训练
|
| 31 |
+
|
| 32 |
+
下载得到的是 jsonl 格式(`[{system, prompt, response}]`),需要用 `convert_jsonl.py` 转成 Alpaca jsonl:
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
# 把 sampled/ 下所有 *.jsonl 合并 → demo/data/data_final.jsonl
|
| 36 |
+
python demo/convert_jsonl.py \
|
| 37 |
+
--input demo/baseline-data/baseline_data/sampled \
|
| 38 |
+
--output demo/data/data_final.jsonl \
|
| 39 |
+
--shuffle --shuffle-seed 2026
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## 3. 目录结构
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
demo/
|
| 46 |
+
├── README.md # 本文件
|
| 47 |
+
├── convertv2.py # parquet → Alpaca JSONL 转换器
|
| 48 |
+
├── convert_jsonl.py # jsonl ({system,prompt,response}) → Alpaca JSONL 转换器
|
| 49 |
+
├── baseline-data/
|
| 50 |
+
│ └── baseline_data/
|
| 51 |
+
│ └── sampled/
|
| 52 |
+
│ └── sampled.parquet # 10 条采样原始 parquet
|
| 53 |
+
├── config/
|
| 54 |
+
│ └── demo.yaml # 训练配置
|
| 55 |
+
├── data/
|
| 56 |
+
│ └── data_final.jsonl # 10 条 alpaca 样本
|
| 57 |
+
├── scripts/
|
| 58 |
+
│ ├── 00_install.sh
|
| 59 |
+
│ ├── 01_convert_data.sh
|
| 60 |
+
│ ├── 02_register_dataset.py
|
| 61 |
+
│ ├── 03_train.sh
|
| 62 |
+
│ └── run_all.sh
|
| 63 |
+
└── output/ # 训练产物 (运行后生成)
|
| 64 |
+
└── onereason_0.8b_sft/
|
| 65 |
+
├── model.safetensors
|
| 66 |
+
├── trainer_state.json
|
| 67 |
+
├── training_loss.png
|
| 68 |
+
└── runs/ # tensorboard
|
| 69 |
+
```
|
demo/baseline-data/baseline_data/sampled/sampled.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:266b2dd1dfd36f4e3fb233c9244f7598c875eb13edd7deb1189ed3d1df21f17d
|
| 3 |
+
size 21984
|
demo/config/demo.yaml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### model
|
| 2 |
+
model_name_or_path: OpenOneRec/OneReason-0.8B-pretrain-competition
|
| 3 |
+
trust_remote_code: true
|
| 4 |
+
flash_attn: fa2
|
| 5 |
+
|
| 6 |
+
### method
|
| 7 |
+
stage: sft
|
| 8 |
+
do_train: true
|
| 9 |
+
finetuning_type: full
|
| 10 |
+
enable_liger_kernel: true
|
| 11 |
+
|
| 12 |
+
### dataset
|
| 13 |
+
dataset: data_final
|
| 14 |
+
dataset_dir: demo/LLaMA-Factory/data
|
| 15 |
+
template: qwen3_nothink
|
| 16 |
+
cutoff_len: 32768
|
| 17 |
+
packing: true
|
| 18 |
+
neat_packing: true
|
| 19 |
+
overwrite_cache: true
|
| 20 |
+
preprocessing_num_workers: 16
|
| 21 |
+
dataloader_num_workers: 8
|
| 22 |
+
|
| 23 |
+
### output
|
| 24 |
+
output_dir: demo/output/onereason_0.8b_sft
|
| 25 |
+
logging_steps: 5
|
| 26 |
+
save_strategy: steps
|
| 27 |
+
save_steps: 500
|
| 28 |
+
save_total_limit: 2
|
| 29 |
+
plot_loss: true
|
| 30 |
+
overwrite_output_dir: true
|
| 31 |
+
save_only_model: false
|
| 32 |
+
report_to: tensorboard
|
| 33 |
+
logging_dir: demo/output/onereason_0.8b_sft/tb
|
| 34 |
+
|
| 35 |
+
### train
|
| 36 |
+
per_device_train_batch_size: 1
|
| 37 |
+
gradient_accumulation_steps: 4
|
| 38 |
+
learning_rate: 2.0e-5
|
| 39 |
+
num_train_epochs: 1
|
| 40 |
+
lr_scheduler_type: cosine
|
| 41 |
+
warmup_ratio: 0.03
|
| 42 |
+
weight_decay: 0.0
|
| 43 |
+
bf16: true
|
| 44 |
+
pure_bf16: true
|
| 45 |
+
seed: 20260701
|
demo/convert_jsonl.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""jsonl (list of {system, prompt, response}) -> Alpaca jsonl converter.
|
| 3 |
+
|
| 4 |
+
Each input line is expected to be a JSON list containing one dict with keys:
|
| 5 |
+
- system -> instruction
|
| 6 |
+
- prompt -> input
|
| 7 |
+
- response -> output
|
| 8 |
+
|
| 9 |
+
Falls back gracefully if the line is itself a dict.
|
| 10 |
+
"""
|
| 11 |
+
import argparse
|
| 12 |
+
import glob
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import random
|
| 16 |
+
import sys
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def iter_records(path: str):
|
| 21 |
+
with open(path, "r", encoding="utf-8") as fp:
|
| 22 |
+
for line_no, line in enumerate(fp, 1):
|
| 23 |
+
line = line.strip()
|
| 24 |
+
if not line:
|
| 25 |
+
continue
|
| 26 |
+
try:
|
| 27 |
+
obj = json.loads(line)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"[WARN] {path}:{line_no} JSON parse error: {e}", file=sys.stderr)
|
| 30 |
+
continue
|
| 31 |
+
|
| 32 |
+
if isinstance(obj, list):
|
| 33 |
+
if not obj:
|
| 34 |
+
continue
|
| 35 |
+
obj = obj[0]
|
| 36 |
+
if not isinstance(obj, dict):
|
| 37 |
+
print(f"[WARN] {path}:{line_no} unexpected type {type(obj)}", file=sys.stderr)
|
| 38 |
+
continue
|
| 39 |
+
|
| 40 |
+
system = obj.get("system", "") or ""
|
| 41 |
+
prompt = obj.get("prompt", "") or ""
|
| 42 |
+
response = obj.get("response", "") or ""
|
| 43 |
+
|
| 44 |
+
if not prompt and not response:
|
| 45 |
+
continue
|
| 46 |
+
|
| 47 |
+
yield {
|
| 48 |
+
"instruction": system,
|
| 49 |
+
"input": prompt,
|
| 50 |
+
"output": response,
|
| 51 |
+
"history": [],
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def main():
|
| 56 |
+
parser = argparse.ArgumentParser()
|
| 57 |
+
parser.add_argument("--input", required=True,
|
| 58 |
+
help="jsonl file/dir/glob (directory will be scanned for *.jsonl)")
|
| 59 |
+
parser.add_argument("--output", required=True, help="output Alpaca jsonl path")
|
| 60 |
+
parser.add_argument("--shuffle", action="store_true")
|
| 61 |
+
parser.add_argument("--shuffle-seed", type=int, default=2026)
|
| 62 |
+
args = parser.parse_args()
|
| 63 |
+
|
| 64 |
+
in_path = Path(args.input)
|
| 65 |
+
if in_path.is_dir():
|
| 66 |
+
files = sorted(str(p) for p in in_path.rglob("*.jsonl"))
|
| 67 |
+
elif any(c in args.input for c in "*?["):
|
| 68 |
+
files = sorted(glob.glob(args.input, recursive=True))
|
| 69 |
+
else:
|
| 70 |
+
files = [args.input]
|
| 71 |
+
|
| 72 |
+
if not files:
|
| 73 |
+
print(f"[ERROR] no jsonl files found under {args.input}", file=sys.stderr)
|
| 74 |
+
sys.exit(1)
|
| 75 |
+
|
| 76 |
+
print(f"[INFO] found {len(files)} jsonl files", file=sys.stderr)
|
| 77 |
+
for f in files:
|
| 78 |
+
print(f" - {f}", file=sys.stderr)
|
| 79 |
+
|
| 80 |
+
records = []
|
| 81 |
+
per_file_counts = {}
|
| 82 |
+
for f in files:
|
| 83 |
+
before = len(records)
|
| 84 |
+
for rec in iter_records(f):
|
| 85 |
+
records.append(rec)
|
| 86 |
+
per_file_counts[f] = len(records) - before
|
| 87 |
+
print(f"[INFO] {os.path.basename(f)}: {per_file_counts[f]} records", file=sys.stderr)
|
| 88 |
+
|
| 89 |
+
print(f"[INFO] total records: {len(records)}", file=sys.stderr)
|
| 90 |
+
|
| 91 |
+
if args.shuffle:
|
| 92 |
+
random.seed(args.shuffle_seed)
|
| 93 |
+
random.shuffle(records)
|
| 94 |
+
print(f"[INFO] shuffled with seed {args.shuffle_seed}", file=sys.stderr)
|
| 95 |
+
|
| 96 |
+
out_path = Path(args.output)
|
| 97 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 98 |
+
with open(out_path, "w", encoding="utf-8") as fp:
|
| 99 |
+
for r in records:
|
| 100 |
+
fp.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 101 |
+
|
| 102 |
+
print(f"[OK] wrote {len(records)} records to {out_path}", file=sys.stderr)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|
demo/convertv2.py
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""parquet → Alpaca JSONL converter v3 with filter logging.
|
| 3 |
+
|
| 4 |
+
Adds --filter-log argument: every dropped/transformed/skipped sample is logged
|
| 5 |
+
to a JSONL file with full content + reason for downstream analysis.
|
| 6 |
+
|
| 7 |
+
Filter reasons logged:
|
| 8 |
+
- drop:itemic_overflow itemic token alphabet exceeds --max_token_types
|
| 9 |
+
- skip:no_messages parquet row has no messages
|
| 10 |
+
- skip:exception messages JSON parse / convert exception
|
| 11 |
+
- skip:to_alpaca_empty user_messages or assistant_messages empty
|
| 12 |
+
- transform:filter_sid tokens were deleted/normalized (kept but logged optionally)
|
| 13 |
+
- transform:think_inject think pattern was injected (kept but logged optionally)
|
| 14 |
+
"""
|
| 15 |
+
import argparse
|
| 16 |
+
import collections
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import sys
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
import pandas as pd
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
_TOKENS_TO_DELETE = [
|
| 26 |
+
"<|sid_end|>",
|
| 27 |
+
"<|goods_sid_end|>",
|
| 28 |
+
"<|living_end|>",
|
| 29 |
+
"<|ad_end|>",
|
| 30 |
+
"<|prod_end|>",
|
| 31 |
+
"<|video_end|>",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
_TOKENS_TO_NORMALIZE = [
|
| 35 |
+
("<|live_begin|>", "<|living_begin|>"),
|
| 36 |
+
("<prod_s_", "<s_"),
|
| 37 |
+
("<|pid_video_begin|>", "<pid_video_begin>"),
|
| 38 |
+
("<|pid_video_end|>", "<pid_video_end>"),
|
| 39 |
+
("<|pid_ad_begin|>", "<pid_ad_begin>"),
|
| 40 |
+
("<|pid_ad_end|>", "<pid_ad_end>"),
|
| 41 |
+
("<|pid_prod_begin|>", "<pid_prod_begin>"),
|
| 42 |
+
("<|pid_prod_end|>", "<pid_prod_end>"),
|
| 43 |
+
("<|pid_living_begin|>", "<pid_living_begin>"),
|
| 44 |
+
("<|pid_living_end|>", "<pid_living_end>"),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
_ITEMIC_TOKEN_RE = re.compile(r"<s_([a-z])_\d+>")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def filter_sid_end_tokens(text: str, stats: dict | None = None,
|
| 51 |
+
token_hits: dict | None = None) -> str:
|
| 52 |
+
for tok in _TOKENS_TO_DELETE:
|
| 53 |
+
if tok in text:
|
| 54 |
+
cnt = text.count(tok)
|
| 55 |
+
if stats is not None:
|
| 56 |
+
stats[f"delete:{tok}"] += cnt
|
| 57 |
+
if token_hits is not None:
|
| 58 |
+
token_hits[f"delete:{tok}"] = token_hits.get(f"delete:{tok}", 0) + cnt
|
| 59 |
+
text = text.replace(tok, "")
|
| 60 |
+
for src, dst in _TOKENS_TO_NORMALIZE:
|
| 61 |
+
if src in text:
|
| 62 |
+
cnt = text.count(src)
|
| 63 |
+
if stats is not None:
|
| 64 |
+
stats[f"normalize:{src}"] += cnt
|
| 65 |
+
if token_hits is not None:
|
| 66 |
+
token_hits[f"normalize:{src}"] = token_hits.get(f"normalize:{src}", 0) + cnt
|
| 67 |
+
text = text.replace(src, dst)
|
| 68 |
+
return text
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def check_itemic_token_types(text: str, max_token_types: int):
|
| 72 |
+
found = set(_ITEMIC_TOKEN_RE.findall(text))
|
| 73 |
+
return len(found) <= max_token_types, found
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def convert_messages(messages: list, add_think_pattern: bool,
|
| 77 |
+
do_filter_sid: bool, stats: dict | None,
|
| 78 |
+
row_token_hits: dict | None,
|
| 79 |
+
row_think_events: list | None) -> list:
|
| 80 |
+
msg_list = []
|
| 81 |
+
for msg in messages:
|
| 82 |
+
role = msg["role"]
|
| 83 |
+
content = msg["content"]
|
| 84 |
+
|
| 85 |
+
if isinstance(content, str):
|
| 86 |
+
text = content
|
| 87 |
+
elif isinstance(content, dict) and content.get("type") == "text":
|
| 88 |
+
text = content["text"]
|
| 89 |
+
elif isinstance(content, list):
|
| 90 |
+
text = "".join(
|
| 91 |
+
c["text"] if isinstance(c, dict) and c.get("type") == "text" else c
|
| 92 |
+
for c in content
|
| 93 |
+
if isinstance(c, (str, dict))
|
| 94 |
+
)
|
| 95 |
+
else:
|
| 96 |
+
raise ValueError(f"Unsupported content type: {type(content)}, value={content!r}")
|
| 97 |
+
|
| 98 |
+
if do_filter_sid:
|
| 99 |
+
text = filter_sid_end_tokens(text, stats, row_token_hits)
|
| 100 |
+
|
| 101 |
+
msg_list.append({"role": role, "content": text})
|
| 102 |
+
|
| 103 |
+
if add_think_pattern:
|
| 104 |
+
for i, msg in enumerate(msg_list):
|
| 105 |
+
if msg["role"] != "assistant":
|
| 106 |
+
continue
|
| 107 |
+
user_idx = i - 1
|
| 108 |
+
if user_idx < 0 or msg_list[user_idx]["role"] != "user":
|
| 109 |
+
continue
|
| 110 |
+
|
| 111 |
+
match = re.search(r"<think>(.*?)</think>", msg["content"], re.DOTALL)
|
| 112 |
+
if match is None:
|
| 113 |
+
msg_list[user_idx]["content"] += "/no_think"
|
| 114 |
+
msg_list[i]["content"] = "<think>\n\n</think>\n" + msg["content"]
|
| 115 |
+
if stats is not None:
|
| 116 |
+
stats["think:inject_empty"] += 1
|
| 117 |
+
if row_think_events is not None:
|
| 118 |
+
row_think_events.append("inject_empty")
|
| 119 |
+
elif match.group(1).strip():
|
| 120 |
+
msg_list[user_idx]["content"] += "/think"
|
| 121 |
+
if stats is not None:
|
| 122 |
+
stats["think:keep_existing"] += 1
|
| 123 |
+
if row_think_events is not None:
|
| 124 |
+
row_think_events.append("keep_existing")
|
| 125 |
+
else:
|
| 126 |
+
msg_list[user_idx]["content"] += "/no_think"
|
| 127 |
+
if stats is not None:
|
| 128 |
+
stats["think:empty_tag"] += 1
|
| 129 |
+
if row_think_events is not None:
|
| 130 |
+
row_think_events.append("empty_tag")
|
| 131 |
+
|
| 132 |
+
return msg_list
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def to_alpaca(msg_list: list):
|
| 136 |
+
instruction = ""
|
| 137 |
+
for msg in msg_list:
|
| 138 |
+
if msg["role"] == "system":
|
| 139 |
+
instruction = msg["content"]
|
| 140 |
+
break
|
| 141 |
+
|
| 142 |
+
user_messages = []
|
| 143 |
+
assistant_messages = []
|
| 144 |
+
|
| 145 |
+
for msg in msg_list:
|
| 146 |
+
if msg["role"] in ("user", "human"):
|
| 147 |
+
user_messages.append(msg["content"])
|
| 148 |
+
elif msg["role"] == "assistant":
|
| 149 |
+
assistant_messages.append(msg["content"])
|
| 150 |
+
|
| 151 |
+
if not user_messages or not assistant_messages:
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
input_text = user_messages[0]
|
| 155 |
+
output_text = assistant_messages[-1]
|
| 156 |
+
|
| 157 |
+
record = {
|
| 158 |
+
"instruction": instruction,
|
| 159 |
+
"input": input_text,
|
| 160 |
+
"output": output_text,
|
| 161 |
+
"history": [],
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
if len(user_messages) > 1 or len(assistant_messages) > 1:
|
| 165 |
+
num_history_pairs = min(len(user_messages) - 1, len(assistant_messages))
|
| 166 |
+
for i in range(num_history_pairs):
|
| 167 |
+
record["history"].append([user_messages[i], assistant_messages[i]])
|
| 168 |
+
|
| 169 |
+
return record
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def _messages_preview(raw_messages, char_limit=4000):
|
| 173 |
+
"""Stringify messages safely for logging."""
|
| 174 |
+
if isinstance(raw_messages, str):
|
| 175 |
+
s = raw_messages
|
| 176 |
+
else:
|
| 177 |
+
try:
|
| 178 |
+
s = json.dumps(raw_messages, ensure_ascii=False)
|
| 179 |
+
except Exception:
|
| 180 |
+
s = repr(raw_messages)
|
| 181 |
+
if len(s) > char_limit:
|
| 182 |
+
return s[:char_limit] + f"...[truncated, full_len={len(s)}]"
|
| 183 |
+
return s
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def process_parquet(path: str, args, stats: dict, filter_logger):
|
| 187 |
+
df = pd.read_parquet(path)
|
| 188 |
+
records = []
|
| 189 |
+
skipped = 0
|
| 190 |
+
dropped_itemic = 0
|
| 191 |
+
|
| 192 |
+
for row_idx, row in df.iterrows():
|
| 193 |
+
raw = row.get("messages")
|
| 194 |
+
row_uuid = row.get("uuid")
|
| 195 |
+
row_source = row.get("source")
|
| 196 |
+
row_line_id = row.get("line_id")
|
| 197 |
+
row_base = {
|
| 198 |
+
"file": str(path),
|
| 199 |
+
"row_idx": int(row_idx) if hasattr(row_idx, "__int__") else row_idx,
|
| 200 |
+
"uuid": row_uuid if isinstance(row_uuid, str) else (str(row_uuid) if row_uuid is not None else None),
|
| 201 |
+
"source": row_source if isinstance(row_source, str) else (str(row_source) if row_source is not None else None),
|
| 202 |
+
"line_id": row_line_id if isinstance(row_line_id, str) else (str(row_line_id) if row_line_id is not None else None),
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
if raw is None or isinstance(raw, float):
|
| 206 |
+
skipped += 1
|
| 207 |
+
stats["skip:no_messages"] += 1
|
| 208 |
+
if filter_logger is not None:
|
| 209 |
+
filter_logger({
|
| 210 |
+
**row_base,
|
| 211 |
+
"reason": "skip:no_messages",
|
| 212 |
+
"raw_messages": None,
|
| 213 |
+
})
|
| 214 |
+
continue
|
| 215 |
+
|
| 216 |
+
try:
|
| 217 |
+
messages = json.loads(raw) if isinstance(raw, str) else raw
|
| 218 |
+
row_token_hits = {}
|
| 219 |
+
row_think_events = []
|
| 220 |
+
msg_list = convert_messages(
|
| 221 |
+
messages,
|
| 222 |
+
add_think_pattern=args.add_think_pattern,
|
| 223 |
+
do_filter_sid=args.filter_sid_tokens,
|
| 224 |
+
stats=stats,
|
| 225 |
+
row_token_hits=row_token_hits,
|
| 226 |
+
row_think_events=row_think_events,
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
if args.max_token_types is not None:
|
| 230 |
+
full_text = "".join(m["content"] for m in msg_list)
|
| 231 |
+
ok, found = check_itemic_token_types(full_text, args.max_token_types)
|
| 232 |
+
if not ok:
|
| 233 |
+
dropped_itemic += 1
|
| 234 |
+
stats["dropped:itemic_overflow"] += 1
|
| 235 |
+
found_key = ",".join(sorted(found))
|
| 236 |
+
stats[f"itemic_set:{found_key}"] += 1
|
| 237 |
+
if filter_logger is not None:
|
| 238 |
+
filter_logger({
|
| 239 |
+
**row_base,
|
| 240 |
+
"reason": "drop:itemic_overflow",
|
| 241 |
+
"max_token_types": args.max_token_types,
|
| 242 |
+
"itemic_letters_found": sorted(found),
|
| 243 |
+
"token_hits": row_token_hits,
|
| 244 |
+
"messages_after_convert": msg_list,
|
| 245 |
+
"raw_messages_preview": _messages_preview(raw),
|
| 246 |
+
})
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
record = to_alpaca(msg_list)
|
| 250 |
+
if record is None:
|
| 251 |
+
stats["skip:to_alpaca_empty"] += 1
|
| 252 |
+
skipped += 1
|
| 253 |
+
if filter_logger is not None:
|
| 254 |
+
filter_logger({
|
| 255 |
+
**row_base,
|
| 256 |
+
"reason": "skip:to_alpaca_empty",
|
| 257 |
+
"token_hits": row_token_hits,
|
| 258 |
+
"messages_after_convert": msg_list,
|
| 259 |
+
"raw_messages_preview": _messages_preview(raw),
|
| 260 |
+
})
|
| 261 |
+
continue
|
| 262 |
+
records.append(record)
|
| 263 |
+
|
| 264 |
+
if args.log_kept_transforms and filter_logger is not None and (row_token_hits or row_think_events):
|
| 265 |
+
filter_logger({
|
| 266 |
+
**row_base,
|
| 267 |
+
"reason": "kept:transform",
|
| 268 |
+
"token_hits": row_token_hits,
|
| 269 |
+
"think_events": row_think_events,
|
| 270 |
+
})
|
| 271 |
+
|
| 272 |
+
except Exception as e:
|
| 273 |
+
stats["skip:exception"] += 1
|
| 274 |
+
skipped += 1
|
| 275 |
+
if filter_logger is not None:
|
| 276 |
+
filter_logger({
|
| 277 |
+
**row_base,
|
| 278 |
+
"reason": "skip:exception",
|
| 279 |
+
"error": repr(e),
|
| 280 |
+
"raw_messages_preview": _messages_preview(raw),
|
| 281 |
+
})
|
| 282 |
+
print(f"[WARN] skipping row due to: {e}", file=sys.stderr)
|
| 283 |
+
|
| 284 |
+
print(
|
| 285 |
+
f"[INFO] {path}: {len(records)} converted, {skipped} skipped, {dropped_itemic} dropped(itemic)",
|
| 286 |
+
file=sys.stderr,
|
| 287 |
+
)
|
| 288 |
+
return records
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def main():
|
| 292 |
+
parser = argparse.ArgumentParser()
|
| 293 |
+
parser.add_argument("--input", nargs="+", required=True,
|
| 294 |
+
help="parquet 文件/目录/glob")
|
| 295 |
+
parser.add_argument("--output", required=True, help="输出 jsonl 路径")
|
| 296 |
+
parser.add_argument("--max_token_types", type=int, default=3,
|
| 297 |
+
help="允许 <s_X_> 字母种类数(默认 3 = a/b/c)。设 None 关闭检查")
|
| 298 |
+
parser.add_argument("--no_filter_sid_tokens", dest="filter_sid_tokens", action="store_false")
|
| 299 |
+
parser.add_argument("--no_add_think_pattern", dest="add_think_pattern", action="store_false")
|
| 300 |
+
parser.add_argument("--report", action="store_true", help="打印变换统计")
|
| 301 |
+
parser.add_argument("--filter-log", default=None,
|
| 302 |
+
help="过滤/转换日志输出路径 (JSONL)。每条 dropped/skipped/transformed 样本一行")
|
| 303 |
+
parser.add_argument("--log-kept-transforms", action="store_true",
|
| 304 |
+
help="日志中也记录保留但发生过 token 替换或 think 注入的样本")
|
| 305 |
+
parser.add_argument("--summary", default=None,
|
| 306 |
+
help="可选:把最终 stats summary 也写到一个 JSON 文件")
|
| 307 |
+
parser.add_argument("--shuffle", action="store_true",
|
| 308 |
+
help="对最终记录全局随机打乱后再写出(仍保留首条有 history 的记录在最前)")
|
| 309 |
+
parser.add_argument("--shuffle-seed", type=int, default=2026, help="shuffle 的随机种子")
|
| 310 |
+
parser.set_defaults(filter_sid_tokens=True, add_think_pattern=True)
|
| 311 |
+
args = parser.parse_args()
|
| 312 |
+
|
| 313 |
+
stats = collections.Counter()
|
| 314 |
+
filter_log_fp = None
|
| 315 |
+
if args.filter_log:
|
| 316 |
+
Path(args.filter_log).parent.mkdir(parents=True, exist_ok=True)
|
| 317 |
+
filter_log_fp = open(args.filter_log, "w", encoding="utf-8")
|
| 318 |
+
filter_log_count = [0]
|
| 319 |
+
|
| 320 |
+
def filter_logger(payload):
|
| 321 |
+
if filter_log_fp is None:
|
| 322 |
+
return
|
| 323 |
+
filter_log_fp.write(json.dumps(payload, ensure_ascii=False) + "\n")
|
| 324 |
+
filter_log_count[0] += 1
|
| 325 |
+
|
| 326 |
+
all_records = []
|
| 327 |
+
for pattern in args.input:
|
| 328 |
+
if "*" in pattern:
|
| 329 |
+
from glob import glob
|
| 330 |
+
paths = sorted(glob(pattern, recursive=True))
|
| 331 |
+
paths = [Path(p) for p in paths]
|
| 332 |
+
else:
|
| 333 |
+
p = Path(pattern)
|
| 334 |
+
if p.is_dir():
|
| 335 |
+
paths = sorted(p.rglob("*.parquet"))
|
| 336 |
+
else:
|
| 337 |
+
paths = [p]
|
| 338 |
+
for p in paths:
|
| 339 |
+
all_records.extend(process_parquet(str(p), args, stats, filter_logger))
|
| 340 |
+
|
| 341 |
+
# Optional shuffle
|
| 342 |
+
if args.shuffle:
|
| 343 |
+
import random
|
| 344 |
+
rng = random.Random(args.shuffle_seed)
|
| 345 |
+
rng.shuffle(all_records)
|
| 346 |
+
print(f"[INFO] shuffled {len(all_records)} records (seed={args.shuffle_seed})", file=sys.stderr)
|
| 347 |
+
|
| 348 |
+
# move first record with history to front (datasets type inference)
|
| 349 |
+
first_hist_idx = next((i for i, r in enumerate(all_records) if r and r.get("history")), None)
|
| 350 |
+
if first_hist_idx is not None and first_hist_idx > 0:
|
| 351 |
+
all_records.insert(0, all_records.pop(first_hist_idx))
|
| 352 |
+
print(
|
| 353 |
+
f"[INFO] moved record {first_hist_idx} to front (has history, avoids datasets null-type inference)",
|
| 354 |
+
file=sys.stderr,
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
|
| 358 |
+
with open(args.output, "w", encoding="utf-8") as f:
|
| 359 |
+
for record in all_records:
|
| 360 |
+
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 361 |
+
|
| 362 |
+
print(f"\n[OK] Written {len(all_records)} samples to {args.output}", file=sys.stderr)
|
| 363 |
+
|
| 364 |
+
if filter_log_fp is not None:
|
| 365 |
+
filter_log_fp.close()
|
| 366 |
+
print(f"[OK] Filter log written: {filter_log_count[0]} entries -> {args.filter_log}",
|
| 367 |
+
file=sys.stderr)
|
| 368 |
+
|
| 369 |
+
summary_payload = {
|
| 370 |
+
"input": args.input,
|
| 371 |
+
"output": args.output,
|
| 372 |
+
"records_written": len(all_records),
|
| 373 |
+
"filter_log": args.filter_log,
|
| 374 |
+
"filter_log_entries": filter_log_count[0],
|
| 375 |
+
"stats": dict(stats),
|
| 376 |
+
}
|
| 377 |
+
if args.summary:
|
| 378 |
+
Path(args.summary).parent.mkdir(parents=True, exist_ok=True)
|
| 379 |
+
Path(args.summary).write_text(
|
| 380 |
+
json.dumps(summary_payload, ensure_ascii=False, indent=2),
|
| 381 |
+
encoding="utf-8",
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
if args.report:
|
| 385 |
+
print("\n=== 统计报告 ===", file=sys.stderr)
|
| 386 |
+
print(f"\n[token filter 命中次数]", file=sys.stderr)
|
| 387 |
+
for k in sorted(stats.keys()):
|
| 388 |
+
if k.startswith(("delete:", "normalize:")):
|
| 389 |
+
print(f" {k:<45} {stats[k]:>10,}", file=sys.stderr)
|
| 390 |
+
print(f"\n[think pattern 注入次数]", file=sys.stderr)
|
| 391 |
+
for k in sorted(stats.keys()):
|
| 392 |
+
if k.startswith("think:"):
|
| 393 |
+
print(f" {k:<45} {stats[k]:>10,}", file=sys.stderr)
|
| 394 |
+
print(f"\n[skip 原因]", file=sys.stderr)
|
| 395 |
+
for k in sorted(stats.keys()):
|
| 396 |
+
if k.startswith("skip:"):
|
| 397 |
+
print(f" {k:<45} {stats[k]:>10,}", file=sys.stderr)
|
| 398 |
+
print(f"\n[itemic 字母种类超限丢弃]", file=sys.stderr)
|
| 399 |
+
print(
|
| 400 |
+
f" dropped:itemic_overflow {stats.get('dropped:itemic_overflow', 0):>10,}",
|
| 401 |
+
file=sys.stderr,
|
| 402 |
+
)
|
| 403 |
+
top_sets = [(k.split(":", 1)[1], v) for k, v in stats.items() if k.startswith("itemic_set:")]
|
| 404 |
+
if top_sets:
|
| 405 |
+
print(f"\n 丢弃样本的 itemic 字母组合(top 10):", file=sys.stderr)
|
| 406 |
+
for s, n in sorted(top_sets, key=lambda x: -x[1])[:10]:
|
| 407 |
+
print(f" {{ {s} }} → {n:,} 条", file=sys.stderr)
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
if __name__ == "__main__":
|
| 411 |
+
main()
|
demo/data/data_final.jsonl
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"instruction": "", "input": "【用户交互历史】:\n【2025-03-13】\n --:-- [直播-关注] <|living_begin|><s_a_1275><s_b_879><s_c_7951>\n【2025-05-13】\n --:-- [直播-关注] <|living_begin|><s_a_4372><s_b_7344><s_c_4647>\n【2025-05-31】\n --:-- [直播-关注] <|living_begin|><s_a_375><s_b_1804><s_c_3568>\n【2025-06-01】\n --:-- [商品-购买] <|prod_begin|><s_a_582><s_b_6878><s_c_7689>\n --:-- [商品-购买] <|prod_begin|><s_a_5801><s_b_6878><s_c_3250>\n【2025-06-07】\n --:-- [商品-购买] <|prod_begin|><s_a_582><s_b_6878><s_c_3517>\n【2025-06-13】\n --:-- [商品-购买] <|prod_begin|><s_a_1273><s_b_5638><s_c_5347>\n【2025-06-14】\n --:-- [商品-购买] <|prod_begin|><s_a_582><s_b_7808><s_c_2165>\n --:-- [商品-购买] <|prod_begin|><s_a_582><s_b_6724><s_c_7491>\n【2025-06-22】\n --:-- [直播-关注] <|living_begin|><s_a_6627><s_b_481><s_c_1620>\n【2025-07-02】\n --:-- [直播-关注] <|living_begin|><s_a_4372><s_b_8150><s_c_4200>\n【2025-07-03】\n --:-- [商品-购买] <|prod_begin|><s_a_3035><s_b_2649><s_c_825>\n --:-- [商品-购买] <|prod_begin|><s_a_310><s_b_1695><s_c_3275>\n【2025-07-08】\n --:-- [商品-购买] <|prod_begin|><s_a_3806><s_b_3037><s_c_6073>\n【2025-07-27】\n --:-- [商品-购买] <|prod_begin|><s_a_8174><s_b_6818><s_c_5835>\n【2025-08-07】\n --:-- [商品-购买] <|prod_begin|><s_a_2757><s_b_6818><s_c_7006>\n【2025-08-20】\n --:-- [商品-购买] <|prod_begin|><s_a_2757><s_b_6818><s_c_7006>\n【2025-08-26】\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_2303><s_c_8053>\n【2025-09-06】\n --:-- [商品-购买] <|prod_begin|><s_a_7304><s_b_6387><s_c_1353>\n【2025-09-17】\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_3776><s_c_3245>\n【2025-09-25】\n --:-- [商品-购买] <|prod_begin|><s_a_8007><s_b_6434><s_c_4908>\n【2025-09-28】\n --:-- [商品-购买] <|prod_begin|><s_a_6406><s_b_5786><s_c_1137>\n【2025-09-30】\n --:-- [商品-购买] <|prod_begin|><s_a_8007><s_b_4538><s_c_5882>\n【2025-10-02】\n --:-- [商品-购买] <|prod_begin|><s_a_2757><s_b_7789><s_c_825>\n【2025-10-07】\n --:-- [商品-购买] <|prod_begin|><s_a_7798><s_b_4406><s_c_2561>\n --:-- [商品-购买] <|prod_begin|><s_a_3806><s_b_3335><s_c_5514>\n【2025-10-08】\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_6818><s_c_5323>\n【2025-10-15】\n --:-- [商品-购买] <|prod_begin|><s_a_5049><s_b_21><s_c_6248>\n --:-- [商品-购买] <|prod_begin|><s_a_324><s_b_6534><s_c_6534>\n --:-- [商品-购买] <|prod_begin|><s_a_167><s_b_5934><s_c_4895>\n【2025-10-17】\n --:-- [商品-购买] <|prod_begin|><s_a_167><s_b_4782><s_c_6534>\n【2025-10-26】\n --:-- [商品-购买] <|prod_begin|><s_a_5848><s_b_2103><s_c_7924>\n【2025-10-29】\n --:-- [商品-购买] <|prod_begin|><s_a_6406><s_b_7270><s_c_1608>\n【2025-11-06】\n --:-- [商品-购买] <|prod_begin|><s_a_5049><s_b_3393><s_c_3250>\n【2025-11-08】\n --:-- [商品-购买] <|prod_begin|><s_a_8174><s_b_6818><s_c_1014>\n【2025-12-12】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_2816><s_c_7517>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5590><s_c_1941>\n【2025-12-15】\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5590><s_c_1941>\n【2025-12-16】\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_6434><s_c_3403>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_2353><s_c_1644>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5590><s_c_1941>\n --:-- [商品-购买] <|prod_begin|><s_a_8174><s_b_5590><s_c_1941>\n【2025-12-18】\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_6818><s_c_1014>\n【2025-12-21】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\n【2025-12-22】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_2498><s_c_457>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_2498><s_c_457>\n【2025-12-23】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_2498><s_c_457>\n【2025-12-25】\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5022><s_c_825>\n【2025-12-26】\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5590><s_c_1941>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5022><s_c_825>\n --:-- [商品-购买] <|prod_begin|><s_a_8174><s_b_5022><s_c_825>\n【2025-12-27】\n --:-- [商品-点击] <|prod_begin|><s_a_582><s_b_7843><s_c_1881>\n【2025-12-29】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_1259><s_c_5087>\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_2498><s_c_457>\n --:-- [商品-点击] <|prod_begin|><s_a_582><s_b_7843><s_c_1881>\n【2025-12-30】\n --:-- [商品-点击] <|prod_begin|><s_a_5360><s_b_843><s_c_2135>\n【2025-12-31】\n --:-- [商品-点击] <|prod_begin|><s_a_3><s_b_4679><s_c_4801>\n --:-- [商品-购买] <|prod_begin|><s_a_3><s_b_4679><s_c_4801>\n【2026-01-02】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\n【2026-01-03】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_6818><s_c_599>\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\n【2026-01-08】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_2498><s_c_7924>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_5022><s_c_825>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_3776><s_c_3245>\n --:-- [商品-购买] <|prod_begin|><s_a_8174><s_b_5022><s_c_825>\n【2026-01-09】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_6696><s_c_4233>\n【2026-01-15】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_5805><s_c_4908>\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_5805><s_c_4908>\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_7858><s_c_7402>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_5805><s_c_4908>\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_7858><s_c_7402>\n【2026-01-17】\n --:-- [商品-点击] <|prod_begin|><s_a_2533><s_b_2532><s_c_2717>\n --:-- [商品-点击] <|prod_begin|><s_a_2533><s_b_3155><s_c_6005>\n【2026-01-29】\n --:-- [商品-购买] <|prod_begin|><s_a_2950><s_b_4659><s_c_7556>\n【2026-02-06】\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_3335><s_c_4233>\n --:-- [商品-点击] <|prod_begin|><s_a_8174><s_b_4464><s_c_511>\n --:-- [商品-点击] <|prod_begin|><s_a_2950><s_b_5805><s_c_4908>\n\n角色任务:你需要以极端严苛的用户行为数据挖掘专家及数据格式化专家的身份,基于以上交互历史,针对给定主题筛选并提取出全部相关的历史交互行为。\n\n主题:从泛化养生到特定眼部健康问题的聚焦与方案升级\n\n输出格式要求:请仅以包含 SID 的 JSON 数组形式返回结果,切勿输出任何额外的解释说明或无关字符。/no_think", "output": "<think>\n\n</think>\n[\"<|living_begin|><s_a_6627><s_b_481><s_c_1620>\", \"<|prod_begin|><s_a_8174><s_b_6818><s_c_5835>\", \"<|prod_begin|><s_a_2757><s_b_6818><s_c_7006>\", \"<|prod_begin|><s_a_2950><s_b_3776><s_c_3245>\", \"<|prod_begin|><s_a_2757><s_b_7789><s_c_825>\", \"<|prod_begin|><s_a_8174><s_b_6818><s_c_1014>\", \"<|prod_begin|><s_a_2950><s_b_6818><s_c_6278>\", \"<|prod_begin|><s_a_8174><s_b_5022><s_c_825>\", \"<|prod_begin|><s_a_2950><s_b_2498><s_c_7924>\", \"<|prod_begin|><s_a_2950><s_b_6696><s_c_4233>\", \"<|prod_begin|><s_a_2950><s_b_5805><s_c_4908>\", \"<|prod_begin|><s_a_2950><s_b_7858><s_c_7402>\", \"<|prod_begin|><s_a_2533><s_b_2532><s_c_2717>\", \"<|prod_begin|><s_a_2533><s_b_3155><s_c_6005>\", \"<|prod_begin|><s_a_2950><s_b_4659><s_c_7556>\", \"<|prod_begin|><s_a_2950><s_b_3335><s_c_4233>\", \"<|prod_begin|><s_a_8174><s_b_4464><s_c_511>\"]", "history": []}
|
| 2 |
+
{"instruction": "作为商品标识生成助手,你需要根据给定的商品描述输出匹配的商品token。", "input": "请依据这段商品特征描述生成商品token:漾亲润益生菌蜂蜜露,专为孕产妇、儿童及老人设计的营养保健产品,由新华制药旗下品牌出品,安全可靠。每支添加300亿活性益生菌(嗜酸乳杆菌与乳双歧杆菌),搭配天然蜂蜜,温和滋养,助力肠道健康。产品采用极简六边形独立包装,每支10ml,每盒12支,三盒装共36支,方便携带与控制用量。常温贮藏,保质期长达540天,产地山东,品质稳定。包装设计清新简约,适合家庭日常使用,尤其适合孕妈妈及产后妈妈,兼顾宝宝与老人的健康需求。产品强调“孕妈妈也适用”,突出其安全性和普适性,是家庭健康护理的理想选择。/no_think", "output": "<think>\n\n</think>\n<|prod_begin|><s_a_5051><s_b_5171><s_c_7920>", "history": []}
|
| 3 |
+
{"instruction": "你负责根据用户多域行为理解用户兴趣偏好,并输出该用户在各场景中的目标内容。", "input": "以下是一个用户的多域历史行为信息:\n用户视频行为: 深度观看了 <|video_begin|><s_a_2015><s_b_6809><s_c_323>, <|video_begin|><s_a_1106><s_b_4092><s_c_1146>, <|video_begin|><s_a_16><s_b_594><s_c_1148>, <|video_begin|><s_a_5058><s_b_7410><s_c_4410>, <|video_begin|><s_a_7971><s_b_1240><s_c_7395>, <|video_begin|><s_a_6321><s_b_5419><s_c_7106>, <|video_begin|><s_a_3429><s_b_7894><s_c_5609>, <|video_begin|><s_a_5062><s_b_7288><s_c_2374>, <|video_begin|><s_a_410><s_b_2251><s_c_7915>, <|video_begin|><s_a_7751><s_b_3059><s_c_5553>, <|video_begin|><s_a_231><s_b_800><s_c_4617>, <|video_begin|><s_a_335><s_b_7155><s_c_4724>, <|video_begin|><s_a_2158><s_b_3185><s_c_7609>, <|video_begin|><s_a_4843><s_b_5551><s_c_1933>, <|video_begin|><s_a_1981><s_b_7111><s_c_4427>, <|video_begin|><s_a_6904><s_b_7554><s_c_1767>, <|video_begin|><s_a_1106><s_b_2221><s_c_2781>, <|video_begin|><s_a_5023><s_b_3902><s_c_6552>, <|video_begin|><s_a_7542><s_b_6973><s_c_1306>, <|video_begin|><s_a_5476><s_b_2221><s_c_3026>, <|video_begin|><s_a_6510><s_b_6782><s_c_5839>, <|video_begin|><s_a_2562><s_b_800><s_c_1161>, <|video_begin|><s_a_231><s_b_7894><s_c_5372>, <|video_begin|><s_a_2562><s_b_850><s_c_1004>, <|video_begin|><s_a_5181><s_b_4491><s_c_4487>, <|video_begin|><s_a_1336><s_b_1822><s_c_7790>, <|video_begin|><s_a_1106><s_b_7975><s_c_1148>, <|video_begin|><s_a_1853><s_b_3185><s_c_7598>, <|video_begin|><s_a_1106><s_b_3665><s_c_25>, <|video_begin|><s_a_2015><s_b_3898><s_c_3842>, <|video_begin|><s_a_578><s_b_2323><s_c_1935>, <|video_begin|><s_a_4392><s_b_581><s_c_5000>, <|video_begin|><s_a_599><s_b_6307><s_c_1423>, <|video_begin|><s_a_3801><s_b_1645><s_c_6805>, <|video_begin|><s_a_1336><s_b_6379><s_c_1337>, <|video_begin|><s_a_4946><s_b_7762><s_c_1529>, <|video_begin|><s_a_4946><s_b_5546><s_c_6364>, <|video_begin|><s_a_2562><s_b_884><s_c_7921>, <|video_begin|><s_a_6510><s_b_7246><s_c_701>, <|video_begin|><s_a_4946><s_b_6033><s_c_804>, <|video_begin|><s_a_6321><s_b_2357><s_c_7598>, <|video_begin|><s_a_2562><s_b_1702><s_c_711>, <|video_begin|><s_a_6704><s_b_3235><s_c_47>, <|video_begin|><s_a_2015><s_b_5760><s_c_6815>, <|video_begin|><s_a_1106><s_b_3915><s_c_909>, <|video_begin|><s_a_5144><s_b_57><s_c_845>, <|video_begin|><s_a_2015><s_b_6311><s_c_7267>, <|video_begin|><s_a_4946><s_b_6582><s_c_3531>, <|video_begin|><s_a_2450><s_b_3228><s_c_8010>, <|video_begin|><s_a_562><s_b_6436><s_c_47>,看过视频 <|video_begin|><s_a_6169><s_b_8179><s_c_6705>, <|video_begin|><s_a_4843><s_b_3059><s_c_2568>, <|video_begin|><s_a_2677><s_b_57><s_c_2038>, <|video_begin|><s_a_5023><s_b_3315><s_c_4424>。\n\n请根据以上信息,给出该用户在直播、电商、视频、广告场景中的目标内容。/think", "output": "<think>好的,请看我的分析:\n\n【兴趣归纳】\n根据用户的交互历史,其核心兴趣可归纳为以下四类:\n1. **社会百态与生活纪实**:此为最核心兴趣。用户深度消费了大量长视频,内容涵盖不同地域、职业、年龄层人群的真实生活状态,如打工生活<|video_begin|><s_a_2158><s_b_3185><s_c_7609>、家庭纠纷<|video_begin|><s_a_4843><s_b_3059><s_c_2568>、特殊群体纪实<|video_begin|><s_a_1106><s_b_3665><s_c_25>等,表现出对社会万象和人情世故的强烈探究欲。\n2. **乡村生活与农业主题**:用户对农村题材表现出稳定且深入的兴趣,多次观看关于乡村养殖(<|video_begin|><s_a_5476><s_b_2221><s_c_3026>、<|video_begin|><s_a_2562><s_b_800><s_c_1161>)、乡土美食<|video_begin|><s_a_7751><s_b_3059><s_c_5553>、农业技术<|video_begin|><s_a_1981><s_b_7111><s_c_4427>和自然风光<|video_begin|><s_a_1336><s_b_6379><s_c_1337>的长视频。\n3. **传统文化与民俗知识**:用户对传统文化有明显偏好,浏览内容涉及古建筑<|video_begin|><s_a_5144><s_b_57><s_c_845>、民间习俗<|video_begin|><s_a_4946><s_b_7762><s_c_1529>、传统工艺<|video_begin|><s_a_5023><s_b_3315><s_c_4424>及社会变迁的怀旧内容<|video_begin|><s_a_4946><s_b_6033><s_c_804>。\n4. **实用技能与知识科普**:用户关注能提升生活认知或解决实际问题的知识,包括健康养生<|video_begin|><s_a_7971><s_b_1240><s_c_7395>、财经资讯(</think>\n该用户最近喜欢的视频有: <|video_begin|><s_a_532><s_b_4571><s_c_2820>", "history": []}
|
| 4 |
+
{"instruction": "你擅长根据广告内容、风格和主题描述,输出对应的广告token。", "input": "请根据这段广告dense caption生成匹配的广告token:视频展示一位身着深色西装的女性坐在办公桌前,背景为办公室环境。画面顶部配有双语标题,底部叠加了关于风雨过后必有晴空、心怀希望等励志文字。视频整体呈现为正能量类口播内容,旨在传递积极向上的生活态度。/think", "output": "<think>职场女性口播,商务办公场景,励志正能量,积极生活态度</think>\n<|ad_begin|><s_a_570><s_b_7472><s_c_4288>", "history": []}
|
| 5 |
+
{"instruction": "你是主播token生成专家,能够将主播描述转化为对应的结构化主播token。", "input": "请分析这段主播特征描述,并生成对应的主播token:该主播是一位定位清晰的80后居家生活女主播,以真实、亲切、略带慵懒的居家形象示人,常以齐刘海长发搭配休闲家居服出镜,营造出“邻家姐姐”的治愈感。直播内容主打轻松闲聊与娱乐互动,融合吃播(如啃玉米)、动漫欣赏、游戏连麦(如《王者荣耀》)及情感话题讨论,内容生活化且节奏舒缓。主播善于通过自然表情和简单互动与观众建立情感连接,评论区氛围温暖友好,主要吸引80后及寻求居家陪伴、情感共鸣的观众群体,整体风格温馨治愈,主打“慢生活”与“真实陪伴”的直播体验。/no_think", "output": "<think>\n\n</think>\n<|living_begin|><s_a_1307><s_b_8024><s_c_3825>", "history": []}
|
| 6 |
+
{"instruction": "你是一名广告token生成助手,需要根据广告内容描述生成最匹配的广告token。", "input": "请根据以下广告内容描述,生成匹配的广告token:该视频为短剧推广广告,面向喜欢剧情类内容的观众,旨在引导用户点击观看完整版。视频展示了剧情片段,包括一位千金假装瘫痪骗未婚夫照顾、五年后丈夫成为总裁、除夕夜准备年夜饭却发现女儿失踪等情节,最后出现“点击下方详情内容观看完整版”的引导信息。/no_think", "output": "<think>\n\n</think>\n<|ad_begin|><s_a_3069><s_b_6234><s_c_5851>", "history": []}
|
| 7 |
+
{"instruction": "作为主播标识生成助手,你需要根据给定的主播描述输出匹配的主播token。", "input": "请从以下主播描述中推断并生成对应的主播token:该主播是一位来自辽宁、自称69岁但心态年轻的中年女性,以亲切接地气的“东北大姐”人设示人,直播主打家庭室内闲聊与连麦互动。内容聚焦家庭教育、护肤保养、地域交流等生活化话题,通过双人分屏连麦与观众进行家常唠嗑,穿插“推力”小游戏增强趣味性。主播性格乐观开朗,强调“心态年轻”,与观众建立情感陪伴关系。评论区氛围轻松活跃,互动以点赞、送礼、解锁挂件等为主,主要吸引中老年群体及家庭主妇,打造温馨治愈、充满烟火气的“中年阿姨连麦唠嗑”直播间风格。/think", "output": "<think>东北大姐人设,家庭室内闲聊,双人连麦互动,中老年受众,温馨治愈烟火气</think>\n<|living_begin|><s_a_4372><s_b_4262><s_c_875>", "history": []}
|
| 8 |
+
{"instruction": "作为视频内容解析助手,你需要根据提供的短视频标识给出精准的视频内容描述。", "input": "请描述视频token:<|video_begin|><s_a_3641><s_b_4515><s_c_2704>的视频内容/think", "output": "<think>这类短视频以强营销转化为核心,通过影视剧情切片、实物展示或视觉冲击吸引注意力,辅以免费福利、利益诱导等话术,构建从情绪刺激到点击消费的短路径商业引流模型。</think>\n该视频为某热门短剧的推广广告,面向喜欢灾难题材的观众,引导用户点击链接免费观看全集。画面展示了一个被洪水淹没的城市场景,一条巨大的鲨鱼在浑浊的洪水中游动,周围漂浮着废弃车辆,一名男子站在高处俯瞰,旁边还有救援人员乘坐的小艇,背景中可见高楼大厦和广告牌。", "history": []}
|
| 9 |
+
{"instruction": "你是一个智能商品解说助手,可以根据输入的商品token创建生动、准确的商品描述。", "input": "给定商品token<|prod_begin|><s_a_2043><s_b_5277><s_c_1251>这件商品有什么特点?/think", "output": "<think>面向大众及中老年女性的平价舒适女鞋与舞蹈用品,强调软底防滑、百搭实用,覆盖日常通勤及广场舞等场景,以标准化电商模板呈现完整的商品详情信息。</think>\n这是一款专为民族舞蹈设计的女式高跟舞鞋,适用于藏族舞、秧歌、胶州民间舞等舞种的日常练功与考级场景。鞋面采用经典黑色绒面材质,搭配PVC与橡胶鞋底,兼具耐磨防滑与舒适支撑,3.5cm实根鞋跟设计稳定不崴脚,适合长时间舞蹈训练。鞋型为圆头设计,内里柔软贴合脚型,提供良好包裹感。产品被舞蹈老师推荐,特别标注“考试专用”,强调其专业性与实用性。广告宣传“买一双用一年,断底包赔”,凸显耐用性与售后保障。整体设计简约经典,兼顾功能性与美观性,是民族舞蹈爱好者及考级学生的理想选择。", "history": []}
|
| 10 |
+
{"instruction": "", "input": "【用户交互历史】:\n【2025-03-01】\n --:-- [直播-关注] <|living_begin|><s_a_3367><s_b_7342><s_c_656>\n【2025-06-12】\n --:-- [直播-关注] <|living_begin|><s_a_4372><s_b_7186><s_c_1649>\n【2025-06-19】\n --:-- [直播-关注] <|living_begin|><s_a_6704><s_b_765><s_c_1423>\n【2025-06-20】\n --:-- [直播-关注] <|living_begin|><s_a_2828><s_b_451><s_c_6278>\n【2025-06-21】\n --:-- [直播-首次打赏] <|living_begin|><s_a_2828><s_b_6973><s_c_4512>\n【2025-06-23】\n --:-- [直播-关注] <|living_begin|><s_a_194><s_b_7342><s_c_958>\n【2025-07-25】\n --:-- [直播-关注] <|living_begin|><s_a_3367><s_b_581><s_c_1246>\n【2025-09-15】\n --:-- [直播-关注] <|living_begin|><s_a_4372><s_b_3313><s_c_2298>\n【2025-10-19】\n --:-- [直播-关注] <|living_begin|><s_a_3367><s_b_451><s_c_1133>\n【2025-10-22】\n --:-- [直播-关注] <|living_begin|><s_a_6492><s_b_451><s_c_7383>\n【2025-12-09】\n --:-- [直播-关注] <|living_begin|><s_a_4372><s_b_451><s_c_6327>\n --:-- [直播-关注] <|living_begin|><s_a_1957><s_b_451><s_c_2403>\n【2026-01-09】\n 08:14 [广告-深度转化] <|ad_begin|><s_a_4178><s_b_5646><s_c_3659>\n 08:14 [广告-点击] <|ad_begin|><s_a_4178><s_b_5646><s_c_3659>\n 08:34 [广告-深度转化] <|ad_begin|><s_a_786><s_b_5707><s_c_1495>\n 08:34 [广告-点击] <|ad_begin|><s_a_786><s_b_5707><s_c_1495>\n 08:34 [广告-点击] <|ad_begin|><s_a_3641><s_b_6047><s_c_5872>\n 08:35 [广告-点击] <|ad_begin|><s_a_3641><s_b_4885><s_c_3047>\n 08:36 [广告-点击] <|ad_begin|><s_a_3641><s_b_3447><s_c_629>\n 08:37 [广告-点击] <|ad_begin|><s_a_1108><s_b_3932><s_c_846>\n 08:39 [广告-点击] <|ad_begin|><s_a_3641><s_b_1206><s_c_7713>\n【2026-01-15】\n --:-- [直播-关注] <|living_begin|><s_a_5728><s_b_5099><s_c_536>\n【2026-01-21】\n 22:07 [视频-点赞/长播] <|video_begin|><s_a_6099><s_b_1310><s_c_495>\n【2026-01-22】\n 22:11 [视频-点赞/长播] <|video_begin|><s_a_3858><s_b_3873><s_c_5452>\n【2026-01-23】\n --:-- [直播-关注] <|living_begin|><s_a_1658><s_b_451><s_c_3676>\n【2026-02-02】\n 06:09 [视频-转发/长播] <|video_begin|><s_a_5741><s_b_6379><s_c_7099>\n【2026-02-03】\n 10:16 [视频-点赞/长播] <|video_begin|><s_a_3431><s_b_1822><s_c_2643>\n 21:16 [视频-转发/长播] <|video_begin|><s_a_3858><s_b_2130><s_c_4631>\n 21:28 [视频-转发/长播] <|video_begin|><s_a_3632><s_b_1013><s_c_3987>\n 22:56 [视频-长播] <|video_begin|><s_a_1427><s_b_7498><s_c_4636>\n 22:56 [视频-长播] <|video_begin|><s_a_3632><s_b_7897><s_c_7598>\n【2026-02-04】\n 07:57 [视频-长播] <|video_begin|><s_a_1409><s_b_3148><s_c_5872>\n 08:02 [视频-长播] <|video_begin|><s_a_1883><s_b_6234><s_c_5673>\n 08:02 [视频-长播] <|video_begin|><s_a_2051><s_b_7946><s_c_532>\n 08:02 [视频-长播] <|video_begin|><s_a_6705><s_b_3063><s_c_3447>\n 08:13 [视频-长播] <|video_begin|><s_a_3632><s_b_978><s_c_7187>\n 08:13 [视频-长播] <|video_begin|><s_a_3632><s_b_1822><s_c_1975>\n 08:13 [视频-长播] <|video_begin|><s_a_3632><s_b_1795><s_c_6185>\n 08:28 [视频-长播] <|video_begin|><s_a_5904><s_b_7111><s_c_7800>\n 08:28 [视频-长播] <|video_begin|><s_a_1340><s_b_1878><s_c_3026>\n 08:43 [视频-长播] <|video_begin|><s_a_3001><s_b_6123><s_c_3402>\n 08:43 [视频-长播] <|video_begin|><s_a_5144><s_b_6379><s_c_7529>\n 08:43 [视频-点赞/长播] <|video_begin|><s_a_3632><s_b_6519><s_c_1009>\n 08:55 [视频-长播] <|video_begin|><s_a_2051><s_b_2960><s_c_853>\n 08:55 [视频-长播] <|video_begin|><s_a_4646><s_b_4033><s_c_6108>\n 08:55 [视频-长播] <|video_begin|><s_a_6140><s_b_6297><s_c_4288>\n 08:58 [视频-长播] <|video_begin|><s_a_5019><s_b_2828><s_c_4859>\n 08:58 [视频-长播] <|video_begin|><s_a_4646><s_b_1822><s_c_853>\n 18:55 [视频-长播] <|video_begin|><s_a_5904><s_b_7897><s_c_7800>\n 18:55 [视频-长播] <|video_begin|><s_a_3632><s_b_713><s_c_7598>\n 19:07 [视频-长播] <|video_begin|><s_a_1883><s_b_632><s_c_7548>\n 19:07 [视频-长播] <|video_begin|><s_a_7879><s_b_6435><s_c_6616>\n 19:07 [视频-长播] <|video_begin|><s_a_2051><s_b_6213><s_c_7076>\n 19:07 [视频-长播] <|video_begin|><s_a_3632><s_b_1740><s_c_728>\n 19:07 [视频-长播] <|video_begin|><s_a_2051><s_b_6889><s_c_3355>\n 19:23 [视频-长播] <|video_begin|><s_a_3858><s_b_575><s_c_5405>\n 19:23 [视频-长播] <|video_begin|><s_a_3373><s_b_946><s_c_141>\n 19:26 [视频-长播] <|video_begin|><s_a_5058><s_b_1937><s_c_3429>\n 19:26 [视频-长播] <|video_begin|><s_a_3632><s_b_3952><s_c_7057>\n 19:39 [视频-长播] <|video_begin|><s_a_5144><s_b_1590><s_c_6559>\n 19:39 [视频-长播] <|video_begin|><s_a_4312><s_b_3857><s_c_6203>\n 21:13 [视频-长播] <|video_begin|><s_a_2015><s_b_6234><s_c_4479>\n 21:20 [视频-长播] <|video_begin|><s_a_4922><s_b_451><s_c_4208>\n 21:25 [视频-长播] <|video_begin|><s_a_3510><s_b_7768><s_c_141>\n 21:25 [视频-长播] <|video_begin|><s_a_6140><s_b_7498><s_c_5209>\n 21:25 [视频-长播] <|video_begin|><s_a_4922><s_b_3518><s_c_4092>\n 22:51 [视频-长播] <|video_begin|><s_a_848><s_b_6186><s_c_3659>\n 22:51 [视频-长播] <|video_begin|><s_a_7003><s_b_4010><s_c_3230>\n 22:56 [视频-长播] <|video_begin|><s_a_4312><s_b_1259><s_c_5563>\n 22:56 [视频-长播] <|video_begin|><s_a_4646><s_b_7665><s_c_4543>\n 23:12 [视频-长播] <|video_begin|><s_a_4646><s_b_8179><s_c_377>\n 23:12 [视频-长播] <|video_begin|><s_a_791><s_b_5841><s_c_7106>\n 23:12 [视频-长播] <|video_begin|><s_a_6321><s_b_3589><s_c_4341>\n 23:12 [视频-长播] <|video_begin|><s_a_6755><s_b_2061><s_c_406>\n 23:21 [视频-长播] <|video_begin|><s_a_3510><s_b_2865><s_c_6831>\n【2026-02-05】\n 04:53 [视频-长播] <|video_begin|><s_a_1106><s_b_6234><s_c_5255>\n 04:53 [视频-长播] <|video_begin|><s_a_7893><s_b_990><s_c_3659>\n 04:53 [视频-长播] <|video_begin|><s_a_7411><s_b_4246><s_c_853>\n 05:02 [视频-长播] <|video_begin|><s_a_3632><s_b_4508><s_c_728>\n 05:02 [视频-长播] <|video_begin|><s_a_3632><s_b_4944><s_c_2930>\n角色任务:你需要扮演极端严苛的用户行为数据挖掘专家以及数据格式化专家,基于以上用户交互历史,针对给定主题识别并提取具有递进逻辑和内在联系的交互行为逻辑链。\n交互行为类型(固定格式严禁更改): 搜索-搜索、视频-浏览、视频-长播、直播-关注、直播-首次打赏、商品-点击、商品-购买、广告-点击、广告-深度转化\n核心判定逻辑(递进性准则):\n请按时间顺序提取 5 步以内的行为链,且后项交互B必须构成前项交互A在场景需求上的协同补充、副作用诱因或兴趣细化升级——即 B 必须源于 A 所延伸出的需求,严禁提取任何品类平级、内容重复或仅由天气/促销触发的并列凑单���为。\n1.场景驱动协同:交互 B 相对于交互 A,必须在同一生活场景与主题类目下形成强需求补完关系。\n2.兴趣因果递进:交互 B 是因为 交互 A 产生的副作用或新需求,或者 A 是 B 的诱因。\n3.需求深度细化:在同一主题类目下,交互 B 需要比交互 A 表达得更具体详细,但不纳入重复性的购买、点击、搜索等行为,避免形成重复节点。\n请面向以下主题提取行为逻辑链:\n主题:从泛化时政关注到聚焦特定人物与事件的深度探究\n\n输出格式:请以 JSON 对象形式返回,结构如下:\n{\n \"logic_chain\": {\n \"name\": \"从泛化时政关注到聚焦特定人物与事件的深度探究\",\n \"events\": [\n {\n \"date\": \"YYYY-MM-DD\",\n \"action\": \"[交互行为类型] 交互内容\"(严格对应Timeline中交互条目,不允许省略),\n \"logic\": \"逻辑说明\"\n }\n ]\n }\n}/think", "output": "<think>\n好的,这项任务要求我基于用户的交互历史,挖掘出一条从泛化时政关注到聚焦特定人物与事件深度探究的行为逻辑链。我需要以第一人称的分析师视角,串联起用户的行为,并解释其中的递进关系。\n\n我首先注意到,这位用户在2025年期间的兴趣主要集中在直播内容上,特别是与情感、交友、才艺展示相关的女主播直播间。然而,在2025年6月19日,我发现了一个显著的兴趣拐点:用户关注了一个解读国际时事、中美关系、军事动态的男性主播直播间<|living_begin|><s_a_6704><s_b_765><s_c_1423>。这次关注行为打破了之前以娱乐和情感内容为主的模式,标志着用户对宏观、严肃的时政军事话题产生了初步兴趣。在这个阶段,我认为用户的兴趣是比较泛化的,他通过观看直播这种信息密度相对较低、氛围轻松的方式,被动地接收关于地缘政治和热点事件的宏观解读。\n\n时间快进到2026年初,用户的兴趣点发生了明显的深化和迁移。在长达数月的时政兴趣酝酿后,我观察到在2026年2月3日,用户对一个解析宋庆龄历史贡献的视频<|video_begin|><s_a_3632><s_b_1013><s_c_3987>进行了转发和长播。这个行为非常关键。首先,用户的交互从被动的“关注”直播升级为主动的“转发”视频,这表明了他对内容的高度认可和分享意愿。其次,内容主题从宽泛的国际时事,精准地聚焦到了中国近代史中的一位特定关键人物及其相关的具体历史事件。这清晰地展示了用户在时政历史领域的兴趣正在从宏观走向微观,从被动接收转向主动探究特定人物的深度故事。\n\n紧接着,就在同一天,用户的探索行为再次演进。在深入了解了近代史人物之后,我看到他紧接着长播了一个详细解读唐朝由盛转衰历史进程的视频<|video_begin|><s_a_1427><s_b_7498><s_c_4636>。这次观看行为体现了用户认知上的又一次跃迁。他不再满足于单个历史人物的故事,而是开始探索一个更宏大的历史叙事单元——一个朝代的兴衰变迁。这表明他的兴趣从“点”(具体人物)扩展到了“线”(朝代历史),开始寻求对历史发展规律和政治变迁的更深层次理解。这种从近代史人物到古代史宏大叙事的横向拓展,与之前的兴趣点构成了显著的递进关系,显示出一种系统性、探究式的学习倾向。\n\n综合来看,我认为用户的行为逻辑链条非常清晰。他最初通过关注时事解读直播<|living_begin|><s_a_6704><s_b_765><s_c_1423>,触发了对宏观时政的泛化兴趣。随后,这种兴趣进一步聚焦,通过转发和观看关于宋庆龄的视频<|video_begin|><s_a_3632><s_b_1013><s_c_3987>,深入到对特定历史人物和事件的探究。最终,他的认知需求再次升级,通过观看唐朝历史视频<|video_begin|><s_a_1427><s_b_7498><s_c_4636>,将探索范围拓展至更宏大的朝代变迁史,体现了从点到线的认知深化。因此,我推断,后续推荐更具深度和系统性的历史解析、人物传记或特定历史事件纪录片,有较大概率会被该用户所吸引。</think>\n{\"logic_chain\": {\"name\": \"从泛化时政关注到聚焦特定人物与事件的深度探究\", \"events\": [{\"date\": \"2025-06-19\", \"action\": \"[直播-关注] <|living_begin|><s_a_6704><s_b_765><s_c_1423>\", \"logic\": \"兴趣触发:通过关注时事解读类直播,表现出对宏观政治、经济、军事话题的初步兴趣,信息获取方式为被动、宽泛的接收。\"}, {\"date\": \"2026-02-03\", \"action\": \"[视频-转发/长播] <|video_begin|><s_a_3632><s_b_1013><s_c_3987>\", \"logic\": \"兴趣聚焦:从宽泛的时事话题,收敛到对中国近代史中特定关键人物(宋庆龄)的具体历史事件进行深度了解。交互行为从被动的“关注”直播深化为主动的“转发”深度解析视频,认知增量���显。\"}, {\"date\": \"2026-02-03\", \"action\": \"[视频-长播] <|video_begin|><s_a_1427><s_b_7498><s_c_4636>\", \"logic\": \"认知深化与横向拓展:在对近代史人物产生兴趣后,进一步将探究范围拓展至古代史,关注更宏大的历史叙事(唐朝由盛转衰),体现了从“点”(具体人物)到“线”(朝代变迁)的认知跃迁,寻求对历史规律的深层理解。\"}]}}", "history": []}
|
demo/scripts/00_install.sh
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# 00_install.sh - 安装 LLaMA-Factory + 加速包(liger-kernel + flash-attn)
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
cd "$(dirname "$0")/../.."
|
| 5 |
+
|
| 6 |
+
ROOT=demo
|
| 7 |
+
LF_DIR=$ROOT/LLaMA-Factory
|
| 8 |
+
VENV=$LF_DIR/.venv
|
| 9 |
+
|
| 10 |
+
# 1.1 拉取 LLaMA-Factory
|
| 11 |
+
if [ -d "$LF_DIR/.git" ]; then
|
| 12 |
+
echo "[skip] $LF_DIR already cloned"
|
| 13 |
+
else
|
| 14 |
+
echo "[run] git clone LLaMA-Factory"
|
| 15 |
+
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git "$LF_DIR"
|
| 16 |
+
fi
|
| 17 |
+
|
| 18 |
+
# 1.2 创建 Python 3.11 venv (flash-attn wheel 是 cp311)
|
| 19 |
+
if [ -x "$VENV/bin/python" ]; then
|
| 20 |
+
echo "[skip] venv already exists at $VENV"
|
| 21 |
+
else
|
| 22 |
+
echo "[run] uv venv --python 3.11"
|
| 23 |
+
uv venv --python 3.11 "$VENV"
|
| 24 |
+
fi
|
| 25 |
+
source "$VENV/bin/activate"
|
| 26 |
+
|
| 27 |
+
# 1.3 LLaMA-Factory + metrics
|
| 28 |
+
echo "[run] install LLaMA-Factory (editable) + metrics deps"
|
| 29 |
+
uv pip install -e "$LF_DIR"
|
| 30 |
+
uv pip install -r "$LF_DIR/requirements/metrics.txt"
|
| 31 |
+
|
| 32 |
+
# 1.4 配置环境(请自行配置)
|
| 33 |
+
echo "[run] pin torch 2.7.1+cu126"
|
| 34 |
+
SP="$VENV/lib/python3.11/site-packages"
|
| 35 |
+
uv pip uninstall torch torchvision torchaudio sympy 2>/dev/null || true
|
| 36 |
+
rm -rf "$SP/torch" "$SP/sympy" "$SP/functorch"
|
| 37 |
+
uv pip install --no-deps \
|
| 38 |
+
--index-url https://download.pytorch.org/whl/cu126 \
|
| 39 |
+
torch==2.7.1+cu126 torchvision==0.22.1+cu126 torchaudio==2.7.1+cu126
|
| 40 |
+
uv pip install --force-reinstall --no-deps "sympy==1.13.3"
|
| 41 |
+
|
| 42 |
+
echo "[run] install liger-kernel 0.8.0 + flash-attn 2.7.4.post1"
|
| 43 |
+
uv pip install --no-deps "liger-kernel==0.8.0"
|
| 44 |
+
uv pip install \
|
| 45 |
+
"https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.7cxx11abiTRUE-cp311-cp311-linux_x86_64.whl" \
|
| 46 |
+
> "$ROOT/flash_install.log" 2>&1 &
|
| 47 |
+
FA_PID=$!
|
| 48 |
+
echo "[run] flash-attn install backgrounded, pid=$FA_PID, log=$ROOT/flash_install.log"
|
| 49 |
+
wait $FA_PID
|
| 50 |
+
uv pip install tensorboard
|
| 51 |
+
|
| 52 |
+
echo "[run] patch transformers/integrations/flash_attention.py (s_aux None guard)"
|
| 53 |
+
FA_PY="$SP/transformers/integrations/flash_attention.py"
|
| 54 |
+
if grep -q "s_aux=s_aux.to(query.dtype) if s_aux is not None else None" "$FA_PY"; then
|
| 55 |
+
echo "[skip] patch already applied"
|
| 56 |
+
else
|
| 57 |
+
sed -i 's|s_aux=s_aux.to(query.dtype),|s_aux=s_aux.to(query.dtype) if s_aux is not None else None,|' "$FA_PY"
|
| 58 |
+
echo "[ok] patched"
|
| 59 |
+
fi
|
| 60 |
+
|
| 61 |
+
# 检查环境
|
| 62 |
+
echo "[verify] versions"
|
| 63 |
+
python - <<'PY'
|
| 64 |
+
import torch, flash_attn, transformers, sympy
|
| 65 |
+
from importlib.metadata import version
|
| 66 |
+
print("torch:", torch.__version__, "cuda:", torch.version.cuda, "cuda_available:", torch.cuda.is_available())
|
| 67 |
+
print("flash_attn:", flash_attn.__version__)
|
| 68 |
+
print("transformers:", transformers.__version__)
|
| 69 |
+
print("liger-kernel:", version("liger-kernel"))
|
| 70 |
+
print("sympy:", sympy.__version__)
|
| 71 |
+
from liger_kernel.transformers import apply_liger_kernel_to_qwen3
|
| 72 |
+
print("liger qwen3 hook: OK")
|
| 73 |
+
PY
|
| 74 |
+
echo "[ok] install finished"
|
demo/scripts/01_convert_data.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# 01_convert_data.sh - 把 baseline_data 的 64 parquet 转 Alpaca JSONL
|
| 3 |
+
# 输出: data/data_final.jsonl + convert_summary.json + convert_filter.log
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
cd "$(dirname "$0")/../.."
|
| 6 |
+
|
| 7 |
+
ROOT=demo
|
| 8 |
+
OUT=$ROOT/data/data_final.jsonl
|
| 9 |
+
|
| 10 |
+
source $ROOT/LLaMA-Factory/.venv/bin/activate
|
| 11 |
+
|
| 12 |
+
if [ -s "$OUT" ]; then
|
| 13 |
+
echo "[skip] $OUT already exists ($(wc -l < "$OUT") lines); rerun by deleting it first"
|
| 14 |
+
exit 0
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
python $ROOT/convertv2.py \
|
| 18 |
+
--input $ROOT/baseline-data/baseline_data \
|
| 19 |
+
--output $OUT \
|
| 20 |
+
--summary $ROOT/data/convert_summary.json \
|
| 21 |
+
--filter-log $ROOT/data/convert_filter.log \
|
| 22 |
+
--max_token_types 3 \
|
| 23 |
+
--shuffle --shuffle-seed 2026 \
|
| 24 |
+
--report
|
| 25 |
+
|
| 26 |
+
echo "[ok] wrote $(wc -l < $OUT) records to $OUT"
|
demo/scripts/02_register_dataset.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Upsert data_final entry into LLaMA-Factory/data/dataset_info.json (idempotent).
|
| 3 |
+
|
| 4 |
+
NOTE: LLaMA-Factory resolves `file_name` relative to `dataset_dir`, so we write
|
| 5 |
+
an absolute path resolved at script run time. The script script is expected
|
| 6 |
+
to be run from the parent dir of `demo/` (which run_all.sh / 03_train.sh do).
|
| 7 |
+
"""
|
| 8 |
+
import json
|
| 9 |
+
import pathlib
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
INFO_PATH = pathlib.Path("demo/LLaMA-Factory/data/dataset_info.json").resolve()
|
| 13 |
+
DATA_PATH = str(pathlib.Path("demo/data/data_final.jsonl").resolve())
|
| 14 |
+
|
| 15 |
+
ENTRY = {
|
| 16 |
+
"file_name": DATA_PATH,
|
| 17 |
+
"formatting": "alpaca",
|
| 18 |
+
"columns": {
|
| 19 |
+
"prompt": "instruction",
|
| 20 |
+
"query": "input",
|
| 21 |
+
"response": "output",
|
| 22 |
+
"history": "history",
|
| 23 |
+
},
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
info = json.loads(INFO_PATH.read_text(encoding="utf-8"))
|
| 27 |
+
info["data_final"] = ENTRY
|
| 28 |
+
INFO_PATH.write_text(json.dumps(info, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 29 |
+
print(f"[OK] upserted 'data_final' in {INFO_PATH}", file=sys.stderr)
|
| 30 |
+
print(json.dumps(info["data_final"], ensure_ascii=False, indent=2))
|
demo/scripts/03_train.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# 03_train.sh - 启动 LLaMA-Factory 单 H800 全量 SFT
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
cd "$(dirname "$0")/../.."
|
| 5 |
+
|
| 6 |
+
ROOT=demo
|
| 7 |
+
CONFIG=$ROOT/config/demo.yaml
|
| 8 |
+
OUT_DIR=$ROOT/output/onereason_0.8b_sft
|
| 9 |
+
LOG=$OUT_DIR/train.log
|
| 10 |
+
|
| 11 |
+
source $ROOT/LLaMA-Factory/.venv/bin/activate
|
| 12 |
+
|
| 13 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 14 |
+
export TOKENIZERS_PARALLELISM=false
|
| 15 |
+
export WANDB_DISABLED=1
|
| 16 |
+
|
| 17 |
+
mkdir -p $OUT_DIR
|
| 18 |
+
|
| 19 |
+
echo "[run] llamafactory-cli train $CONFIG"
|
| 20 |
+
echo "[run] log -> $LOG"
|
| 21 |
+
llamafactory-cli train $CONFIG 2>&1 | tee $LOG
|
demo/scripts/run_all.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
bash demo/scripts/00_install.sh
|
| 6 |
+
bash demo/scripts/01_convert_data.sh
|
| 7 |
+
demo/LLaMA-Factory/.venv/bin/python demo/scripts/02_register_dataset.py
|
| 8 |
+
bash demo/scripts/03_train.sh
|