feat(m7-m8): evaluation harness, privacy self-test, localisation and release
M7: corpus manifest loader/validation, chrF/BLEU/token/numeric metrics, raw-output and report.md/report.json writer, and sprachmittler-cli languages/detect/eval. A synthetic 4-segment run with the 7B validated the harness; the private-corpus and 1.8B evaluation and the default-model ADR remain open. M8: privacy-check root fixture + seeded self-test wired into make verify; English/German localisation for the app shell; end-user USER_GUIDE; release.sh (unsigned archive, Developer ID sign, notarise/staple, DMG, --dry-run); idle CPU/memory and warm 7B measurements in PERFORMANCE. Docs: PROGRESS M7–M8, MODEL_EVALUATION results log/gate status, PERFORMANCE measurements, TESTING evaluation cases, ADR-008 status. Compatibility/VoiceOver/notarisation gates remain manual. Verified: make verify green (format, strict lint, privacy self-test, Debug+Release signatures, 227 package tests); CLI languages/detect/eval run; release dry-run.
This commit is contained in:
1 parent
a78572adc3
commit
0ab5ae78bf
26 files changed
+1799
-28
No files matched your search
@@ -0,0 +1,116 @@
|
||||
import Foundation
|
||||
|
||||
/// Writes `report.md` and `report.json` (`docs/MODEL_EVALUATION.md` §4).
|
||||
public enum EvaluationReportWriter {
|
||||
/// Writes both report files into `directory`.
|
||||
public static func write(_ report: EvaluationReport, to directory: URL) throws {
|
||||
let fileManager = FileManager.default
|
||||
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
|
||||
let json = try JSONEncoder.reportEncoder.encode(report)
|
||||
try json.write(to: directory.appendingPathComponent("report.json"), options: .atomic)
|
||||
try markdown(report).write(
|
||||
to: directory.appendingPathComponent("report.md"),
|
||||
atomically: true,
|
||||
encoding: .utf8
|
||||
)
|
||||
}
|
||||
|
||||
/// The Markdown report.
|
||||
public static func markdown(_ report: EvaluationReport) -> String {
|
||||
var lines = [
|
||||
"# Sprachmittler evaluation",
|
||||
"",
|
||||
"Generated: \(ISO8601DateFormatter().string(from: report.generatedAt))",
|
||||
"",
|
||||
"## Environment",
|
||||
"",
|
||||
]
|
||||
lines.append(contentsOf: environmentLines(report.environment))
|
||||
lines.append("")
|
||||
for model in report.models {
|
||||
lines.append(contentsOf: modelLines(model))
|
||||
lines.append("")
|
||||
}
|
||||
lines.append(contentsOf: observations)
|
||||
return lines.joined(separator: "\n")
|
||||
}
|
||||
|
||||
private static func environmentLines(_ environment: EvaluationEnvironment) -> [String] {
|
||||
var lines = [
|
||||
"| Key | Value |",
|
||||
"|---|---|",
|
||||
"| Ollama | \(environment.ollamaVersion) |",
|
||||
"| Server | \(environment.serverVersion) |",
|
||||
"| Hardware | \(environment.hardware) |",
|
||||
"| macOS | \(environment.macOS) |",
|
||||
]
|
||||
for (model, digest) in environment.models.sorted(by: { $0.key < $1.key }) {
|
||||
lines.append("| \(model) | \(digest) |")
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
private static func modelLines(_ model: ModelRunResult) -> [String] {
|
||||
var lines = [
|
||||
"## \(model.model)",
|
||||
"",
|
||||
"Temperature \(format(model.temperature)), \(model.runs) run(s) per segment.",
|
||||
"",
|
||||
"| Model | Temp | Category | Segments | Fail % | chrF | BLEU | Token retention | "
|
||||
+ "Num. consistency | First token p50/p90 | Warm s/seg p50/p90 |",
|
||||
"|---|---|---|---|---|---|---|---|---|---|---|",
|
||||
]
|
||||
for category in model.categories {
|
||||
lines.append(
|
||||
"| \(model.model) | \(format(model.temperature)) | \(category.category.rawValue) | "
|
||||
+ "\(category.segments) | \(format(category.failureRate)) | \(format(category.chrF)) | "
|
||||
+ "\(format(category.bleu)) | \(format(category.tokenRetention)) | "
|
||||
+ "\(format(category.numericConsistency)) | "
|
||||
+ "\(latency(category.firstTokenP50, category.firstTokenP90)) | "
|
||||
+ "\(seconds(category.totalP50, category.totalP90)) |"
|
||||
)
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
private static var observations: [String] {
|
||||
[
|
||||
"## Observations",
|
||||
"",
|
||||
"- Automated metrics only; review a sample in the panel and record correction minutes.",
|
||||
"- Token retention below 1.0 or a failure rate above 2% disqualifies a default candidate.",
|
||||
"",
|
||||
"## Limitations",
|
||||
"",
|
||||
"- chrF/BLEU are mechanical and do not judge meaning or style.",
|
||||
"- Memory is not included in this report; use `ollama ps` and record it in PERFORMANCE.md.",
|
||||
"- Private corpus text and raw outputs stay under the ignored results directory.",
|
||||
"",
|
||||
]
|
||||
}
|
||||
|
||||
private static func format(_ value: Double) -> String {
|
||||
String(format: "%.2f", value)
|
||||
}
|
||||
|
||||
private static func latency(_ p50: Int?, _ p90: Int?) -> String {
|
||||
let left = p50.map(String.init) ?? "—"
|
||||
let right = p90.map(String.init) ?? "—"
|
||||
return "\(left)/\(right) ms"
|
||||
}
|
||||
|
||||
private static func seconds(_ p50: Int?, _ p90: Int?) -> String {
|
||||
let left = p50.map { String(format: "%.2f", Double($0) / 1000) } ?? "—"
|
||||
let right = p90.map { String(format: "%.2f", Double($0) / 1000) } ?? "—"
|
||||
return "\(left)/\(right) s"
|
||||
}
|
||||
}
|
||||
|
||||
private extension JSONEncoder {
|
||||
static var reportEncoder: JSONEncoder {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
return encoder
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user