Datasets:
Update LifeTextSingleTurnStreamingCoT to v0.4.1 loading config and HQ subset patch
Browse files- .gitattributes +3 -0
- README.md +78 -0
- audit_report_v0.4.md +764 -0
- data/eval.jsonl +3 -0
- data/eval.parquet +3 -0
- data/eval_high_quality.jsonl +0 -0
- data/eval_high_quality.parquet +3 -0
- data/train.jsonl +3 -0
- data/train.parquet +3 -0
- data/train_high_quality.jsonl +3 -0
- data/train_high_quality.parquet +3 -0
- dataset_card.md +78 -0
- dataset_info.json +185 -0
- requirements.txt +5 -0
- samples_for_review.jsonl +0 -0
- scripts/analyze_quality.py +56 -0
- scripts/apply_v041_quality_patch.py +522 -0
- scripts/augment_with_llm.py +193 -0
- scripts/build_life_streaming_cot.py +1774 -0
- scripts/upload_to_hf.py +74 -0
- scripts/validate_dataset.py +461 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,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
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
data/eval.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
data/train.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
data/train_high_quality.jsonl filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: LifeTextSingleTurnStreamingCoT
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
version: "v0.4.1"
|
| 7 |
+
configs:
|
| 8 |
+
- config_name: default
|
| 9 |
+
data_files:
|
| 10 |
+
- split: train
|
| 11 |
+
path: data/train.parquet
|
| 12 |
+
- split: test
|
| 13 |
+
path: data/eval.parquet
|
| 14 |
+
- config_name: high_quality
|
| 15 |
+
data_files:
|
| 16 |
+
- split: train
|
| 17 |
+
path: data/train_high_quality.parquet
|
| 18 |
+
- split: test
|
| 19 |
+
path: data/eval_high_quality.parquet
|
| 20 |
+
task_categories:
|
| 21 |
+
- text-generation
|
| 22 |
+
tags:
|
| 23 |
+
- streaming-reasoning
|
| 24 |
+
- supervised-fine-tuning
|
| 25 |
+
- life-assistant
|
| 26 |
+
---
|
| 27 |
+
# LifeTextSingleTurnStreamingCoT
|
| 28 |
+
|
| 29 |
+
LifeTextSingleTurnStreamingCoT is the canonical text/single-turn member of the Life Streaming CoT family. It supersedes the older `LifeStreamingCoT` name while preserving the existing v0.4.1 data and backward-compatible fields.
|
| 30 |
+
|
| 31 |
+
## Summary
|
| 32 |
+
|
| 33 |
+
- Modality: text
|
| 34 |
+
- Turn type: single_turn
|
| 35 |
+
- Version: v0.4.1
|
| 36 |
+
- HF repo: `skyzhou06/LifeTextSingleTurnStreamingCoT`
|
| 37 |
+
- Rows: 9322 total, 7457 train, 1865 eval
|
| 38 |
+
- High-quality rows: 2570 train, 634 eval
|
| 39 |
+
- Source distribution: `{"b-mc2/wikihow_lists": 622, "pietrolesci/multiwoz_all_versions": 2987, "pixelsandpointers/better_daily_dialog": 3713, "pixelsandpointers/empathetic_dialogues_for_lm": 2000}`
|
| 40 |
+
- Category distribution: `{"daily_life": 2987, "information_extraction": 622, "social_communication": 5713}`
|
| 41 |
+
- Length buckets: `{"short": 5575, "short_medium": 1345, "very_short": 2402}`
|
| 42 |
+
|
| 43 |
+
## Schema
|
| 44 |
+
|
| 45 |
+
Core legacy fields include `id`, `domain`, `source_dataset`, `instruction`, `context`, `context_chunks`, `streaming_reasoning`, `deep_reasoning`, `answer`, `messages`, `text`, `quality_flags`, `quality_score`, `is_high_quality`, and `split`.
|
| 46 |
+
|
| 47 |
+
Normalized backward-compatible fields were added where feasible: `modality`, `turn_type`, `taxonomy`, `input`, `streaming`, `output`, and `quality`.
|
| 48 |
+
|
| 49 |
+
## Taxonomy
|
| 50 |
+
|
| 51 |
+
Rows include normalized `taxonomy.category`, `taxonomy.subcategory`, `taxonomy.intent_type`, and `taxonomy.difficulty`. Existing `domain` remains available for backward compatibility.
|
| 52 |
+
|
| 53 |
+
## Streaming and Deep Reasoning
|
| 54 |
+
|
| 55 |
+
Streaming reasoning is deterministic, selective, and chunk-aligned. Deep reasoning is a compact full-context summary. No `sft_messages` field is required.
|
| 56 |
+
|
| 57 |
+
## Quality Filters
|
| 58 |
+
|
| 59 |
+
The release keeps quality scores, high-quality split files, quality flags, source attribution, and validation scripts. The high-quality config is recommended for stricter SFT experiments.
|
| 60 |
+
|
| 61 |
+
## How to use for SFT
|
| 62 |
+
|
| 63 |
+
- Input: `input.instruction` plus `input.context` or legacy `instruction` plus `context`.
|
| 64 |
+
- Target: `output.answer` or legacy `answer`.
|
| 65 |
+
- Optional reasoning target: `streaming.streaming_reasoning`, `output.deep_reasoning`, then `output.answer`.
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from datasets import load_dataset
|
| 69 |
+
|
| 70 |
+
full = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "default")
|
| 71 |
+
hq = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "high_quality")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## Limitations
|
| 75 |
+
|
| 76 |
+
- Reasoning is deterministic/rule-based unless optional LLM augmentation is run separately.
|
| 77 |
+
- Some rows originate from dialogue-style sources and may not perfectly match direct assistant behavior.
|
| 78 |
+
- Not intended for expert medical, legal, financial, emergency, or safety-critical advice.
|
audit_report_v0.4.md
ADDED
|
@@ -0,0 +1,764 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
- generation_method: `source_grounded_rule_based_v0.4_quality_refined`
|
| 9 |
+
- reasoning_policy: `selective_concise`
|
| 10 |
+
- chunking_method: `semantic_sentence_split_v0.4_refined`
|
| 11 |
+
- train rows: `7457`
|
| 12 |
+
- eval rows: `1865`
|
| 13 |
+
- high-quality train rows: `7207`
|
| 14 |
+
- high-quality eval rows: `1807`
|
| 15 |
+
- full train+eval rows: `9322`
|
| 16 |
+
- high-quality subset rows: `9014`
|
| 17 |
+
- all uploaded data rows if all data files are counted: `18336`
|
| 18 |
+
|
| 19 |
+
## 2. Duplicate and Overlap Statistics
|
| 20 |
+
|
| 21 |
+
File-level stats:
|
| 22 |
+
|
| 23 |
+
```json
|
| 24 |
+
{
|
| 25 |
+
"train": {
|
| 26 |
+
"rows": 7457,
|
| 27 |
+
"unique_ids": 7457,
|
| 28 |
+
"duplicate_id_count": 0,
|
| 29 |
+
"unique_texts": 7457,
|
| 30 |
+
"duplicate_text_count": 0
|
| 31 |
+
},
|
| 32 |
+
"eval": {
|
| 33 |
+
"rows": 1865,
|
| 34 |
+
"unique_ids": 1865,
|
| 35 |
+
"duplicate_id_count": 0,
|
| 36 |
+
"unique_texts": 1865,
|
| 37 |
+
"duplicate_text_count": 0
|
| 38 |
+
},
|
| 39 |
+
"train_high_quality": {
|
| 40 |
+
"rows": 7207,
|
| 41 |
+
"unique_ids": 7207,
|
| 42 |
+
"duplicate_id_count": 0,
|
| 43 |
+
"unique_texts": 7207,
|
| 44 |
+
"duplicate_text_count": 0
|
| 45 |
+
},
|
| 46 |
+
"eval_high_quality": {
|
| 47 |
+
"rows": 1807,
|
| 48 |
+
"unique_ids": 1807,
|
| 49 |
+
"duplicate_id_count": 0,
|
| 50 |
+
"unique_texts": 1807,
|
| 51 |
+
"duplicate_text_count": 0
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Overlap stats:
|
| 57 |
+
|
| 58 |
+
```json
|
| 59 |
+
{
|
| 60 |
+
"full_id_count": 9322,
|
| 61 |
+
"hq_id_count": 9014,
|
| 62 |
+
"full_hq_id_overlap": 9014,
|
| 63 |
+
"full_text_count": 9322,
|
| 64 |
+
"hq_text_count": 9014,
|
| 65 |
+
"full_hq_text_overlap": 9014,
|
| 66 |
+
"train_eval_id_overlap": 0,
|
| 67 |
+
"train_eval_text_overlap": 0
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Interpretation: high-quality rows are intended to be a subset of the full train/eval rows. Therefore the `9014` id overlap and `9014` text overlap are expected locally. There is no train/eval overlap by id or text inside the full dataset.
|
| 72 |
+
|
| 73 |
+
## 3. Hugging Face Viewer / `load_dataset` Interpretation
|
| 74 |
+
|
| 75 |
+
```json
|
| 76 |
+
{
|
| 77 |
+
"configs": [
|
| 78 |
+
"default"
|
| 79 |
+
],
|
| 80 |
+
"splits": {
|
| 81 |
+
"train": 14664,
|
| 82 |
+
"test": 3672
|
| 83 |
+
},
|
| 84 |
+
"columns": {
|
| 85 |
+
"train": [
|
| 86 |
+
"id",
|
| 87 |
+
"domain",
|
| 88 |
+
"source_dataset",
|
| 89 |
+
"instruction",
|
| 90 |
+
"context",
|
| 91 |
+
"context_chunks",
|
| 92 |
+
"streaming_reasoning",
|
| 93 |
+
"deep_reasoning",
|
| 94 |
+
"answer",
|
| 95 |
+
"response",
|
| 96 |
+
"messages",
|
| 97 |
+
"text",
|
| 98 |
+
"num_chunks",
|
| 99 |
+
"language",
|
| 100 |
+
"split",
|
| 101 |
+
"generation_method",
|
| 102 |
+
"quality_flags",
|
| 103 |
+
"version",
|
| 104 |
+
"reasoning_policy",
|
| 105 |
+
"chunking_method",
|
| 106 |
+
"chunk_labels",
|
| 107 |
+
"skip_chunks",
|
| 108 |
+
"skip_reasons",
|
| 109 |
+
"reasoning_token_budget",
|
| 110 |
+
"original_num_chunks",
|
| 111 |
+
"chunk_split_count",
|
| 112 |
+
"quality_score",
|
| 113 |
+
"is_high_quality",
|
| 114 |
+
"refinement_method",
|
| 115 |
+
"llm_augmented",
|
| 116 |
+
"llm_augmentation_model",
|
| 117 |
+
"rejected_reason",
|
| 118 |
+
"state_tracking_confidence"
|
| 119 |
+
],
|
| 120 |
+
"test": [
|
| 121 |
+
"id",
|
| 122 |
+
"domain",
|
| 123 |
+
"source_dataset",
|
| 124 |
+
"instruction",
|
| 125 |
+
"context",
|
| 126 |
+
"context_chunks",
|
| 127 |
+
"streaming_reasoning",
|
| 128 |
+
"deep_reasoning",
|
| 129 |
+
"answer",
|
| 130 |
+
"response",
|
| 131 |
+
"messages",
|
| 132 |
+
"text",
|
| 133 |
+
"num_chunks",
|
| 134 |
+
"language",
|
| 135 |
+
"split",
|
| 136 |
+
"generation_method",
|
| 137 |
+
"quality_flags",
|
| 138 |
+
"version",
|
| 139 |
+
"reasoning_policy",
|
| 140 |
+
"chunking_method",
|
| 141 |
+
"chunk_labels",
|
| 142 |
+
"skip_chunks",
|
| 143 |
+
"skip_reasons",
|
| 144 |
+
"reasoning_token_budget",
|
| 145 |
+
"original_num_chunks",
|
| 146 |
+
"chunk_split_count",
|
| 147 |
+
"quality_score",
|
| 148 |
+
"is_high_quality",
|
| 149 |
+
"refinement_method",
|
| 150 |
+
"llm_augmented",
|
| 151 |
+
"llm_augmentation_model",
|
| 152 |
+
"rejected_reason",
|
| 153 |
+
"state_tracking_confidence"
|
| 154 |
+
]
|
| 155 |
+
},
|
| 156 |
+
"first_row_keys": {
|
| 157 |
+
"train": [
|
| 158 |
+
"id",
|
| 159 |
+
"domain",
|
| 160 |
+
"source_dataset",
|
| 161 |
+
"instruction",
|
| 162 |
+
"context",
|
| 163 |
+
"context_chunks",
|
| 164 |
+
"streaming_reasoning",
|
| 165 |
+
"deep_reasoning",
|
| 166 |
+
"answer",
|
| 167 |
+
"response",
|
| 168 |
+
"messages",
|
| 169 |
+
"text",
|
| 170 |
+
"num_chunks",
|
| 171 |
+
"language",
|
| 172 |
+
"split",
|
| 173 |
+
"generation_method",
|
| 174 |
+
"quality_flags",
|
| 175 |
+
"version",
|
| 176 |
+
"reasoning_policy",
|
| 177 |
+
"chunking_method",
|
| 178 |
+
"chunk_labels",
|
| 179 |
+
"skip_chunks",
|
| 180 |
+
"skip_reasons",
|
| 181 |
+
"reasoning_token_budget",
|
| 182 |
+
"original_num_chunks",
|
| 183 |
+
"chunk_split_count",
|
| 184 |
+
"quality_score",
|
| 185 |
+
"is_high_quality",
|
| 186 |
+
"refinement_method",
|
| 187 |
+
"llm_augmented",
|
| 188 |
+
"llm_augmentation_model",
|
| 189 |
+
"rejected_reason",
|
| 190 |
+
"state_tracking_confidence"
|
| 191 |
+
],
|
| 192 |
+
"test": [
|
| 193 |
+
"id",
|
| 194 |
+
"domain",
|
| 195 |
+
"source_dataset",
|
| 196 |
+
"instruction",
|
| 197 |
+
"context",
|
| 198 |
+
"context_chunks",
|
| 199 |
+
"streaming_reasoning",
|
| 200 |
+
"deep_reasoning",
|
| 201 |
+
"answer",
|
| 202 |
+
"response",
|
| 203 |
+
"messages",
|
| 204 |
+
"text",
|
| 205 |
+
"num_chunks",
|
| 206 |
+
"language",
|
| 207 |
+
"split",
|
| 208 |
+
"generation_method",
|
| 209 |
+
"quality_flags",
|
| 210 |
+
"version",
|
| 211 |
+
"reasoning_policy",
|
| 212 |
+
"chunking_method",
|
| 213 |
+
"chunk_labels",
|
| 214 |
+
"skip_chunks",
|
| 215 |
+
"skip_reasons",
|
| 216 |
+
"reasoning_token_budget",
|
| 217 |
+
"original_num_chunks",
|
| 218 |
+
"chunk_split_count",
|
| 219 |
+
"quality_score",
|
| 220 |
+
"is_high_quality",
|
| 221 |
+
"refinement_method",
|
| 222 |
+
"llm_augmented",
|
| 223 |
+
"llm_augmentation_model",
|
| 224 |
+
"rejected_reason",
|
| 225 |
+
"state_tracking_confidence"
|
| 226 |
+
]
|
| 227 |
+
},
|
| 228 |
+
"total_rows": 18336
|
| 229 |
+
}
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
Interpretation: the default Hugging Face builder detected only the `default` config and exposed splits `train` and `test`. The `train` split row count is `14664`, which equals local `train.jsonl` `7457` plus `train_high_quality.jsonl` `7207`. The `test` split row count is `3672`, which equals local `eval.jsonl` `1865` plus `eval_high_quality.jsonl` `1807`.
|
| 233 |
+
|
| 234 |
+
This means the ~18.3k viewer count is expected from file auto-detection, but it is not the intended default full-dataset count. The high-quality subset files are being merged into the default splits by `datasets.load_dataset`.
|
| 235 |
+
|
| 236 |
+
Recommended fix for v0.4.1: add explicit dataset card YAML configs/data_files so the default config only loads `data/train.parquet` and `data/eval.parquet`, and a separate `high_quality` config loads `data/train_high_quality.parquet` and `data/eval_high_quality.parquet`. Alternatively move high-quality files outside automatic split patterns or provide a dataset loading script.
|
| 237 |
+
|
| 238 |
+
## Addendum: Hugging Face-Loaded Duplicate Rows
|
| 239 |
+
|
| 240 |
+
When loaded through `datasets.load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT")`, the automatic file resolver merges the high-quality subset files into the default splits. That creates duplicate ids/text inside the loaded HF splits even though the local source files are individually clean.
|
| 241 |
+
|
| 242 |
+
```json
|
| 243 |
+
{
|
| 244 |
+
"train": {
|
| 245 |
+
"rows": 14664,
|
| 246 |
+
"unique_ids": 7457,
|
| 247 |
+
"duplicate_id_rows": 7207,
|
| 248 |
+
"unique_texts": 7457,
|
| 249 |
+
"duplicate_text_rows": 7207
|
| 250 |
+
},
|
| 251 |
+
"test": {
|
| 252 |
+
"rows": 3672,
|
| 253 |
+
"unique_ids": 1865,
|
| 254 |
+
"duplicate_id_rows": 1807,
|
| 255 |
+
"unique_texts": 1865,
|
| 256 |
+
"duplicate_text_rows": 1807
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
## 4. v0.4 Field Validation
|
| 262 |
+
|
| 263 |
+
Full train/eval validation:
|
| 264 |
+
|
| 265 |
+
```json
|
| 266 |
+
{
|
| 267 |
+
"errors_count": 0,
|
| 268 |
+
"missing_fields": {},
|
| 269 |
+
"bad_values": {},
|
| 270 |
+
"structural": {},
|
| 271 |
+
"sample_errors": []
|
| 272 |
+
}
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
High-quality file validation:
|
| 276 |
+
|
| 277 |
+
```json
|
| 278 |
+
{
|
| 279 |
+
"errors_count": 0,
|
| 280 |
+
"missing_fields": {},
|
| 281 |
+
"bad_values": {},
|
| 282 |
+
"structural": {},
|
| 283 |
+
"sample_errors": []
|
| 284 |
+
}
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
## 5. Forbidden Phrase Counts
|
| 288 |
+
|
| 289 |
+
```json
|
| 290 |
+
{}
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
Examples if any:
|
| 294 |
+
|
| 295 |
+
```json
|
| 296 |
+
{}
|
| 297 |
+
```
|
| 298 |
+
|
| 299 |
+
## 6. Known Quality Issue Counts
|
| 300 |
+
|
| 301 |
+
Full dataset issue counts:
|
| 302 |
+
|
| 303 |
+
```json
|
| 304 |
+
{
|
| 305 |
+
"examples_with_repeated_chunks": 537,
|
| 306 |
+
"examples_with_gt30pct_repeated_chunks": 39,
|
| 307 |
+
"answer_contains_especially with": 986,
|
| 308 |
+
"emotional_keyword_stitching": 1022,
|
| 309 |
+
"answer_contains_certainly,": 15,
|
| 310 |
+
"answer_keyword_list_style": 2128,
|
| 311 |
+
"examples_with_under4_word_fragmentish_chunks": 647,
|
| 312 |
+
"examples_num_chunks_gt12": 170,
|
| 313 |
+
"task_closing_answer_asks_missing_slots": 97
|
| 314 |
+
}
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
High-quality subset issue counts:
|
| 318 |
+
|
| 319 |
+
```json
|
| 320 |
+
{
|
| 321 |
+
"examples_with_repeated_chunks": 514,
|
| 322 |
+
"examples_with_gt30pct_repeated_chunks": 36,
|
| 323 |
+
"answer_contains_especially with": 980,
|
| 324 |
+
"emotional_keyword_stitching": 1016,
|
| 325 |
+
"answer_contains_certainly,": 15,
|
| 326 |
+
"answer_keyword_list_style": 2064,
|
| 327 |
+
"examples_with_under4_word_fragmentish_chunks": 620,
|
| 328 |
+
"task_closing_answer_asks_missing_slots": 97
|
| 329 |
+
}
|
| 330 |
+
```
|
| 331 |
+
|
| 332 |
+
Representative issue example ids from full dataset:
|
| 333 |
+
|
| 334 |
+
```json
|
| 335 |
+
{
|
| 336 |
+
"examples_with_repeated_chunks": [
|
| 337 |
+
"life_emotional_support_000001",
|
| 338 |
+
"life_emotional_support_000003",
|
| 339 |
+
"life_emotional_support_000008",
|
| 340 |
+
"life_emotional_support_000010",
|
| 341 |
+
"life_emotional_support_000011",
|
| 342 |
+
"life_task_oriented_assistant_000021",
|
| 343 |
+
"life_emotional_support_000013",
|
| 344 |
+
"life_emotional_support_000015",
|
| 345 |
+
"life_emotional_support_000019",
|
| 346 |
+
"life_emotional_support_000021"
|
| 347 |
+
],
|
| 348 |
+
"examples_with_gt30pct_repeated_chunks": [
|
| 349 |
+
"life_emotional_support_000001",
|
| 350 |
+
"life_emotional_support_000032",
|
| 351 |
+
"life_emotional_support_000166",
|
| 352 |
+
"life_emotional_support_000248",
|
| 353 |
+
"life_emotional_support_000250",
|
| 354 |
+
"life_emotional_support_000337",
|
| 355 |
+
"life_emotional_support_000377",
|
| 356 |
+
"life_emotional_support_000379",
|
| 357 |
+
"life_emotional_support_000405",
|
| 358 |
+
"life_emotional_support_000408"
|
| 359 |
+
],
|
| 360 |
+
"answer_contains_especially with": [
|
| 361 |
+
"life_emotional_support_000001",
|
| 362 |
+
"life_emotional_support_000002",
|
| 363 |
+
"life_emotional_support_000004",
|
| 364 |
+
"life_emotional_support_000005",
|
| 365 |
+
"life_emotional_support_000007",
|
| 366 |
+
"life_emotional_support_000010",
|
| 367 |
+
"life_emotional_support_000011",
|
| 368 |
+
"life_emotional_support_000012",
|
| 369 |
+
"life_emotional_support_000014",
|
| 370 |
+
"life_emotional_support_000015"
|
| 371 |
+
],
|
| 372 |
+
"emotional_keyword_stitching": [
|
| 373 |
+
"life_emotional_support_000001",
|
| 374 |
+
"life_emotional_support_000002",
|
| 375 |
+
"life_emotional_support_000004",
|
| 376 |
+
"life_emotional_support_000005",
|
| 377 |
+
"life_emotional_support_000007",
|
| 378 |
+
"life_emotional_support_000010",
|
| 379 |
+
"life_emotional_support_000011",
|
| 380 |
+
"life_emotional_support_000012",
|
| 381 |
+
"life_emotional_support_000014",
|
| 382 |
+
"life_emotional_support_000015"
|
| 383 |
+
],
|
| 384 |
+
"answer_contains_certainly,": [
|
| 385 |
+
"life_daily_dialogue_000001",
|
| 386 |
+
"life_daily_dialogue_000632",
|
| 387 |
+
"life_daily_dialogue_000906",
|
| 388 |
+
"life_daily_dialogue_001086",
|
| 389 |
+
"life_daily_dialogue_001094",
|
| 390 |
+
"life_daily_dialogue_001228",
|
| 391 |
+
"life_daily_dialogue_001312",
|
| 392 |
+
"life_daily_dialogue_001338",
|
| 393 |
+
"life_daily_dialogue_001508",
|
| 394 |
+
"life_daily_dialogue_001981"
|
| 395 |
+
],
|
| 396 |
+
"answer_keyword_list_style": [
|
| 397 |
+
"life_daily_dialogue_000001",
|
| 398 |
+
"life_daily_dialogue_000002",
|
| 399 |
+
"life_daily_dialogue_000003",
|
| 400 |
+
"life_daily_dialogue_000004",
|
| 401 |
+
"life_daily_dialogue_000006",
|
| 402 |
+
"life_daily_dialogue_000007",
|
| 403 |
+
"life_daily_dialogue_000008",
|
| 404 |
+
"life_daily_dialogue_000009",
|
| 405 |
+
"life_daily_dialogue_000011",
|
| 406 |
+
"life_daily_dialogue_000014"
|
| 407 |
+
],
|
| 408 |
+
"examples_with_under4_word_fragmentish_chunks": [
|
| 409 |
+
"life_daily_dialogue_000005",
|
| 410 |
+
"life_daily_dialogue_000019",
|
| 411 |
+
"life_task_oriented_assistant_000027",
|
| 412 |
+
"life_daily_dialogue_000025",
|
| 413 |
+
"life_task_oriented_assistant_000032",
|
| 414 |
+
"life_daily_dialogue_000035",
|
| 415 |
+
"life_daily_dialogue_000046",
|
| 416 |
+
"life_daily_dialogue_000054",
|
| 417 |
+
"life_daily_dialogue_000057",
|
| 418 |
+
"life_daily_dialogue_000058"
|
| 419 |
+
],
|
| 420 |
+
"examples_num_chunks_gt12": [
|
| 421 |
+
"life_daily_dialogue_000011",
|
| 422 |
+
"life_daily_dialogue_000047",
|
| 423 |
+
"life_daily_dialogue_000052",
|
| 424 |
+
"life_emotional_support_000031",
|
| 425 |
+
"life_task_oriented_assistant_000106",
|
| 426 |
+
"life_task_oriented_assistant_000112",
|
| 427 |
+
"life_daily_dialogue_000116",
|
| 428 |
+
"life_daily_dialogue_000135",
|
| 429 |
+
"life_task_oriented_assistant_000206",
|
| 430 |
+
"life_daily_dialogue_000250"
|
| 431 |
+
],
|
| 432 |
+
"task_closing_answer_asks_missing_slots": [
|
| 433 |
+
"life_task_oriented_assistant_000018",
|
| 434 |
+
"life_task_oriented_assistant_000085",
|
| 435 |
+
"life_task_oriented_assistant_000097",
|
| 436 |
+
"life_task_oriented_assistant_000144",
|
| 437 |
+
"life_task_oriented_assistant_000228",
|
| 438 |
+
"life_task_oriented_assistant_000272",
|
| 439 |
+
"life_task_oriented_assistant_000290",
|
| 440 |
+
"life_task_oriented_assistant_000311",
|
| 441 |
+
"life_task_oriented_assistant_000338",
|
| 442 |
+
"life_task_oriented_assistant_000362"
|
| 443 |
+
]
|
| 444 |
+
}
|
| 445 |
+
```
|
| 446 |
+
|
| 447 |
+
## 7. Full vs High-Quality Comparison
|
| 448 |
+
|
| 449 |
+
| Metric | Full train/eval | High-quality subset |
|
| 450 |
+
| --- | ---: | ---: |
|
| 451 |
+
| Rows | 9322 | 9014 |
|
| 452 |
+
| Average quality_score | 0.989 | 0.993 |
|
| 453 |
+
| Average streaming_reasoning words | 28.501 | 28.117 |
|
| 454 |
+
| Average deep_reasoning words | 16.481 | 16.015 |
|
| 455 |
+
| Average num_chunks | 6.454 | 6.332 |
|
| 456 |
+
| Average chunk length | 8.953 | 8.914 |
|
| 457 |
+
| % quality_flags == [] | 32.22% | 32.65% |
|
| 458 |
+
| % any severe flags | 1.94% | 0.00% |
|
| 459 |
+
| % repeated chunks | 5.76% | 5.70% |
|
| 460 |
+
| % fragment-ish under-4-word chunks | 6.94% | 6.88% |
|
| 461 |
+
| % awkward answers | 33.31% | 33.67% |
|
| 462 |
+
| % closing_mishandled | 0.08% | 0.00% |
|
| 463 |
+
| % possible_slot_error | 0.00% | 0.00% |
|
| 464 |
+
| % low_specificity | 0.00% | 0.00% |
|
| 465 |
+
| % excessive_chunking | 1.87% | 0.00% |
|
| 466 |
+
|
| 467 |
+
## 8. Representative Good Examples: High-Quality Subset
|
| 468 |
+
|
| 469 |
+
### life_task_oriented_assistant_000001 (task_oriented_assistant, score=1.0, flags=[])
|
| 470 |
+
- chunks: `["I'm looking for a restaurant called the gandhi.", "Can you book it for 8 people on Sunday at 14:45?", "I would also like to find somewhere fun in the middle of town to go.", "Sorry, I actually wanted somewhere in the west.", "Sure, please provide me with the postcode and address.", "Thank you for your help, that is all I need today."]`
|
| 471 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'skip']` skip_reasons: `{'6': 'closing_only'}`
|
| 472 |
+
- streaming: C1 domain=restaurant; goal=search. C2 goal=booking; time+=8, 14:45; day+=sunday; party_size+=8 people. C3 destination+=find somewhere fun in the middle of town. C4 area+=west. C5 goal=request_info; requested_info+=address, postcode. C6 [SKIP: closing_only].
|
| 473 |
+
- deep: Need domain=restaurant; goal=search, booking, request_info; area=west; party_size=8 people; destination=find somewhere fun in the middle of town; requested_info=address, postcode; when=sunday, 8, 14:45; closing_detected.
|
| 474 |
+
- answer: You're welcome. Glad I could help; have a great day.
|
| 475 |
+
|
| 476 |
+
### life_task_oriented_assistant_000002 (task_oriented_assistant, score=1.0, flags=['merged_fragments'])
|
| 477 |
+
- chunks: `["Can you find a moderately priced restaurant in the east side?", "I want to find a italian restaurant.", "It is for 7 people.", "The time is tuesday, 7, 14:30.", "Please make a booking.", "How about either of the Indian restaurants in the same area and price range?", "I would like to try the restaurant at 451 Newmarket Road Fen Ditton since it's close by.", "Can you try a booking, please?", "That is all for today Thank you."]`
|
| 478 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'skip', 'skip']` skip_reasons: `{'8': 'repeated_information', '9': 'closing_only'}`
|
| 479 |
+
- streaming: C1 domain=restaurant; goal=search; area+=east; price+=moderate. C2 cuisine+=italian; destination+=find a italian restaurant. C3 party_size+=7 people. C4 time+=7, 14:30; day+=tuesday. C5 goal=booking. C6 goal=modify_constraint; cuisine+=indian. C7 destination+=try the restaurant at 451 newmarket road. C8 [SKIP: repeated_information]. C9 [SKIP: closing_only].
|
| 480 |
+
- deep: Need domain=restaurant; goal=search, booking, recommendation, modify_constraint; area=east; food=italian, indian; price=moderate; party_size=7 people; destination=find a italian restaurant, try the restaurant at 451 newmarket road; when=tuesday, 7, 14:30; closing_detected.
|
| 481 |
+
- answer: You're welcome. Glad I could help; have a great day.
|
| 482 |
+
|
| 483 |
+
### life_task_oriented_assistant_000003 (task_oriented_assistant, score=1.0, flags=['merged_fragments'])
|
| 484 |
+
- chunks: `["Am looking for the Addenbrookes Hospital.", "I need the phone number.", "Thanks, that's all Good bye."]`
|
| 485 |
+
- labels: `['reason', 'reason', 'skip']` skip_reasons: `{'3': 'closing_only'}`
|
| 486 |
+
- streaming: C1 domain=hospital; goal=search. C2 goal=request_info; requested_info+=phone. C3 [SKIP: closing_only].
|
| 487 |
+
- deep: Need domain=hospital; goal=search, request_info; requested_info=phone; closing_detected.
|
| 488 |
+
- answer: You're welcome. Glad I could help; have a great day.
|
| 489 |
+
|
| 490 |
+
### life_task_oriented_assistant_000004 (task_oriented_assistant, score=1.0, flags=['merged_fragments'])
|
| 491 |
+
- chunks: `["Please make a booking for eight people staying for 4 nights from Saturday.", "That will do it.", "Thank you for your assistance!", "Have a good day!", "Actually, I also need a train to go to cambridge and should arrive by 11:45.", "I want to find a hotel.", "The time is 11:45.", "Please make a booking No, thank you.", "I don't need a ticket at this time.", "That is all for now Thank you."]`
|
| 492 |
+
- labels: `['reason', 'reason', 'skip', 'reason', 'reason', 'reason', 'reason', 'skip', 'reason', 'skip']` skip_reasons: `{'3': 'thanks_only', '8': 'repeated_information', '10': 'closing_only'}`
|
| 493 |
+
- streaming: C1 goal=booking; day+=saturday; party_size+=8 people; stay_length+=4 nights. C2 intent=context_update. C3 [SKIP: thanks_only]. C4 intent=context_update. C5 domain=train; goal=search; time+=11:45; destination+=go to cambridge and should arrive by 11:4. C6 domain=hotel; hotel_type+=hotel; destination+=find a hotel. C7 intent=context_update. C8 [SKIP: repeated_information]. C9 intent=context_update. C10 [SKIP: closing_only].
|
| 494 |
+
- deep: Need domain=train, hotel; goal=booking, search; party_size=8 people; stay_length=4 nights; destination=go to cambridge and should arrive by 11:4, find a hotel; when=saturday, 11:45; closing_detected.
|
| 495 |
+
- answer: You're welcome. Glad I could help; have a great day.
|
| 496 |
+
|
| 497 |
+
### life_task_oriented_assistant_000005 (task_oriented_assistant, score=1.0, flags=[])
|
| 498 |
+
- chunks: `["Hi, I am planning a trip for my family and could use some help with a place to stay.", "I want to find a affordable hotel.", "It should be in the west part of town.", "I want the cheap one.", "Please book that for 3 people for 3 nights starting on Friday."]`
|
| 499 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 500 |
+
- streaming: C1 domain=hotel; goal=search; destination+=stay. C2 price+=affordable; hotel_type+=hotel; destination+=find a affordable hotel. C3 area+=west. C4 price+=cheap. C5 goal=booking; time+=3; day+=friday; party_size+=3 people; stay_length+=3 nights.
|
| 501 |
+
- deep: Need domain=hotel; goal=search, booking; area=west; price=affordable, cheap; party_size=3 people; stay_length=3 nights; destination=stay, find a affordable hotel; when=friday, 3.
|
| 502 |
+
- answer: Got it. I will use hotel, west, affordable, cheap, 3 people, friday, 3 and move the task forward.
|
| 503 |
+
|
| 504 |
+
### life_emotional_support_000001 (emotional_support, score=1.0, flags=[])
|
| 505 |
+
- chunks: `["About four years ago, my apartment was robbed.", "I discovered the state of my apartment.", "Everything turn over, any object that had some value was taken.", "I was totaly destroyed.", "About four years ago, my apartment was robbed.", "I discovered the state of my apartment.", "Everything turn over, any object that had some value was taken.", "I was totaly destroyed.", "Holy moly, that must've been a very depressing sight.", "Did the police end up finding the culprit?", "The police were useless.", "They came once then I never heard from them again."]`
|
| 506 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'skip', 'skip', 'skip', 'skip', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{'5': 'repeated_information', '6': 'repeated_information', '7': 'repeated_information', '8': 'repeated_information'}`
|
| 507 |
+
- streaming: C1 cause=four years ago, my apartment was robbed; need=encouragement. C2 support_signal=received. C3 support_signal=received. C4 support_signal=received. C5 [SKIP: repeated_information]. C6 [SKIP: repeated_information]. C7 [SKIP: repeated_information]. C8 [SKIP: repeated_information]. C9 support_signal=received. C10 support_signal=received. C11 support_signal=received. C12 support_signal=received.
|
| 508 |
+
- deep: User is processing four years ago, my apartment was robbed and needs encouragement.
|
| 509 |
+
- answer: That sounds like a lot to process, especially with four years ago, my apartment was robbed. Start with one small next step and give yourself room to sort it out.
|
| 510 |
+
|
| 511 |
+
### life_emotional_support_000002 (emotional_support, score=1.0, flags=[])
|
| 512 |
+
- chunks: `["I was standing in a long line at a store on black friday.", "I had to use the restroom really bad.", "The person behind me offered to watch my items and hold my place.", "when I came back they had taken some of my items to purchase themselves and left my other stuff sitting in an.", "On Black Friday, I was in line at a store and it was taking forever.", "I had to use the restroom so bad.", "Oh yeah those lines can be super long.", "What did you do?", "The person behind me offered to hold my place and watch my stuff, but they didn't."]`
|
| 513 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'skip', 'reason', 'reason', 'reason']` skip_reasons: `{'6': 'repeated_information'}`
|
| 514 |
+
- streaming: C1 need=validation. C2 support_signal=received. C3 support_signal=received. C4 cause=I came back they had taken some of my items to purchase; need=encouragement. C5 support_signal=received. C6 [SKIP: repeated_information]. C7 support_signal=received. C8 support_signal=received. C9 support_signal=received.
|
| 515 |
+
- deep: User is processing I came back they had taken some of my items to purchase and needs encouragement.
|
| 516 |
+
- answer: That sounds like a lot to process, especially with I came back they had taken some of my items to purchase. Start with one small next step and give yourself room to sort it out.
|
| 517 |
+
|
| 518 |
+
### life_emotional_support_000003 (emotional_support, score=1.0, flags=['merged_fragments'])
|
| 519 |
+
- chunks: `["I'm really proud of my mom.", "of how she's stepping up to help my brother raise his children as he struggles to do it alone.", "I'm really proud of my mom.", "of how she's stepping up to help my brother raise his children as he struggles to do it alone Thats very admirable.", "Yeah, I'm proud of her.", "But sometimes I feel like she's enabling him and acts as a crutch for him.", "Don't know if it's my business to say so, though."]`
|
| 520 |
+
- labels: `['reason', 'reason', 'skip', 'skip', 'reason', 'reason', 'reason']` skip_reasons: `{'3': 'repeated_information', '4': 'repeated_information'}`
|
| 521 |
+
- streaming: C1 emotion=proud; event=really of my mom; need=celebration. C2 emotion=lonely; cause=of how she's stepping up to help my brother raise his children; need=validation. C3 [SKIP: repeated_information]. C4 [SKIP: repeated_information]. C5 emotion=proud; event=Yeah, I'm of her; need=celebration. C6 support_signal=received. C7 emotion=confused; cause=Don't know if it's my business to say so, though; need=reassurance.
|
| 522 |
+
- deep: User feels confused after Don't know if it's my business to say so, though and needs reassurance.
|
| 523 |
+
- answer: It makes sense to feel confused after Don't know if it's my business to say so, though. Slow down, check what is actually known, and take one small step before deciding what comes next.
|
| 524 |
+
|
| 525 |
+
### life_emotional_support_000004 (emotional_support, score=1.0, flags=['merged_fragments'])
|
| 526 |
+
- chunks: `["My son woke up soooo early this morning.", "I barely got any sleep.", "MY son woke up at the crack of dawn this morning Its summer vacation.", "I hope you got enough sleep or it might be a long day for you.", "He is so spoiled.", "He just couldnt lay in the bed with me.", "He had to roll around and pull my hair and things so I would get up too.", "Oh ok I see.", "Im sure he will want a nap later.", "Hopefully that gives you time to recharge a little."]`
|
| 527 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 528 |
+
- streaming: C1 need=validation. C2 support_signal=received. C3 support_signal=received. C4 support_signal=received. C5 support_signal=received. C6 support_signal=received. C7 support_signal=received. C8 support_signal=received. C9 support_signal=received. C10 support_signal=received.
|
| 529 |
+
- deep: User is processing the situation and needs validation.
|
| 530 |
+
- answer: That sounds like a lot to process, especially with what happened. Start with one small next step and give yourself room to sort it out.
|
| 531 |
+
|
| 532 |
+
### life_emotional_support_000005 (emotional_support, score=1.0, flags=['merged_fragments'])
|
| 533 |
+
- chunks: `["She wanted to bring her kids too and I just wasn't feeling it I feel terrible.", "I like her kids.", "Well, next time try telling her the truth, like, I am too tired right now, can we do it another day.", "and that way you won't feel bad Yeah.", "That's what I should have done.", "I'm sure she would understand if she is a good friend She is.", "I'm going to invite her over tomorrow and cook."]`
|
| 534 |
+
- labels: `['reason', 'skip', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{'2': 'repeated_information'}`
|
| 535 |
+
- streaming: C1 need=validation. C2 [SKIP: repeated_information]. C3 support_signal=received. C4 support_signal=received. C5 support_signal=received. C6 cause=sure she would understand if she is a good friend She is; need=encouragement. C7 support_signal=received.
|
| 536 |
+
- deep: User is processing sure she would understand if she is a good friend She is and needs encouragement.
|
| 537 |
+
- answer: That sounds like a lot to process, especially with sure she would understand if she is a good friend She is. Start with one small next step and give yourself room to sort it out.
|
| 538 |
+
|
| 539 |
+
### life_daily_dialogue_000001 (daily_dialogue, score=1.0, flags=['merged_fragments'])
|
| 540 |
+
- chunks: `["Certainly.", "And Roman really loves life.", "He knows how to enjoy himself Not always.", "But they like good meal Really?", "How can I go there to have a taste?"]`
|
| 541 |
+
- labels: `['skip', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{'1': 'low_information'}`
|
| 542 |
+
- streaming: C1 [SKIP: low_information]. C2 casual_comment=roman, loves. C3 casual_comment=knows, enjoy. C4 question=true. C5 question=true.
|
| 543 |
+
- deep: Dialogue state: question around roman, loves, knows, enjoy; respond briefly.
|
| 544 |
+
- answer: Good question. The main topic is certainly, roman, loves, life, so I would answer that directly first.
|
| 545 |
+
|
| 546 |
+
### life_daily_dialogue_000002 (daily_dialogue, score=1.0, flags=[])
|
| 547 |
+
- chunks: `["Will the cords keep it from turning on?", "It won't turn on if the cords aren't connected.", "I didn't think of that.", "Try it and see if it works.", "I think that I will, thanks."]`
|
| 548 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 549 |
+
- streaming: C1 question=true. C2 casual_comment=won't, turn. C3 casual_comment=didn't, think. C4 casual_comment=try, see. C5 casual_comment=think, will.
|
| 550 |
+
- deep: Dialogue state: question around won't, turn, didn't, think; respond briefly.
|
| 551 |
+
- answer: Good question. The main topic is will, cords, keep, turning, so I would answer that directly first.
|
| 552 |
+
|
| 553 |
+
### life_daily_dialogue_000003 (daily_dialogue, score=1.0, flags=['merged_fragments'])
|
| 554 |
+
- chunks: `["No, not at all.", "Are these the clothes you want to have washed?", "Yes.", "When can I get them back?", "Well, if they are collected right now, you can get them back tonight That's fine.", "By the way, please have that suit dry cleaned."]`
|
| 555 |
+
- labels: `['reason', 'reason', 'skip', 'reason', 'reason', 'reason']` skip_reasons: `{'3': 'acknowledgement_only'}`
|
| 556 |
+
- streaming: C1 casual_comment=not, all. C2 question=true. C3 [SKIP: acknowledgement_only]. C4 question=true. C5 casual_comment=collected, right. C6 casual_comment=way, suit.
|
| 557 |
+
- deep: Dialogue state: question around not, all, collected, right; respond briefly.
|
| 558 |
+
- answer: Good question. The main topic is not, all, clothes, washed, so I would answer that directly first.
|
| 559 |
+
|
| 560 |
+
### life_daily_dialogue_000004 (daily_dialogue, score=1.0, flags=[])
|
| 561 |
+
- chunks: `["I have never you mention this friend.", "Are you on very good terms with him or her?", "We have been on good terms.", "She is a very nice girl.", "But she got in Dutch with her boss.", "I don ' t have the heart to see her pounding the pavements.", "You must be stuck on her, or you would not use your elbow grease."]`
|
| 562 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 563 |
+
- streaming: C1 casual_comment=never, mention. C2 question=true. C3 casual_comment=been, terms. C4 casual_comment=she, very. C5 casual_comment=she, dutch. C6 casual_comment=don, heart. C7 casual_comment=must, stuck.
|
| 564 |
+
- deep: Dialogue state: question around never, mention, been, terms; respond briefly.
|
| 565 |
+
- answer: Good question. The main topic is never, mention, friend, very, so I would answer that directly first.
|
| 566 |
+
|
| 567 |
+
### life_daily_dialogue_000005 (daily_dialogue, score=1.0, flags=[])
|
| 568 |
+
- chunks: `["I don't know.", "I think you might be over the hill.", "Well, if not gymnastics, then mountain biking.", "Mountain biking is an Olympic sport?"]`
|
| 569 |
+
- labels: `['reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 570 |
+
- streaming: C1 casual_comment=don't. C2 casual_comment=think, might. C3 casual_comment=not, gymnastics. C4 question=true.
|
| 571 |
+
- deep: Dialogue state: question around don't, think, might, not; respond briefly.
|
| 572 |
+
- answer: Good question. The main topic is don't, think, might, over, so I would answer that directly first.
|
| 573 |
+
|
| 574 |
+
### life_how_to_guidance_000002 (how_to_guidance, score=0.85, flags=['copied_source_response'])
|
| 575 |
+
- chunks: `["Task: Make Yahoo! Your Internet Explorer Home Page.", "Go to https://www.yahoo.com 3.", "Click the gear icon in the top-right."]`
|
| 576 |
+
- labels: `['reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 577 |
+
- streaming: C1 task=make_yahoo_your_internet. C2 step=go_to_httpswwwyahoocom_3. C3 step=click_the_gear_icon.
|
| 578 |
+
- deep: Procedure for Make Yahoo! Your Internet Explorer Home Page: Go to https://www.yahoo.com 3, Click the gear icon in the top-right.
|
| 579 |
+
- answer: For Make Yahoo! Your Internet Explorer Home Page, follow the steps in order: Go to https://www.yahoo.com 3, Click the gear icon in the top-right.
|
| 580 |
+
|
| 581 |
+
### life_how_to_guidance_000003 (how_to_guidance, score=0.85, flags=['copied_source_response'])
|
| 582 |
+
- chunks: `["Task: IOS 14 Home Screen Layout Ideas.", "Go black and white for a minimalist look.", "Try a seasonal color scheme.", "Use pastels for a soothing look.", "Go neofuturistic with a neon theme.", "Choose retro icons for a nostalgic vibe."]`
|
| 583 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 584 |
+
- streaming: C1 task=ios_14_home_screen. C2 step=go_black_and_white. C3 step=try_a_seasonal_color. C4 step=use_pastels_for_a. C5 step=go_neofuturistic_with_a. C6 step=choose_retro_icons_for.
|
| 585 |
+
- deep: Procedure for IOS 14 Home Screen Layout Ideas: Go black and white for a minimalist look, Try a seasonal color scheme, Use pastels for a soothing look, Go neofuturistic with a neon theme, Choose retro icons for a nostalgic vibe.
|
| 586 |
+
- answer: For IOS 14 Home Screen Layout Ideas, follow the steps in order: Go black and white for a minimalist look, Try a seasonal color scheme, Use pastels for a soothing look, Go neofuturistic with a neon theme.
|
| 587 |
+
|
| 588 |
+
### life_how_to_guidance_000004 (how_to_guidance, score=0.85, flags=['copied_source_response'])
|
| 589 |
+
- chunks: `["Task: Record a Zoom Meeting on Android.", "Upgrade to a Licensed Zoom account.", "Tap More in the lower-right corner.", "Tap More when you are ready to stop.", "Tap the Pause or Stop icon.", "Check your email to access the meeting recording via Cloud Recording."]`
|
| 590 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 591 |
+
- streaming: C1 task=record_a_zoom_meeting. C2 step=upgrade_to_a_licensed. C3 step=tap_more_in_the. C4 step=tap_more_when_you. C5 step=tap_the_pause_or. C6 step=check_your_email_to.
|
| 592 |
+
- deep: Procedure for Record a Zoom Meeting on Android: Upgrade to a Licensed Zoom account, Tap More in the lower-right corner, Tap More when you are ready to stop, Tap the Pause or Stop icon, Check your email to access the meeting recording via Cloud.
|
| 593 |
+
- answer: For Record a Zoom Meeting on Android, follow the steps in order: Upgrade to a Licensed Zoom account, Tap More in the lower-right corner, Tap More when you are ready to stop, Tap the Pause or Stop icon.
|
| 594 |
+
|
| 595 |
+
### life_how_to_guidance_000005 (how_to_guidance, score=0.85, flags=['copied_source_response'])
|
| 596 |
+
- chunks: `["Task: Unfriend Someone Without Them Knowing.", "Search for the person you want to unfollow.", "Tap the three-dot menu icon.", "Tap Block and Dismiss."]`
|
| 597 |
+
- labels: `['reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 598 |
+
- streaming: C1 task=unfriend_someone_without_them. C2 step=search_for_the_person. C3 step=tap_the_threedot_menu. C4 step=tap_block_and_dismiss.
|
| 599 |
+
- deep: Procedure for Unfriend Someone Without Them Knowing: Search for the person you want to unfollow, Tap the three-dot menu icon, Tap Block and Dismiss.
|
| 600 |
+
- answer: For Unfriend Someone Without Them Knowing, follow the steps in order: Search for the person you want to unfollow, Tap the three-dot menu icon, Tap Block and Dismiss.
|
| 601 |
+
|
| 602 |
+
### life_how_to_guidance_000006 (how_to_guidance, score=0.85, flags=['copied_source_response'])
|
| 603 |
+
- chunks: `["Task: Add Friends on Discord.", "Click the Home button on the top-left.", "Click Friends on the menu.", "Click Add Friend at the top.", "Type your friend's Discord Tag.", "Click Send Friend Request."]`
|
| 604 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 605 |
+
- streaming: C1 task=add_friends_on_discord. C2 step=click_the_home_button. C3 step=click_friends_on_the. C4 step=click_add_friend_at. C5 step=type_your_friends_discord. C6 step=click_send_friend_request.
|
| 606 |
+
- deep: Procedure for Add Friends on Discord: Click the Home button on the top-left, Click Friends on the menu, Click Add Friend at the top, Type your friend's Discord Tag, Click Send Friend Request.
|
| 607 |
+
- answer: For Add Friends on Discord, follow the steps in order: Click the Home button on the top-left, Click Friends on the menu, Click Add Friend at the top, Type your friend's Discord Tag.
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
## 9. Representative Bad Examples: Lowest Quality Scores in Full Dataset
|
| 611 |
+
|
| 612 |
+
### life_how_to_guidance_000016 (how_to_guidance, score=0.75, flags=['merged_fragments', 'copied_source_response', 'weak_context'])
|
| 613 |
+
- chunks: `["Task: Bench Press.", "• Weightlifting training • Barbells • Weights • A weight Bench."]`
|
| 614 |
+
- labels: `['reason', 'reason']` skip_reasons: `{}`
|
| 615 |
+
- streaming: C1 task=bench_press. C2 step=weightlifting_training_barbells_weights.
|
| 616 |
+
- deep: Procedure for Bench Press: Weightlifting training Barbells Weights A weight Bench.
|
| 617 |
+
- answer: For Bench Press, follow the steps in order: Weightlifting training Barbells Weights A weight Bench.
|
| 618 |
+
|
| 619 |
+
### life_how_to_guidance_000010 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 620 |
+
- chunks: `["Task: Why Is My Laptop Not Connecting to WiFi.", "Check your laptop's Wi-Fi button or switch.", "Make sure Wi-Fi is turned on.", "Try disconnecting and reconnecting.", "Turn off your modem and router and turn them back on.", "Forget and re-add the wireless network."]`
|
| 621 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 622 |
+
- streaming: C1 task=why_is_my_laptop. C2 step=check_your_laptops_wifi. C3 step=make_sure_wifi_is. C4 step=try_disconnecting_and_reconnecting. C5 step=turn_off_your_modem; safety=true. C6 step=forget_and_readd_the.
|
| 623 |
+
- deep: Procedure for Why Is My Laptop Not Connecting to WiFi: Check your laptop's Wi-Fi button or switch, Make sure Wi-Fi is turned on, Try disconnecting and reconnecting, Turn off your modem and router and turn them back, Forget and re-add the wireless network; keep safety/order constraints.
|
| 624 |
+
- answer: For Why Is My Laptop Not Connecting to WiFi, follow the steps in order: Check your laptop's Wi-Fi button or switch, Make sure Wi-Fi is turned on, Try disconnecting and reconnecting, Turn off your modem and router and turn them back. Keep the order and pause if a step seems unsafe.
|
| 625 |
+
|
| 626 |
+
### life_how_to_guidance_000024 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 627 |
+
- chunks: `["Task: Give Your Hamster a Bath.", "• A bowl of lukewarm water • A hand towel • Very mild pet shampoo (only for extremely sticky hamsters) • An assistant, preferably one with whom your hamster is familiar.", "• Chinchilla sand and a bowl to keep your hamster clean in the future.", "• A clear space so that you can have all your materials.", "• Paper towel or napkin to pick up roaming stools.", "• Treats to reward your hamster."]`
|
| 628 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 629 |
+
- streaming: C1 task=give_your_hamster_a. C2 step=a_bowl_of_lukewarm. C3 step=chinchilla_sand_and_a. C4 step=a_clear_space_so. C5 step=paper_towel_or_napkin. C6 step=treats_to_reward_your.
|
| 630 |
+
- deep: Procedure for Give Your Hamster a Bath: A bowl of lukewarm water A hand towel Very mild, Chinchilla sand and a bowl to keep your hamster clean, A clear space so that you can have all your, Paper towel or napkin to pick up roaming stools, Treats to reward your hamster.
|
| 631 |
+
- answer: For Give Your Hamster a Bath, follow the steps in order: A bowl of lukewarm water A hand towel Very mild, Chinchilla sand and a bowl to keep your hamster clean, A clear space so that you can have all your, Paper towel or napkin to pick up roaming stools.
|
| 632 |
+
|
| 633 |
+
### life_how_to_guidance_000031 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 634 |
+
- chunks: `["Task: Add Photos to a PDF on a Mobile Device.", "Open Foxit PDF Editor.", "Tap Home and select Edit.", "Tap the image icon in the editing menu at the top of your screen.", "Tap the document to place your photo.", "Insert a picture from your gallery or take a new picture using your camera."]`
|
| 635 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 636 |
+
- streaming: C1 task=add_photos_to_a. C2 step=open_foxit_pdf_editor. C3 step=tap_home_and_select. C4 step=tap_the_image_icon. C5 step=tap_the_document_to. C6 step=insert_a_picture_from.
|
| 637 |
+
- deep: Procedure for Add Photos to a PDF on a Mobile: Open Foxit PDF Editor, Tap Home and select Edit, Tap the image icon in the editing menu at the, Tap the document to place your photo, Insert a picture from your gallery or take a new.
|
| 638 |
+
- answer: For Add Photos to a PDF on a Mobile, follow the steps in order: Open Foxit PDF Editor, Tap Home and select Edit, Tap the image icon in the editing menu at the, Tap the document to place your photo.
|
| 639 |
+
|
| 640 |
+
### life_how_to_guidance_000070 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 641 |
+
- chunks: `["Task: Retrieve and Deliver the Dragonstone in Bleak Falls Barrow in Skyrim.", "Speak to Farengar Secret-Fire in Dragonsreach in Whiterun.", "Travel to Bleak Falls Barrow southwest of Whiterun.", "Enter Bleak Falls Temple and make your way through the corridors.", "Use the combination Snake, Snake, Fish to solve the pillar puzzle and open the gate.", "Make your way further through the corridors and defeat the Giant Spider."]`
|
| 642 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 643 |
+
- streaming: C1 task=retrieve_and_deliver_the. C2 step=speak_to_farengar_secretfire. C3 step=travel_to_bleak_falls. C4 step=enter_bleak_falls_temple. C5 step=use_the_combination_snake. C6 step=make_your_way_further.
|
| 644 |
+
- deep: Procedure for Retrieve and Deliver the Dragonstone in Bleak Falls: Speak to Farengar Secret-Fire in Dragonsreach in Whiterun, Travel to Bleak Falls Barrow southwest of Whiterun, Enter Bleak Falls Temple and make your way through the, Use the combination Snake, Snake, Fish to solve the pillar, Make your way further through the corridors and defeat the.
|
| 645 |
+
- answer: For Retrieve and Deliver the Dragonstone in Bleak Falls, follow the steps in order: Speak to Farengar Secret-Fire in Dragonsreach in Whiterun, Travel to Bleak Falls Barrow southwest of Whiterun, Enter Bleak Falls Temple and make your way through the, Use the combination Snake, Snake, Fish to solve the pillar.
|
| 646 |
+
|
| 647 |
+
### life_how_to_guidance_000073 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 648 |
+
- chunks: `["Task: Create Transparent Backgrounds Using Pixlr.", "Go to https://pixlr.com/editor/ in a web browser and click Continue with Pixlr Editor.", "Click Create a New Image.", "Click the checkbox next to \"Transparent\".", "Click Open Image as Layer under the \"Layers\" menu.", "Use the Wand Tool to select the background."]`
|
| 649 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 650 |
+
- streaming: C1 task=create_transparent_backgrounds_using. C2 step=go_to_httpspixlrcomeditor_in. C3 step=click_create_a_new. C4 step=click_the_checkbox_next. C5 step=click_open_image_as. C6 step=use_the_wand_tool.
|
| 651 |
+
- deep: Procedure for Create Transparent Backgrounds Using Pixlr: Go to https://pixlr.com/editor/ in a web browser and click Continue, Click Create a New Image, Click the checkbox next to "Transparent", Click Open Image as Layer under the "Layers" menu, Use the Wand Tool to select the background.
|
| 652 |
+
- answer: For Create Transparent Backgrounds Using Pixlr, follow the steps in order: Go to https://pixlr.com/editor/ in a web browser and click Continue, Click Create a New Image, Click the checkbox next to "Transparent", Click Open Image as Layer under the "Layers" menu.
|
| 653 |
+
|
| 654 |
+
### life_how_to_guidance_000094 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 655 |
+
- chunks: `["Task: Go Back in Time on Google Maps.", "Go to https://maps.google.com/ in a web browser.", "Drag and drop the orange human icon to a location on the map.", "Click the clock icon.", "Drag and slide the slider to the year you want to see.", "Click the preview image to select it."]`
|
| 656 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 657 |
+
- streaming: C1 task=go_back_in_time. C2 step=go_to_httpsmapsgooglecom_in. C3 step=drag_and_drop_the. C4 step=click_the_clock_icon. C5 step=drag_and_slide_the. C6 step=click_the_preview_image.
|
| 658 |
+
- deep: Procedure for Go Back in Time on Google Maps: Go to https://maps.google.com/ in a web browser, Drag and drop the orange human icon to a location, Click the clock icon, Drag and slide the slider to the year you want, Click the preview image to select it.
|
| 659 |
+
- answer: For Go Back in Time on Google Maps, follow the steps in order: Go to https://maps.google.com/ in a web browser, Drag and drop the orange human icon to a location, Click the clock icon, Drag and slide the slider to the year you want.
|
| 660 |
+
|
| 661 |
+
### life_how_to_guidance_000100 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 662 |
+
- chunks: `["Task: Accept Christ As Your Savior.", "• The Bible: In some countries there are few Bibles, and there is persecution of Christians -- or lack of funds and supply.", "The word of God, especially the Book of John in the Bible, tells how to be a Christian.", "Owning a Bible isn't -- but access to the Bible is -- essential.", "• Other Christians to encourage and guide you.", "If you don't know any, praise God for the mission field that He has placed you in!"]`
|
| 663 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 664 |
+
- streaming: C1 task=accept_christ_as_your. C2 step=the_bible_in_some. C3 step=the_word_of_god. C4 step=owning_a_bible_isnt. C5 step=other_christians_to_encourage. C6 step=if_you_dont_know; safety=true.
|
| 665 |
+
- deep: Procedure for Accept Christ As Your Savior: The Bible: In some countries there are few Bibles, and, The word of God, especially the Book of John in, Owning a Bible isn't -- but access to the Bible, Other Christians to encourage and guide you, If you don't know any, praise God for the mission; keep safety/order constraints.
|
| 666 |
+
- answer: For Accept Christ As Your Savior, follow the steps in order: The Bible: In some countries there are few Bibles, and, The word of God, especially the Book of John in, Owning a Bible isn't -- but access to the Bible, Other Christians to encourage and guide you. Keep the order and pause if a step seems unsafe.
|
| 667 |
+
|
| 668 |
+
### life_how_to_guidance_000123 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 669 |
+
- chunks: `["Task: Make Your Cell Phone Battery Last Longer.", "Reduce screen time and brightness.", "Disable Wi-Fi, GPS, and Bluetooth when not in use.", "Enable Low Power Mode or Power Saving Mode.", "Find out which apps use the most battery power.", "Uninstall those apps or use them less frequently."]`
|
| 670 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 671 |
+
- streaming: C1 task=make_your_cell_phone. C2 step=reduce_screen_time_and. C3 step=disable_wifi_gps_and. C4 step=enable_low_power_mode. C5 step=find_out_which_apps. C6 step=uninstall_those_apps_or.
|
| 672 |
+
- deep: Procedure for Make Your Cell Phone Battery Last Longer: Reduce screen time and brightness, Disable Wi-Fi, GPS, and Bluetooth when not in use, Enable Low Power Mode or Power Saving Mode, Find out which apps use the most battery power, Uninstall those apps or use them less frequently.
|
| 673 |
+
- answer: For Make Your Cell Phone Battery Last Longer, follow the steps in order: Reduce screen time and brightness, Disable Wi-Fi, GPS, and Bluetooth when not in use, Enable Low Power Mode or Power Saving Mode, Find out which apps use the most battery power.
|
| 674 |
+
|
| 675 |
+
### life_how_to_guidance_000132 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 676 |
+
- chunks: `["Task: Download the Skype Desktop Program (Not the App) for Windows 8.", "Go to https://www.skype.com/en/get-skype/ in your browser.", "Click the \"Skype for Desktop\" drop-down box.", "Scroll down and click Get classic Skype 4.", "Open the Skype setup file and complete the installation wizard.", "Sign into Skype when prompted."]`
|
| 677 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 678 |
+
- streaming: C1 task=download_the_skype_desktop. C2 step=go_to_httpswwwskypecomengetskype_in. C3 step=click_the_skype_for. C4 step=scroll_down_and_click. C5 step=open_the_skype_setup. C6 step=sign_into_skype_when.
|
| 679 |
+
- deep: Procedure for Download the Skype Desktop Program for Windows 8: Go to https://www.skype.com/en/get-skype/ in your browser, Click the "Skype for Desktop" drop-down box, Scroll down and click Get classic Skype 4, Open the Skype setup file and complete the installation wizard, Sign into Skype when prompted.
|
| 680 |
+
- answer: For Download the Skype Desktop Program for Windows 8, follow the steps in order: Go to https://www.skype.com/en/get-skype/ in your browser, Click the "Skype for Desktop" drop-down box, Scroll down and click Get classic Skype 4, Open the Skype setup file and complete the installation wizard.
|
| 681 |
+
|
| 682 |
+
### life_how_to_guidance_000151 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 683 |
+
- chunks: `["Task: Install a Logitech Webcam.", "Place the webcam in the desired location.", "Plug in the USB cable.", "Open the Windows Camera app or Mac's Facetime to test.", "Configure your webcam's microphone in your sound settings.", "Select your webcam when streaming or recording in your favorite apps."]`
|
| 684 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 685 |
+
- streaming: C1 task=install_a_logitech_webcam. C2 step=place_the_webcam_in. C3 step=plug_in_the_usb. C4 step=open_the_windows_camera. C5 step=configure_your_webcams_microphone. C6 step=select_your_webcam_when.
|
| 686 |
+
- deep: Procedure for Install a Logitech Webcam: Place the webcam in the desired location, Plug in the USB cable, Open the Windows Camera app or Mac's Facetime to test, Configure your webcam's microphone in your sound settings, Select your webcam when streaming or recording in your favorite.
|
| 687 |
+
- answer: For Install a Logitech Webcam, follow the steps in order: Place the webcam in the desired location, Plug in the USB cable, Open the Windows Camera app or Mac's Facetime to test, Configure your webcam's microphone in your sound settings.
|
| 688 |
+
|
| 689 |
+
### life_how_to_guidance_000154 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 690 |
+
- chunks: `["Task: Speed Up Videos on an iPhone.", "Tap the tile with the large plus sign.", "Tap to select the video you want to speed up as well as the checkmark.", "Tap the video clip in the timeline.", "Tap the speedometer icon.", "Drag the speed slider toward the rabbit on the right."]`
|
| 691 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 692 |
+
- streaming: C1 task=speed_up_videos_on. C2 step=tap_the_tile_with. C3 step=tap_to_select_the. C4 step=tap_the_video_clip. C5 step=tap_the_speedometer_icon. C6 step=drag_the_speed_slider.
|
| 693 |
+
- deep: Procedure for Speed Up Videos on an iPhone: Tap the tile with the large plus sign, Tap to select the video you want to speed up, Tap the video clip in the timeline, Tap the speedometer icon, Drag the speed slider toward the rabbit on the right.
|
| 694 |
+
- answer: For Speed Up Videos on an iPhone, follow the steps in order: Tap the tile with the large plus sign, Tap to select the video you want to speed up, Tap the video clip in the timeline, Tap the speedometer icon.
|
| 695 |
+
|
| 696 |
+
### life_how_to_guidance_000183 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 697 |
+
- chunks: `["Task: Knit a Coat Hanger Cover.", "Method 1 • Wooden clothes hanger, single length/width with hanger hook already installed (from clothing stores, thrift stores, charity shops, home d•cor stores, etc.) • 1 ball wool/yarn (around 8 ply) • 2 knitting needles (no.", "8/ 4mm needles) • Wadding • Sewing thread and needle • Ribbon as decoration • Scissors Method 2 • Wooden clothes hanger, single bar type, around 40-43cm in length • 4 ply wool.", "3 25g balls each of a differing color of choice (make them match though) • 2 knitting needles (no.", "10/3.25mm) • Sewing thread and needle • Scissors."]`
|
| 698 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 699 |
+
- streaming: C1 task=knit_a_coat_hanger. C2 step=method_1_wooden_clothes. C3 step=8_4mm_needles_wadding. C4 step=3_25g_balls_each. C5 step=10325mm_sewing_thread_and.
|
| 700 |
+
- deep: Procedure for Knit a Coat Hanger Cover: Method 1 Wooden clothes hanger, single length/width with hanger hook, 8/ 4mm needles) Wadding Sewing thread and needle Ribbon as, 3 25g balls each of a differing color of choice, 10/3.25mm) Sewing thread and needle Scissors.
|
| 701 |
+
- answer: For Knit a Coat Hanger Cover, follow the steps in order: Method 1 Wooden clothes hanger, single length/width with hanger hook, 8/ 4mm needles) Wadding Sewing thread and needle Ribbon as, 3 25g balls each of a differing color of choice, 10/3.25mm) Sewing thread and needle Scissors.
|
| 702 |
+
|
| 703 |
+
### life_how_to_guidance_000192 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 704 |
+
- chunks: `["Task: Farm in 7 Days to Die.", "Craft a farm plot from 8 wood, 10 rotting flesh, 5 nitrate powder, and 25 clay soil.", "Equip a farm plot and place it in an area with lots of natural light.", "Loot, purchase, or craft seeds.", "Equip the seeds and place them in the farm plot.", "Wait for the plants to fully mature."]`
|
| 705 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 706 |
+
- streaming: C1 task=farm_in_7_days. C2 step=craft_a_farm_plot. C3 step=equip_a_farm_plot. C4 step=loot_purchase_or_craft. C5 step=equip_the_seeds_and. C6 step=wait_for_the_plants.
|
| 707 |
+
- deep: Procedure for Farm in 7 Days to Die: Craft a farm plot from 8 wood, 10 rotting flesh,, Equip a farm plot and place it in an area, Loot, purchase, or craft seeds, Equip the seeds and place them in the farm plot, Wait for the plants to fully mature.
|
| 708 |
+
- answer: For Farm in 7 Days to Die, follow the steps in order: Craft a farm plot from 8 wood, 10 rotting flesh,, Equip a farm plot and place it in an area, Loot, purchase, or craft seeds, Equip the seeds and place them in the farm plot.
|
| 709 |
+
|
| 710 |
+
### life_how_to_guidance_000229 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 711 |
+
- chunks: `["Task: Make Money with Sweatcoin.", "Keep your phone or Apple Watch on you at all times so all of your steps are logged.", "Sign up for a Premium plan to increase your earning limits.", "Complete three Daily Bonus activities per day for extra sweatcoins.", "Join races and complete goals to earn additional sweatcoins.", "Get 5 sweatcoins for each friend you invite."]`
|
| 712 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 713 |
+
- streaming: C1 task=make_money_with_sweatcoin. C2 step=keep_your_phone_or. C3 step=sign_up_for_a. C4 step=complete_three_daily_bonus. C5 step=join_races_and_complete. C6 step=get_5_sweatcoins_for.
|
| 714 |
+
- deep: Procedure for Make Money with Sweatcoin: Keep your phone or Apple Watch on you at all, Sign up for a Premium plan to increase your earning, Complete three Daily Bonus activities per day for extra sweatcoins, Join races and complete goals to earn additional sweatcoins, Get 5 sweatcoins for each friend you invite.
|
| 715 |
+
- answer: For Make Money with Sweatcoin, follow the steps in order: Keep your phone or Apple Watch on you at all, Sign up for a Premium plan to increase your earning, Complete three Daily Bonus activities per day for extra sweatcoins, Join races and complete goals to earn additional sweatcoins.
|
| 716 |
+
|
| 717 |
+
### life_how_to_guidance_000244 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 718 |
+
- chunks: `["Task: Add the Time to a Snapchat.", "Shoot a photo or video snap.", "Tap the Stickers icon that resembles a sheet of paper 4.", "Tap the time sticker in the stickers listed under the Star tab.", "Tap and drag the sticker to where you want to place it.", "Send the snap or save it to your phone."]`
|
| 719 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 720 |
+
- streaming: C1 task=add_the_time_to. C2 step=shoot_a_photo_or. C3 step=tap_the_stickers_icon. C4 step=tap_the_time_sticker. C5 step=tap_and_drag_the. C6 step=send_the_snap_or.
|
| 721 |
+
- deep: Procedure for Add the Time to a Snapchat: Shoot a photo or video snap, Tap the Stickers icon that resembles a sheet of paper, Tap the time sticker in the stickers listed under the, Tap and drag the sticker to where you want to, Send the snap or save it to your phone.
|
| 722 |
+
- answer: For Add the Time to a Snapchat, follow the steps in order: Shoot a photo or video snap, Tap the Stickers icon that resembles a sheet of paper, Tap the time sticker in the stickers listed under the, Tap and drag the sticker to where you want to.
|
| 723 |
+
|
| 724 |
+
### life_how_to_guidance_000259 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 725 |
+
- chunks: `["Task: Temporarily Remove a Key from a Macbook.", "Turn off the Mac and unplug it.", "Find a guitar pick, credit card, or plastic spudger.", "Find a toothpick and Q-tip for cleaning.", "Use the toothpick to clean around the key.", "Dampen the Q-tip to clean around the key."]`
|
| 726 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 727 |
+
- streaming: C1 task=temporarily_remove_a_key. C2 step=turn_off_the_mac; safety=true. C3 step=find_a_guitar_pick. C4 step=find_a_toothpick_and. C5 step=use_the_toothpick_to. C6 step=dampen_the_qtip_to.
|
| 728 |
+
- deep: Procedure for Temporarily Remove a Key from a Macbook: Turn off the Mac and unplug it, Find a guitar pick, credit card, or plastic spudger, Find a toothpick and Q-tip for cleaning, Use the toothpick to clean around the key, Dampen the Q-tip to clean around the key; keep safety/order constraints.
|
| 729 |
+
- answer: For Temporarily Remove a Key from a Macbook, follow the steps in order: Turn off the Mac and unplug it, Find a guitar pick, credit card, or plastic spudger, Find a toothpick and Q-tip for cleaning, Use the toothpick to clean around the key. Keep the order and pause if a step seems unsafe.
|
| 730 |
+
|
| 731 |
+
### life_how_to_guidance_000260 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 732 |
+
- chunks: `["Task: Tile a Table Top.", "• Notched trowel to spread the thinset mortar • Regular trowel • Good sponge to work the grout • Float / squeegee • Sandpaper (60, 100 and 200 grit) • Thinset mortar to set your tile • Masonite (if required, see step #4) • Grout of a color complimentary to.", "it depends upon your tile) • 2.", "3 disposable sponge brushes 1.", "2\" wide • Stain for your edge molding • Clear finish for your molding • Masking tape • Pencil • Ruler / straight edge • Tape measure • Drop cloth • Rolling pin • small hammer and small finishing nails about 1\".", "1.5\" long • Nail set • Wood filler • Small hand saw with a fine cut • Protective eyewear • Heavy duty rubber gloves • Construction adhesive (Liquid Nails, for example but this is optional."]`
|
| 733 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 734 |
+
- streaming: C1 task=tile_a_table_top. C2 step=notched_trowel_to_spread. C3 step=it_depends_upon_your. C4 step=3_disposable_sponge_brushes. C5 step=2_wide_stain_for. C6 step=15_long_nail_set.
|
| 735 |
+
- deep: Procedure for Tile a Table Top: Notched trowel to spread the thinset mortar Regular trowel Good, it depends upon your tile) 2, 3 disposable sponge brushes 1, 2" wide Stain for your edge molding Clear finish for, 1.5" long Nail set Wood filler Small hand saw with.
|
| 736 |
+
- answer: For Tile a Table Top, follow the steps in order: Notched trowel to spread the thinset mortar Regular trowel Good, it depends upon your tile) 2, 3 disposable sponge brushes 1, 2" wide Stain for your edge molding Clear finish for.
|
| 737 |
+
|
| 738 |
+
### life_how_to_guidance_000300 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 739 |
+
- chunks: `["Task: Play Nintendo Switch on Chromebook.", "Insert your Switch into the Dock.", "Plug-in the HDMI from your Dock to the capture card.", "Open the video capture card software on your Chromebook.", "Turn on your Switch.", "Plug-in the USB cable from your capture card to your Chromebook."]`
|
| 740 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 741 |
+
- streaming: C1 task=play_nintendo_switch_on. C2 step=insert_your_switch_into. C3 step=plugin_the_hdmi_from. C4 step=open_the_video_capture. C5 step=turn_on_your_switch. C6 step=plugin_the_usb_cable.
|
| 742 |
+
- deep: Procedure for Play Nintendo Switch on Chromebook: Insert your Switch into the Dock, Plug-in the HDMI from your Dock to the capture card, Open the video capture card software on your Chromebook, Turn on your Switch, Plug-in the USB cable from your capture card to your.
|
| 743 |
+
- answer: For Play Nintendo Switch on Chromebook, follow the steps in order: Insert your Switch into the Dock, Plug-in the HDMI from your Dock to the capture card, Open the video capture card software on your Chromebook, Turn on your Switch.
|
| 744 |
+
|
| 745 |
+
### life_how_to_guidance_000328 (how_to_guidance, score=0.8, flags=['copied_source_response'])
|
| 746 |
+
- chunks: `["Task: Make Sea Salt Ice Cream from Kingdom Hearts.", "Separate the whites and yolk from 2 eggs.", "Beat the egg whites.", "Mix 1/3 cups of sugar with the yolk.", "Put 2 cups of milk in a pot and cook it to a simmer.", "Pour the milk in with the sugar and yolk mixture."]`
|
| 747 |
+
- labels: `['reason', 'reason', 'reason', 'reason', 'reason', 'reason']` skip_reasons: `{}`
|
| 748 |
+
- streaming: C1 task=make_sea_salt_ice. C2 step=separate_the_whites_and. C3 step=beat_the_egg_whites. C4 step=mix_13_cups_of. C5 step=put_2_cups_of. C6 step=pour_the_milk_in.
|
| 749 |
+
- deep: Procedure for Make Sea Salt Ice Cream from Kingdom Hearts: Separate the whites and yolk from 2 eggs, Beat the egg whites, Mix 1/3 cups of sugar with the yolk, Put 2 cups of milk in a pot and cook, Pour the milk in with the sugar and yolk mixture.
|
| 750 |
+
- answer: For Make Sea Salt Ice Cream from Kingdom Hearts, follow the steps in order: Separate the whites and yolk from 2 eggs, Beat the egg whites, Mix 1/3 cups of sugar with the yolk, Put 2 cups of milk in a pot and cook.
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
## 10. Recommended v0.4.1 Fixes
|
| 754 |
+
|
| 755 |
+
1. Add explicit Hugging Face dataset configs/data_files to prevent high-quality subset files from merging into default `train`/`test` splits.
|
| 756 |
+
2. Tighten high-quality filtering: exclude `copied_source_response` from high-quality rows or lower its score below the high-quality threshold.
|
| 757 |
+
3. Add a `repeated_context_chunks` quality flag and exclude examples with repeated chunk ratios above 30% from the high-quality subset.
|
| 758 |
+
4. Improve emotional-support phrasing to avoid awkward templates such as `especially with ...` and keyword-list-like causes.
|
| 759 |
+
5. Improve daily-dialogue answer templates to avoid keyword-list phrases such as `The main topic is certainly, roman...`.
|
| 760 |
+
6. Review task-oriented time/slot extraction edge cases such as `8 people` being treated as time in a few examples.
|
| 761 |
+
|
| 762 |
+
## Bottom Line
|
| 763 |
+
|
| 764 |
+
The local v0.4 files are structurally valid, but the Hugging Face default loader currently merges high-quality subset files into the default `train` and `test` splits. The 18.3k count is explainable and expected given automatic file detection, but suspicious relative to the intended public loading behavior. A v0.4.1 metadata/config patch is recommended before treating the uploaded repo as final for downstream loading.
|
data/eval.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:789b685445a2e59230f9a053a11228eb9cb7807c6c8bd90b07c34085d1675d0f
|
| 3 |
+
size 11543664
|
data/eval.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0ff5c1f79b8c5efb0a927cd1c55d808218cd719e204fa5a4380f913134ea016f
|
| 3 |
+
size 3263619
|
data/eval_high_quality.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/eval_high_quality.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:507c84e96188f87c5676f1470680ab0c3bb8e3a8d825882ef786df7809e8244e
|
| 3 |
+
size 1040671
|
data/train.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a471b77bbaeb766f2add098e55400a08fe40f30f31cfd0a77b742a7d78b2e2ab
|
| 3 |
+
size 46525242
|
data/train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9e44ed1020c2ee02092bda326dd909d3a072266f9e9581e80e668c12adf3951
|
| 3 |
+
size 13098201
|
data/train_high_quality.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9820313006cd06aa68c77ff9df07ff562add6cf45f5179db84fc8f387c11bd5e
|
| 3 |
+
size 16499232
|
data/train_high_quality.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19345b89baecbfa619cf97e761978953929258b7153695cbbdb36ac74ca5f38e
|
| 3 |
+
size 4073500
|
dataset_card.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: LifeTextSingleTurnStreamingCoT
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
version: "v0.4.1"
|
| 7 |
+
configs:
|
| 8 |
+
- config_name: default
|
| 9 |
+
data_files:
|
| 10 |
+
- split: train
|
| 11 |
+
path: data/train.parquet
|
| 12 |
+
- split: test
|
| 13 |
+
path: data/eval.parquet
|
| 14 |
+
- config_name: high_quality
|
| 15 |
+
data_files:
|
| 16 |
+
- split: train
|
| 17 |
+
path: data/train_high_quality.parquet
|
| 18 |
+
- split: test
|
| 19 |
+
path: data/eval_high_quality.parquet
|
| 20 |
+
task_categories:
|
| 21 |
+
- text-generation
|
| 22 |
+
tags:
|
| 23 |
+
- streaming-reasoning
|
| 24 |
+
- supervised-fine-tuning
|
| 25 |
+
- life-assistant
|
| 26 |
+
---
|
| 27 |
+
# LifeTextSingleTurnStreamingCoT
|
| 28 |
+
|
| 29 |
+
LifeTextSingleTurnStreamingCoT is the canonical text/single-turn member of the Life Streaming CoT family. It supersedes the older `LifeStreamingCoT` name while preserving the existing v0.4.1 data and backward-compatible fields.
|
| 30 |
+
|
| 31 |
+
## Summary
|
| 32 |
+
|
| 33 |
+
- Modality: text
|
| 34 |
+
- Turn type: single_turn
|
| 35 |
+
- Version: v0.4.1
|
| 36 |
+
- HF repo: `skyzhou06/LifeTextSingleTurnStreamingCoT`
|
| 37 |
+
- Rows: 9322 total, 7457 train, 1865 eval
|
| 38 |
+
- High-quality rows: 2570 train, 634 eval
|
| 39 |
+
- Source distribution: `{"b-mc2/wikihow_lists": 622, "pietrolesci/multiwoz_all_versions": 2987, "pixelsandpointers/better_daily_dialog": 3713, "pixelsandpointers/empathetic_dialogues_for_lm": 2000}`
|
| 40 |
+
- Category distribution: `{"daily_life": 2987, "information_extraction": 622, "social_communication": 5713}`
|
| 41 |
+
- Length buckets: `{"short": 5575, "short_medium": 1345, "very_short": 2402}`
|
| 42 |
+
|
| 43 |
+
## Schema
|
| 44 |
+
|
| 45 |
+
Core legacy fields include `id`, `domain`, `source_dataset`, `instruction`, `context`, `context_chunks`, `streaming_reasoning`, `deep_reasoning`, `answer`, `messages`, `text`, `quality_flags`, `quality_score`, `is_high_quality`, and `split`.
|
| 46 |
+
|
| 47 |
+
Normalized backward-compatible fields were added where feasible: `modality`, `turn_type`, `taxonomy`, `input`, `streaming`, `output`, and `quality`.
|
| 48 |
+
|
| 49 |
+
## Taxonomy
|
| 50 |
+
|
| 51 |
+
Rows include normalized `taxonomy.category`, `taxonomy.subcategory`, `taxonomy.intent_type`, and `taxonomy.difficulty`. Existing `domain` remains available for backward compatibility.
|
| 52 |
+
|
| 53 |
+
## Streaming and Deep Reasoning
|
| 54 |
+
|
| 55 |
+
Streaming reasoning is deterministic, selective, and chunk-aligned. Deep reasoning is a compact full-context summary. No `sft_messages` field is required.
|
| 56 |
+
|
| 57 |
+
## Quality Filters
|
| 58 |
+
|
| 59 |
+
The release keeps quality scores, high-quality split files, quality flags, source attribution, and validation scripts. The high-quality config is recommended for stricter SFT experiments.
|
| 60 |
+
|
| 61 |
+
## How to use for SFT
|
| 62 |
+
|
| 63 |
+
- Input: `input.instruction` plus `input.context` or legacy `instruction` plus `context`.
|
| 64 |
+
- Target: `output.answer` or legacy `answer`.
|
| 65 |
+
- Optional reasoning target: `streaming.streaming_reasoning`, `output.deep_reasoning`, then `output.answer`.
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from datasets import load_dataset
|
| 69 |
+
|
| 70 |
+
full = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "default")
|
| 71 |
+
hq = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "high_quality")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## Limitations
|
| 75 |
+
|
| 76 |
+
- Reasoning is deterministic/rule-based unless optional LLM augmentation is run separately.
|
| 77 |
+
- Some rows originate from dialogue-style sources and may not perfectly match direct assistant behavior.
|
| 78 |
+
- Not intended for expert medical, legal, financial, emergency, or safety-critical advice.
|
dataset_info.json
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dataset_name": "LifeTextSingleTurnStreamingCoT",
|
| 3 |
+
"repo_id": "skyzhou06/LifeTextSingleTurnStreamingCoT",
|
| 4 |
+
"version": "v0.4.1",
|
| 5 |
+
"created_by": "skyzhou06 with Codex",
|
| 6 |
+
"generation_method": "source_grounded_rule_based_v0.4.1_quality_patch",
|
| 7 |
+
"reasoning_policy": "selective_concise",
|
| 8 |
+
"chunking_method": "semantic_sentence_split_v0.4_refined",
|
| 9 |
+
"refinement_method": "rule_based_quality_patch_v0.4.1",
|
| 10 |
+
"schema": {
|
| 11 |
+
"id": "required",
|
| 12 |
+
"domain": "required",
|
| 13 |
+
"source_dataset": "required",
|
| 14 |
+
"instruction": "required",
|
| 15 |
+
"context": "required",
|
| 16 |
+
"context_chunks": "required",
|
| 17 |
+
"streaming_reasoning": "required",
|
| 18 |
+
"deep_reasoning": "required",
|
| 19 |
+
"answer": "required",
|
| 20 |
+
"response": "required",
|
| 21 |
+
"messages": "required",
|
| 22 |
+
"text": "required",
|
| 23 |
+
"num_chunks": "required",
|
| 24 |
+
"language": "required",
|
| 25 |
+
"split": "required",
|
| 26 |
+
"generation_method": "required",
|
| 27 |
+
"quality_flags": "required",
|
| 28 |
+
"version": "required",
|
| 29 |
+
"reasoning_policy": "required",
|
| 30 |
+
"chunking_method": "required",
|
| 31 |
+
"chunk_labels": "required",
|
| 32 |
+
"skip_chunks": "required",
|
| 33 |
+
"skip_reasons": "required",
|
| 34 |
+
"reasoning_token_budget": "required",
|
| 35 |
+
"original_num_chunks": "required",
|
| 36 |
+
"chunk_split_count": "required",
|
| 37 |
+
"quality_score": "required",
|
| 38 |
+
"is_high_quality": "required",
|
| 39 |
+
"refinement_method": "required",
|
| 40 |
+
"llm_augmented": "required",
|
| 41 |
+
"llm_augmentation_model": "required",
|
| 42 |
+
"rejected_reason": "required",
|
| 43 |
+
"state_tracking_confidence": "required",
|
| 44 |
+
"modality": "optional_normalized_backward_compatible",
|
| 45 |
+
"turn_type": "optional_normalized_backward_compatible",
|
| 46 |
+
"taxonomy": "optional_normalized_backward_compatible",
|
| 47 |
+
"input": "optional_normalized_backward_compatible",
|
| 48 |
+
"streaming": "optional_normalized_backward_compatible",
|
| 49 |
+
"output": "optional_normalized_backward_compatible",
|
| 50 |
+
"quality": "optional_normalized_backward_compatible"
|
| 51 |
+
},
|
| 52 |
+
"source_datasets_used": [
|
| 53 |
+
{
|
| 54 |
+
"name": "b-mc2/wikihow_lists",
|
| 55 |
+
"domain": "how_to_guidance",
|
| 56 |
+
"rows": 622
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"name": "pietrolesci/multiwoz_all_versions",
|
| 60 |
+
"domain": "task_oriented_assistant",
|
| 61 |
+
"rows": 2987
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "pixelsandpointers/better_daily_dialog",
|
| 65 |
+
"domain": "daily_dialogue",
|
| 66 |
+
"rows": 3713
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "pixelsandpointers/empathetic_dialogues_for_lm",
|
| 70 |
+
"domain": "emotional_support",
|
| 71 |
+
"rows": 2000
|
| 72 |
+
}
|
| 73 |
+
],
|
| 74 |
+
"skipped_source_datasets": [],
|
| 75 |
+
"total_rows": 9322,
|
| 76 |
+
"train_rows": 7457,
|
| 77 |
+
"eval_rows": 1865,
|
| 78 |
+
"high_quality_train_rows": 2570,
|
| 79 |
+
"high_quality_eval_rows": 634,
|
| 80 |
+
"domains": {
|
| 81 |
+
"daily_dialogue": 3713,
|
| 82 |
+
"emotional_support": 2000,
|
| 83 |
+
"how_to_guidance": 622,
|
| 84 |
+
"task_oriented_assistant": 2987
|
| 85 |
+
},
|
| 86 |
+
"average_num_chunks": 6.45419437888865,
|
| 87 |
+
"average_chunk_length": 8.952847122959811,
|
| 88 |
+
"average_original_num_chunks": 4.753271830079382,
|
| 89 |
+
"average_chunk_split_count": 1.7806264750053638,
|
| 90 |
+
"average_streaming_reasoning_words": 28.501180004290926,
|
| 91 |
+
"average_deep_reasoning_words": 16.480583565758423,
|
| 92 |
+
"average_quality_score": 0.7602231280841022,
|
| 93 |
+
"high_quality_percentage": 0.3437030680111564,
|
| 94 |
+
"skip_chunk_ratio": 0.11189043645912974,
|
| 95 |
+
"examples_with_at_least_one_skip": 4486,
|
| 96 |
+
"quality_flags_distribution": {
|
| 97 |
+
"awkward_answer": 3441,
|
| 98 |
+
"closing_mishandled": 104,
|
| 99 |
+
"copied_source_response": 469,
|
| 100 |
+
"excessive_chunking": 174,
|
| 101 |
+
"keyword_stitching": 1827,
|
| 102 |
+
"long_deep_reasoning": 2,
|
| 103 |
+
"merged_fragments": 5797,
|
| 104 |
+
"repeated_context_chunks": 537,
|
| 105 |
+
"too_many_skips": 2,
|
| 106 |
+
"weak_context": 10,
|
| 107 |
+
"weak_high_quality_candidate": 3565
|
| 108 |
+
},
|
| 109 |
+
"llm_augmented_count": 0,
|
| 110 |
+
"limitations": [
|
| 111 |
+
"v0.4 is primarily rule-based unless optional LLM augmentation is run.",
|
| 112 |
+
"The high-quality subset is recommended for serious SFT experiments.",
|
| 113 |
+
"Some source datasets are dialogue-style and may not perfectly match ideal assistant behavior.",
|
| 114 |
+
"The dataset is not intended for expert medical, legal, financial, emergency, or safety-critical advice."
|
| 115 |
+
],
|
| 116 |
+
"samples_for_review": "samples_for_review.jsonl",
|
| 117 |
+
"patch_name": "v0.4.1 loading config and high-quality subset patch",
|
| 118 |
+
"patch_notes": [
|
| 119 |
+
"Adds explicit Hugging Face dataset card configs so default loading uses only data/train.parquet and data/eval.parquet.",
|
| 120 |
+
"Adds a separate high_quality config backed by data/train_high_quality.parquet and data/eval_high_quality.parquet.",
|
| 121 |
+
"Tightens high-quality subset filtering to remove copied-source responses, awkward answer templates, keyword-stitching, repeated chunks, and weak candidates."
|
| 122 |
+
],
|
| 123 |
+
"hf_config_fixed": true,
|
| 124 |
+
"old_v0_4_counts": {
|
| 125 |
+
"train_rows": 7457,
|
| 126 |
+
"eval_rows": 1865,
|
| 127 |
+
"high_quality_train_rows": 7207,
|
| 128 |
+
"high_quality_eval_rows": 1807,
|
| 129 |
+
"hf_auto_detected_total_rows": 18336
|
| 130 |
+
},
|
| 131 |
+
"high_quality_metrics": {
|
| 132 |
+
"rows": 3204,
|
| 133 |
+
"average_quality_score": 0.9999531835205993,
|
| 134 |
+
"average_streaming_reasoning_words": 34.70536828963795,
|
| 135 |
+
"average_deep_reasoning_words": 21.18196004993758,
|
| 136 |
+
"average_num_chunks": 6.717540574282148,
|
| 137 |
+
"average_chunk_length": 8.440737815360313,
|
| 138 |
+
"skip_chunk_ratio": 0.18882126097662966,
|
| 139 |
+
"severe_flag_percentage": 0.0,
|
| 140 |
+
"quality_flags_distribution": {
|
| 141 |
+
"merged_fragments": 2187,
|
| 142 |
+
"too_many_skips": 2,
|
| 143 |
+
"weak_context": 1
|
| 144 |
+
}
|
| 145 |
+
},
|
| 146 |
+
"high_quality_filtering_rules": [
|
| 147 |
+
"awkward_answer",
|
| 148 |
+
"closing_mishandled",
|
| 149 |
+
"copied_source_response",
|
| 150 |
+
"excessive_chunking",
|
| 151 |
+
"fragment_chunk",
|
| 152 |
+
"generic_reasoning",
|
| 153 |
+
"keyword_stitching",
|
| 154 |
+
"low_specificity",
|
| 155 |
+
"no repeated context chunks",
|
| 156 |
+
"possible_slot_error",
|
| 157 |
+
"quality_score >= 0.85",
|
| 158 |
+
"repeated_context_chunks",
|
| 159 |
+
"streaming/deep length limits",
|
| 160 |
+
"weak_high_quality_candidate"
|
| 161 |
+
],
|
| 162 |
+
"old_dataset_name": "LifeStreamingCoT",
|
| 163 |
+
"old_repo_id": "skyzhou06/LifeStreamingCoT",
|
| 164 |
+
"hf_repo_url": "https://huggingface.co/datasets/skyzhou06/LifeTextSingleTurnStreamingCoT",
|
| 165 |
+
"modality": "text",
|
| 166 |
+
"turn_type": "single_turn",
|
| 167 |
+
"category_distribution": {
|
| 168 |
+
"daily_life": 2987,
|
| 169 |
+
"information_extraction": 622,
|
| 170 |
+
"social_communication": 5713
|
| 171 |
+
},
|
| 172 |
+
"length_bucket_distribution": {
|
| 173 |
+
"short": 5575,
|
| 174 |
+
"short_medium": 1345,
|
| 175 |
+
"very_short": 2402
|
| 176 |
+
},
|
| 177 |
+
"sft_readiness": {
|
| 178 |
+
"status": "PASS",
|
| 179 |
+
"blockers": []
|
| 180 |
+
},
|
| 181 |
+
"publishability_gate": {
|
| 182 |
+
"status": "PASS",
|
| 183 |
+
"blockers": []
|
| 184 |
+
}
|
| 185 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
datasets
|
| 2 |
+
pandas
|
| 3 |
+
pyarrow
|
| 4 |
+
huggingface_hub
|
| 5 |
+
tqdm
|
samples_for_review.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/analyze_quality.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
from collections import Counter
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 13 |
+
rows: list[dict[str, Any]] = []
|
| 14 |
+
if not path.exists():
|
| 15 |
+
return rows
|
| 16 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 17 |
+
for line in handle:
|
| 18 |
+
line = line.strip()
|
| 19 |
+
if line:
|
| 20 |
+
rows.append(json.loads(line))
|
| 21 |
+
return rows
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def word_count(text: Any) -> int:
|
| 25 |
+
return len(re.findall(r"\b[\w'-]+\b", str(text)))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def avg(values: list[float]) -> float:
|
| 29 |
+
return sum(values) / len(values) if values else 0.0
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def main() -> None:
|
| 33 |
+
parser = argparse.ArgumentParser(description="Summarize LifeTextSingleTurnStreamingCoT v0.4 quality metrics.")
|
| 34 |
+
parser.add_argument("--data-dir", default="life_streaming_cot_dataset")
|
| 35 |
+
args = parser.parse_args()
|
| 36 |
+
|
| 37 |
+
data_dir = Path(args.data_dir) / "data"
|
| 38 |
+
rows = read_jsonl(data_dir / "train.jsonl") + read_jsonl(data_dir / "eval.jsonl")
|
| 39 |
+
hq_rows = read_jsonl(data_dir / "train_high_quality.jsonl") + read_jsonl(data_dir / "eval_high_quality.jsonl")
|
| 40 |
+
total_chunks = sum(row.get("num_chunks", 0) for row in rows)
|
| 41 |
+
skip_chunks = sum(len(row.get("skip_chunks", [])) for row in rows)
|
| 42 |
+
|
| 43 |
+
print("Quality analysis")
|
| 44 |
+
print(f"total rows: {len(rows)}")
|
| 45 |
+
print(f"high-quality rows: {len(hq_rows)}")
|
| 46 |
+
print(f"domains: {dict(sorted(Counter(row.get('domain') for row in rows).items()))}")
|
| 47 |
+
print(f"quality flags: {dict(sorted(Counter(flag for row in rows for flag in row.get('quality_flags', [])).items()))}")
|
| 48 |
+
print(f"average quality_score: {avg([float(row.get('quality_score', 0)) for row in rows]):.3f}")
|
| 49 |
+
print(f"average streaming words: {avg([word_count(row.get('streaming_reasoning', '')) for row in rows]):.2f}")
|
| 50 |
+
print(f"average deep words: {avg([word_count(row.get('deep_reasoning', '')) for row in rows]):.2f}")
|
| 51 |
+
print(f"skip ratio: {skip_chunks / total_chunks if total_chunks else 0:.4f}")
|
| 52 |
+
print(f"llm_augmented rows: {sum(1 for row in rows if row.get('llm_augmented'))}")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
main()
|
scripts/apply_v041_quality_patch.py
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import shutil
|
| 7 |
+
import statistics
|
| 8 |
+
from collections import Counter, defaultdict
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import pandas as pd
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
ROOT = Path("life_streaming_cot_dataset")
|
| 16 |
+
DATA_DIR = ROOT / "data"
|
| 17 |
+
VERSION = "v0.4.1"
|
| 18 |
+
GENERATION_METHOD = "source_grounded_rule_based_v0.4.1_quality_patch"
|
| 19 |
+
REFINEMENT_METHOD = "rule_based_quality_patch_v0.4.1"
|
| 20 |
+
REPO_ID = "skyzhou06/LifeTextSingleTurnStreamingCoT"
|
| 21 |
+
EXCLUDED_HQ_FLAGS = {
|
| 22 |
+
"copied_source_response",
|
| 23 |
+
"awkward_answer",
|
| 24 |
+
"keyword_stitching",
|
| 25 |
+
"repeated_context_chunks",
|
| 26 |
+
"weak_high_quality_candidate",
|
| 27 |
+
"generic_reasoning",
|
| 28 |
+
"closing_mishandled",
|
| 29 |
+
"possible_slot_error",
|
| 30 |
+
"excessive_chunking",
|
| 31 |
+
"fragment_chunk",
|
| 32 |
+
"low_specificity",
|
| 33 |
+
}
|
| 34 |
+
SEVERE_FLAGS = {
|
| 35 |
+
"generic_reasoning",
|
| 36 |
+
"closing_mishandled",
|
| 37 |
+
"possible_slot_error",
|
| 38 |
+
"excessive_chunking",
|
| 39 |
+
"fragment_chunk",
|
| 40 |
+
"low_specificity",
|
| 41 |
+
}
|
| 42 |
+
BASE_FIELDS = [
|
| 43 |
+
"id",
|
| 44 |
+
"domain",
|
| 45 |
+
"source_dataset",
|
| 46 |
+
"instruction",
|
| 47 |
+
"context",
|
| 48 |
+
"context_chunks",
|
| 49 |
+
"streaming_reasoning",
|
| 50 |
+
"deep_reasoning",
|
| 51 |
+
"answer",
|
| 52 |
+
"response",
|
| 53 |
+
"messages",
|
| 54 |
+
"text",
|
| 55 |
+
"num_chunks",
|
| 56 |
+
"language",
|
| 57 |
+
"split",
|
| 58 |
+
"generation_method",
|
| 59 |
+
"quality_flags",
|
| 60 |
+
"version",
|
| 61 |
+
"reasoning_policy",
|
| 62 |
+
"chunking_method",
|
| 63 |
+
"chunk_labels",
|
| 64 |
+
"skip_chunks",
|
| 65 |
+
"skip_reasons",
|
| 66 |
+
"reasoning_token_budget",
|
| 67 |
+
"original_num_chunks",
|
| 68 |
+
"chunk_split_count",
|
| 69 |
+
"quality_score",
|
| 70 |
+
"is_high_quality",
|
| 71 |
+
"refinement_method",
|
| 72 |
+
"llm_augmented",
|
| 73 |
+
"llm_augmentation_model",
|
| 74 |
+
"rejected_reason",
|
| 75 |
+
"state_tracking_confidence",
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 80 |
+
rows: list[dict[str, Any]] = []
|
| 81 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 82 |
+
for line in handle:
|
| 83 |
+
line = line.strip()
|
| 84 |
+
if line:
|
| 85 |
+
rows.append(json.loads(line))
|
| 86 |
+
return rows
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def write_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 90 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 91 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 92 |
+
for row in rows:
|
| 93 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def write_parquet(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 97 |
+
pd.DataFrame(rows, columns=BASE_FIELDS).to_parquet(path, index=False)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def word_count(text: Any) -> int:
|
| 101 |
+
return len(re.findall(r"\b[\w'-]+\b", str(text)))
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def normalize(text: Any) -> str:
|
| 105 |
+
return re.sub(r"\W+", " ", str(text).lower()).strip()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def avg(values: list[float]) -> float:
|
| 109 |
+
return statistics.mean(values) if values else 0.0
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def repeated_chunk_ratio(row: dict[str, Any]) -> tuple[int, float]:
|
| 113 |
+
chunks = [normalize(chunk) for chunk in row.get("context_chunks", []) if normalize(chunk)]
|
| 114 |
+
counts = Counter(chunks)
|
| 115 |
+
repeated = sum(count - 1 for count in counts.values() if count > 1)
|
| 116 |
+
return repeated, repeated / len(chunks) if chunks else 0.0
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def hard_fragment(chunk: str) -> bool:
|
| 120 |
+
text = str(chunk or "").strip()
|
| 121 |
+
normalized = normalize(text)
|
| 122 |
+
if not text or not normalized:
|
| 123 |
+
return True
|
| 124 |
+
if normalized in {"mr", "mrs", "ms", "dr", "prof", "macmillan"}:
|
| 125 |
+
return True
|
| 126 |
+
if re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\.?", text):
|
| 127 |
+
return True
|
| 128 |
+
if re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\s+\.", text):
|
| 129 |
+
return True
|
| 130 |
+
return word_count(text) <= 2 and bool(re.fullmatch(r"[\W_]+", text))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def short_fragmentish(chunk: str) -> bool:
|
| 134 |
+
text = str(chunk or "").strip()
|
| 135 |
+
if hard_fragment(text):
|
| 136 |
+
return True
|
| 137 |
+
if word_count(text) >= 4:
|
| 138 |
+
return False
|
| 139 |
+
safe_short = re.search(
|
| 140 |
+
r"\b(hi|hello|thanks|thank|yes|no|ok|okay|bye|goodbye|wow|well|sure|certainly|yeah|yep|nope|sorry|wait|listen|right|exactly|perfect|interesting|tomorrow|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b",
|
| 141 |
+
text,
|
| 142 |
+
flags=re.IGNORECASE,
|
| 143 |
+
)
|
| 144 |
+
meaningful_short = re.search(
|
| 145 |
+
r"\b(book|leave|go|wait|stop|help|call|turn|tap|click|wipe|wash|unplug|rinse)\b",
|
| 146 |
+
text,
|
| 147 |
+
flags=re.IGNORECASE,
|
| 148 |
+
)
|
| 149 |
+
return not (safe_short or meaningful_short)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def keyword_list_style(text: str) -> bool:
|
| 153 |
+
lower = str(text).lower()
|
| 154 |
+
if re.search(r"\b(main topic is|especially with|after|because|around)\s+[a-z][a-z'-]+,\s+[a-z][a-z'-]+", lower):
|
| 155 |
+
return True
|
| 156 |
+
if re.search(r"\b[a-z][a-z'-]+,\s+[a-z][a-z'-]+,\s+[a-z][a-z'-]+(?:,\s+[a-z][a-z'-]+)?\b", lower):
|
| 157 |
+
return any(marker in lower for marker in ["user feels", "user is processing", "main topic", "especially with", "dialogue state"])
|
| 158 |
+
return False
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def awkward_answer(row: dict[str, Any]) -> bool:
|
| 162 |
+
answer = str(row.get("answer", ""))
|
| 163 |
+
lower = answer.lower()
|
| 164 |
+
return (
|
| 165 |
+
"especially with" in lower
|
| 166 |
+
or "the main topic is" in lower
|
| 167 |
+
or "certainly," in lower
|
| 168 |
+
or keyword_list_style(answer)
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def emotional_keyword_stitching(row: dict[str, Any]) -> bool:
|
| 173 |
+
if row.get("domain") != "emotional_support":
|
| 174 |
+
return False
|
| 175 |
+
stream = str(row.get("streaming_reasoning", ""))
|
| 176 |
+
deep = str(row.get("deep_reasoning", ""))
|
| 177 |
+
answer = str(row.get("answer", ""))
|
| 178 |
+
support_signals = stream.count("support_signal=received")
|
| 179 |
+
chunks = max(1, int(row.get("num_chunks", 1)))
|
| 180 |
+
return (
|
| 181 |
+
support_signals >= 3
|
| 182 |
+
or support_signals / chunks > 0.35
|
| 183 |
+
or "especially with" in answer.lower()
|
| 184 |
+
or keyword_list_style(deep)
|
| 185 |
+
or keyword_list_style(answer)
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def task_closing_mishandled(row: dict[str, Any]) -> bool:
|
| 190 |
+
if row.get("domain") != "task_oriented_assistant":
|
| 191 |
+
return False
|
| 192 |
+
context = " ".join(row.get("context_chunks", []))
|
| 193 |
+
closing = re.search(
|
| 194 |
+
r"\b(thanks|thank you|goodbye|bye|that'?s all|that is all|all i need|all i needed|all set|take care|good bye)\b",
|
| 195 |
+
context,
|
| 196 |
+
flags=re.IGNORECASE,
|
| 197 |
+
)
|
| 198 |
+
asks = re.search(r"\?|what .*(should|would)|please (provide|confirm|tell)|which .* should|share .*", str(row.get("answer", "")), flags=re.IGNORECASE)
|
| 199 |
+
return bool(closing and asks)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def recompute_flags(row: dict[str, Any]) -> list[str]:
|
| 203 |
+
flags = list(dict.fromkeys(row.get("quality_flags", [])))
|
| 204 |
+
chunks = row.get("context_chunks", [])
|
| 205 |
+
repeated, ratio = repeated_chunk_ratio(row)
|
| 206 |
+
if repeated:
|
| 207 |
+
flags.append("repeated_context_chunks")
|
| 208 |
+
if any(hard_fragment(chunk) for chunk in chunks):
|
| 209 |
+
flags.append("fragment_chunk")
|
| 210 |
+
if any(short_fragmentish(chunk) for chunk in chunks):
|
| 211 |
+
flags.append("weak_high_quality_candidate")
|
| 212 |
+
avg_chunk_words = avg([word_count(chunk) for chunk in chunks])
|
| 213 |
+
if avg_chunk_words < 4 or row.get("num_chunks", 0) > 12:
|
| 214 |
+
flags.append("excessive_chunking")
|
| 215 |
+
if awkward_answer(row):
|
| 216 |
+
flags.append("awkward_answer")
|
| 217 |
+
if emotional_keyword_stitching(row):
|
| 218 |
+
flags.append("keyword_stitching")
|
| 219 |
+
if "Dialogue state:" in str(row.get("deep_reasoning", "")):
|
| 220 |
+
flags.append("weak_high_quality_candidate")
|
| 221 |
+
if task_closing_mishandled(row):
|
| 222 |
+
flags.append("closing_mishandled")
|
| 223 |
+
if ratio > 0.30:
|
| 224 |
+
flags.append("weak_high_quality_candidate")
|
| 225 |
+
return list(dict.fromkeys(flags))
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def recompute_quality_score(row: dict[str, Any], flags: list[str]) -> float:
|
| 229 |
+
penalties = {
|
| 230 |
+
"generic_reasoning": 0.20,
|
| 231 |
+
"copied_source_response": 0.20,
|
| 232 |
+
"awkward_answer": 0.25,
|
| 233 |
+
"keyword_stitching": 0.25,
|
| 234 |
+
"weak_high_quality_candidate": 0.20,
|
| 235 |
+
"repeated_context_chunks": 0.10,
|
| 236 |
+
"fragment_chunk": 0.20,
|
| 237 |
+
"excessive_chunking": 0.15,
|
| 238 |
+
"closing_mishandled": 0.20,
|
| 239 |
+
"possible_slot_error": 0.15,
|
| 240 |
+
"low_specificity": 0.15,
|
| 241 |
+
"long_streaming_reasoning": 0.05,
|
| 242 |
+
"long_deep_reasoning": 0.05,
|
| 243 |
+
"too_many_skips": 0.05,
|
| 244 |
+
"weak_context": 0.05,
|
| 245 |
+
}
|
| 246 |
+
score = 1.0 - sum(penalties.get(flag, 0.0) for flag in set(flags))
|
| 247 |
+
if repeated_chunk_ratio(row)[1] > 0.30:
|
| 248 |
+
score -= 0.10
|
| 249 |
+
if word_count(row.get("streaming_reasoning", "")) > 120:
|
| 250 |
+
score -= 0.05
|
| 251 |
+
if word_count(row.get("deep_reasoning", "")) > 45:
|
| 252 |
+
score -= 0.05
|
| 253 |
+
return round(max(0.0, min(1.0, score)), 3)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def is_high_quality(row: dict[str, Any]) -> bool:
|
| 257 |
+
flags = set(row.get("quality_flags", []))
|
| 258 |
+
if row.get("quality_score", 0) < 0.85:
|
| 259 |
+
return False
|
| 260 |
+
if flags & EXCLUDED_HQ_FLAGS:
|
| 261 |
+
return False
|
| 262 |
+
if repeated_chunk_ratio(row)[1] > 0:
|
| 263 |
+
return False
|
| 264 |
+
if word_count(row.get("streaming_reasoning", "")) > 120 or word_count(row.get("deep_reasoning", "")) > 45:
|
| 265 |
+
return False
|
| 266 |
+
return True
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def update_row(row: dict[str, Any]) -> dict[str, Any]:
|
| 270 |
+
row = dict(row)
|
| 271 |
+
row["version"] = VERSION
|
| 272 |
+
row["generation_method"] = GENERATION_METHOD
|
| 273 |
+
row["refinement_method"] = REFINEMENT_METHOD
|
| 274 |
+
flags = recompute_flags(row)
|
| 275 |
+
row["quality_flags"] = flags
|
| 276 |
+
row["quality_score"] = recompute_quality_score(row, flags)
|
| 277 |
+
row["is_high_quality"] = is_high_quality(row)
|
| 278 |
+
return row
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def quality_counts(rows: list[dict[str, Any]]) -> dict[str, int]:
|
| 282 |
+
return dict(sorted(Counter(flag for row in rows for flag in row.get("quality_flags", [])).items()))
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def source_summary(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 286 |
+
counts = Counter(row["source_dataset"] for row in rows)
|
| 287 |
+
domains: dict[str, set[str]] = defaultdict(set)
|
| 288 |
+
for row in rows:
|
| 289 |
+
domains[row["source_dataset"]].add(row["domain"])
|
| 290 |
+
return [{"name": source, "domain": ",".join(sorted(domains[source])), "rows": count} for source, count in sorted(counts.items())]
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def metrics(rows: list[dict[str, Any]]) -> dict[str, Any]:
|
| 294 |
+
total_chunks = sum(row.get("num_chunks", 0) for row in rows)
|
| 295 |
+
skip_chunks = sum(len(row.get("skip_chunks", [])) for row in rows)
|
| 296 |
+
severe = sum(1 for row in rows if set(row.get("quality_flags", [])) & SEVERE_FLAGS)
|
| 297 |
+
return {
|
| 298 |
+
"rows": len(rows),
|
| 299 |
+
"average_quality_score": avg([float(row.get("quality_score", 0)) for row in rows]),
|
| 300 |
+
"average_streaming_reasoning_words": avg([word_count(row.get("streaming_reasoning", "")) for row in rows]),
|
| 301 |
+
"average_deep_reasoning_words": avg([word_count(row.get("deep_reasoning", "")) for row in rows]),
|
| 302 |
+
"average_num_chunks": avg([row.get("num_chunks", 0) for row in rows]),
|
| 303 |
+
"average_chunk_length": avg([word_count(chunk) for row in rows for chunk in row.get("context_chunks", [])]),
|
| 304 |
+
"skip_chunk_ratio": skip_chunks / total_chunks if total_chunks else 0,
|
| 305 |
+
"severe_flag_percentage": severe / len(rows) if rows else 0,
|
| 306 |
+
"quality_flags_distribution": quality_counts(rows),
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def select_review_samples(rows: list[dict[str, Any]], hq_rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 311 |
+
fields = [
|
| 312 |
+
"id",
|
| 313 |
+
"domain",
|
| 314 |
+
"context_chunks",
|
| 315 |
+
"chunk_labels",
|
| 316 |
+
"skip_reasons",
|
| 317 |
+
"streaming_reasoning",
|
| 318 |
+
"deep_reasoning",
|
| 319 |
+
"answer",
|
| 320 |
+
"quality_flags",
|
| 321 |
+
"quality_score",
|
| 322 |
+
"is_high_quality",
|
| 323 |
+
"refinement_method",
|
| 324 |
+
"split",
|
| 325 |
+
]
|
| 326 |
+
selected: list[dict[str, Any]] = []
|
| 327 |
+
seen: set[str] = set()
|
| 328 |
+
by_domain: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
| 329 |
+
for row in hq_rows + rows:
|
| 330 |
+
by_domain[row["domain"]].append(row)
|
| 331 |
+
for domain in ["task_oriented_assistant", "emotional_support", "daily_dialogue", "how_to_guidance"]:
|
| 332 |
+
for row in by_domain.get(domain, [])[:30]:
|
| 333 |
+
if row["id"] in seen:
|
| 334 |
+
continue
|
| 335 |
+
selected.append({field: row.get(field) for field in fields})
|
| 336 |
+
seen.add(row["id"])
|
| 337 |
+
for row in rows:
|
| 338 |
+
if len(selected) >= 120:
|
| 339 |
+
break
|
| 340 |
+
if row["id"] not in seen:
|
| 341 |
+
selected.append({field: row.get(field) for field in fields})
|
| 342 |
+
seen.add(row["id"])
|
| 343 |
+
return selected[:120]
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def update_dataset_info(
|
| 347 |
+
train_rows: list[dict[str, Any]],
|
| 348 |
+
eval_rows: list[dict[str, Any]],
|
| 349 |
+
hq_train: list[dict[str, Any]],
|
| 350 |
+
hq_eval: list[dict[str, Any]],
|
| 351 |
+
old_info: dict[str, Any],
|
| 352 |
+
) -> dict[str, Any]:
|
| 353 |
+
rows = train_rows + eval_rows
|
| 354 |
+
hq_rows = hq_train + hq_eval
|
| 355 |
+
full_metrics = metrics(rows)
|
| 356 |
+
hq_metrics = metrics(hq_rows)
|
| 357 |
+
return {
|
| 358 |
+
**old_info,
|
| 359 |
+
"version": VERSION,
|
| 360 |
+
"repo_id": REPO_ID,
|
| 361 |
+
"generation_method": GENERATION_METHOD,
|
| 362 |
+
"refinement_method": REFINEMENT_METHOD,
|
| 363 |
+
"patch_name": "v0.4.1 loading config and high-quality subset patch",
|
| 364 |
+
"patch_notes": [
|
| 365 |
+
"Adds explicit Hugging Face dataset card configs so default loading uses only data/train.parquet and data/eval.parquet.",
|
| 366 |
+
"Adds a separate high_quality config backed by data/train_high_quality.parquet and data/eval_high_quality.parquet.",
|
| 367 |
+
"Tightens high-quality subset filtering to remove copied-source responses, awkward answer templates, keyword-stitching, repeated chunks, and weak candidates.",
|
| 368 |
+
],
|
| 369 |
+
"hf_config_fixed": True,
|
| 370 |
+
"old_v0_4_counts": {
|
| 371 |
+
"train_rows": old_info.get("train_rows"),
|
| 372 |
+
"eval_rows": old_info.get("eval_rows"),
|
| 373 |
+
"high_quality_train_rows": old_info.get("high_quality_train_rows"),
|
| 374 |
+
"high_quality_eval_rows": old_info.get("high_quality_eval_rows"),
|
| 375 |
+
"hf_auto_detected_total_rows": 18336,
|
| 376 |
+
},
|
| 377 |
+
"total_rows": len(rows),
|
| 378 |
+
"train_rows": len(train_rows),
|
| 379 |
+
"eval_rows": len(eval_rows),
|
| 380 |
+
"high_quality_train_rows": len(hq_train),
|
| 381 |
+
"high_quality_eval_rows": len(hq_eval),
|
| 382 |
+
"domains": dict(sorted(Counter(row["domain"] for row in rows).items())),
|
| 383 |
+
"source_datasets_used": source_summary(rows),
|
| 384 |
+
"average_streaming_reasoning_words": full_metrics["average_streaming_reasoning_words"],
|
| 385 |
+
"average_deep_reasoning_words": full_metrics["average_deep_reasoning_words"],
|
| 386 |
+
"average_quality_score": full_metrics["average_quality_score"],
|
| 387 |
+
"high_quality_percentage": len(hq_rows) / len(rows) if rows else 0,
|
| 388 |
+
"skip_chunk_ratio": full_metrics["skip_chunk_ratio"],
|
| 389 |
+
"quality_flags_distribution": full_metrics["quality_flags_distribution"],
|
| 390 |
+
"high_quality_metrics": hq_metrics,
|
| 391 |
+
"high_quality_filtering_rules": sorted(EXCLUDED_HQ_FLAGS | {"quality_score >= 0.85", "no repeated context chunks", "streaming/deep length limits"}),
|
| 392 |
+
"llm_augmented_count": sum(1 for row in rows if row.get("llm_augmented")),
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def yaml_front_matter() -> str:
|
| 397 |
+
return f"""---
|
| 398 |
+
pretty_name: LifeTextSingleTurnStreamingCoT
|
| 399 |
+
language:
|
| 400 |
+
- en
|
| 401 |
+
license: apache-2.0
|
| 402 |
+
version: "{VERSION}"
|
| 403 |
+
configs:
|
| 404 |
+
- config_name: default
|
| 405 |
+
data_files:
|
| 406 |
+
- split: train
|
| 407 |
+
path: data/train.parquet
|
| 408 |
+
- split: test
|
| 409 |
+
path: data/eval.parquet
|
| 410 |
+
- config_name: high_quality
|
| 411 |
+
data_files:
|
| 412 |
+
- split: train
|
| 413 |
+
path: data/train_high_quality.parquet
|
| 414 |
+
- split: test
|
| 415 |
+
path: data/eval_high_quality.parquet
|
| 416 |
+
task_categories:
|
| 417 |
+
- text-generation
|
| 418 |
+
tags:
|
| 419 |
+
- streaming-reasoning
|
| 420 |
+
- selective-reasoning
|
| 421 |
+
- quality-refined
|
| 422 |
+
- supervised-fine-tuning
|
| 423 |
+
- sft
|
| 424 |
+
- dialogue
|
| 425 |
+
- task-oriented-dialogue
|
| 426 |
+
- life-assistant
|
| 427 |
+
- streamingthinker
|
| 428 |
+
size_categories:
|
| 429 |
+
- 1K<n<10K
|
| 430 |
+
---
|
| 431 |
+
"""
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
def update_readme(info: dict[str, Any]) -> None:
|
| 435 |
+
path = ROOT / "README.md"
|
| 436 |
+
text = path.read_text(encoding="utf-8")
|
| 437 |
+
body = re.sub(r"\A---.*?---\s*", "", text, flags=re.DOTALL)
|
| 438 |
+
body = body.replace(
|
| 439 |
+
"Current version: v0.4: Quality-Refined Selective Streaming Reasoning",
|
| 440 |
+
"Current version: v0.4.1: Loading Config and High-Quality Subset Patch",
|
| 441 |
+
)
|
| 442 |
+
body = body.replace(
|
| 443 |
+
"| v0.4 | Quality refinement, quality scores, high-quality subset |",
|
| 444 |
+
"| v0.4 | Quality refinement, quality scores, high-quality subset |\n| v0.4.1 | HF loading config fix, stricter high-quality filtering |",
|
| 445 |
+
)
|
| 446 |
+
if "## Version 0.4.1: Loading Config and High-Quality Subset Patch" not in body:
|
| 447 |
+
section = f"""
|
| 448 |
+
## Version 0.4.1: Loading Config and High-Quality Subset Patch
|
| 449 |
+
|
| 450 |
+
v0.4.1 is a patch over v0.4. It fixes Hugging Face loading behavior by adding explicit dataset card configs. The default config now points only to the full dataset files, while the `high_quality` config points only to the stricter high-quality subset files.
|
| 451 |
+
|
| 452 |
+
```python
|
| 453 |
+
from datasets import load_dataset
|
| 454 |
+
|
| 455 |
+
full = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "default")
|
| 456 |
+
hq = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT", "high_quality")
|
| 457 |
+
```
|
| 458 |
+
|
| 459 |
+
Expected split sizes for v0.4.1:
|
| 460 |
+
|
| 461 |
+
- `default/train`: {info['train_rows']}
|
| 462 |
+
- `default/test`: {info['eval_rows']}
|
| 463 |
+
- `high_quality/train`: {info['high_quality_train_rows']}
|
| 464 |
+
- `high_quality/test`: {info['high_quality_eval_rows']}
|
| 465 |
+
|
| 466 |
+
The high-quality subset excludes copied-source responses, awkward answer templates, keyword-stitching, repeated context chunks, weak candidates, and severe quality flags.
|
| 467 |
+
"""
|
| 468 |
+
body = body.replace("## Version History\n", section + "\n## Version History\n")
|
| 469 |
+
body = re.sub(r"- Train: \d+", f"- Train: {info['train_rows']}", body)
|
| 470 |
+
body = re.sub(r"- Eval: \d+", f"- Eval: {info['eval_rows']}", body)
|
| 471 |
+
body = re.sub(r"- Total: \d+", f"- Total: {info['total_rows']}", body)
|
| 472 |
+
body = re.sub(r"- High-quality train: \d+", f"- High-quality train: {info['high_quality_train_rows']}", body)
|
| 473 |
+
body = re.sub(r"- High-quality eval: \d+", f"- High-quality eval: {info['high_quality_eval_rows']}", body)
|
| 474 |
+
body = body.replace("v0.4 improves quality", "v0.4 improved quality")
|
| 475 |
+
path.write_text(yaml_front_matter() + body, encoding="utf-8")
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def sync_scripts() -> None:
|
| 479 |
+
target = ROOT / "scripts"
|
| 480 |
+
target.mkdir(parents=True, exist_ok=True)
|
| 481 |
+
for src in Path("scripts").glob("*.py"):
|
| 482 |
+
shutil.copy2(src, target / src.name)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def main() -> None:
|
| 486 |
+
old_info = json.loads((ROOT / "dataset_info.json").read_text(encoding="utf-8"))
|
| 487 |
+
train_rows = [update_row(row) for row in read_jsonl(DATA_DIR / "train.jsonl")]
|
| 488 |
+
eval_rows = [update_row(row) for row in read_jsonl(DATA_DIR / "eval.jsonl")]
|
| 489 |
+
hq_train = [row for row in train_rows if row["is_high_quality"]]
|
| 490 |
+
hq_eval = [row for row in eval_rows if row["is_high_quality"]]
|
| 491 |
+
if len(hq_train) + len(hq_eval) < 1000:
|
| 492 |
+
raise RuntimeError("v0.4.1 high-quality filtering produced fewer than 1000 rows.")
|
| 493 |
+
|
| 494 |
+
write_jsonl(DATA_DIR / "train.jsonl", train_rows)
|
| 495 |
+
write_jsonl(DATA_DIR / "eval.jsonl", eval_rows)
|
| 496 |
+
write_jsonl(DATA_DIR / "train_high_quality.jsonl", hq_train)
|
| 497 |
+
write_jsonl(DATA_DIR / "eval_high_quality.jsonl", hq_eval)
|
| 498 |
+
write_parquet(DATA_DIR / "train.parquet", train_rows)
|
| 499 |
+
write_parquet(DATA_DIR / "eval.parquet", eval_rows)
|
| 500 |
+
write_parquet(DATA_DIR / "train_high_quality.parquet", hq_train)
|
| 501 |
+
write_parquet(DATA_DIR / "eval_high_quality.parquet", hq_eval)
|
| 502 |
+
|
| 503 |
+
info = update_dataset_info(train_rows, eval_rows, hq_train, hq_eval, old_info)
|
| 504 |
+
(ROOT / "dataset_info.json").write_text(json.dumps(info, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
| 505 |
+
write_jsonl(ROOT / "samples_for_review.jsonl", select_review_samples(train_rows + eval_rows, hq_train + hq_eval))
|
| 506 |
+
update_readme(info)
|
| 507 |
+
sync_scripts()
|
| 508 |
+
|
| 509 |
+
print(json.dumps({
|
| 510 |
+
"version": VERSION,
|
| 511 |
+
"train_rows": len(train_rows),
|
| 512 |
+
"eval_rows": len(eval_rows),
|
| 513 |
+
"high_quality_train_rows": len(hq_train),
|
| 514 |
+
"high_quality_eval_rows": len(hq_eval),
|
| 515 |
+
"high_quality_total": len(hq_train) + len(hq_eval),
|
| 516 |
+
"full_quality_flags": quality_counts(train_rows + eval_rows),
|
| 517 |
+
"high_quality_flags": quality_counts(hq_train + hq_eval),
|
| 518 |
+
}, ensure_ascii=False, indent=2))
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
if __name__ == "__main__":
|
| 522 |
+
main()
|
scripts/augment_with_llm.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
import urllib.request
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from types import SimpleNamespace
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
DEFAULT_MODEL = "gpt-4.1-mini"
|
| 16 |
+
FORBIDDEN_PHRASES = [
|
| 17 |
+
"the user is sharing everyday context",
|
| 18 |
+
"the situation is about an everyday life situation",
|
| 19 |
+
"the assistant should stay conversational",
|
| 20 |
+
"the user is asking for help, clarification, or a next step",
|
| 21 |
+
"support need centers on",
|
| 22 |
+
"task_detail=noted",
|
| 23 |
+
"emotion=positive; cause=",
|
| 24 |
+
"emotion=negative; cause=",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 29 |
+
rows: list[dict[str, Any]] = []
|
| 30 |
+
if not path.exists():
|
| 31 |
+
return rows
|
| 32 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 33 |
+
for line in handle:
|
| 34 |
+
line = line.strip()
|
| 35 |
+
if line:
|
| 36 |
+
rows.append(json.loads(line))
|
| 37 |
+
return rows
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def write_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 41 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 43 |
+
for row in rows:
|
| 44 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def make_response(streaming_reasoning: str, deep_reasoning: str, answer: str) -> str:
|
| 48 |
+
return f"Streaming reasoning: {streaming_reasoning}\n\nDeep reasoning: {deep_reasoning}\n\nAnswer: {answer}"
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def make_messages(instruction: str, context: str, response: str) -> list[dict[str, str]]:
|
| 52 |
+
return [
|
| 53 |
+
{"role": "user", "content": f"Instruction: {instruction}\n\nContext:\n{context}"},
|
| 54 |
+
{"role": "assistant", "content": response},
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def make_text(messages: list[dict[str, str]]) -> str:
|
| 59 |
+
return f"<|user|>\n{messages[0]['content']}\n<|assistant|>\n{messages[1]['content']}"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def has_forbidden(text: str) -> bool:
|
| 63 |
+
lower = text.lower()
|
| 64 |
+
return any(phrase in lower for phrase in FORBIDDEN_PHRASES)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def word_count(text: str) -> int:
|
| 68 |
+
return len(re.findall(r"\b[\w'-]+\b", text))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def parse_json_object(text: str) -> dict[str, str]:
|
| 72 |
+
match = re.search(r"\{.*\}", text, flags=re.DOTALL)
|
| 73 |
+
if not match:
|
| 74 |
+
raise ValueError("model did not return a JSON object")
|
| 75 |
+
data = json.loads(match.group(0))
|
| 76 |
+
required = ["streaming_reasoning", "deep_reasoning", "answer"]
|
| 77 |
+
if not all(isinstance(data.get(key), str) and data[key].strip() for key in required):
|
| 78 |
+
raise ValueError("model JSON is missing required string fields")
|
| 79 |
+
return {key: data[key].strip() for key in required}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def augment_row(client: Any, row: dict[str, Any], model: str) -> dict[str, Any]:
|
| 83 |
+
prompt = {
|
| 84 |
+
"domain": row.get("domain"),
|
| 85 |
+
"context_chunks": row.get("context_chunks"),
|
| 86 |
+
"chunk_labels": row.get("chunk_labels"),
|
| 87 |
+
"skip_reasons": row.get("skip_reasons"),
|
| 88 |
+
"current_streaming_reasoning": row.get("streaming_reasoning"),
|
| 89 |
+
"current_deep_reasoning": row.get("deep_reasoning"),
|
| 90 |
+
"current_answer": row.get("answer"),
|
| 91 |
+
}
|
| 92 |
+
completion = client.chat.completions.create(
|
| 93 |
+
model=model,
|
| 94 |
+
temperature=0.2,
|
| 95 |
+
messages=[
|
| 96 |
+
{
|
| 97 |
+
"role": "system",
|
| 98 |
+
"content": (
|
| 99 |
+
"Rewrite synthetic supervised rationale summaries for a streaming assistant dataset. "
|
| 100 |
+
"Keep the source context fixed. Rewrite only streaming_reasoning, deep_reasoning, and answer. "
|
| 101 |
+
"Use concise state updates, not private chain-of-thought. Do not invent facts. "
|
| 102 |
+
"Return only a JSON object with those three keys."
|
| 103 |
+
),
|
| 104 |
+
},
|
| 105 |
+
{"role": "user", "content": json.dumps(prompt, ensure_ascii=False)},
|
| 106 |
+
],
|
| 107 |
+
)
|
| 108 |
+
content = completion.choices[0].message.content or ""
|
| 109 |
+
rewritten = parse_json_object(content)
|
| 110 |
+
combined = "\n".join(rewritten.values())
|
| 111 |
+
if has_forbidden(combined):
|
| 112 |
+
raise ValueError("rewrite contains forbidden phrase")
|
| 113 |
+
if word_count(rewritten["streaming_reasoning"]) > 140 or word_count(rewritten["deep_reasoning"]) > 55:
|
| 114 |
+
raise ValueError("rewrite is too long")
|
| 115 |
+
|
| 116 |
+
updated = dict(row)
|
| 117 |
+
updated.update(rewritten)
|
| 118 |
+
updated["response"] = make_response(updated["streaming_reasoning"], updated["deep_reasoning"], updated["answer"])
|
| 119 |
+
updated["messages"] = make_messages(updated["instruction"], updated["context"], updated["response"])
|
| 120 |
+
updated["text"] = make_text(updated["messages"])
|
| 121 |
+
updated["llm_augmented"] = True
|
| 122 |
+
updated["llm_augmentation_model"] = model
|
| 123 |
+
updated["refinement_method"] = "llm_augmented_quality_refinement_v0.4"
|
| 124 |
+
return updated
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class HttpChatCompletions:
|
| 128 |
+
def __init__(self, api_key: str, base_url: str) -> None:
|
| 129 |
+
self.api_key = api_key
|
| 130 |
+
self.base_url = base_url.rstrip("/")
|
| 131 |
+
|
| 132 |
+
def create(self, **payload: Any) -> Any:
|
| 133 |
+
body = json.dumps(payload).encode("utf-8")
|
| 134 |
+
request = urllib.request.Request(
|
| 135 |
+
f"{self.base_url}/chat/completions",
|
| 136 |
+
data=body,
|
| 137 |
+
headers={
|
| 138 |
+
"Authorization": f"Bearer {self.api_key}",
|
| 139 |
+
"Content-Type": "application/json",
|
| 140 |
+
},
|
| 141 |
+
method="POST",
|
| 142 |
+
)
|
| 143 |
+
with urllib.request.urlopen(request, timeout=60) as response: # noqa: S310 - caller opts into API use
|
| 144 |
+
data = json.loads(response.read().decode("utf-8"))
|
| 145 |
+
content = data["choices"][0]["message"]["content"]
|
| 146 |
+
return SimpleNamespace(choices=[SimpleNamespace(message=SimpleNamespace(content=content))])
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class HttpOpenAICompatClient:
|
| 150 |
+
def __init__(self, api_key: str, base_url: str) -> None:
|
| 151 |
+
self.chat = SimpleNamespace(completions=HttpChatCompletions(api_key, base_url))
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def main() -> None:
|
| 155 |
+
parser = argparse.ArgumentParser(description="Optionally augment a small v0.4 subset with an LLM.")
|
| 156 |
+
parser.add_argument("--input", default="life_streaming_cot_dataset/data/train_high_quality.jsonl")
|
| 157 |
+
parser.add_argument("--output", default="life_streaming_cot_dataset/data/train_high_quality_llm_augmented.jsonl")
|
| 158 |
+
parser.add_argument("--limit", type=int, default=100)
|
| 159 |
+
parser.add_argument("--model", default=os.getenv("OPENAI_MODEL", DEFAULT_MODEL))
|
| 160 |
+
args = parser.parse_args()
|
| 161 |
+
|
| 162 |
+
if not os.getenv("OPENAI_API_KEY"):
|
| 163 |
+
print("LLM augmentation skipped: OPENAI_API_KEY is not set.")
|
| 164 |
+
return
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
from openai import OpenAI
|
| 168 |
+
|
| 169 |
+
client = OpenAI()
|
| 170 |
+
except Exception as exc: # noqa: BLE001
|
| 171 |
+
base_url = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
| 172 |
+
print(f"openai package unavailable ({type(exc).__name__}); using HTTPS fallback client.")
|
| 173 |
+
client = HttpOpenAICompatClient(os.environ["OPENAI_API_KEY"], base_url)
|
| 174 |
+
|
| 175 |
+
rows = read_jsonl(Path(args.input))
|
| 176 |
+
if not rows:
|
| 177 |
+
print(f"LLM augmentation skipped: no rows found in {args.input}.")
|
| 178 |
+
return
|
| 179 |
+
|
| 180 |
+
output_rows: list[dict[str, Any]] = []
|
| 181 |
+
failures = 0
|
| 182 |
+
for row in rows[: args.limit]:
|
| 183 |
+
try:
|
| 184 |
+
output_rows.append(augment_row(client, row, args.model))
|
| 185 |
+
except Exception: # noqa: BLE001
|
| 186 |
+
failures += 1
|
| 187 |
+
output_rows.append(row)
|
| 188 |
+
write_jsonl(Path(args.output), output_rows)
|
| 189 |
+
print(f"wrote {len(output_rows)} rows to {args.output}; failed rewrites: {failures}")
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
if __name__ == "__main__":
|
| 193 |
+
sys.exit(main())
|
scripts/build_life_streaming_cot.py
ADDED
|
@@ -0,0 +1,1774 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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import os
|
| 8 |
+
import random
|
| 9 |
+
import re
|
| 10 |
+
import shutil
|
| 11 |
+
import statistics
|
| 12 |
+
from collections import Counter, defaultdict
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
import pandas as pd
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
DATASET_NAME = "LifeTextSingleTurnStreamingCoT"
|
| 20 |
+
REPO_ID = "skyzhou06/LifeTextSingleTurnStreamingCoT"
|
| 21 |
+
DATASET_VERSION = "v0.4"
|
| 22 |
+
GENERATION_METHOD = "source_grounded_rule_based_v0.4_quality_refined"
|
| 23 |
+
REASONING_POLICY = "selective_concise"
|
| 24 |
+
CHUNKING_METHOD = "semantic_sentence_split_v0.4_refined"
|
| 25 |
+
REFINEMENT_METHOD = "rule_based_quality_refinement_v0.4"
|
| 26 |
+
INSTRUCTION = "Help the user complete a real-life task based on gradually revealed information."
|
| 27 |
+
CACHE_DIR = Path(".lifesct_cache")
|
| 28 |
+
SOURCE_CACHE = CACHE_DIR / "v0_2_source_rows.jsonl"
|
| 29 |
+
|
| 30 |
+
BASE_FIELDS = [
|
| 31 |
+
"id",
|
| 32 |
+
"domain",
|
| 33 |
+
"source_dataset",
|
| 34 |
+
"instruction",
|
| 35 |
+
"context",
|
| 36 |
+
"context_chunks",
|
| 37 |
+
"streaming_reasoning",
|
| 38 |
+
"deep_reasoning",
|
| 39 |
+
"answer",
|
| 40 |
+
"response",
|
| 41 |
+
"messages",
|
| 42 |
+
"text",
|
| 43 |
+
"num_chunks",
|
| 44 |
+
"language",
|
| 45 |
+
"split",
|
| 46 |
+
"generation_method",
|
| 47 |
+
"quality_flags",
|
| 48 |
+
"version",
|
| 49 |
+
"reasoning_policy",
|
| 50 |
+
"chunking_method",
|
| 51 |
+
"chunk_labels",
|
| 52 |
+
"skip_chunks",
|
| 53 |
+
"skip_reasons",
|
| 54 |
+
"reasoning_token_budget",
|
| 55 |
+
"original_num_chunks",
|
| 56 |
+
"chunk_split_count",
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
V04_FIELDS = [
|
| 60 |
+
"quality_score",
|
| 61 |
+
"is_high_quality",
|
| 62 |
+
"refinement_method",
|
| 63 |
+
"llm_augmented",
|
| 64 |
+
"llm_augmentation_model",
|
| 65 |
+
"rejected_reason",
|
| 66 |
+
"state_tracking_confidence",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
REQUIRED_FIELDS = BASE_FIELDS + V04_FIELDS
|
| 70 |
+
|
| 71 |
+
REASONING_TOKEN_BUDGET = {
|
| 72 |
+
"streaming_reasoning_max_words_per_chunk": 18,
|
| 73 |
+
"deep_reasoning_max_words": 45,
|
| 74 |
+
"answer_max_sentences": 3,
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
FORBIDDEN_GENERIC_PHRASES = [
|
| 78 |
+
"the user is sharing everyday context",
|
| 79 |
+
"the situation is about an everyday life situation",
|
| 80 |
+
"the assistant should stay conversational",
|
| 81 |
+
"the user is asking for help, clarification, or a next step",
|
| 82 |
+
"support need centers on",
|
| 83 |
+
"task_detail=noted",
|
| 84 |
+
"emotion=positive; cause=",
|
| 85 |
+
"emotion=negative; cause=",
|
| 86 |
+
"given the full context",
|
| 87 |
+
"tracked constraints so far",
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
BLOCKLIST = [
|
| 91 |
+
"suicide",
|
| 92 |
+
"self-harm",
|
| 93 |
+
"self harm",
|
| 94 |
+
"kill myself",
|
| 95 |
+
"kill yourself",
|
| 96 |
+
"sexual assault",
|
| 97 |
+
"rape",
|
| 98 |
+
"explicit sex",
|
| 99 |
+
"porn",
|
| 100 |
+
"build a gun",
|
| 101 |
+
"make a bomb",
|
| 102 |
+
"legal advice",
|
| 103 |
+
"lawsuit",
|
| 104 |
+
"attorney",
|
| 105 |
+
"court case",
|
| 106 |
+
"cocaine",
|
| 107 |
+
"heroin",
|
| 108 |
+
"methamphetamine",
|
| 109 |
+
"credit card number",
|
| 110 |
+
"social security number",
|
| 111 |
+
]
|
| 112 |
+
|
| 113 |
+
STOPWORDS = {
|
| 114 |
+
"about",
|
| 115 |
+
"after",
|
| 116 |
+
"again",
|
| 117 |
+
"also",
|
| 118 |
+
"and",
|
| 119 |
+
"are",
|
| 120 |
+
"because",
|
| 121 |
+
"before",
|
| 122 |
+
"being",
|
| 123 |
+
"but",
|
| 124 |
+
"can",
|
| 125 |
+
"could",
|
| 126 |
+
"does",
|
| 127 |
+
"doing",
|
| 128 |
+
"for",
|
| 129 |
+
"from",
|
| 130 |
+
"get",
|
| 131 |
+
"got",
|
| 132 |
+
"good",
|
| 133 |
+
"great",
|
| 134 |
+
"had",
|
| 135 |
+
"has",
|
| 136 |
+
"have",
|
| 137 |
+
"how",
|
| 138 |
+
"into",
|
| 139 |
+
"its",
|
| 140 |
+
"it's",
|
| 141 |
+
"just",
|
| 142 |
+
"know",
|
| 143 |
+
"later",
|
| 144 |
+
"like",
|
| 145 |
+
"more",
|
| 146 |
+
"much",
|
| 147 |
+
"need",
|
| 148 |
+
"only",
|
| 149 |
+
"please",
|
| 150 |
+
"really",
|
| 151 |
+
"should",
|
| 152 |
+
"some",
|
| 153 |
+
"sure",
|
| 154 |
+
"that",
|
| 155 |
+
"the",
|
| 156 |
+
"their",
|
| 157 |
+
"there",
|
| 158 |
+
"these",
|
| 159 |
+
"they",
|
| 160 |
+
"thing",
|
| 161 |
+
"things",
|
| 162 |
+
"this",
|
| 163 |
+
"time",
|
| 164 |
+
"today",
|
| 165 |
+
"want",
|
| 166 |
+
"was",
|
| 167 |
+
"were",
|
| 168 |
+
"well",
|
| 169 |
+
"what",
|
| 170 |
+
"when",
|
| 171 |
+
"where",
|
| 172 |
+
"which",
|
| 173 |
+
"with",
|
| 174 |
+
"would",
|
| 175 |
+
"yeah",
|
| 176 |
+
"yes",
|
| 177 |
+
"you",
|
| 178 |
+
"your",
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
NUMBER_WORDS = {
|
| 182 |
+
"one": 1,
|
| 183 |
+
"two": 2,
|
| 184 |
+
"three": 3,
|
| 185 |
+
"four": 4,
|
| 186 |
+
"five": 5,
|
| 187 |
+
"six": 6,
|
| 188 |
+
"seven": 7,
|
| 189 |
+
"eight": 8,
|
| 190 |
+
"nine": 9,
|
| 191 |
+
"ten": 10,
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
SEVERE_FLAGS = {
|
| 195 |
+
"generic_reasoning",
|
| 196 |
+
"closing_mishandled",
|
| 197 |
+
"possible_slot_error",
|
| 198 |
+
"excessive_chunking",
|
| 199 |
+
"fragment_chunk",
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
FLAG_PENALTIES = {
|
| 203 |
+
"generic_reasoning": 0.20,
|
| 204 |
+
"excessive_chunking": 0.15,
|
| 205 |
+
"fragment_chunk": 0.15,
|
| 206 |
+
"copied_source_response": 0.15,
|
| 207 |
+
"closing_mishandled": 0.15,
|
| 208 |
+
"short_answer": 0.10,
|
| 209 |
+
"weak_context": 0.10,
|
| 210 |
+
"low_specificity": 0.10,
|
| 211 |
+
"possible_slot_error": 0.10,
|
| 212 |
+
"too_many_skips": 0.05,
|
| 213 |
+
"no_skip_labels": 0.05,
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def clean_text(value: Any, max_chars: int = 420) -> str:
|
| 218 |
+
if value is None:
|
| 219 |
+
return ""
|
| 220 |
+
if isinstance(value, (list, tuple)):
|
| 221 |
+
value = " ".join(clean_text(item, max_chars=max_chars) for item in value)
|
| 222 |
+
text = str(value)
|
| 223 |
+
text = text.replace("_comma_", ",")
|
| 224 |
+
text = text.replace("\r", " ").replace("\n", " ").replace("\t", " ")
|
| 225 |
+
text = text.replace("\u2019", "'").replace("\u2018", "'")
|
| 226 |
+
text = text.replace("\u201c", '"').replace("\u201d", '"')
|
| 227 |
+
text = re.sub(r"<[^>]{1,40}>", " ", text)
|
| 228 |
+
text = re.sub(r"\b(Mr|Mrs|Ms|Dr)\s+\.", r"\1.", text)
|
| 229 |
+
text = re.sub(r"\b([A-Za-z])\s+'\s+([A-Za-z])", r"\1'\2", text)
|
| 230 |
+
text = re.sub(r"\s+([,.!?;:])", r"\1", text)
|
| 231 |
+
text = re.sub(r"\s+", " ", text).strip()
|
| 232 |
+
text = re.sub(r"\b[\w.+-]+@[\w-]+\.[\w.-]+\b", "[email removed]", text)
|
| 233 |
+
text = re.sub(r"\b(?:\+?\d[\d .()-]{7,}\d)\b", "[phone removed]", text)
|
| 234 |
+
if len(text) > max_chars:
|
| 235 |
+
cut = text[:max_chars].rsplit(" ", 1)[0].strip()
|
| 236 |
+
text = f"{cut}."
|
| 237 |
+
return text
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def normalize(text: str) -> str:
|
| 241 |
+
return re.sub(r"\W+", " ", text.lower()).strip()
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def word_count(text: str) -> int:
|
| 245 |
+
return len(re.findall(r"\b[\w'-]+\b", str(text)))
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def tokenize_words(text: str) -> list[str]:
|
| 249 |
+
return re.findall(r"[a-zA-Z][a-zA-Z'-]{2,}", text.lower())
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def salient_terms(text: str, limit: int = 5) -> list[str]:
|
| 253 |
+
terms: list[str] = []
|
| 254 |
+
for word in tokenize_words(text):
|
| 255 |
+
word = word.strip("'")
|
| 256 |
+
if word not in STOPWORDS and word not in terms:
|
| 257 |
+
terms.append(word)
|
| 258 |
+
if len(terms) >= limit:
|
| 259 |
+
break
|
| 260 |
+
return terms
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def compact_join(items: list[str], fallback: str = "") -> str:
|
| 264 |
+
unique = [item for idx, item in enumerate(items) if item and item not in items[:idx]]
|
| 265 |
+
if not unique:
|
| 266 |
+
return fallback
|
| 267 |
+
if len(unique) == 1:
|
| 268 |
+
return unique[0]
|
| 269 |
+
return ", ".join(unique[:-1]) + f", {unique[-1]}"
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def finish_sentence(text: str) -> str:
|
| 273 |
+
text = clean_text(text, max_chars=500)
|
| 274 |
+
if text and text[-1] not in ".!?":
|
| 275 |
+
text += "."
|
| 276 |
+
return text
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 280 |
+
rows: list[dict[str, Any]] = []
|
| 281 |
+
if not path.exists():
|
| 282 |
+
return rows
|
| 283 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 284 |
+
for line in handle:
|
| 285 |
+
line = line.strip()
|
| 286 |
+
if line:
|
| 287 |
+
rows.append(json.loads(line))
|
| 288 |
+
return rows
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def write_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 292 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 293 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 294 |
+
for row in rows:
|
| 295 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def parse_context_chunks(row: dict[str, Any]) -> list[str]:
|
| 299 |
+
chunks = row.get("context_chunks")
|
| 300 |
+
if isinstance(chunks, list):
|
| 301 |
+
return [clean_text(chunk, max_chars=420) for chunk in chunks if clean_text(chunk)]
|
| 302 |
+
parsed: list[str] = []
|
| 303 |
+
for line in str(row.get("context") or "").splitlines():
|
| 304 |
+
match = re.match(r"\s*Chunk\s+\d+\s*:\s*(.+)$", line)
|
| 305 |
+
if match:
|
| 306 |
+
parsed.append(clean_text(match.group(1), max_chars=420))
|
| 307 |
+
return parsed
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def load_source_rows(output_dir: Path) -> tuple[list[dict[str, Any]], list[dict[str, str]]]:
|
| 311 |
+
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
| 312 |
+
if SOURCE_CACHE.exists():
|
| 313 |
+
return read_jsonl(SOURCE_CACHE), []
|
| 314 |
+
local_rows = read_jsonl(output_dir / "data" / "train.jsonl") + read_jsonl(output_dir / "data" / "eval.jsonl")
|
| 315 |
+
if local_rows:
|
| 316 |
+
write_jsonl(SOURCE_CACHE, local_rows)
|
| 317 |
+
return local_rows, [{"name": "local output", "reason": "v0.2 cache was missing; used local dataset rows"}]
|
| 318 |
+
try:
|
| 319 |
+
from datasets import load_dataset
|
| 320 |
+
|
| 321 |
+
ds = load_dataset(REPO_ID)
|
| 322 |
+
rows: list[dict[str, Any]] = []
|
| 323 |
+
for split in ds:
|
| 324 |
+
for row in ds[split]:
|
| 325 |
+
rows.append(dict(row))
|
| 326 |
+
if rows:
|
| 327 |
+
write_jsonl(SOURCE_CACHE, rows)
|
| 328 |
+
return rows, []
|
| 329 |
+
except Exception as exc: # noqa: BLE001
|
| 330 |
+
return [], [{"name": REPO_ID, "reason": f"could not load existing dataset: {type(exc).__name__}"}]
|
| 331 |
+
return [], [{"name": "source rows", "reason": "no local or remote source rows available"}]
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def build_context(chunks: list[str]) -> str:
|
| 335 |
+
return "\n".join(f"Chunk {idx}: {chunk}" for idx, chunk in enumerate(chunks, start=1))
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def protect_abbreviations(text: str) -> str:
|
| 339 |
+
for abbr in ["Mr.", "Mrs.", "Ms.", "Dr.", "Prof.", "St."]:
|
| 340 |
+
text = text.replace(abbr, abbr.replace(".", "<prd>"))
|
| 341 |
+
return text
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def restore_abbreviations(text: str) -> str:
|
| 345 |
+
return text.replace("<prd>", ".")
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def split_plain_sentences(text: str) -> list[str]:
|
| 349 |
+
text = clean_text(text, max_chars=700)
|
| 350 |
+
if not text:
|
| 351 |
+
return []
|
| 352 |
+
protected = protect_abbreviations(text)
|
| 353 |
+
pieces = re.split(r"(?<=[.!?])\s+|;\s+", protected)
|
| 354 |
+
out: list[str] = []
|
| 355 |
+
for piece in pieces:
|
| 356 |
+
piece = restore_abbreviations(piece)
|
| 357 |
+
piece = clean_text(piece, max_chars=320).strip(" ,;")
|
| 358 |
+
if piece:
|
| 359 |
+
out.append(finish_sentence(piece))
|
| 360 |
+
return out or [finish_sentence(text)]
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def skip_reason_for_text(text: str) -> str | None:
|
| 364 |
+
lower = normalize(text)
|
| 365 |
+
raw = text.lower()
|
| 366 |
+
if not lower:
|
| 367 |
+
return "low_information"
|
| 368 |
+
strong_info = re.search(
|
| 369 |
+
r"\b(address|phone|postcode|post code|reference|book|booking|reserve|restaurant|hotel|train|taxi|attraction|museum|cost|fee|travel time|can i|get|could you|would you)\b",
|
| 370 |
+
raw,
|
| 371 |
+
)
|
| 372 |
+
if re.search(r"\b(that'?s all|that is all|that will be all|all i need(?:ed)?|everything i need(?:ed)?|that should be it|will be all|that was all i needed)\b", raw):
|
| 373 |
+
return None if strong_info else "closing_only"
|
| 374 |
+
if lower in {"hi", "hello", "hey", "good morning", "good afternoon", "good evening"}:
|
| 375 |
+
return "greeting_only"
|
| 376 |
+
if re.fullmatch(r"(great\s+)?thanks( so much)?( a lot)?( for your help( today)?)?", lower):
|
| 377 |
+
return "thanks_only"
|
| 378 |
+
if re.match(r"^(thank you|thanks|no thanks|no thank you|awesome thanks|great thanks)\b", lower) and not strong_info:
|
| 379 |
+
return "thanks_only"
|
| 380 |
+
if lower in {"goodbye", "bye", "see you", "see you later", "have a nice day", "have a great day"}:
|
| 381 |
+
return "closing_only"
|
| 382 |
+
if lower in {"ok", "okay", "alright", "sure", "sounds good", "fine", "got it", "really", "who", "what", "wow"}:
|
| 383 |
+
return "backchannel_only" if lower in {"ok", "okay", "alright", "sure", "sounds good", "fine", "got it"} else "low_information"
|
| 384 |
+
if lower in {"um", "uh", "hmm", "well", "let me see"}:
|
| 385 |
+
return "filler_only"
|
| 386 |
+
if lower in {"youre welcome", "you re welcome", "you're welcome", "you are welcome"}:
|
| 387 |
+
return "acknowledgement_only"
|
| 388 |
+
if re.fullmatch(r"(please|sorry|excuse me)[.!]?", raw.strip()):
|
| 389 |
+
return "politeness_only"
|
| 390 |
+
if word_count(text) <= 2 and not re.search(r"\b(book|yes|no|where|when|phone|address|cost|fee)\b", raw):
|
| 391 |
+
return "low_information"
|
| 392 |
+
return None
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def is_closing_or_thanks(text: str) -> bool:
|
| 396 |
+
return skip_reason_for_text(text) in {"thanks_only", "closing_only", "politeness_only"}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def is_meaningful_short_chunk(text: str) -> bool:
|
| 400 |
+
lower = normalize(text)
|
| 401 |
+
return lower in {"yes", "no", "ok", "okay", "thanks", "bye", "hello", "hi"} or bool(re.search(r"\b(stop|wait|leave|book|call|go|pay|wash|rinse|wipe|unplug)\b", lower))
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def is_fragment_chunk(text: str) -> bool:
|
| 405 |
+
stripped = clean_text(text, max_chars=80).strip()
|
| 406 |
+
if not stripped:
|
| 407 |
+
return True
|
| 408 |
+
wc = word_count(stripped)
|
| 409 |
+
if wc == 0:
|
| 410 |
+
return True
|
| 411 |
+
if wc <= 2 and re.fullmatch(r"[\W_]+", stripped):
|
| 412 |
+
return True
|
| 413 |
+
if re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\.?", stripped):
|
| 414 |
+
return True
|
| 415 |
+
if normalize(stripped) == "macmillan":
|
| 416 |
+
return True
|
| 417 |
+
if skip_reason_for_text(stripped) or is_meaningful_short_chunk(stripped):
|
| 418 |
+
return False
|
| 419 |
+
if wc <= 2 and re.fullmatch(r"[A-Z][a-z]+\.?", stripped):
|
| 420 |
+
return True
|
| 421 |
+
return False
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def merge_fragments(chunks: list[str]) -> tuple[list[str], bool]:
|
| 425 |
+
merged: list[str] = []
|
| 426 |
+
changed = False
|
| 427 |
+
prefix = ""
|
| 428 |
+
for chunk in chunks:
|
| 429 |
+
chunk = clean_text(chunk, max_chars=360)
|
| 430 |
+
if not chunk:
|
| 431 |
+
continue
|
| 432 |
+
if is_fragment_chunk(chunk):
|
| 433 |
+
changed = True
|
| 434 |
+
if merged:
|
| 435 |
+
merged[-1] = finish_sentence(merged[-1].rstrip(".!?") + " " + chunk.strip())
|
| 436 |
+
else:
|
| 437 |
+
prefix = f"{prefix} {chunk}".strip()
|
| 438 |
+
continue
|
| 439 |
+
if prefix:
|
| 440 |
+
chunk = finish_sentence(prefix + " " + chunk)
|
| 441 |
+
prefix = ""
|
| 442 |
+
if word_count(chunk) < 4 and merged and not is_meaningful_short_chunk(chunk):
|
| 443 |
+
changed = True
|
| 444 |
+
merged[-1] = finish_sentence(merged[-1].rstrip(".!?") + " " + chunk)
|
| 445 |
+
else:
|
| 446 |
+
merged.append(finish_sentence(chunk))
|
| 447 |
+
if prefix and merged:
|
| 448 |
+
merged[-1] = finish_sentence(merged[-1].rstrip(".!?") + " " + prefix)
|
| 449 |
+
return merged, changed
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def split_on_conjunctions(text: str, domain: str) -> list[str]:
|
| 453 |
+
text = clean_text(text, max_chars=700)
|
| 454 |
+
if word_count(text) <= 30:
|
| 455 |
+
return [finish_sentence(text)]
|
| 456 |
+
patterns = [r",\s+and\s+I\s+", r"\s+and\s+I\s+", r",\s+then\s+", r"\s+then\s+", r"\s+before\s+"]
|
| 457 |
+
if domain == "emotional_support":
|
| 458 |
+
patterns.extend([r"\s+because\s+", r",\s+but\s+", r"\s+but\s+"])
|
| 459 |
+
regex = "|".join(f"(?:{pattern})" for pattern in patterns)
|
| 460 |
+
pieces = [clean_text(piece, max_chars=260).strip(" ,;") for piece in re.split(regex, text) if clean_text(piece)]
|
| 461 |
+
if len(pieces) <= 1:
|
| 462 |
+
return [finish_sentence(text)]
|
| 463 |
+
merged, _ = merge_fragments([finish_sentence(piece) for piece in pieces if word_count(piece) >= 3])
|
| 464 |
+
return merged or [finish_sentence(text)]
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def contains_term(text: str, term: str) -> bool:
|
| 468 |
+
if " " in term:
|
| 469 |
+
return term in text
|
| 470 |
+
return bool(re.search(rf"\b{re.escape(term)}\b", text))
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
def extract_task_details(text: str) -> dict[str, list[str]]:
|
| 474 |
+
if is_closing_or_thanks(text):
|
| 475 |
+
return {}
|
| 476 |
+
lower = text.lower()
|
| 477 |
+
details: dict[str, list[str]] = defaultdict(list)
|
| 478 |
+
domain_terms = {
|
| 479 |
+
"restaurant": ["restaurant", "food", "eat", "dinner", "lunch", "breakfast", "cuisine"],
|
| 480 |
+
"hotel": ["hotel", "guesthouse", "guest house", "room", "stay", "lodging"],
|
| 481 |
+
"taxi": ["taxi", "cab", "pickup", "pick me up"],
|
| 482 |
+
"train": ["train", "rail", "station"],
|
| 483 |
+
"attraction": ["museum", "park", "theatre", "theater", "attraction", "gallery", "college", "arts"],
|
| 484 |
+
"hospital": ["hospital", "clinic"],
|
| 485 |
+
}
|
| 486 |
+
for label, terms in domain_terms.items():
|
| 487 |
+
if any(contains_term(lower, term) for term in terms):
|
| 488 |
+
details["domain"].append(label)
|
| 489 |
+
if re.search(r"\b(find|looking for|look for|need|want|search|assist|help|getting|get me)\b", lower):
|
| 490 |
+
details["goal"].append("search")
|
| 491 |
+
if re.search(r"\b(book|booking|reservation|reserve)\b", lower):
|
| 492 |
+
details["goal"].append("booking")
|
| 493 |
+
if re.search(r"\b(recommend|suggest|favorite|what about|how about)\b", lower):
|
| 494 |
+
details["goal"].append("recommendation")
|
| 495 |
+
if re.search(r"\b(different|another|alternative|instead|else)\b", lower):
|
| 496 |
+
details["goal"].append("compare_alternative")
|
| 497 |
+
if re.search(r"\b(change|switch|make it|same price|same pricerange|same area)\b", lower):
|
| 498 |
+
details["goal"].append("modify_constraint")
|
| 499 |
+
if re.search(r"\b(can i|get|give me|tell me|what is|what's|how much|phone|address|postcode|reference|travel time|fee|cost)\b", lower):
|
| 500 |
+
details["goal"].append("request_info")
|
| 501 |
+
if re.search(r"\b(yes|that works|perfect|sounds good|that will be fine)\b", lower) and re.search(r"\b(book|reservation|option|one)\b", lower):
|
| 502 |
+
details["goal"].append("confirm_booking")
|
| 503 |
+
for price in ["cheap", "moderate", "expensive", "affordable", "budget", "not too expensive", "same pricerange", "same price"]:
|
| 504 |
+
if price in lower:
|
| 505 |
+
details["price"].append("affordable" if price == "budget" else price.replace("same pricerange", "same price range"))
|
| 506 |
+
for area in ["north", "south", "east", "west", "centre", "center", "downtown", "campus"]:
|
| 507 |
+
if re.search(rf"\b{re.escape(area)}\b", lower):
|
| 508 |
+
details["area"].append("centre" if area == "center" else area)
|
| 509 |
+
for cuisine in ["italian", "chinese", "indian", "korean", "thai", "french", "mexican", "japanese", "british", "vegetarian", "seafood", "danish", "persian", "european", "turkish"]:
|
| 510 |
+
if re.search(rf"\b{cuisine}\b", lower):
|
| 511 |
+
details["food"].append(cuisine)
|
| 512 |
+
for day in ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "tomorrow"]:
|
| 513 |
+
if re.search(rf"\b{day}\b", lower):
|
| 514 |
+
details["day"].append(day)
|
| 515 |
+
if re.search(r"\btoday\b", lower) and not is_closing_or_thanks(text):
|
| 516 |
+
details["day"].append("today")
|
| 517 |
+
for match in re.finditer(r"\b\d{1,2}(?::\d{2})?\s?(?:am|pm)?\b", lower):
|
| 518 |
+
token = match.group(0).strip()
|
| 519 |
+
window = lower[max(0, match.start() - 28) : min(len(lower), match.end() + 28)]
|
| 520 |
+
if ":" in token or "am" in token or "pm" in token or re.search(r"\b(at|after|before|around|by|leave|arrive|time|starting)\b", window):
|
| 521 |
+
details["time"].append(token)
|
| 522 |
+
people_match = re.search(r"\b(?:for|party of|it would be|there will be|we are)\s+(\d+)\s+(?:people|guests|persons)\b", lower)
|
| 523 |
+
if people_match:
|
| 524 |
+
details["party_size"].append(f"{people_match.group(1)} people")
|
| 525 |
+
else:
|
| 526 |
+
bare_people_match = re.search(r"\b(\d+)\s+(?:people|guests|persons)\b", lower)
|
| 527 |
+
if bare_people_match:
|
| 528 |
+
details["party_size"].append(f"{bare_people_match.group(1)} people")
|
| 529 |
+
if not details.get("party_size"):
|
| 530 |
+
phrase_match = re.search(r"\bfor\s+the\s+(\w+)\s+of\s+us\b", lower)
|
| 531 |
+
if phrase_match and phrase_match.group(1) in NUMBER_WORDS:
|
| 532 |
+
details["party_size"].append(f"{NUMBER_WORDS[phrase_match.group(1)]} people")
|
| 533 |
+
if not details.get("party_size"):
|
| 534 |
+
for word, number in NUMBER_WORDS.items():
|
| 535 |
+
if re.search(rf"\b{word}\b[^.?!]{{0,20}}\b(people|guests|of us)\b", lower):
|
| 536 |
+
details["party_size"].append(f"{number} people")
|
| 537 |
+
break
|
| 538 |
+
stay_match = re.search(r"\b(\d+)\s+nights?\b", lower)
|
| 539 |
+
if stay_match:
|
| 540 |
+
details["stay_length"].append(f"{stay_match.group(1)} nights")
|
| 541 |
+
star_match = re.search(r"\b(\d+)\s*stars?\b", lower)
|
| 542 |
+
if star_match:
|
| 543 |
+
details["stars"].append(f"{star_match.group(1)} stars")
|
| 544 |
+
for amenity in ["parking", "wifi", "internet", "free parking", "pool", "breakfast"]:
|
| 545 |
+
if amenity in lower:
|
| 546 |
+
details["amenities"].append(amenity)
|
| 547 |
+
if "guesthouse" in lower or "guest house" in lower:
|
| 548 |
+
details["hotel_type"].append("guesthouse")
|
| 549 |
+
if "hotel" in lower:
|
| 550 |
+
details["hotel_type"].append("hotel")
|
| 551 |
+
route_match = re.search(r"\bfrom\s+(.+?)\s+(?:to|going to)\s+([^,.?]+)", lower)
|
| 552 |
+
if route_match:
|
| 553 |
+
details["departure"].append(re.sub(r"\b(going|on|at|after|before)\b.*$", "", route_match.group(1)).strip())
|
| 554 |
+
destination = re.sub(r"\b(on|at|after|before)\b.*$", "", route_match.group(2)).strip()
|
| 555 |
+
details["destination"].append(destination)
|
| 556 |
+
depart_match = re.search(r"\bdepart(?:ing)? from\s+([^,.?]+)", lower)
|
| 557 |
+
if depart_match:
|
| 558 |
+
details["departure"].append(depart_match.group(1).strip())
|
| 559 |
+
dest_match = re.search(r"\b(?:going to|heading to|arrive at|to)\s+([A-Z]?[a-z][^,.?]{2,40})", text)
|
| 560 |
+
if dest_match and " from " not in lower and " to " not in lower[:8]:
|
| 561 |
+
candidate = clean_text(dest_match.group(1), max_chars=60).lower()
|
| 562 |
+
if not any(stop in candidate for stop in ["get ", "see ", "help", "book"]):
|
| 563 |
+
details["destination"].append(candidate)
|
| 564 |
+
if "no area preference" in lower or "any area" in lower:
|
| 565 |
+
details["area"].append("any")
|
| 566 |
+
if re.search(r"\bpark\b", lower):
|
| 567 |
+
details["domain"].append("attraction")
|
| 568 |
+
details["type"].append("park")
|
| 569 |
+
info_map = [
|
| 570 |
+
("address", "address"),
|
| 571 |
+
("phone", "phone"),
|
| 572 |
+
("telephone", "phone"),
|
| 573 |
+
("postcode", "postcode"),
|
| 574 |
+
("post code", "postcode"),
|
| 575 |
+
("postal code", "postcode"),
|
| 576 |
+
("reference", "reference_number"),
|
| 577 |
+
("travel time", "travel_time"),
|
| 578 |
+
("entrance fee", "entrance_fee"),
|
| 579 |
+
("admission", "entrance_fee"),
|
| 580 |
+
("cost", "price"),
|
| 581 |
+
("price", "price"),
|
| 582 |
+
("recommendation", "recommendation"),
|
| 583 |
+
]
|
| 584 |
+
requestish = bool(re.search(r"\b(can you|could you|tell me|give me|what is|what's|how much|how long|need|need a|need an|i'll need|get a|get the)\b", lower))
|
| 585 |
+
for needle, label in info_map:
|
| 586 |
+
if re.search(rf"\b{re.escape(needle)}\b", lower):
|
| 587 |
+
always_info = label in {"phone", "address", "postcode", "reference_number", "travel_time", "entrance_fee"}
|
| 588 |
+
if always_info or requestish:
|
| 589 |
+
details["requested_info"].append(label)
|
| 590 |
+
if re.search(r"\bhow long\b.*\b(journey|trip|travel|take)\b|\bjourney take\b", lower):
|
| 591 |
+
details["requested_info"].append("travel_time")
|
| 592 |
+
if re.search(r"\bfine arts?\b", lower):
|
| 593 |
+
details["type"].append("fine_arts_museum")
|
| 594 |
+
if re.search(r"\bsports?\b", lower):
|
| 595 |
+
details["type"].append("sports")
|
| 596 |
+
return {key: list(dict.fromkeys(values)) for key, values in details.items()}
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
def semantic_split_task(text: str) -> list[str]:
|
| 600 |
+
if is_closing_or_thanks(text):
|
| 601 |
+
return split_plain_sentences(text)
|
| 602 |
+
details = extract_task_details(text)
|
| 603 |
+
slot_count = sum(len(values) for key, values in details.items() if key not in {"goal"})
|
| 604 |
+
if word_count(text) >= 18 and slot_count >= 4:
|
| 605 |
+
chunks: list[str] = []
|
| 606 |
+
domains = details.get("domain", [])
|
| 607 |
+
if "restaurant" in domains:
|
| 608 |
+
desc = " ".join(part for part in [details.get("price", [""])[0], details.get("food", [""])[0], "restaurant"] if part)
|
| 609 |
+
chunks.append(f"I want to find a {desc}.")
|
| 610 |
+
elif "hotel" in domains:
|
| 611 |
+
desc = " ".join(part for part in [details.get("price", [""])[0], details.get("hotel_type", ["hotel"])[0]] if part)
|
| 612 |
+
chunks.append(f"I want to find a {desc}.")
|
| 613 |
+
elif domains:
|
| 614 |
+
chunks.append(f"I need help with {domains[0]}.")
|
| 615 |
+
if details.get("area"):
|
| 616 |
+
chunks.append(f"It should be in the {details['area'][0]} part of town.")
|
| 617 |
+
if details.get("party_size"):
|
| 618 |
+
chunks.append(f"It is for {details['party_size'][0]}.")
|
| 619 |
+
if details.get("day") or details.get("time"):
|
| 620 |
+
when = compact_join(details.get("day", []) + details.get("time", []))
|
| 621 |
+
chunks.append(f"The time is {when}.")
|
| 622 |
+
if details.get("goal") and "booking" in details["goal"]:
|
| 623 |
+
chunks.append("Please make a booking.")
|
| 624 |
+
for info in details.get("requested_info", []):
|
| 625 |
+
chunks.append(f"I also need the {info.replace('_', ' ')}.")
|
| 626 |
+
if len(chunks) >= 2:
|
| 627 |
+
return chunks
|
| 628 |
+
out: list[str] = []
|
| 629 |
+
for sentence in split_plain_sentences(text):
|
| 630 |
+
if word_count(sentence) > 30:
|
| 631 |
+
out.extend(split_on_conjunctions(sentence, "task_oriented_assistant"))
|
| 632 |
+
else:
|
| 633 |
+
out.append(sentence)
|
| 634 |
+
return out
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def semantic_split_emotional(text: str) -> list[str]:
|
| 638 |
+
text = clean_text(text, max_chars=700)
|
| 639 |
+
if word_count(text) <= 25:
|
| 640 |
+
return split_plain_sentences(text)
|
| 641 |
+
pieces = re.split(r"(?<=[.!?])\s+|,\s+and\s+I\s+|\s+and\s+I\s+|,\s+because\s+|\s+because\s+|,\s+but\s+|\s+but\s+", text, flags=re.IGNORECASE)
|
| 642 |
+
pieces = [finish_sentence(piece.strip(" ,;")) for piece in pieces if word_count(piece) >= 4]
|
| 643 |
+
return pieces if len(pieces) > 1 else split_plain_sentences(text)
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
def semantic_split_daily(text: str) -> list[str]:
|
| 647 |
+
out: list[str] = []
|
| 648 |
+
for sentence in split_plain_sentences(text):
|
| 649 |
+
if word_count(sentence) > 30:
|
| 650 |
+
out.extend(split_on_conjunctions(sentence, "daily_dialogue"))
|
| 651 |
+
else:
|
| 652 |
+
out.append(sentence)
|
| 653 |
+
return out
|
| 654 |
+
|
| 655 |
+
|
| 656 |
+
def semantic_split_how_to(text: str) -> list[str]:
|
| 657 |
+
text = clean_text(text, max_chars=700)
|
| 658 |
+
if text.lower().startswith("task:") or word_count(text) <= 30:
|
| 659 |
+
return [finish_sentence(text)]
|
| 660 |
+
pieces = re.split(r"(?<=[.!?])\s+|;\s+|,\s+then\s+|,\s+before\s+|\s+then\s+|\s+before\s+", text, flags=re.IGNORECASE)
|
| 661 |
+
pieces = [finish_sentence(piece.strip(" ,;")) for piece in pieces if word_count(piece) >= 4]
|
| 662 |
+
return pieces if len(pieces) > 1 else [finish_sentence(text)]
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
def semantic_split_utterance(text: str, domain: str) -> tuple[list[str], bool]:
|
| 666 |
+
text = clean_text(text, max_chars=700)
|
| 667 |
+
if not text:
|
| 668 |
+
return [], False
|
| 669 |
+
if domain == "task_oriented_assistant":
|
| 670 |
+
chunks = semantic_split_task(text)
|
| 671 |
+
elif domain == "emotional_support":
|
| 672 |
+
chunks = semantic_split_emotional(text)
|
| 673 |
+
elif domain == "how_to_guidance":
|
| 674 |
+
chunks = semantic_split_how_to(text)
|
| 675 |
+
else:
|
| 676 |
+
chunks = semantic_split_daily(text)
|
| 677 |
+
merged, changed = merge_fragments(chunks)
|
| 678 |
+
return merged or [finish_sentence(text)], changed
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
def detect_emotion(text: str) -> str:
|
| 682 |
+
lower = text.lower()
|
| 683 |
+
rules = [
|
| 684 |
+
("proud", ["proud", "accomplished", "achievement", "graduated", "promotion"]),
|
| 685 |
+
("happy", ["happy", "excited", "glad", "thrilled", "relieved", "wonderful"]),
|
| 686 |
+
("stressed", ["stressed", "stress", "overwhelmed", "burned out", "too much", "busy"]),
|
| 687 |
+
("anxious", ["anxious", "nervous", "panic", "afraid", "scared", "scary", "freaked", "embarrassing", "embarrassed"]),
|
| 688 |
+
("worried", ["worried", "worry", "concerned"]),
|
| 689 |
+
("sad", ["sad", "upset", "cry", "heartbroken", "grief"]),
|
| 690 |
+
("disappointed", ["disappointed", "let down", "failed", "badly", "poorly"]),
|
| 691 |
+
("frustrated", ["frustrated", "furious", "angry", "mad", "annoyed"]),
|
| 692 |
+
("lonely", ["lonely", "alone", "miss her", "miss him", "miss them"]),
|
| 693 |
+
("confused", ["confused", "unsure", "not sure", "don't know", "dont know"]),
|
| 694 |
+
]
|
| 695 |
+
for label, words in rules:
|
| 696 |
+
if any(word in lower for word in words):
|
| 697 |
+
return label
|
| 698 |
+
return "neutral"
|
| 699 |
+
|
| 700 |
+
|
| 701 |
+
def clean_cause_phrase(phrase: str) -> str:
|
| 702 |
+
phrase = clean_text(phrase, max_chars=180).strip(" .")
|
| 703 |
+
phrase = re.sub(r"^(i am|i'm|i feel|i felt|i get|i was|because|when|after)\s+", "", phrase, flags=re.IGNORECASE)
|
| 704 |
+
phrase = re.sub(r"\b(stressed|anxious|worried|sad|happy|excited|disappointed|frustrated|furious|angry|lonely|confused|proud|scared|scary|embarrassed|embarrassing)\b", "", phrase, flags=re.IGNORECASE)
|
| 705 |
+
phrase = re.sub(r"\bi\s+(?:was|am|feel|felt)\s*$", "", phrase, flags=re.IGNORECASE)
|
| 706 |
+
phrase = re.sub(r"\s+", " ", phrase).strip(" ,.")
|
| 707 |
+
words = phrase.split()
|
| 708 |
+
if len(words) > 12:
|
| 709 |
+
phrase = " ".join(words[:12])
|
| 710 |
+
return phrase
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def extract_emotional_cause(text: str) -> str:
|
| 714 |
+
lower = text.lower()
|
| 715 |
+
if re.search(r"\b(that must have been|i bet you|you'll be fine|did they|what game|what language|would'?ve freaked|would have freaked)\b", lower):
|
| 716 |
+
return ""
|
| 717 |
+
won_match = re.search(r"\bwhen\s+(.+?)\s+i\s+(?:was|felt)\s+(?:happy|excited|proud|glad|thrilled)\b", text, flags=re.IGNORECASE)
|
| 718 |
+
if won_match:
|
| 719 |
+
phrase = clean_cause_phrase(won_match.group(1))
|
| 720 |
+
if word_count(phrase) >= 3:
|
| 721 |
+
return phrase
|
| 722 |
+
patterns = [
|
| 723 |
+
r"\bbecause\s+(.+?)(?:[.!?]|$)",
|
| 724 |
+
r"\bafter\s+(.+?)(?:[.!?]|$)",
|
| 725 |
+
r"\bwhen\s+(.+?)(?:[.!?]|$)",
|
| 726 |
+
r"\babout\s+(.+?)(?:[.!?]|$)",
|
| 727 |
+
]
|
| 728 |
+
for pattern in patterns:
|
| 729 |
+
match = re.search(pattern, text, flags=re.IGNORECASE)
|
| 730 |
+
if match:
|
| 731 |
+
phrase = clean_cause_phrase(match.group(1))
|
| 732 |
+
if word_count(phrase) >= 3:
|
| 733 |
+
return phrase
|
| 734 |
+
if re.search(r"\bstudied\b.*\b(exam|test)\b", lower):
|
| 735 |
+
return "studied hard but the exam went poorly"
|
| 736 |
+
if re.search(r"\bcar\b.{0,40}\b(died|broke down|stopped)\b", lower):
|
| 737 |
+
return "car broke down at night"
|
| 738 |
+
if re.search(r"\btripped\b", lower):
|
| 739 |
+
return "tripped in front of other people"
|
| 740 |
+
if re.search(r"\bforeign language class\b", lower):
|
| 741 |
+
return "worried about a required foreign language class"
|
| 742 |
+
if re.search(r"\bspeak it in front of others\b", lower):
|
| 743 |
+
return "worried about speaking in front of others"
|
| 744 |
+
if re.search(r"\btime\b.*\b(flying|goes by|faster)\b", lower):
|
| 745 |
+
return "time seems to be passing quickly"
|
| 746 |
+
if re.search(r"\bvacation request\b", lower):
|
| 747 |
+
return "vacation request may be denied"
|
| 748 |
+
if re.search(r"\b(passed away|died)\b", lower) and not re.search(r"\b(car|phone|battery|engine|lights?)\b", lower):
|
| 749 |
+
return "someone important passed away"
|
| 750 |
+
if re.search(r"\bfriend|relationship|family|brother|sister|parent|grandmother|grandpa\b", lower):
|
| 751 |
+
return clean_cause_phrase(text) or "a relationship or family situation"
|
| 752 |
+
phrase = clean_cause_phrase(text)
|
| 753 |
+
if word_count(phrase) >= 3 and re.search(r"\b(i|my|we|our)\b", lower) and detect_emotion(text) != "neutral":
|
| 754 |
+
return phrase
|
| 755 |
+
return ""
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
def detect_user_need(text: str, emotion: str, cause: str) -> str:
|
| 759 |
+
lower = text.lower()
|
| 760 |
+
if re.search(r"\b(what should|how do|how can|advice|help me|catch up|plan)\b", lower):
|
| 761 |
+
return "planning_help" if "plan" in lower or "catch up" in lower else "practical_next_step"
|
| 762 |
+
if "?" in text:
|
| 763 |
+
return "clarification"
|
| 764 |
+
if emotion in {"happy", "proud"}:
|
| 765 |
+
return "celebration"
|
| 766 |
+
if emotion in {"anxious", "worried", "confused"}:
|
| 767 |
+
return "reassurance"
|
| 768 |
+
if emotion in {"sad", "disappointed", "frustrated", "lonely", "stressed"}:
|
| 769 |
+
return "validation"
|
| 770 |
+
return "encouragement" if cause else "validation"
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
def classify_chunk(chunk: str, previous_chunks: list[str], domain: str, state: dict[str, Any]) -> tuple[str, str]:
|
| 774 |
+
lower = chunk.lower().strip()
|
| 775 |
+
base_skip = skip_reason_for_text(chunk)
|
| 776 |
+
if re.fullmatch(r"(okay|ok)[.!]?", lower):
|
| 777 |
+
return "skip", base_skip or "backchannel_only"
|
| 778 |
+
if re.fullmatch(r"(yes|yeah|yep|sure|sounds good)[.!]?", lower):
|
| 779 |
+
if state.get("proposal_pending") or state.get("booking_intent") or "book" in " ".join(previous_chunks).lower():
|
| 780 |
+
return "reason", "booking_confirmation" if domain == "task_oriented_assistant" else "decision_point"
|
| 781 |
+
return "skip", base_skip or "acknowledgement_only"
|
| 782 |
+
if re.fullmatch(r"(no|nope|nah)[.!]?", lower):
|
| 783 |
+
if state.get("proposal_pending") or state.get("booking_intent") or re.search(r"\b(anything else|more|book|confirm)\b", " ".join(previous_chunks).lower()):
|
| 784 |
+
return "reason", "decision_point"
|
| 785 |
+
return "skip", "acknowledgement_only"
|
| 786 |
+
if base_skip:
|
| 787 |
+
return "skip", base_skip
|
| 788 |
+
terms = salient_terms(chunk, 5)
|
| 789 |
+
seen = set(state.get("seen_terms", []))
|
| 790 |
+
if terms and set(terms).issubset(seen) and word_count(chunk) <= 26:
|
| 791 |
+
return "skip", "repeated_information"
|
| 792 |
+
if domain == "task_oriented_assistant":
|
| 793 |
+
details = extract_task_details(chunk)
|
| 794 |
+
if details.get("goal") or details.get("domain") or details.get("requested_info"):
|
| 795 |
+
return "reason", details.get("goal", ["new_constraint"])[0]
|
| 796 |
+
return "reason", "new_constraint"
|
| 797 |
+
if domain == "emotional_support":
|
| 798 |
+
emotion = detect_emotion(chunk)
|
| 799 |
+
if emotion != "neutral":
|
| 800 |
+
return "reason", "new_emotion"
|
| 801 |
+
if extract_emotional_cause(chunk):
|
| 802 |
+
return "reason", "new_cause"
|
| 803 |
+
return "reason", "new_request" if "?" in chunk else "task_progress_update"
|
| 804 |
+
if domain == "how_to_guidance":
|
| 805 |
+
return "reason", "safety_or_order_constraint" if re.search(r"\b(turn off|unplug|avoid|careful|before|do not|don't)\b", lower) else "task_progress_update"
|
| 806 |
+
return "reason", "daily_state_update"
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
def state_add(state: dict[str, Any], key: str, values: list[str]) -> list[str]:
|
| 810 |
+
state.setdefault(key, [])
|
| 811 |
+
added: list[str] = []
|
| 812 |
+
for value in values:
|
| 813 |
+
if value and value not in state[key]:
|
| 814 |
+
state[key].append(value)
|
| 815 |
+
added.append(value)
|
| 816 |
+
return added
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
def update_seen_terms(state: dict[str, Any], chunk: str) -> None:
|
| 820 |
+
seen = state.setdefault("seen_terms", [])
|
| 821 |
+
for term in salient_terms(chunk, 5):
|
| 822 |
+
if term not in seen:
|
| 823 |
+
seen.append(term)
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
def task_update(chunk: str, state: dict[str, Any]) -> str:
|
| 827 |
+
details = extract_task_details(chunk)
|
| 828 |
+
if is_closing_or_thanks(chunk):
|
| 829 |
+
state["closing_detected"] = True
|
| 830 |
+
return "goal=closing"
|
| 831 |
+
pieces: list[str] = []
|
| 832 |
+
for key in ["domain", "goal", "area", "food", "price", "time", "day", "party_size", "stay_length", "hotel_type", "stars", "amenities", "destination", "departure", "requested_info", "type"]:
|
| 833 |
+
added = state_add(state, key, details.get(key, []))
|
| 834 |
+
if not added:
|
| 835 |
+
continue
|
| 836 |
+
label = "cuisine" if key == "food" else key
|
| 837 |
+
if key == "goal" and "booking" in added:
|
| 838 |
+
state["booking_intent"] = True
|
| 839 |
+
if key == "requested_info":
|
| 840 |
+
pieces.append(f"requested_info+={compact_join(added)}")
|
| 841 |
+
elif key == "domain":
|
| 842 |
+
pieces.append(f"domain={added[-1]}")
|
| 843 |
+
elif key == "goal":
|
| 844 |
+
pieces.append(f"goal={added[-1]}")
|
| 845 |
+
else:
|
| 846 |
+
pieces.append(f"{label}+={compact_join(added)}")
|
| 847 |
+
if re.search(r"\b(yes|perfect|sounds good|that works|that will be fine)\b", chunk.lower()):
|
| 848 |
+
if state.get("booking_intent"):
|
| 849 |
+
pieces.append("goal=confirm_booking")
|
| 850 |
+
else:
|
| 851 |
+
pieces.append("acceptance=selected_option")
|
| 852 |
+
if "not picky" in chunk.lower() or "isn't important" in chunk.lower():
|
| 853 |
+
pieces.append("preference=flexible")
|
| 854 |
+
if not pieces:
|
| 855 |
+
if "?" in chunk:
|
| 856 |
+
pieces.append("goal=request_info")
|
| 857 |
+
elif re.search(r"\b(no|not|instead|second thought)\b", chunk.lower()):
|
| 858 |
+
pieces.append("goal=modify_constraint")
|
| 859 |
+
else:
|
| 860 |
+
pieces.append("intent=context_update")
|
| 861 |
+
return "; ".join(pieces)
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
def emotional_update(chunk: str, state: dict[str, Any]) -> str:
|
| 865 |
+
emotion = detect_emotion(chunk)
|
| 866 |
+
cause = extract_emotional_cause(chunk)
|
| 867 |
+
need = detect_user_need(chunk, emotion, cause)
|
| 868 |
+
pieces: list[str] = []
|
| 869 |
+
if emotion != "neutral":
|
| 870 |
+
state["emotion"] = emotion
|
| 871 |
+
pieces.append(f"emotion={emotion}")
|
| 872 |
+
if cause and (not state.get("cause") or emotion != "neutral" or cause.startswith("worried about speaking")):
|
| 873 |
+
state["cause"] = cause
|
| 874 |
+
if emotion in {"happy", "proud"}:
|
| 875 |
+
pieces.append(f"event={cause}")
|
| 876 |
+
else:
|
| 877 |
+
pieces.append(f"cause={cause}")
|
| 878 |
+
stable_needs = {"reassurance", "celebration", "planning_help", "practical_next_step"}
|
| 879 |
+
if (
|
| 880 |
+
need
|
| 881 |
+
and need != state.get("user_need")
|
| 882 |
+
and (emotion != "neutral" or cause or not state.get("user_need"))
|
| 883 |
+
and not (emotion == "neutral" and state.get("user_need") in stable_needs and need in {"encouragement", "validation"})
|
| 884 |
+
):
|
| 885 |
+
state["user_need"] = need
|
| 886 |
+
pieces.append(f"need={need}")
|
| 887 |
+
if not pieces:
|
| 888 |
+
return "support_signal=received"
|
| 889 |
+
return "; ".join(pieces)
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
def daily_label_and_value(chunk: str, state: dict[str, Any]) -> str:
|
| 893 |
+
lower = chunk.lower()
|
| 894 |
+
if re.search(r"\b(drive safely|safe drive|icy roads?|ice on the roads?|be careful)\b", lower):
|
| 895 |
+
state["safety_reminder"] = True
|
| 896 |
+
return "safety_reminder=icy_roads" if "ice" in lower or "icy" in lower else "safety_reminder=true"
|
| 897 |
+
if re.search(r"\b(have to|must|had better|need to)\s+(go|leave|head off|be going)\b|\bi'?m afraid i have to go\b", lower):
|
| 898 |
+
state["closing"] = True
|
| 899 |
+
return "leaving_reason=needs_to_go"
|
| 900 |
+
dinner_plan = re.search(r"\b(?:i'?m|i am|we'?re|we are)\s+(?:meeting|going to meet)\s+(.+?)\s+for\s+dinner\b", lower)
|
| 901 |
+
if dinner_plan:
|
| 902 |
+
person = clean_text(dinner_plan.group(1), max_chars=50).replace("my ", "")
|
| 903 |
+
state["plan_update"] = True
|
| 904 |
+
return f"plan_update=dinner_with_{normalize(person).replace(' ', '_') or 'someone'}"
|
| 905 |
+
if re.search(r"\b(would you like(?:\s+to|\s+a|\s+some)?|do you want to|want to come|invite you|join me|come with me)\b", lower):
|
| 906 |
+
state["proposal_pending"] = True
|
| 907 |
+
state["invitation"] = True
|
| 908 |
+
return "invitation=true"
|
| 909 |
+
if re.search(r"\b(can you|could you|may i|would you)\b", lower) or "?" in chunk:
|
| 910 |
+
state["question"] = True
|
| 911 |
+
return "question=true"
|
| 912 |
+
if re.search(r"\b(i'll keep it in mind|keep that in mind|thanks for the advice|advice)\b", lower):
|
| 913 |
+
state["advice_received"] = True
|
| 914 |
+
return "advice_received=true"
|
| 915 |
+
if re.search(r"\b(can't|cannot|busy|appointment|schedule conflict|have to work|at work|in class)\b", lower):
|
| 916 |
+
state["schedule_conflict"] = True
|
| 917 |
+
return "schedule_conflict=true"
|
| 918 |
+
if re.search(r"\b(yes|sure|sounds good|why not|ok|okay)\b", lower) and state.get("proposal_pending"):
|
| 919 |
+
state["acceptance"] = True
|
| 920 |
+
return "acceptance=true"
|
| 921 |
+
if re.search(r"\b(no|can't|cannot|not possible)\b", lower) and state.get("proposal_pending"):
|
| 922 |
+
state["refusal"] = True
|
| 923 |
+
return "refusal=true"
|
| 924 |
+
if re.search(r"\b(prefer|like|would rather|favorite)\b", lower):
|
| 925 |
+
state["preference"] = True
|
| 926 |
+
return "preference=true"
|
| 927 |
+
if is_closing_or_thanks(chunk):
|
| 928 |
+
state["closing"] = True
|
| 929 |
+
return "closing=true"
|
| 930 |
+
terms = salient_terms(chunk, 3)
|
| 931 |
+
state_add(state, "casual_terms", terms[:2])
|
| 932 |
+
return f"casual_comment={compact_join(terms[:2], 'context')}"
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
def action_label(chunk: str) -> str:
|
| 936 |
+
text = re.sub(r"^Task:\s*", "", clean_text(chunk, max_chars=180), flags=re.IGNORECASE)
|
| 937 |
+
text = re.sub(r"[•*]+", " ", text)
|
| 938 |
+
words = text.strip(" .").split()
|
| 939 |
+
if not words:
|
| 940 |
+
return "continue"
|
| 941 |
+
return "_".join(re.sub(r"[^a-z0-9]+", "", word.lower()) for word in words[:4]).strip("_") or "continue"
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
def action_text(chunk: str, max_words: int = 10) -> str:
|
| 945 |
+
text = re.sub(r"^Task:\s*", "", clean_text(chunk, max_chars=260), flags=re.IGNORECASE)
|
| 946 |
+
text = re.sub(r"[•*]+", " ", text)
|
| 947 |
+
text = re.sub(r"\([^)]{0,80}\)", " ", text)
|
| 948 |
+
text = re.sub(r"\s+", " ", text).strip(" .;:-")
|
| 949 |
+
return " ".join(text.split()[:max_words]) or "continue"
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
def how_to_update(chunk: str, state: dict[str, Any], idx: int) -> str:
|
| 953 |
+
lower = chunk.lower()
|
| 954 |
+
if lower.startswith("task:") or (idx == 1 and not state.get("task")):
|
| 955 |
+
state["task"] = action_label(chunk)
|
| 956 |
+
state["task_text"] = action_text(chunk, 8)
|
| 957 |
+
return f"task={state['task']}"
|
| 958 |
+
label = action_label(chunk)
|
| 959 |
+
state_add(state, "steps", [label])
|
| 960 |
+
state_add(state, "step_texts", [action_text(chunk)])
|
| 961 |
+
if re.search(r"\b(turn off|unplug|avoid|careful|before|do not|don't|must)\b", lower):
|
| 962 |
+
state_add(state, "safety", [label])
|
| 963 |
+
return f"step={label}; safety=true"
|
| 964 |
+
return f"step={label}"
|
| 965 |
+
|
| 966 |
+
|
| 967 |
+
def build_reasoning(domain: str, chunks: list[str]) -> tuple[str, str, list[str], list[int], dict[str, str], dict[str, Any]]:
|
| 968 |
+
state: dict[str, Any] = {}
|
| 969 |
+
parts: list[str] = []
|
| 970 |
+
labels: list[str] = []
|
| 971 |
+
skip_chunks: list[int] = []
|
| 972 |
+
skip_reasons: dict[str, str] = {}
|
| 973 |
+
previous: list[str] = []
|
| 974 |
+
for idx, chunk in enumerate(chunks, start=1):
|
| 975 |
+
label, reason = classify_chunk(chunk, previous, domain, state)
|
| 976 |
+
if label == "skip":
|
| 977 |
+
labels.append("skip")
|
| 978 |
+
skip_chunks.append(idx)
|
| 979 |
+
skip_reasons[str(idx)] = reason
|
| 980 |
+
if reason in {"closing_only", "thanks_only"}:
|
| 981 |
+
state["closing_detected" if domain == "task_oriented_assistant" else "closing"] = True
|
| 982 |
+
parts.append(f"C{idx} [SKIP: {reason}].")
|
| 983 |
+
else:
|
| 984 |
+
labels.append("reason")
|
| 985 |
+
if domain == "task_oriented_assistant":
|
| 986 |
+
update = task_update(chunk, state)
|
| 987 |
+
elif domain == "emotional_support":
|
| 988 |
+
update = emotional_update(chunk, state)
|
| 989 |
+
elif domain == "how_to_guidance":
|
| 990 |
+
update = how_to_update(chunk, state, idx)
|
| 991 |
+
else:
|
| 992 |
+
update = daily_label_and_value(chunk, state)
|
| 993 |
+
parts.append(f"C{idx} {update}.")
|
| 994 |
+
update_seen_terms(state, chunk)
|
| 995 |
+
previous.append(chunk)
|
| 996 |
+
streaming = " ".join(parts)
|
| 997 |
+
deep = build_deep_reasoning(domain, state, chunks)
|
| 998 |
+
return streaming, deep, labels, skip_chunks, skip_reasons, state
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
def build_deep_reasoning(domain: str, state: dict[str, Any], chunks: list[str]) -> str:
|
| 1002 |
+
if domain == "task_oriented_assistant":
|
| 1003 |
+
bits: list[str] = []
|
| 1004 |
+
if state.get("domain"):
|
| 1005 |
+
bits.append(f"domain={compact_join(state['domain'])}")
|
| 1006 |
+
if state.get("goal"):
|
| 1007 |
+
bits.append(f"goal={compact_join(state['goal'])}")
|
| 1008 |
+
for key in ["area", "food", "price", "party_size", "stay_length", "stars", "amenities", "destination", "departure", "requested_info"]:
|
| 1009 |
+
if state.get(key):
|
| 1010 |
+
bits.append(f"{key}={compact_join(state[key])}")
|
| 1011 |
+
when = state.get("day", []) + state.get("time", [])
|
| 1012 |
+
if when:
|
| 1013 |
+
bits.append(f"when={compact_join(when)}")
|
| 1014 |
+
if state.get("closing_detected"):
|
| 1015 |
+
bits.append("closing_detected")
|
| 1016 |
+
return "Need " + "; ".join(bits) + "." if bits else "Need more concrete task details before acting."
|
| 1017 |
+
if domain == "emotional_support":
|
| 1018 |
+
emotion = state.get("emotion", "neutral")
|
| 1019 |
+
cause = state.get("cause", "the situation")
|
| 1020 |
+
need = state.get("user_need", "validation")
|
| 1021 |
+
if emotion == "neutral":
|
| 1022 |
+
return f"User is processing {cause} and needs {need}."
|
| 1023 |
+
if emotion in {"happy", "proud"}:
|
| 1024 |
+
return f"User feels {emotion} because {cause} and needs {need}."
|
| 1025 |
+
return f"User feels {emotion} after {cause} and needs {need}."
|
| 1026 |
+
if domain == "how_to_guidance":
|
| 1027 |
+
task = state.get("task_text") or (state.get("task") or action_label(chunks[0] if chunks else "task")).replace("_", " ")
|
| 1028 |
+
steps = compact_join(state.get("step_texts", [])[:5], "ordered steps")
|
| 1029 |
+
safety = "; keep safety/order constraints" if state.get("safety") else ""
|
| 1030 |
+
return f"Procedure for {task}: {steps}{safety}."
|
| 1031 |
+
if state.get("safety_reminder"):
|
| 1032 |
+
return "Conversation is closing with a safety reminder; answer politely and acknowledge caution."
|
| 1033 |
+
if state.get("closing"):
|
| 1034 |
+
return "Conversation is closing; answer politely without adding a new task."
|
| 1035 |
+
daily_bits: list[str] = []
|
| 1036 |
+
if state.get("invitation"):
|
| 1037 |
+
daily_bits.append("invitation")
|
| 1038 |
+
if state.get("question"):
|
| 1039 |
+
daily_bits.append("question")
|
| 1040 |
+
if state.get("plan_update"):
|
| 1041 |
+
daily_bits.append("plan update")
|
| 1042 |
+
if state.get("schedule_conflict"):
|
| 1043 |
+
daily_bits.append("schedule conflict")
|
| 1044 |
+
if state.get("preference"):
|
| 1045 |
+
daily_bits.append("preference")
|
| 1046 |
+
if state.get("advice_received"):
|
| 1047 |
+
daily_bits.append("advice received")
|
| 1048 |
+
topic = compact_join(state.get("casual_terms", [])[:4], "current topic")
|
| 1049 |
+
if daily_bits:
|
| 1050 |
+
return f"Dialogue state: {compact_join(daily_bits)} around {topic}; respond briefly."
|
| 1051 |
+
return f"Dialogue state: casual exchange about {topic}; respond briefly."
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
def missing_task_slots(state: dict[str, Any]) -> list[str]:
|
| 1055 |
+
domains = set(state.get("domain", []))
|
| 1056 |
+
missing: list[str] = []
|
| 1057 |
+
if "restaurant" in domains:
|
| 1058 |
+
for key, label in [("area", "area"), ("food", "cuisine"), ("price", "price range")]:
|
| 1059 |
+
if not state.get(key):
|
| 1060 |
+
missing.append(label)
|
| 1061 |
+
if "hotel" in domains:
|
| 1062 |
+
for key, label in [("area", "area"), ("price", "price range"), ("day", "date"), ("party_size", "guests")]:
|
| 1063 |
+
if not state.get(key):
|
| 1064 |
+
missing.append(label)
|
| 1065 |
+
if domains & {"taxi", "train"}:
|
| 1066 |
+
for key, label in [("destination", "destination"), ("departure", "departure"), ("day", "date"), ("time", "time")]:
|
| 1067 |
+
if not state.get(key):
|
| 1068 |
+
missing.append(label)
|
| 1069 |
+
return missing[:2]
|
| 1070 |
+
|
| 1071 |
+
|
| 1072 |
+
def build_task_answer(state: dict[str, Any]) -> str:
|
| 1073 |
+
if state.get("closing_detected"):
|
| 1074 |
+
return "You're welcome. Glad I could help; have a great day."
|
| 1075 |
+
if state.get("requested_info"):
|
| 1076 |
+
return f"I can help with that and include the {compact_join(state['requested_info']).replace('_', ' ')} once I find the matching option."
|
| 1077 |
+
missing = missing_task_slots(state)
|
| 1078 |
+
if missing:
|
| 1079 |
+
return f"What {compact_join(missing)} should I use for the search?"
|
| 1080 |
+
pieces = []
|
| 1081 |
+
if state.get("domain"):
|
| 1082 |
+
pieces.append(compact_join(state["domain"]))
|
| 1083 |
+
for key in ["area", "food", "price", "party_size"]:
|
| 1084 |
+
if state.get(key):
|
| 1085 |
+
pieces.append(compact_join(state[key]))
|
| 1086 |
+
if state.get("day") or state.get("time"):
|
| 1087 |
+
pieces.append(compact_join(state.get("day", []) + state.get("time", [])))
|
| 1088 |
+
return f"Got it. I will use {compact_join(pieces, 'those details')} and move the task forward."
|
| 1089 |
+
|
| 1090 |
+
|
| 1091 |
+
def build_emotional_answer(state: dict[str, Any]) -> str:
|
| 1092 |
+
emotion = state.get("emotion", "neutral")
|
| 1093 |
+
cause = state.get("cause", "what happened")
|
| 1094 |
+
need = state.get("user_need", "validation")
|
| 1095 |
+
if emotion == "neutral":
|
| 1096 |
+
return f"That sounds like a lot to process, especially with {cause}. Start with one small next step and give yourself room to sort it out."
|
| 1097 |
+
if emotion in {"happy", "proud"}:
|
| 1098 |
+
return f"That is worth celebrating, especially because {cause}. Take a moment to enjoy it and share the good news with someone who will be happy for you."
|
| 1099 |
+
if need in {"planning_help", "practical_next_step"}:
|
| 1100 |
+
return f"That is frustrating, especially after {cause}. Start with one concrete next step, then focus your energy on the part you can control today."
|
| 1101 |
+
if need == "reassurance":
|
| 1102 |
+
return f"It makes sense to feel {emotion} after {cause}. Slow down, check what is actually known, and take one small step before deciding what comes next."
|
| 1103 |
+
return f"It makes sense to feel {emotion} after {cause}. Give yourself a moment, then choose one manageable action instead of trying to solve everything at once."
|
| 1104 |
+
|
| 1105 |
+
|
| 1106 |
+
def build_how_to_answer(state: dict[str, Any], chunks: list[str]) -> str:
|
| 1107 |
+
task = state.get("task_text") or (state.get("task") or action_label(chunks[0] if chunks else "task")).replace("_", " ")
|
| 1108 |
+
steps = state.get("step_texts", [])[:4] or [action_text(chunk) for chunk in chunks[:4]]
|
| 1109 |
+
caution = " Keep the order and pause if a step seems unsafe." if state.get("safety") else ""
|
| 1110 |
+
return f"For {task}, follow the steps in order: {compact_join(steps)}.{caution}".strip()
|
| 1111 |
+
|
| 1112 |
+
|
| 1113 |
+
def build_daily_answer(state: dict[str, Any], chunks: list[str]) -> str:
|
| 1114 |
+
if state.get("safety_reminder"):
|
| 1115 |
+
return "Thanks, I'll be careful. See you next time."
|
| 1116 |
+
if state.get("closing"):
|
| 1117 |
+
return "Sounds good. Take care, and see you next time."
|
| 1118 |
+
joined = " ".join(chunks).lower()
|
| 1119 |
+
if state.get("invitation"):
|
| 1120 |
+
return "That sounds nice. I can join; what time should I be there?"
|
| 1121 |
+
if state.get("question"):
|
| 1122 |
+
topic = compact_join(salient_terms(" ".join(chunks), 4), "the situation")
|
| 1123 |
+
return f"Good question. The main topic is {topic}, so I would answer that directly first."
|
| 1124 |
+
if "dinner" in joined and "meeting" in joined:
|
| 1125 |
+
return "Thanks, I should head out for dinner now. See you next time."
|
| 1126 |
+
topic = compact_join(salient_terms(" ".join(chunks), 4), "the situation")
|
| 1127 |
+
return f"Got it. The main point is {topic}, so I will keep the reply brief and clear."
|
| 1128 |
+
|
| 1129 |
+
|
| 1130 |
+
def build_answer(domain: str, state: dict[str, Any], chunks: list[str]) -> str:
|
| 1131 |
+
if domain == "task_oriented_assistant":
|
| 1132 |
+
answer = build_task_answer(state)
|
| 1133 |
+
elif domain == "emotional_support":
|
| 1134 |
+
answer = build_emotional_answer(state)
|
| 1135 |
+
elif domain == "how_to_guidance":
|
| 1136 |
+
answer = build_how_to_answer(state, chunks)
|
| 1137 |
+
else:
|
| 1138 |
+
answer = build_daily_answer(state, chunks)
|
| 1139 |
+
return " ".join(re.split(r"(?<=[.!?])\s+", finish_sentence(answer))[:3]).strip()
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
def copied_ratio(answer: str, source_answer: str | None) -> float:
|
| 1143 |
+
source = normalize(source_answer or "")
|
| 1144 |
+
generated = normalize(answer)
|
| 1145 |
+
if not source or not generated:
|
| 1146 |
+
return 0.0
|
| 1147 |
+
if source in generated or generated in source:
|
| 1148 |
+
return 1.0
|
| 1149 |
+
return difflib.SequenceMatcher(None, source, generated).ratio()
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
def has_forbidden_phrase(*texts: str) -> bool:
|
| 1153 |
+
joined = "\n".join(texts).lower()
|
| 1154 |
+
return any(phrase in joined for phrase in FORBIDDEN_GENERIC_PHRASES)
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
def is_safe_example(chunks: list[str], answer: str) -> bool:
|
| 1158 |
+
joined = " ".join(chunks + [answer]).lower()
|
| 1159 |
+
if any(term in joined for term in BLOCKLIST):
|
| 1160 |
+
return False
|
| 1161 |
+
if "[email removed]" in joined or "[phone removed]" in joined:
|
| 1162 |
+
return False
|
| 1163 |
+
return sum(word_count(chunk) for chunk in chunks) >= 8 and word_count(answer) >= 3
|
| 1164 |
+
|
| 1165 |
+
|
| 1166 |
+
def is_undesired_how_to(chunks: list[str]) -> bool:
|
| 1167 |
+
joined = " ".join(chunks).lower()
|
| 1168 |
+
off_topic = [
|
| 1169 |
+
"windows movie maker",
|
| 1170 |
+
"movie maker",
|
| 1171 |
+
"inshot",
|
| 1172 |
+
"pinterest",
|
| 1173 |
+
"ipod",
|
| 1174 |
+
"jailbreak",
|
| 1175 |
+
"slackline",
|
| 1176 |
+
"bonfire",
|
| 1177 |
+
"lighter fluid",
|
| 1178 |
+
"synthetic coon",
|
| 1179 |
+
"manga",
|
| 1180 |
+
"runescape",
|
| 1181 |
+
"minecraft",
|
| 1182 |
+
"photoshop",
|
| 1183 |
+
"illustrator",
|
| 1184 |
+
"html",
|
| 1185 |
+
"css",
|
| 1186 |
+
"javascript",
|
| 1187 |
+
"server",
|
| 1188 |
+
"login",
|
| 1189 |
+
"paypal",
|
| 1190 |
+
"twitter",
|
| 1191 |
+
"instagram",
|
| 1192 |
+
"tiktok",
|
| 1193 |
+
]
|
| 1194 |
+
return any(term in joined for term in off_topic)
|
| 1195 |
+
|
| 1196 |
+
|
| 1197 |
+
def compute_quality_flags(
|
| 1198 |
+
domain: str,
|
| 1199 |
+
chunks: list[str],
|
| 1200 |
+
labels: list[str],
|
| 1201 |
+
state: dict[str, Any],
|
| 1202 |
+
source_answer: str | None,
|
| 1203 |
+
streaming_reasoning: str,
|
| 1204 |
+
deep_reasoning: str,
|
| 1205 |
+
answer: str,
|
| 1206 |
+
merged_fragments: bool,
|
| 1207 |
+
) -> list[str]:
|
| 1208 |
+
flags: list[str] = []
|
| 1209 |
+
if word_count(streaming_reasoning) > 160:
|
| 1210 |
+
flags.append("long_streaming_reasoning")
|
| 1211 |
+
if word_count(deep_reasoning) > 60:
|
| 1212 |
+
flags.append("long_deep_reasoning")
|
| 1213 |
+
if any(skip_reason_for_text(chunk) for chunk in chunks) and "skip" not in labels:
|
| 1214 |
+
flags.append("no_skip_labels")
|
| 1215 |
+
if labels and labels.count("skip") / len(labels) > 0.70:
|
| 1216 |
+
flags.append("too_many_skips")
|
| 1217 |
+
avg_chunk_words = statistics.mean(word_count(chunk) for chunk in chunks) if chunks else 0
|
| 1218 |
+
if avg_chunk_words < 4 or len(chunks) > 12:
|
| 1219 |
+
flags.append("excessive_chunking")
|
| 1220 |
+
if any(is_fragment_chunk(chunk) for chunk in chunks):
|
| 1221 |
+
flags.append("fragment_chunk")
|
| 1222 |
+
if merged_fragments:
|
| 1223 |
+
flags.append("merged_fragments")
|
| 1224 |
+
if has_forbidden_phrase(streaming_reasoning, deep_reasoning, answer):
|
| 1225 |
+
flags.append("generic_reasoning")
|
| 1226 |
+
if copied_ratio(answer, source_answer) >= 0.72:
|
| 1227 |
+
flags.append("copied_source_response")
|
| 1228 |
+
if word_count(answer) < 5:
|
| 1229 |
+
flags.append("short_answer")
|
| 1230 |
+
if len(chunks) < 2 or sum(word_count(chunk) for chunk in chunks) < 12:
|
| 1231 |
+
flags.append("weak_context")
|
| 1232 |
+
if is_closing_or_thanks(" ".join(chunks)) and "today" in state.get("day", []):
|
| 1233 |
+
flags.append("possible_slot_error")
|
| 1234 |
+
if (state.get("closing_detected") or state.get("closing")) and re.search(r"\?|please confirm|what .*should|share .*", answer.lower()):
|
| 1235 |
+
flags.append("closing_mishandled")
|
| 1236 |
+
if domain == "task_oriented_assistant" and not any(state.get(key) for key in ["domain", "goal", "requested_info", "destination", "departure"]):
|
| 1237 |
+
flags.append("low_specificity")
|
| 1238 |
+
if domain == "emotional_support" and re.search(r"\b[a-z]+,\s+[a-z]+,\s+[a-z]+", deep_reasoning.lower()):
|
| 1239 |
+
flags.append("generic_reasoning")
|
| 1240 |
+
return list(dict.fromkeys(flags))
|
| 1241 |
+
|
| 1242 |
+
|
| 1243 |
+
def compute_state_tracking_confidence(domain: str, state: dict[str, Any], flags: list[str]) -> float:
|
| 1244 |
+
score = 0.85
|
| 1245 |
+
if domain == "task_oriented_assistant":
|
| 1246 |
+
if state.get("domain"):
|
| 1247 |
+
score += 0.06
|
| 1248 |
+
if state.get("goal"):
|
| 1249 |
+
score += 0.05
|
| 1250 |
+
if state.get("requested_info"):
|
| 1251 |
+
score += 0.03
|
| 1252 |
+
elif domain == "emotional_support":
|
| 1253 |
+
if state.get("emotion") and state.get("emotion") != "neutral":
|
| 1254 |
+
score += 0.06
|
| 1255 |
+
if state.get("cause"):
|
| 1256 |
+
score += 0.05
|
| 1257 |
+
if state.get("user_need"):
|
| 1258 |
+
score += 0.03
|
| 1259 |
+
elif domain == "daily_dialogue":
|
| 1260 |
+
if state.get("closing") or state.get("safety_reminder") or state.get("proposal_pending"):
|
| 1261 |
+
score += 0.04
|
| 1262 |
+
else:
|
| 1263 |
+
if state.get("steps"):
|
| 1264 |
+
score += 0.06
|
| 1265 |
+
score -= 0.05 * len([flag for flag in flags if flag in SEVERE_FLAGS])
|
| 1266 |
+
return round(max(0.0, min(1.0, score)), 3)
|
| 1267 |
+
|
| 1268 |
+
|
| 1269 |
+
def compute_quality_score(flags: list[str], streaming_reasoning: str, deep_reasoning: str) -> float:
|
| 1270 |
+
score = 1.0
|
| 1271 |
+
for flag in set(flags):
|
| 1272 |
+
score -= FLAG_PENALTIES.get(flag, 0.0)
|
| 1273 |
+
if word_count(streaming_reasoning) > 120:
|
| 1274 |
+
score -= 0.05
|
| 1275 |
+
if word_count(deep_reasoning) > 45:
|
| 1276 |
+
score -= 0.05
|
| 1277 |
+
return round(max(0.0, min(1.0, score)), 3)
|
| 1278 |
+
|
| 1279 |
+
|
| 1280 |
+
def is_high_quality_row(row: dict[str, Any]) -> bool:
|
| 1281 |
+
flags = set(row.get("quality_flags", []))
|
| 1282 |
+
return (
|
| 1283 |
+
row.get("quality_score", 0) >= 0.85
|
| 1284 |
+
and not (flags & SEVERE_FLAGS)
|
| 1285 |
+
and word_count(row.get("streaming_reasoning", "")) <= 120
|
| 1286 |
+
and word_count(row.get("deep_reasoning", "")) <= 45
|
| 1287 |
+
and not has_forbidden_phrase(row.get("streaming_reasoning", ""), row.get("deep_reasoning", ""), row.get("answer", ""))
|
| 1288 |
+
)
|
| 1289 |
+
|
| 1290 |
+
|
| 1291 |
+
def make_response(streaming_reasoning: str, deep_reasoning: str, answer: str) -> str:
|
| 1292 |
+
return f"Streaming reasoning: {streaming_reasoning}\n\nDeep reasoning: {deep_reasoning}\n\nAnswer: {answer}"
|
| 1293 |
+
|
| 1294 |
+
|
| 1295 |
+
def make_messages(instruction: str, context: str, response: str) -> list[dict[str, str]]:
|
| 1296 |
+
return [
|
| 1297 |
+
{"role": "user", "content": f"Instruction: {instruction}\n\nContext:\n{context}"},
|
| 1298 |
+
{"role": "assistant", "content": response},
|
| 1299 |
+
]
|
| 1300 |
+
|
| 1301 |
+
|
| 1302 |
+
def make_text(messages: list[dict[str, str]]) -> str:
|
| 1303 |
+
return f"<|user|>\n{messages[0]['content']}\n<|assistant|>\n{messages[1]['content']}"
|
| 1304 |
+
|
| 1305 |
+
|
| 1306 |
+
def transform_row(row: dict[str, Any]) -> dict[str, Any] | None:
|
| 1307 |
+
domain = str(row.get("domain") or "daily_dialogue")
|
| 1308 |
+
source_dataset = str(row.get("source_dataset") or "local_source")
|
| 1309 |
+
original_chunks = parse_context_chunks(row)
|
| 1310 |
+
if len(original_chunks) < 2:
|
| 1311 |
+
return None
|
| 1312 |
+
chunks: list[str] = []
|
| 1313 |
+
merged_fragments = False
|
| 1314 |
+
for chunk in original_chunks:
|
| 1315 |
+
split_chunks, changed = semantic_split_utterance(chunk, domain)
|
| 1316 |
+
chunks.extend(split_chunks)
|
| 1317 |
+
merged_fragments = merged_fragments or changed
|
| 1318 |
+
chunks, changed = merge_fragments(chunks)
|
| 1319 |
+
merged_fragments = merged_fragments or changed
|
| 1320 |
+
chunks = [clean_text(chunk, max_chars=340) for chunk in chunks if clean_text(chunk)]
|
| 1321 |
+
if len(chunks) < 2:
|
| 1322 |
+
return None
|
| 1323 |
+
if len(chunks) > 13:
|
| 1324 |
+
chunks = chunks[:13]
|
| 1325 |
+
if domain == "how_to_guidance" and is_undesired_how_to(chunks):
|
| 1326 |
+
return None
|
| 1327 |
+
streaming, deep, labels, skip_chunks, skip_reasons, state = build_reasoning(domain, chunks)
|
| 1328 |
+
answer = build_answer(domain, state, chunks)
|
| 1329 |
+
if not is_safe_example(chunks, answer):
|
| 1330 |
+
return None
|
| 1331 |
+
flags = compute_quality_flags(domain, chunks, labels, state, row.get("answer"), streaming, deep, answer, merged_fragments)
|
| 1332 |
+
quality_score = compute_quality_score(flags, streaming, deep)
|
| 1333 |
+
confidence = compute_state_tracking_confidence(domain, state, flags)
|
| 1334 |
+
context = build_context(chunks)
|
| 1335 |
+
response = make_response(streaming, deep, answer)
|
| 1336 |
+
messages = make_messages(INSTRUCTION, context, response)
|
| 1337 |
+
example = {
|
| 1338 |
+
"id": "",
|
| 1339 |
+
"domain": domain,
|
| 1340 |
+
"source_dataset": source_dataset,
|
| 1341 |
+
"instruction": INSTRUCTION,
|
| 1342 |
+
"context": context,
|
| 1343 |
+
"context_chunks": chunks,
|
| 1344 |
+
"streaming_reasoning": streaming,
|
| 1345 |
+
"deep_reasoning": deep,
|
| 1346 |
+
"answer": answer,
|
| 1347 |
+
"response": response,
|
| 1348 |
+
"messages": messages,
|
| 1349 |
+
"text": make_text(messages),
|
| 1350 |
+
"num_chunks": len(chunks),
|
| 1351 |
+
"language": "en",
|
| 1352 |
+
"split": "",
|
| 1353 |
+
"generation_method": GENERATION_METHOD,
|
| 1354 |
+
"quality_flags": flags,
|
| 1355 |
+
"version": DATASET_VERSION,
|
| 1356 |
+
"reasoning_policy": REASONING_POLICY,
|
| 1357 |
+
"chunking_method": CHUNKING_METHOD,
|
| 1358 |
+
"chunk_labels": labels,
|
| 1359 |
+
"skip_chunks": skip_chunks,
|
| 1360 |
+
"skip_reasons": skip_reasons,
|
| 1361 |
+
"reasoning_token_budget": REASONING_TOKEN_BUDGET,
|
| 1362 |
+
"original_num_chunks": len(original_chunks),
|
| 1363 |
+
"chunk_split_count": max(0, len(chunks) - len(original_chunks)),
|
| 1364 |
+
"quality_score": quality_score,
|
| 1365 |
+
"is_high_quality": False,
|
| 1366 |
+
"refinement_method": REFINEMENT_METHOD,
|
| 1367 |
+
"llm_augmented": False,
|
| 1368 |
+
"llm_augmentation_model": None,
|
| 1369 |
+
"rejected_reason": None,
|
| 1370 |
+
"state_tracking_confidence": confidence,
|
| 1371 |
+
}
|
| 1372 |
+
example["is_high_quality"] = is_high_quality_row(example)
|
| 1373 |
+
return example
|
| 1374 |
+
|
| 1375 |
+
|
| 1376 |
+
def select_source_rows(rows: list[dict[str, Any]], max_examples: int, seed: int) -> list[dict[str, Any]]:
|
| 1377 |
+
groups: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
| 1378 |
+
for row in rows:
|
| 1379 |
+
groups[str(row.get("domain") or "daily_dialogue")].append(row)
|
| 1380 |
+
rng = random.Random(seed)
|
| 1381 |
+
for group in groups.values():
|
| 1382 |
+
rng.shuffle(group)
|
| 1383 |
+
selected: list[dict[str, Any]] = []
|
| 1384 |
+
domains = sorted(groups)
|
| 1385 |
+
index = 0
|
| 1386 |
+
while len(selected) < max_examples:
|
| 1387 |
+
added = False
|
| 1388 |
+
for domain in domains:
|
| 1389 |
+
if index < len(groups[domain]):
|
| 1390 |
+
selected.append(groups[domain][index])
|
| 1391 |
+
added = True
|
| 1392 |
+
if len(selected) >= max_examples:
|
| 1393 |
+
break
|
| 1394 |
+
if not added:
|
| 1395 |
+
break
|
| 1396 |
+
index += 1
|
| 1397 |
+
return selected
|
| 1398 |
+
|
| 1399 |
+
|
| 1400 |
+
def deduplicate(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 1401 |
+
seen_texts: set[str] = set()
|
| 1402 |
+
unique: list[dict[str, Any]] = []
|
| 1403 |
+
for row in rows:
|
| 1404 |
+
key = normalize(row["text"])
|
| 1405 |
+
if not key or key in seen_texts:
|
| 1406 |
+
continue
|
| 1407 |
+
seen_texts.add(key)
|
| 1408 |
+
unique.append(row)
|
| 1409 |
+
return unique
|
| 1410 |
+
|
| 1411 |
+
|
| 1412 |
+
def assign_ids_and_splits(rows: list[dict[str, Any]], seed: int) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
| 1413 |
+
rng = random.Random(seed)
|
| 1414 |
+
rng.shuffle(rows)
|
| 1415 |
+
split_at = max(1, int(len(rows) * 0.8))
|
| 1416 |
+
train_rows = rows[:split_at]
|
| 1417 |
+
eval_rows = rows[split_at:]
|
| 1418 |
+
if not eval_rows and len(train_rows) > 1:
|
| 1419 |
+
eval_rows = [train_rows.pop()]
|
| 1420 |
+
domain_counts: Counter[str] = Counter()
|
| 1421 |
+
for split_name, split_rows in [("train", train_rows), ("eval", eval_rows)]:
|
| 1422 |
+
for row in split_rows:
|
| 1423 |
+
domain_counts[row["domain"]] += 1
|
| 1424 |
+
slug = re.sub(r"[^a-z0-9]+", "_", row["domain"].lower()).strip("_")
|
| 1425 |
+
row["id"] = f"life_{slug}_{domain_counts[row['domain']]:06d}"
|
| 1426 |
+
row["split"] = split_name
|
| 1427 |
+
row["messages"] = make_messages(row["instruction"], row["context"], row["response"])
|
| 1428 |
+
row["text"] = make_text(row["messages"])
|
| 1429 |
+
return train_rows, eval_rows
|
| 1430 |
+
|
| 1431 |
+
|
| 1432 |
+
def select_review_samples(rows: list[dict[str, Any]], sample_size: int = 120) -> list[dict[str, Any]]:
|
| 1433 |
+
by_domain: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
| 1434 |
+
for row in rows:
|
| 1435 |
+
by_domain[row["domain"]].append(row)
|
| 1436 |
+
selected: list[dict[str, Any]] = []
|
| 1437 |
+
seen: set[str] = set()
|
| 1438 |
+
per_domain = 30
|
| 1439 |
+
for domain in ["task_oriented_assistant", "emotional_support", "daily_dialogue", "how_to_guidance"]:
|
| 1440 |
+
candidates = by_domain.get(domain, [])
|
| 1441 |
+
buckets = [
|
| 1442 |
+
[row for row in candidates if row.get("is_high_quality")],
|
| 1443 |
+
[row for row in candidates if row.get("skip_chunks")],
|
| 1444 |
+
[row for row in candidates if row.get("quality_flags")],
|
| 1445 |
+
candidates,
|
| 1446 |
+
]
|
| 1447 |
+
picked = 0
|
| 1448 |
+
for bucket in buckets:
|
| 1449 |
+
for row in bucket:
|
| 1450 |
+
if row["id"] in seen:
|
| 1451 |
+
continue
|
| 1452 |
+
selected.append(row)
|
| 1453 |
+
seen.add(row["id"])
|
| 1454 |
+
picked += 1
|
| 1455 |
+
if picked >= per_domain:
|
| 1456 |
+
break
|
| 1457 |
+
if picked >= per_domain:
|
| 1458 |
+
break
|
| 1459 |
+
for row in rows:
|
| 1460 |
+
if len(selected) >= sample_size:
|
| 1461 |
+
break
|
| 1462 |
+
if row["id"] not in seen:
|
| 1463 |
+
selected.append(row)
|
| 1464 |
+
seen.add(row["id"])
|
| 1465 |
+
sample_fields = [
|
| 1466 |
+
"id",
|
| 1467 |
+
"domain",
|
| 1468 |
+
"context_chunks",
|
| 1469 |
+
"chunk_labels",
|
| 1470 |
+
"skip_reasons",
|
| 1471 |
+
"streaming_reasoning",
|
| 1472 |
+
"deep_reasoning",
|
| 1473 |
+
"answer",
|
| 1474 |
+
"quality_flags",
|
| 1475 |
+
"quality_score",
|
| 1476 |
+
"is_high_quality",
|
| 1477 |
+
"refinement_method",
|
| 1478 |
+
"split",
|
| 1479 |
+
]
|
| 1480 |
+
return [{field: row.get(field) for field in sample_fields} for row in selected[:sample_size]]
|
| 1481 |
+
|
| 1482 |
+
|
| 1483 |
+
def write_parquet(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 1484 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 1485 |
+
pd.DataFrame(rows, columns=REQUIRED_FIELDS).to_parquet(path, index=False)
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
def source_summary(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 1489 |
+
counts = Counter(row["source_dataset"] for row in rows)
|
| 1490 |
+
domains: dict[str, set[str]] = defaultdict(set)
|
| 1491 |
+
for row in rows:
|
| 1492 |
+
domains[row["source_dataset"]].add(row["domain"])
|
| 1493 |
+
return [{"name": source, "domain": ",".join(sorted(domains[source])), "rows": count} for source, count in sorted(counts.items())]
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
def quality_counts(rows: list[dict[str, Any]]) -> dict[str, int]:
|
| 1497 |
+
return dict(sorted(Counter(flag for row in rows for flag in row.get("quality_flags", [])).items()))
|
| 1498 |
+
|
| 1499 |
+
|
| 1500 |
+
def avg(values: list[float]) -> float:
|
| 1501 |
+
return statistics.mean(values) if values else 0.0
|
| 1502 |
+
|
| 1503 |
+
|
| 1504 |
+
def build_dataset_info(train_rows: list[dict[str, Any]], eval_rows: list[dict[str, Any]], hq_train: list[dict[str, Any]], hq_eval: list[dict[str, Any]], skipped_sources: list[dict[str, str]]) -> dict[str, Any]:
|
| 1505 |
+
rows = train_rows + eval_rows
|
| 1506 |
+
total_chunks = sum(row["num_chunks"] for row in rows)
|
| 1507 |
+
skip_chunks = sum(len(row["skip_chunks"]) for row in rows)
|
| 1508 |
+
return {
|
| 1509 |
+
"dataset_name": DATASET_NAME,
|
| 1510 |
+
"repo_id": REPO_ID,
|
| 1511 |
+
"version": DATASET_VERSION,
|
| 1512 |
+
"created_by": "skyzhou06 with Codex",
|
| 1513 |
+
"generation_method": GENERATION_METHOD,
|
| 1514 |
+
"reasoning_policy": REASONING_POLICY,
|
| 1515 |
+
"chunking_method": CHUNKING_METHOD,
|
| 1516 |
+
"refinement_method": REFINEMENT_METHOD,
|
| 1517 |
+
"schema": {field: "required" for field in REQUIRED_FIELDS},
|
| 1518 |
+
"source_datasets_used": source_summary(rows),
|
| 1519 |
+
"skipped_source_datasets": skipped_sources,
|
| 1520 |
+
"total_rows": len(rows),
|
| 1521 |
+
"train_rows": len(train_rows),
|
| 1522 |
+
"eval_rows": len(eval_rows),
|
| 1523 |
+
"high_quality_train_rows": len(hq_train),
|
| 1524 |
+
"high_quality_eval_rows": len(hq_eval),
|
| 1525 |
+
"domains": dict(sorted(Counter(row["domain"] for row in rows).items())),
|
| 1526 |
+
"average_num_chunks": avg([row["num_chunks"] for row in rows]),
|
| 1527 |
+
"average_chunk_length": avg([word_count(chunk) for row in rows for chunk in row["context_chunks"]]),
|
| 1528 |
+
"average_original_num_chunks": avg([row["original_num_chunks"] for row in rows]),
|
| 1529 |
+
"average_chunk_split_count": avg([row["chunk_split_count"] for row in rows]),
|
| 1530 |
+
"average_streaming_reasoning_words": avg([word_count(row["streaming_reasoning"]) for row in rows]),
|
| 1531 |
+
"average_deep_reasoning_words": avg([word_count(row["deep_reasoning"]) for row in rows]),
|
| 1532 |
+
"average_quality_score": avg([row["quality_score"] for row in rows]),
|
| 1533 |
+
"high_quality_percentage": (len(hq_train) + len(hq_eval)) / len(rows) if rows else 0,
|
| 1534 |
+
"skip_chunk_ratio": skip_chunks / total_chunks if total_chunks else 0,
|
| 1535 |
+
"examples_with_at_least_one_skip": sum(1 for row in rows if row["skip_chunks"]),
|
| 1536 |
+
"quality_flags_distribution": quality_counts(rows),
|
| 1537 |
+
"llm_augmented_count": sum(1 for row in rows if row.get("llm_augmented")),
|
| 1538 |
+
"limitations": [
|
| 1539 |
+
"v0.4 is primarily rule-based unless optional LLM augmentation is run.",
|
| 1540 |
+
"The high-quality subset is recommended for serious SFT experiments.",
|
| 1541 |
+
"Some source datasets are dialogue-style and may not perfectly match ideal assistant behavior.",
|
| 1542 |
+
"The dataset is not intended for expert medical, legal, financial, emergency, or safety-critical advice.",
|
| 1543 |
+
],
|
| 1544 |
+
"samples_for_review": "samples_for_review.jsonl",
|
| 1545 |
+
}
|
| 1546 |
+
|
| 1547 |
+
|
| 1548 |
+
def dataset_card(info: dict[str, Any], example: dict[str, Any] | None) -> str:
|
| 1549 |
+
used = "\n".join(f"- `{item['name']}`: {item['rows']} rows, domain `{item['domain']}`" for item in info["source_datasets_used"]) or "- None"
|
| 1550 |
+
skipped = "\n".join(f"- `{item['name']}`: {item['reason']}" for item in info["skipped_source_datasets"]) or "- None"
|
| 1551 |
+
flags = "\n".join(f"- `{flag}`: {count}" for flag, count in info["quality_flags_distribution"].items()) or "- None"
|
| 1552 |
+
example_json = json.dumps(example or {}, ensure_ascii=False, indent=2)
|
| 1553 |
+
schema = "\n".join(f"- `{field}`" for field in REQUIRED_FIELDS)
|
| 1554 |
+
return f"""---
|
| 1555 |
+
pretty_name: LifeTextSingleTurnStreamingCoT
|
| 1556 |
+
language:
|
| 1557 |
+
- en
|
| 1558 |
+
license: apache-2.0
|
| 1559 |
+
version: "{DATASET_VERSION}"
|
| 1560 |
+
task_categories:
|
| 1561 |
+
- text-generation
|
| 1562 |
+
tags:
|
| 1563 |
+
- streaming-reasoning
|
| 1564 |
+
- selective-reasoning
|
| 1565 |
+
- quality-refined
|
| 1566 |
+
- supervised-fine-tuning
|
| 1567 |
+
- sft
|
| 1568 |
+
- dialogue
|
| 1569 |
+
- task-oriented-dialogue
|
| 1570 |
+
- life-assistant
|
| 1571 |
+
- streamingthinker
|
| 1572 |
+
size_categories:
|
| 1573 |
+
- 1K<n<10K
|
| 1574 |
+
---
|
| 1575 |
+
|
| 1576 |
+
# LifeTextSingleTurnStreamingCoT
|
| 1577 |
+
|
| 1578 |
+
Current version: v0.4: Quality-Refined Selective Streaming Reasoning
|
| 1579 |
+
|
| 1580 |
+
LifeTextSingleTurnStreamingCoT is a text-only, life-scenario adaptation of StreamingCoT-style data for StreamingThinker-style supervised fine-tuning. It keeps compatibility with earlier LifeTextSingleTurnStreamingCoT schemas while adding quality metadata and high-quality subset files.
|
| 1581 |
+
|
| 1582 |
+
## Version 0.4: Quality Refinement
|
| 1583 |
+
|
| 1584 |
+
v0.3 introduced selective concise streaming reasoning, semantic chunk splitting, skip labels, and chunk-level metadata. v0.4 improves quality by fixing keyword-stitching in emotional support examples, reducing daily-dialogue intent mistakes, replacing vague task-oriented updates, reducing fragment chunks, and adding `quality_score` plus `is_high_quality`.
|
| 1585 |
+
|
| 1586 |
+
v0.4 also provides high-quality subset files:
|
| 1587 |
+
|
| 1588 |
+
- `data/train_high_quality.jsonl`
|
| 1589 |
+
- `data/eval_high_quality.jsonl`
|
| 1590 |
+
- `data/train_high_quality.parquet`
|
| 1591 |
+
- `data/eval_high_quality.parquet`
|
| 1592 |
+
|
| 1593 |
+
## Version History
|
| 1594 |
+
|
| 1595 |
+
| Version | Summary |
|
| 1596 |
+
| --- | --- |
|
| 1597 |
+
| v0.1 | Schema-complete source-grounded baseline |
|
| 1598 |
+
| v0.2 | More specific rule-based reasoning and quality flags |
|
| 1599 |
+
| v0.3 | Selective concise reasoning, skip labels, semantic chunking |
|
| 1600 |
+
| v0.4 | Quality refinement, quality scores, high-quality subset |
|
| 1601 |
+
|
| 1602 |
+
## Recommended Usage
|
| 1603 |
+
|
| 1604 |
+
Full dataset:
|
| 1605 |
+
|
| 1606 |
+
```python
|
| 1607 |
+
from datasets import load_dataset
|
| 1608 |
+
ds = load_dataset("skyzhou06/LifeTextSingleTurnStreamingCoT")
|
| 1609 |
+
```
|
| 1610 |
+
|
| 1611 |
+
Quality filtering:
|
| 1612 |
+
|
| 1613 |
+
```python
|
| 1614 |
+
clean = ds.filter(lambda x: x["is_high_quality"] and x["quality_score"] >= 0.85)
|
| 1615 |
+
```
|
| 1616 |
+
|
| 1617 |
+
Removing flagged data:
|
| 1618 |
+
|
| 1619 |
+
```python
|
| 1620 |
+
clean = ds.filter(lambda x: len(x["quality_flags"]) == 0)
|
| 1621 |
+
```
|
| 1622 |
+
|
| 1623 |
+
## Schema
|
| 1624 |
+
|
| 1625 |
+
{schema}
|
| 1626 |
+
|
| 1627 |
+
## Source Datasets
|
| 1628 |
+
|
| 1629 |
+
Used sources:
|
| 1630 |
+
|
| 1631 |
+
{used}
|
| 1632 |
+
|
| 1633 |
+
Skipped sources:
|
| 1634 |
+
|
| 1635 |
+
{skipped}
|
| 1636 |
+
|
| 1637 |
+
## Splits
|
| 1638 |
+
|
| 1639 |
+
- Train: {info['train_rows']}
|
| 1640 |
+
- Eval: {info['eval_rows']}
|
| 1641 |
+
- Total: {info['total_rows']}
|
| 1642 |
+
- High-quality train: {info['high_quality_train_rows']}
|
| 1643 |
+
- High-quality eval: {info['high_quality_eval_rows']}
|
| 1644 |
+
|
| 1645 |
+
## Statistics
|
| 1646 |
+
|
| 1647 |
+
- Average chunks: {info['average_num_chunks']:.2f}
|
| 1648 |
+
- Average chunk length: {info['average_chunk_length']:.2f}
|
| 1649 |
+
- Average streaming reasoning words: {info['average_streaming_reasoning_words']:.2f}
|
| 1650 |
+
- Average deep reasoning words: {info['average_deep_reasoning_words']:.2f}
|
| 1651 |
+
- Average quality score: {info['average_quality_score']:.3f}
|
| 1652 |
+
- High-quality percentage: {info['high_quality_percentage']:.2%}
|
| 1653 |
+
- Skip chunk ratio: {info['skip_chunk_ratio']:.4f}
|
| 1654 |
+
- LLM augmented rows: {info['llm_augmented_count']}
|
| 1655 |
+
|
| 1656 |
+
## Quality Flags
|
| 1657 |
+
|
| 1658 |
+
{flags}
|
| 1659 |
+
|
| 1660 |
+
## Example
|
| 1661 |
+
|
| 1662 |
+
```json
|
| 1663 |
+
{example_json}
|
| 1664 |
+
```
|
| 1665 |
+
|
| 1666 |
+
## Limitations
|
| 1667 |
+
|
| 1668 |
+
- Still primarily rule-based unless optional LLM augmentation is run.
|
| 1669 |
+
- Not expert advice.
|
| 1670 |
+
- Some source datasets are dialogue-style and may not perfectly match assistant behavior.
|
| 1671 |
+
- The high-quality subset is recommended for serious SFT experiments.
|
| 1672 |
+
"""
|
| 1673 |
+
|
| 1674 |
+
|
| 1675 |
+
def print_stats(rows: list[dict[str, Any]], train_rows: list[dict[str, Any]], eval_rows: list[dict[str, Any]], hq_train: list[dict[str, Any]], hq_eval: list[dict[str, Any]], skipped: list[dict[str, str]], llm_status: str) -> None:
|
| 1676 |
+
total_chunks = sum(row["num_chunks"] for row in rows)
|
| 1677 |
+
skip_chunks = sum(len(row["skip_chunks"]) for row in rows)
|
| 1678 |
+
print("\nBuild stats")
|
| 1679 |
+
print(f"total examples: {len(rows)}")
|
| 1680 |
+
print(f"train examples: {len(train_rows)}")
|
| 1681 |
+
print(f"eval examples: {len(eval_rows)}")
|
| 1682 |
+
print(f"high-quality train examples: {len(hq_train)}")
|
| 1683 |
+
print(f"high-quality eval examples: {len(hq_eval)}")
|
| 1684 |
+
print(f"domains: {dict(sorted(Counter(row['domain'] for row in rows).items()))}")
|
| 1685 |
+
print(f"source datasets: {dict(Counter(row['source_dataset'] for row in rows))}")
|
| 1686 |
+
print(f"average chunks: {avg([row['num_chunks'] for row in rows]):.2f}")
|
| 1687 |
+
print(f"average chunk length: {avg([word_count(chunk) for row in rows for chunk in row['context_chunks']]):.2f}")
|
| 1688 |
+
print(f"average streaming reasoning words: {avg([word_count(row['streaming_reasoning']) for row in rows]):.2f}")
|
| 1689 |
+
print(f"average deep reasoning words: {avg([word_count(row['deep_reasoning']) for row in rows]):.2f}")
|
| 1690 |
+
print(f"average quality score: {avg([row['quality_score'] for row in rows]):.3f}")
|
| 1691 |
+
print(f"high-quality percentage: {(len(hq_train) + len(hq_eval)) / len(rows) if rows else 0:.2%}")
|
| 1692 |
+
print(f"skip chunk ratio: {skip_chunks / total_chunks if total_chunks else 0:.4f}")
|
| 1693 |
+
print(f"quality flags: {quality_counts(rows)}")
|
| 1694 |
+
print(f"llm augmentation: {llm_status}")
|
| 1695 |
+
print(f"skipped source datasets: {skipped}")
|
| 1696 |
+
|
| 1697 |
+
|
| 1698 |
+
def sync_scripts_to_dataset(output_dir: Path) -> None:
|
| 1699 |
+
script_dir = Path(__file__).resolve().parent
|
| 1700 |
+
target = output_dir / "scripts"
|
| 1701 |
+
target.mkdir(parents=True, exist_ok=True)
|
| 1702 |
+
for name in ["build_life_streaming_cot.py", "validate_dataset.py", "upload_to_hf.py", "augment_with_llm.py", "analyze_quality.py"]:
|
| 1703 |
+
src = script_dir / name
|
| 1704 |
+
if src.exists():
|
| 1705 |
+
shutil.copy2(src, target / name)
|
| 1706 |
+
|
| 1707 |
+
|
| 1708 |
+
def main() -> None:
|
| 1709 |
+
parser = argparse.ArgumentParser()
|
| 1710 |
+
parser.add_argument("--output-dir", default="life_streaming_cot_dataset")
|
| 1711 |
+
parser.add_argument("--max-examples", type=int, default=10000)
|
| 1712 |
+
parser.add_argument("--smoke-test", action="store_true")
|
| 1713 |
+
parser.add_argument("--seed", type=int, default=42)
|
| 1714 |
+
parser.add_argument("--llm-augment", action="store_true", help="Reserved hook for optional LLM augmentation.")
|
| 1715 |
+
args = parser.parse_args()
|
| 1716 |
+
|
| 1717 |
+
output_dir = Path(args.output_dir)
|
| 1718 |
+
data_dir = output_dir / "data"
|
| 1719 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 1720 |
+
max_examples = min(args.max_examples, 300 if args.smoke_test else args.max_examples)
|
| 1721 |
+
|
| 1722 |
+
source_rows, skipped_sources = load_source_rows(output_dir)
|
| 1723 |
+
if not source_rows:
|
| 1724 |
+
raise RuntimeError("No source rows were available.")
|
| 1725 |
+
source_rows = select_source_rows(source_rows, max_examples=max_examples * 5, seed=args.seed)
|
| 1726 |
+
|
| 1727 |
+
rows: list[dict[str, Any]] = []
|
| 1728 |
+
for source_row in source_rows:
|
| 1729 |
+
example = transform_row(source_row)
|
| 1730 |
+
if example:
|
| 1731 |
+
rows.append(example)
|
| 1732 |
+
if len(rows) >= max_examples:
|
| 1733 |
+
break
|
| 1734 |
+
rows = deduplicate(rows)
|
| 1735 |
+
if len(rows) > max_examples:
|
| 1736 |
+
rows = rows[:max_examples]
|
| 1737 |
+
if len(rows) < min(5000, max_examples) and not args.smoke_test:
|
| 1738 |
+
raise RuntimeError(f"Only {len(rows)} examples were produced; expected at least {min(5000, max_examples)}.")
|
| 1739 |
+
if len(rows) < 10:
|
| 1740 |
+
raise RuntimeError("Fewer than 10 examples were produced.")
|
| 1741 |
+
|
| 1742 |
+
llm_available = bool(os.getenv("OPENAI_API_KEY") or os.getenv("OPENAI_BASE_URL") or os.getenv("LOCAL_LLM_BASE_URL"))
|
| 1743 |
+
if args.llm_augment and llm_available:
|
| 1744 |
+
llm_status = "available but not run in build script; use scripts/augment_with_llm.py for explicit augmentation"
|
| 1745 |
+
elif args.llm_augment:
|
| 1746 |
+
llm_status = "skipped: no supported API key or local model endpoint found"
|
| 1747 |
+
else:
|
| 1748 |
+
llm_status = "skipped: optional LLM augmentation was not requested"
|
| 1749 |
+
|
| 1750 |
+
train_rows, eval_rows = assign_ids_and_splits(rows, args.seed)
|
| 1751 |
+
all_rows = train_rows + eval_rows
|
| 1752 |
+
hq_train = [row for row in train_rows if row["is_high_quality"]]
|
| 1753 |
+
hq_eval = [row for row in eval_rows if row["is_high_quality"]]
|
| 1754 |
+
|
| 1755 |
+
write_jsonl(data_dir / "train.jsonl", train_rows)
|
| 1756 |
+
write_jsonl(data_dir / "eval.jsonl", eval_rows)
|
| 1757 |
+
write_jsonl(data_dir / "train_high_quality.jsonl", hq_train)
|
| 1758 |
+
write_jsonl(data_dir / "eval_high_quality.jsonl", hq_eval)
|
| 1759 |
+
write_parquet(data_dir / "train.parquet", train_rows)
|
| 1760 |
+
write_parquet(data_dir / "eval.parquet", eval_rows)
|
| 1761 |
+
write_parquet(data_dir / "train_high_quality.parquet", hq_train)
|
| 1762 |
+
write_parquet(data_dir / "eval_high_quality.parquet", hq_eval)
|
| 1763 |
+
write_jsonl(output_dir / "samples_for_review.jsonl", select_review_samples(all_rows, sample_size=120))
|
| 1764 |
+
|
| 1765 |
+
info = build_dataset_info(train_rows, eval_rows, hq_train, hq_eval, skipped_sources)
|
| 1766 |
+
(output_dir / "dataset_info.json").write_text(json.dumps(info, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
| 1767 |
+
(output_dir / "README.md").write_text(dataset_card(info, hq_train[0] if hq_train else train_rows[0]), encoding="utf-8")
|
| 1768 |
+
(output_dir / "requirements.txt").write_text(Path("requirements.txt").read_text(encoding="utf-8"), encoding="utf-8")
|
| 1769 |
+
sync_scripts_to_dataset(output_dir)
|
| 1770 |
+
print_stats(all_rows, train_rows, eval_rows, hq_train, hq_eval, skipped_sources, llm_status)
|
| 1771 |
+
|
| 1772 |
+
|
| 1773 |
+
if __name__ == "__main__":
|
| 1774 |
+
main()
|
scripts/upload_to_hf.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
from huggingface_hub import HfApi
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
CANONICAL_REPO_ID = "skyzhou06/LifeTextSingleTurnStreamingCoT"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main() -> None:
|
| 16 |
+
parser = argparse.ArgumentParser()
|
| 17 |
+
parser.add_argument("--repo-id", default=CANONICAL_REPO_ID)
|
| 18 |
+
parser.add_argument("--folder", "--input-dir", dest="folder", default="life_streaming_cot_dataset")
|
| 19 |
+
parser.add_argument("--version", default="v0.4.1")
|
| 20 |
+
parser.add_argument("--private", action="store_true")
|
| 21 |
+
args = parser.parse_args()
|
| 22 |
+
|
| 23 |
+
folder = Path(args.folder)
|
| 24 |
+
if not folder.exists():
|
| 25 |
+
print(f"Dataset folder does not exist: {folder}", file=sys.stderr)
|
| 26 |
+
sys.exit(1)
|
| 27 |
+
|
| 28 |
+
info_path = folder / "dataset_info.json"
|
| 29 |
+
if not info_path.exists():
|
| 30 |
+
print(f"Missing dataset_info.json in {folder}", file=sys.stderr)
|
| 31 |
+
sys.exit(1)
|
| 32 |
+
info = json.loads(info_path.read_text(encoding="utf-8"))
|
| 33 |
+
if info.get("version") != "v0.4.1":
|
| 34 |
+
print("Refusing upload: dataset_info.json is not version v0.4.1.", file=sys.stderr)
|
| 35 |
+
sys.exit(1)
|
| 36 |
+
if info.get("repo_id") != CANONICAL_REPO_ID:
|
| 37 |
+
print(f"Refusing upload: dataset_info.json repo_id is not {CANONICAL_REPO_ID}.", file=sys.stderr)
|
| 38 |
+
sys.exit(1)
|
| 39 |
+
if "v0.4.1" not in str(info.get("generation_method", "")):
|
| 40 |
+
print("Refusing upload: generation_method does not contain v0.4.1.", file=sys.stderr)
|
| 41 |
+
sys.exit(1)
|
| 42 |
+
if args.repo_id != CANONICAL_REPO_ID:
|
| 43 |
+
print(f"Refusing upload: target repo must be {CANONICAL_REPO_ID}.", file=sys.stderr)
|
| 44 |
+
sys.exit(1)
|
| 45 |
+
|
| 46 |
+
api = HfApi()
|
| 47 |
+
try:
|
| 48 |
+
api.whoami()
|
| 49 |
+
except Exception: # noqa: BLE001 - do not print auth internals or tokens
|
| 50 |
+
print("Hugging Face authentication is missing or invalid.")
|
| 51 |
+
print("Run this command, then rerun the upload:")
|
| 52 |
+
print("huggingface-cli login")
|
| 53 |
+
sys.exit(2)
|
| 54 |
+
|
| 55 |
+
api.create_repo(repo_id=args.repo_id, repo_type="dataset", private=args.private, exist_ok=True)
|
| 56 |
+
api.upload_folder(
|
| 57 |
+
repo_id=args.repo_id,
|
| 58 |
+
repo_type="dataset",
|
| 59 |
+
folder_path=str(folder),
|
| 60 |
+
path_in_repo=".",
|
| 61 |
+
commit_message="Update LifeTextSingleTurnStreamingCoT to v0.4.1 loading config and HQ subset patch",
|
| 62 |
+
ignore_patterns=[
|
| 63 |
+
".DS_Store",
|
| 64 |
+
"*/.DS_Store",
|
| 65 |
+
"__pycache__",
|
| 66 |
+
"*/__pycache__/*",
|
| 67 |
+
"*.pyc",
|
| 68 |
+
],
|
| 69 |
+
)
|
| 70 |
+
print(f"https://huggingface.co/datasets/{args.repo_id}")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
main()
|
scripts/validate_dataset.py
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
import sys
|
| 8 |
+
from collections import Counter
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import pandas as pd
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
REQUIRED_V03_FIELDS = [
|
| 16 |
+
"id",
|
| 17 |
+
"domain",
|
| 18 |
+
"source_dataset",
|
| 19 |
+
"instruction",
|
| 20 |
+
"context",
|
| 21 |
+
"context_chunks",
|
| 22 |
+
"streaming_reasoning",
|
| 23 |
+
"deep_reasoning",
|
| 24 |
+
"answer",
|
| 25 |
+
"response",
|
| 26 |
+
"messages",
|
| 27 |
+
"text",
|
| 28 |
+
"num_chunks",
|
| 29 |
+
"language",
|
| 30 |
+
"split",
|
| 31 |
+
"generation_method",
|
| 32 |
+
"quality_flags",
|
| 33 |
+
"version",
|
| 34 |
+
"reasoning_policy",
|
| 35 |
+
"chunking_method",
|
| 36 |
+
"chunk_labels",
|
| 37 |
+
"skip_chunks",
|
| 38 |
+
"skip_reasons",
|
| 39 |
+
"reasoning_token_budget",
|
| 40 |
+
"original_num_chunks",
|
| 41 |
+
"chunk_split_count",
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
REQUIRED_V04_FIELDS = [
|
| 45 |
+
"quality_score",
|
| 46 |
+
"is_high_quality",
|
| 47 |
+
"refinement_method",
|
| 48 |
+
"llm_augmented",
|
| 49 |
+
"llm_augmentation_model",
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
OPTIONAL_V04_FIELDS = [
|
| 53 |
+
"rejected_reason",
|
| 54 |
+
"state_tracking_confidence",
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
REQUIRED_FIELDS = REQUIRED_V03_FIELDS + REQUIRED_V04_FIELDS + OPTIONAL_V04_FIELDS
|
| 58 |
+
|
| 59 |
+
REQUIRED_STRING_FIELDS = [
|
| 60 |
+
"id",
|
| 61 |
+
"domain",
|
| 62 |
+
"source_dataset",
|
| 63 |
+
"instruction",
|
| 64 |
+
"context",
|
| 65 |
+
"streaming_reasoning",
|
| 66 |
+
"deep_reasoning",
|
| 67 |
+
"answer",
|
| 68 |
+
"response",
|
| 69 |
+
"text",
|
| 70 |
+
"language",
|
| 71 |
+
"split",
|
| 72 |
+
"generation_method",
|
| 73 |
+
"version",
|
| 74 |
+
"reasoning_policy",
|
| 75 |
+
"chunking_method",
|
| 76 |
+
"refinement_method",
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
FORBIDDEN_PHRASES = [
|
| 80 |
+
"the user is sharing everyday context",
|
| 81 |
+
"the situation is about an everyday life situation",
|
| 82 |
+
"the assistant should stay conversational",
|
| 83 |
+
"the user is asking for help, clarification, or a next step",
|
| 84 |
+
"support need centers on",
|
| 85 |
+
"task_detail=noted",
|
| 86 |
+
"emotion=positive; cause=",
|
| 87 |
+
"emotion=negative; cause=",
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
SEVERE_FLAGS = {
|
| 91 |
+
"generic_reasoning",
|
| 92 |
+
"closing_mishandled",
|
| 93 |
+
"possible_slot_error",
|
| 94 |
+
"excessive_chunking",
|
| 95 |
+
"fragment_chunk",
|
| 96 |
+
"low_specificity",
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
HIGH_QUALITY_EXCLUDED_FLAGS = SEVERE_FLAGS | {
|
| 100 |
+
"copied_source_response",
|
| 101 |
+
"awkward_answer",
|
| 102 |
+
"keyword_stitching",
|
| 103 |
+
"repeated_context_chunks",
|
| 104 |
+
"weak_high_quality_candidate",
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
REVIEW_SAMPLE_FIELDS = [
|
| 108 |
+
"id",
|
| 109 |
+
"domain",
|
| 110 |
+
"context_chunks",
|
| 111 |
+
"chunk_labels",
|
| 112 |
+
"skip_reasons",
|
| 113 |
+
"streaming_reasoning",
|
| 114 |
+
"deep_reasoning",
|
| 115 |
+
"answer",
|
| 116 |
+
"quality_flags",
|
| 117 |
+
"quality_score",
|
| 118 |
+
"is_high_quality",
|
| 119 |
+
"refinement_method",
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def word_count(text: Any) -> int:
|
| 124 |
+
return len(re.findall(r"\b[\w'-]+\b", str(text)))
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 128 |
+
rows: list[dict[str, Any]] = []
|
| 129 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 130 |
+
for line_no, line in enumerate(handle, start=1):
|
| 131 |
+
line = line.strip()
|
| 132 |
+
if not line:
|
| 133 |
+
continue
|
| 134 |
+
try:
|
| 135 |
+
rows.append(json.loads(line))
|
| 136 |
+
except json.JSONDecodeError as exc:
|
| 137 |
+
raise ValueError(f"{path}:{line_no}: invalid JSON: {exc}") from exc
|
| 138 |
+
return rows
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def forbidden_phrase_count(row: dict[str, Any]) -> int:
|
| 142 |
+
text = "\n".join(str(row.get(field, "")) for field in ["streaming_reasoning", "deep_reasoning", "answer"]).lower()
|
| 143 |
+
return sum(text.count(phrase) for phrase in FORBIDDEN_PHRASES)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def normalize(text: Any) -> str:
|
| 147 |
+
return re.sub(r"\W+", " ", str(text).lower()).strip()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def is_fragment_chunk(text: Any) -> bool:
|
| 151 |
+
stripped = str(text or "").strip()
|
| 152 |
+
normalized = normalize(stripped)
|
| 153 |
+
if not stripped or not normalized:
|
| 154 |
+
return True
|
| 155 |
+
if normalized in {"mr", "mrs", "ms", "dr", "prof", "macmillan"}:
|
| 156 |
+
return True
|
| 157 |
+
if re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\.?", stripped):
|
| 158 |
+
return True
|
| 159 |
+
if re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\s+\.", stripped):
|
| 160 |
+
return True
|
| 161 |
+
if word_count(stripped) <= 2 and re.fullmatch(r"[\W_]+", stripped):
|
| 162 |
+
return True
|
| 163 |
+
return False
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def validate_row(row: dict[str, Any], expected_split: str, idx: int, high_quality_file: bool = False) -> list[str]:
|
| 167 |
+
errors: list[str] = []
|
| 168 |
+
row_id = row.get("id", f"row-{idx}")
|
| 169 |
+
|
| 170 |
+
for field in REQUIRED_FIELDS:
|
| 171 |
+
if field not in row:
|
| 172 |
+
errors.append(f"{row_id}: missing field {field}")
|
| 173 |
+
for field in REQUIRED_STRING_FIELDS:
|
| 174 |
+
if not isinstance(row.get(field), str) or not row.get(field, "").strip():
|
| 175 |
+
errors.append(f"{row_id}: empty or non-string field {field}")
|
| 176 |
+
|
| 177 |
+
if row.get("version") != "v0.4.1":
|
| 178 |
+
errors.append(f"{row_id}: version must be v0.4.1")
|
| 179 |
+
if "v0.4" not in str(row.get("generation_method", "")):
|
| 180 |
+
errors.append(f"{row_id}: generation_method must contain v0.4")
|
| 181 |
+
if row.get("reasoning_policy") != "selective_concise":
|
| 182 |
+
errors.append(f"{row_id}: reasoning_policy must be selective_concise")
|
| 183 |
+
if not str(row.get("chunking_method", "")).strip():
|
| 184 |
+
errors.append(f"{row_id}: chunking_method is required")
|
| 185 |
+
|
| 186 |
+
chunks = row.get("context_chunks")
|
| 187 |
+
if not isinstance(chunks, list) or not chunks or not all(isinstance(chunk, str) and chunk.strip() for chunk in chunks):
|
| 188 |
+
errors.append(f"{row_id}: context_chunks must be a non-empty list of strings")
|
| 189 |
+
chunks = []
|
| 190 |
+
context = row.get("context", "")
|
| 191 |
+
for chunk in chunks:
|
| 192 |
+
if chunk not in context:
|
| 193 |
+
errors.append(f"{row_id}: context does not contain chunk text: {chunk[:80]}")
|
| 194 |
+
if row.get("num_chunks") != len(chunks):
|
| 195 |
+
errors.append(f"{row_id}: num_chunks does not match context_chunks length")
|
| 196 |
+
if any(is_fragment_chunk(chunk) for chunk in chunks):
|
| 197 |
+
errors.append(f"{row_id}: contains excessive fragment chunk")
|
| 198 |
+
if any(re.fullmatch(r"(Mr|Mrs|Ms|Dr|Prof)\s+\.", str(chunk).strip()) for chunk in chunks):
|
| 199 |
+
errors.append(f"{row_id}: contains isolated title fragment")
|
| 200 |
+
|
| 201 |
+
chunk_labels = row.get("chunk_labels")
|
| 202 |
+
if not isinstance(chunk_labels, list) or len(chunk_labels) != len(chunks):
|
| 203 |
+
errors.append(f"{row_id}: chunk_labels length must equal num_chunks")
|
| 204 |
+
chunk_labels = []
|
| 205 |
+
else:
|
| 206 |
+
bad_labels = [label for label in chunk_labels if label not in {"reason", "skip"}]
|
| 207 |
+
if bad_labels:
|
| 208 |
+
errors.append(f"{row_id}: chunk_labels can only contain reason or skip")
|
| 209 |
+
|
| 210 |
+
skip_chunks = row.get("skip_chunks")
|
| 211 |
+
skip_reasons = row.get("skip_reasons")
|
| 212 |
+
if not isinstance(skip_chunks, list) or not all(isinstance(item, int) for item in skip_chunks):
|
| 213 |
+
errors.append(f"{row_id}: skip_chunks must be a list of ints")
|
| 214 |
+
skip_chunks = []
|
| 215 |
+
if not isinstance(skip_reasons, dict):
|
| 216 |
+
errors.append(f"{row_id}: skip_reasons must be a dict")
|
| 217 |
+
skip_reasons = {}
|
| 218 |
+
if chunk_labels:
|
| 219 |
+
expected_skips = [i + 1 for i, label in enumerate(chunk_labels) if label == "skip"]
|
| 220 |
+
if skip_chunks != expected_skips:
|
| 221 |
+
errors.append(f"{row_id}: skip_chunks must correspond to skip labels")
|
| 222 |
+
for chunk_index in expected_skips:
|
| 223 |
+
if str(chunk_index) not in skip_reasons:
|
| 224 |
+
errors.append(f"{row_id}: missing skip_reasons entry for chunk {chunk_index}")
|
| 225 |
+
|
| 226 |
+
if not isinstance(row.get("reasoning_token_budget"), dict) or not row.get("reasoning_token_budget"):
|
| 227 |
+
errors.append(f"{row_id}: reasoning_token_budget must be a non-empty dict")
|
| 228 |
+
if not isinstance(row.get("original_num_chunks"), int) or row.get("original_num_chunks", 0) <= 0:
|
| 229 |
+
errors.append(f"{row_id}: original_num_chunks must be a positive int")
|
| 230 |
+
if not isinstance(row.get("chunk_split_count"), int) or row.get("chunk_split_count", -1) < 0:
|
| 231 |
+
errors.append(f"{row_id}: chunk_split_count must be a non-negative int")
|
| 232 |
+
|
| 233 |
+
messages = row.get("messages")
|
| 234 |
+
if not isinstance(messages, list) or len(messages) != 2:
|
| 235 |
+
errors.append(f"{row_id}: messages must contain exactly one user and one assistant message")
|
| 236 |
+
else:
|
| 237 |
+
if messages[0].get("role") != "user" or messages[1].get("role") != "assistant":
|
| 238 |
+
errors.append(f"{row_id}: messages roles must be user then assistant")
|
| 239 |
+
if not messages[0].get("content") or not messages[1].get("content"):
|
| 240 |
+
errors.append(f"{row_id}: message content cannot be empty")
|
| 241 |
+
|
| 242 |
+
response = row.get("response", "")
|
| 243 |
+
for marker in ["Streaming reasoning:", "Deep reasoning:", "Answer:"]:
|
| 244 |
+
if marker not in response:
|
| 245 |
+
errors.append(f"{row_id}: response missing marker {marker}")
|
| 246 |
+
if row.get("split") != expected_split:
|
| 247 |
+
errors.append(f"{row_id}: split is {row.get('split')!r}, expected {expected_split!r}")
|
| 248 |
+
if row.get("split") not in {"train", "eval"}:
|
| 249 |
+
errors.append(f"{row_id}: split must be train or eval")
|
| 250 |
+
|
| 251 |
+
if not isinstance(row.get("quality_flags"), list):
|
| 252 |
+
errors.append(f"{row_id}: quality_flags must be a list")
|
| 253 |
+
elif not all(isinstance(flag, str) and flag.strip() for flag in row.get("quality_flags", [])):
|
| 254 |
+
errors.append(f"{row_id}: quality_flags must contain only non-empty strings")
|
| 255 |
+
|
| 256 |
+
score = row.get("quality_score")
|
| 257 |
+
if not isinstance(score, (int, float)) or not 0 <= float(score) <= 1:
|
| 258 |
+
errors.append(f"{row_id}: quality_score must be a number in [0, 1]")
|
| 259 |
+
if not isinstance(row.get("is_high_quality"), bool):
|
| 260 |
+
errors.append(f"{row_id}: is_high_quality must be boolean")
|
| 261 |
+
if not isinstance(row.get("llm_augmented"), bool):
|
| 262 |
+
errors.append(f"{row_id}: llm_augmented must be boolean")
|
| 263 |
+
if row.get("llm_augmentation_model") is not None and not isinstance(row.get("llm_augmentation_model"), str):
|
| 264 |
+
errors.append(f"{row_id}: llm_augmentation_model must be string or null")
|
| 265 |
+
if row.get("state_tracking_confidence") is not None and not isinstance(row.get("state_tracking_confidence"), (int, float)):
|
| 266 |
+
errors.append(f"{row_id}: state_tracking_confidence must be numeric or null")
|
| 267 |
+
|
| 268 |
+
if forbidden_phrase_count(row):
|
| 269 |
+
errors.append(f"{row_id}: forbidden phrase appears in generated fields")
|
| 270 |
+
flags = set(row.get("quality_flags", [])) if isinstance(row.get("quality_flags"), list) else set()
|
| 271 |
+
if high_quality_file:
|
| 272 |
+
if row.get("is_high_quality") is not True:
|
| 273 |
+
errors.append(f"{row_id}: high-quality file contains non-high-quality row")
|
| 274 |
+
if float(row.get("quality_score", 0)) < 0.85:
|
| 275 |
+
errors.append(f"{row_id}: high-quality row has quality_score < 0.85")
|
| 276 |
+
if flags & SEVERE_FLAGS:
|
| 277 |
+
errors.append(f"{row_id}: high-quality row has severe flags {sorted(flags & SEVERE_FLAGS)}")
|
| 278 |
+
if flags & HIGH_QUALITY_EXCLUDED_FLAGS:
|
| 279 |
+
errors.append(f"{row_id}: high-quality row has excluded flags {sorted(flags & HIGH_QUALITY_EXCLUDED_FLAGS)}")
|
| 280 |
+
if word_count(row.get("streaming_reasoning", "")) > 120:
|
| 281 |
+
errors.append(f"{row_id}: high-quality row has long streaming_reasoning")
|
| 282 |
+
if word_count(row.get("deep_reasoning", "")) > 45:
|
| 283 |
+
errors.append(f"{row_id}: high-quality row has long deep_reasoning")
|
| 284 |
+
|
| 285 |
+
return errors
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def validate_review_samples(sample_rows: list[dict[str, Any]], dataset_ids: set[str]) -> list[str]:
|
| 289 |
+
errors: list[str] = []
|
| 290 |
+
if len(sample_rows) < 120:
|
| 291 |
+
errors.append(f"samples_for_review.jsonl must contain at least 120 rows, found {len(sample_rows)}")
|
| 292 |
+
domain_counts = Counter(row.get("domain") for row in sample_rows)
|
| 293 |
+
for domain in ["task_oriented_assistant", "emotional_support", "daily_dialogue", "how_to_guidance"]:
|
| 294 |
+
if domain_counts.get(domain, 0) < 30:
|
| 295 |
+
errors.append(f"samples_for_review.jsonl should include at least 30 {domain} rows, found {domain_counts.get(domain, 0)}")
|
| 296 |
+
for idx, row in enumerate(sample_rows, start=1):
|
| 297 |
+
for field in REVIEW_SAMPLE_FIELDS:
|
| 298 |
+
if field not in row:
|
| 299 |
+
errors.append(f"sample row {idx}: missing field {field}")
|
| 300 |
+
if row.get("id") not in dataset_ids:
|
| 301 |
+
errors.append(f"sample row {idx}: id not present in train/eval: {row.get('id')}")
|
| 302 |
+
if forbidden_phrase_count(row):
|
| 303 |
+
errors.append(f"sample row {idx}: forbidden phrase appears")
|
| 304 |
+
return errors
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def parquet_count(path: Path) -> int:
|
| 308 |
+
return len(pd.read_parquet(path))
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def validate(data_dir: Path) -> int:
|
| 312 |
+
errors: list[str] = []
|
| 313 |
+
paths = {
|
| 314 |
+
"train_jsonl": data_dir / "data" / "train.jsonl",
|
| 315 |
+
"eval_jsonl": data_dir / "data" / "eval.jsonl",
|
| 316 |
+
"train_parquet": data_dir / "data" / "train.parquet",
|
| 317 |
+
"eval_parquet": data_dir / "data" / "eval.parquet",
|
| 318 |
+
"hq_train_jsonl": data_dir / "data" / "train_high_quality.jsonl",
|
| 319 |
+
"hq_eval_jsonl": data_dir / "data" / "eval_high_quality.jsonl",
|
| 320 |
+
"hq_train_parquet": data_dir / "data" / "train_high_quality.parquet",
|
| 321 |
+
"hq_eval_parquet": data_dir / "data" / "eval_high_quality.parquet",
|
| 322 |
+
"readme": data_dir / "README.md",
|
| 323 |
+
"info": data_dir / "dataset_info.json",
|
| 324 |
+
"samples": data_dir / "samples_for_review.jsonl",
|
| 325 |
+
}
|
| 326 |
+
for name, path in paths.items():
|
| 327 |
+
if not path.exists():
|
| 328 |
+
errors.append(f"missing required file {name}: {path}")
|
| 329 |
+
if errors:
|
| 330 |
+
for error in errors:
|
| 331 |
+
print(f"ERROR: {error}")
|
| 332 |
+
return 1
|
| 333 |
+
|
| 334 |
+
train_rows = read_jsonl(paths["train_jsonl"])
|
| 335 |
+
eval_rows = read_jsonl(paths["eval_jsonl"])
|
| 336 |
+
hq_train_rows = read_jsonl(paths["hq_train_jsonl"])
|
| 337 |
+
hq_eval_rows = read_jsonl(paths["hq_eval_jsonl"])
|
| 338 |
+
sample_rows = read_jsonl(paths["samples"])
|
| 339 |
+
|
| 340 |
+
if not train_rows:
|
| 341 |
+
errors.append("train.jsonl is empty")
|
| 342 |
+
if not eval_rows:
|
| 343 |
+
errors.append("eval.jsonl is empty")
|
| 344 |
+
if not hq_train_rows:
|
| 345 |
+
errors.append("train_high_quality.jsonl is empty")
|
| 346 |
+
if not hq_eval_rows:
|
| 347 |
+
errors.append("eval_high_quality.jsonl is empty")
|
| 348 |
+
|
| 349 |
+
for idx, row in enumerate(train_rows, start=1):
|
| 350 |
+
errors.extend(validate_row(row, "train", idx))
|
| 351 |
+
for idx, row in enumerate(eval_rows, start=1):
|
| 352 |
+
errors.extend(validate_row(row, "eval", idx))
|
| 353 |
+
for idx, row in enumerate(hq_train_rows, start=1):
|
| 354 |
+
errors.extend(validate_row(row, "train", idx, high_quality_file=True))
|
| 355 |
+
for idx, row in enumerate(hq_eval_rows, start=1):
|
| 356 |
+
errors.extend(validate_row(row, "eval", idx, high_quality_file=True))
|
| 357 |
+
|
| 358 |
+
all_rows = train_rows + eval_rows
|
| 359 |
+
ids = [row.get("id") for row in all_rows]
|
| 360 |
+
texts = [row.get("text") for row in all_rows]
|
| 361 |
+
duplicate_ids = [item for item, count in Counter(ids).items() if count > 1]
|
| 362 |
+
duplicate_texts = [item for item, count in Counter(texts).items() if count > 1]
|
| 363 |
+
if duplicate_ids:
|
| 364 |
+
errors.append(f"duplicate ids found: {duplicate_ids[:5]}")
|
| 365 |
+
if duplicate_texts:
|
| 366 |
+
errors.append(f"duplicate text fields found: {len(duplicate_texts)} duplicates")
|
| 367 |
+
errors.extend(validate_review_samples(sample_rows, set(ids)))
|
| 368 |
+
|
| 369 |
+
row_count_pairs = [
|
| 370 |
+
(paths["train_jsonl"], paths["train_parquet"], len(train_rows)),
|
| 371 |
+
(paths["eval_jsonl"], paths["eval_parquet"], len(eval_rows)),
|
| 372 |
+
(paths["hq_train_jsonl"], paths["hq_train_parquet"], len(hq_train_rows)),
|
| 373 |
+
(paths["hq_eval_jsonl"], paths["hq_eval_parquet"], len(hq_eval_rows)),
|
| 374 |
+
]
|
| 375 |
+
for jsonl_path, parquet_path, expected_count in row_count_pairs:
|
| 376 |
+
actual_count = parquet_count(parquet_path)
|
| 377 |
+
if actual_count != expected_count:
|
| 378 |
+
errors.append(f"{parquet_path.name} row count {actual_count} does not match {jsonl_path.name} {expected_count}")
|
| 379 |
+
for parquet_path in [paths["train_parquet"], paths["eval_parquet"], paths["hq_train_parquet"], paths["hq_eval_parquet"]]:
|
| 380 |
+
columns = set(pd.read_parquet(parquet_path).columns)
|
| 381 |
+
for field in REQUIRED_FIELDS:
|
| 382 |
+
if field not in columns:
|
| 383 |
+
errors.append(f"{parquet_path.name} missing column {field}")
|
| 384 |
+
|
| 385 |
+
try:
|
| 386 |
+
info = json.loads(paths["info"].read_text(encoding="utf-8"))
|
| 387 |
+
except json.JSONDecodeError as exc:
|
| 388 |
+
errors.append(f"dataset_info.json invalid JSON: {exc}")
|
| 389 |
+
info = {}
|
| 390 |
+
if info.get("version") != "v0.4.1":
|
| 391 |
+
errors.append("dataset_info.json version must be v0.4.1")
|
| 392 |
+
if info.get("repo_id") != "skyzhou06/LifeTextSingleTurnStreamingCoT":
|
| 393 |
+
errors.append("dataset_info.json repo_id must be skyzhou06/LifeTextSingleTurnStreamingCoT")
|
| 394 |
+
if info.get("generation_method") != "source_grounded_rule_based_v0.4.1_quality_patch":
|
| 395 |
+
errors.append("dataset_info.json generation_method is incorrect")
|
| 396 |
+
if info.get("reasoning_policy") != "selective_concise":
|
| 397 |
+
errors.append("dataset_info.json reasoning_policy is incorrect")
|
| 398 |
+
if info.get("chunking_method") != "semantic_sentence_split_v0.4_refined":
|
| 399 |
+
errors.append("dataset_info.json chunking_method is incorrect")
|
| 400 |
+
|
| 401 |
+
total_chunks = sum(row.get("num_chunks", 0) for row in all_rows)
|
| 402 |
+
skip_chunks = sum(len(row.get("skip_chunks", [])) for row in all_rows)
|
| 403 |
+
chunk_word_counts = [word_count(chunk) for row in all_rows for chunk in row.get("context_chunks", [])]
|
| 404 |
+
forbidden_count = sum(forbidden_phrase_count(row) for row in all_rows)
|
| 405 |
+
fragment_count = sum(1 for row in all_rows for chunk in row.get("context_chunks", []) if is_fragment_chunk(chunk))
|
| 406 |
+
if forbidden_count:
|
| 407 |
+
errors.append(f"forbidden phrase count must be 0, found {forbidden_count}")
|
| 408 |
+
if fragment_count:
|
| 409 |
+
errors.append(f"fragment chunk count must be 0, found {fragment_count}")
|
| 410 |
+
|
| 411 |
+
domains = Counter(row.get("domain") for row in all_rows)
|
| 412 |
+
source_datasets = Counter(row.get("source_dataset") for row in all_rows)
|
| 413 |
+
avg_chunks = sum(row.get("num_chunks", 0) for row in all_rows) / len(all_rows) if all_rows else 0
|
| 414 |
+
avg_chunk_length = sum(chunk_word_counts) / len(chunk_word_counts) if chunk_word_counts else 0
|
| 415 |
+
avg_stream = sum(word_count(row.get("streaming_reasoning", "")) for row in all_rows) / len(all_rows) if all_rows else 0
|
| 416 |
+
avg_deep = sum(word_count(row.get("deep_reasoning", "")) for row in all_rows) / len(all_rows) if all_rows else 0
|
| 417 |
+
avg_score = sum(float(row.get("quality_score", 0)) for row in all_rows) / len(all_rows) if all_rows else 0
|
| 418 |
+
hq_total = len(hq_train_rows) + len(hq_eval_rows)
|
| 419 |
+
quality_flags = Counter(flag for row in all_rows for flag in row.get("quality_flags", []))
|
| 420 |
+
llm_augmented_count = sum(1 for row in all_rows if row.get("llm_augmented"))
|
| 421 |
+
|
| 422 |
+
print("Validation summary")
|
| 423 |
+
print(f"total rows: {len(all_rows)}")
|
| 424 |
+
print(f"train rows: {len(train_rows)}")
|
| 425 |
+
print(f"eval rows: {len(eval_rows)}")
|
| 426 |
+
print(f"high-quality train rows: {len(hq_train_rows)}")
|
| 427 |
+
print(f"high-quality eval rows: {len(hq_eval_rows)}")
|
| 428 |
+
print(f"domains: {dict(sorted(domains.items()))}")
|
| 429 |
+
print(f"source datasets: {dict(sorted(source_datasets.items()))}")
|
| 430 |
+
print(f"average num_chunks: {avg_chunks:.2f}")
|
| 431 |
+
print(f"average chunk length: {avg_chunk_length:.2f}")
|
| 432 |
+
print(f"average streaming_reasoning words: {avg_stream:.2f}")
|
| 433 |
+
print(f"average deep_reasoning words: {avg_deep:.2f}")
|
| 434 |
+
print(f"skip ratio: {skip_chunks / total_chunks if total_chunks else 0:.4f}")
|
| 435 |
+
print(f"quality_flags distribution: {dict(sorted(quality_flags.items()))}")
|
| 436 |
+
print(f"average quality_score: {avg_score:.3f}")
|
| 437 |
+
print(f"high-quality percentage: {hq_total / len(all_rows) if all_rows else 0:.2%}")
|
| 438 |
+
print(f"forbidden phrase count: {forbidden_count}")
|
| 439 |
+
print(f"fragment chunk count: {fragment_count}")
|
| 440 |
+
print(f"llm_augmented count: {llm_augmented_count}")
|
| 441 |
+
print(f"review sample rows: {len(sample_rows)}")
|
| 442 |
+
print(f"errors: {len(errors)}")
|
| 443 |
+
if errors:
|
| 444 |
+
for error in errors[:160]:
|
| 445 |
+
print(f"ERROR: {error}")
|
| 446 |
+
if len(errors) > 160:
|
| 447 |
+
print(f"ERROR: ... {len(errors) - 160} more")
|
| 448 |
+
return 1
|
| 449 |
+
print("validation passed")
|
| 450 |
+
return 0
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def main() -> None:
|
| 454 |
+
parser = argparse.ArgumentParser()
|
| 455 |
+
parser.add_argument("--data-dir", default="life_streaming_cot_dataset")
|
| 456 |
+
args = parser.parse_args()
|
| 457 |
+
sys.exit(validate(Path(args.data_dir)))
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
if __name__ == "__main__":
|
| 461 |
+
main()
|