()
| 27 | |
| 28 | |
| 29 | def main(): |
| 30 | train_path = Path("uncommon_route/data/v2_splits/train.jsonl") |
| 31 | if not train_path.exists(): |
| 32 | raise FileNotFoundError(f"Run split_data.py first: {train_path}") |
| 33 | |
| 34 | from sentence_transformers import SentenceTransformer |
| 35 | model = SentenceTransformer("BAAI/bge-small-en-v1.5") |
| 36 | |
| 37 | rows = [] |
| 38 | with open(train_path, encoding="utf-8") as f: |
| 39 | for line in f: |
| 40 | line = line.strip() |
| 41 | if line: |
| 42 | rows.append(json.loads(line)) |
| 43 | |
| 44 | texts, labels = [], [] |
| 45 | for row in rows: |
| 46 | for m in reversed(row.get("messages", [])): |
| 47 | if m.get("role") == "user": |
| 48 | text = _extract_text(m.get("content", "")) |
| 49 | if text.strip(): |
| 50 | texts.append(text) |
| 51 | labels.append(row["target_tier_id"]) |
| 52 | break |
| 53 | |
| 54 | print(f"Embedding {len(texts)} texts...") |
| 55 | embeddings = model.encode(texts, normalize_embeddings=True, show_progress_bar=True) |
| 56 | |
| 57 | out_dir = Path("uncommon_route/data/v2_splits") |
| 58 | np.save(out_dir / "seed_embeddings.npy", embeddings) |
| 59 | with open(out_dir / "seed_labels.json", "w") as f: |
| 60 | json.dump(labels, f) |
| 61 | print(f"Saved: {embeddings.shape[0]} embeddings ({embeddings.shape[1]}d) + labels") |
| 62 | |
| 63 | |
| 64 | if __name__ == "__main__": |
no test coverage detected