(path)
| 17 | model = SentenceTransformer("BAAI/bge-small-en-v1.5") |
| 18 | |
| 19 | def load_features(path): |
| 20 | rows = [] |
| 21 | with open(path) as f: |
| 22 | for line in f: |
| 23 | if line.strip(): rows.append(json.loads(line)) |
| 24 | texts, meta_feats, labels = [], [], [] |
| 25 | for row in rows: |
| 26 | msgs = row.get("messages", []) |
| 27 | text = "" |
| 28 | for m in reversed(msgs): |
| 29 | if m.get("role") == "user": |
| 30 | text = _normalize_content(m.get("content", "")) |
| 31 | break |
| 32 | if not text.strip(): |
| 33 | continue |
| 34 | msg_count = len(msgs) |
| 35 | has_tools = int(any(m.get("role") == "tool" or m.get("tool_calls") for m in msgs)) |
| 36 | tool_count = sum(1 for m in msgs if m.get("role") == "tool" or m.get("tool_calls")) |
| 37 | user_len = len(text) |
| 38 | user_words = len(text.split()) |
| 39 | has_code = int("```" in text) |
| 40 | has_question = int("?" in text[-50:] if len(text) > 50 else "?" in text) |
| 41 | meta_feats.append([msg_count, has_tools, tool_count, user_len, user_words, has_code, has_question]) |
| 42 | texts.append(text) |
| 43 | labels.append(row["target_tier_id"]) |
| 44 | embeddings = model.encode(texts, normalize_embeddings=True, show_progress_bar=False) |
| 45 | return embeddings, np.array(meta_feats, dtype=float), labels |
| 46 | |
| 47 | print("Loading...") |
| 48 | train_emb, train_meta, train_labels = load_features(d / "train.jsonl") |
no test coverage detected