Parse perplexity value (mean±std format) from llama-perplexity output.
(self, output)
| 205 | } |
| 206 | |
| 207 | def parse_perplexity(self, output): |
| 208 | """Parse perplexity value (mean±std format) from llama-perplexity output.""" |
| 209 | # First try to match "PPL = mean +/- std" format |
| 210 | pattern_with_std = r'PPL\s*=\s*(\d+\.?\d*)\s*\+/-\s*(\d+\.?\d*)' |
| 211 | match = re.search(pattern_with_std, output, re.IGNORECASE | re.MULTILINE) |
| 212 | if match: |
| 213 | try: |
| 214 | mean = float(match.group(1)) |
| 215 | std = float(match.group(2)) |
| 216 | return f"{mean:.4f}±{std:.4f}" |
| 217 | except ValueError: |
| 218 | pass |
| 219 | |
| 220 | # Fallback to patterns without std |
| 221 | patterns = [ |
| 222 | r'Final estimate:\s*PPL\s*=\s*(\d+\.?\d*)', |
| 223 | r'Final perplexity:\s*(\d+\.?\d*)', |
| 224 | r'PPL\s*=\s*(\d+\.?\d*)', |
| 225 | r'PPL:\s*(\d+\.?\d*)', |
| 226 | r'perplexity:\s*(\d+\.?\d*)', |
| 227 | r'ppl\s*=\s*(\d+\.?\d*)', |
| 228 | r'Perplexity:\s*(\d+\.?\d*)', |
| 229 | ] |
| 230 | |
| 231 | for pattern in patterns: |
| 232 | match = re.search(pattern, output, re.IGNORECASE | re.MULTILINE) |
| 233 | if match: |
| 234 | try: |
| 235 | return f"{float(match.group(1)):.4f}" |
| 236 | except ValueError: |
| 237 | continue |
| 238 | |
| 239 | return None |
| 240 | |
| 241 | def quantize_embedding(self, embedding_type, output_suffix): |
| 242 | """ |