Extract the complete feature vector — no keywords. Structural features detect code/math/structure via symbols and character-level statistics. N-grams learn vocabulary-equivalent patterns from training data. Context features encode agentic step information as pure numerical signals
(
prompt: str,
system_prompt: str | None = None,
context_features: dict[str, float] | None = None,
)
| 127 | |
| 128 | |
| 129 | def _extract_all_features( |
| 130 | prompt: str, |
| 131 | system_prompt: str | None = None, |
| 132 | context_features: dict[str, float] | None = None, |
| 133 | ) -> dict[str, float]: |
| 134 | """Extract the complete feature vector — no keywords. |
| 135 | |
| 136 | Structural features detect code/math/structure via symbols and |
| 137 | character-level statistics. N-grams learn vocabulary-equivalent |
| 138 | patterns from training data. Context features encode agentic |
| 139 | step information as pure numerical signals. |
| 140 | """ |
| 141 | feature_text = _merge_feature_text(prompt, system_prompt) |
| 142 | struct_dims = extract_structural_features(feature_text) |
| 143 | structural_scores = {d.name: d.score for d in struct_dims} |
| 144 | |
| 145 | unicode_blocks = extract_unicode_block_features(feature_text) |
| 146 | |
| 147 | if _model is not None: |
| 148 | return _model._build_features( |
| 149 | structural_scores, |
| 150 | unicode_blocks, |
| 151 | keyword_scores=None, |
| 152 | prompt=feature_text, |
| 153 | context_features=context_features, |
| 154 | ) |
| 155 | |
| 156 | features: dict[str, float] = {} |
| 157 | for name, score in structural_scores.items(): |
| 158 | features[f"s_{name}"] = score |
| 159 | for name, prop in unicode_blocks.items(): |
| 160 | features[f"u_{name}"] = prop |
| 161 | if context_features: |
| 162 | for name, value in context_features.items(): |
| 163 | key = name if name.startswith("ctx_") else f"ctx_{name}" |
| 164 | features[key] = value |
| 165 | return features |
| 166 | |
| 167 | |
| 168 | def train_and_save_model(data_path: str, out_path: str | None = None) -> None: |
no test coverage detected