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,56 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SprachmittlerText
|
||||
|
||||
struct DetectCommand: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "detect",
|
||||
abstract: "Detect the source language of text (advisory)."
|
||||
)
|
||||
|
||||
@Option(name: .long, help: "Text to inspect.")
|
||||
var text: String?
|
||||
|
||||
@Option(name: .long, help: "UTF-8 file to inspect.")
|
||||
var file: String?
|
||||
|
||||
@Flag(name: .long, help: "Emit JSON.")
|
||||
var json = false
|
||||
|
||||
func validate() throws {
|
||||
if (text == nil) == (file == nil) {
|
||||
throw ValidationError("Use exactly one of --text or --file.")
|
||||
}
|
||||
}
|
||||
|
||||
func run() throws {
|
||||
let source: String
|
||||
if let text {
|
||||
source = text
|
||||
} else if let file {
|
||||
source = try String(contentsOfFile: file, encoding: .utf8)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
let detection = NaturalLanguageDetector().detect(source)
|
||||
guard let detection else {
|
||||
if json {
|
||||
print(#"{"language":null,"confidence":0,"alternatives":[]}"#)
|
||||
} else {
|
||||
print("unknown")
|
||||
}
|
||||
return
|
||||
}
|
||||
if json {
|
||||
let object: [String: Any] = [
|
||||
"language": detection.code,
|
||||
"confidence": detection.confidence,
|
||||
"alternatives": detection.alternatives,
|
||||
]
|
||||
let data = try JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted, .sortedKeys])
|
||||
print(String(data: data, encoding: .utf8) ?? "{}")
|
||||
} else {
|
||||
print("\(detection.code)\t\(String(format: "%.2f", detection.confidence))")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SprachmittlerCore
|
||||
import SprachmittlerEngines
|
||||
import SprachmittlerEval
|
||||
import SprachmittlerOllama
|
||||
|
||||
struct EvalCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "eval",
|
||||
abstract: "Run the private-corpus evaluation and write report.md/report.json."
|
||||
)
|
||||
|
||||
@Option(name: .long, help: "Corpus manifest JSON.")
|
||||
var manifest: String
|
||||
|
||||
@Option(name: .long, help: "Comma-separated model tags.")
|
||||
var models = HyMT3ModelPreset.defaultModel
|
||||
|
||||
@Option(name: .long, help: "Target BCP-47 code.")
|
||||
var target = "de"
|
||||
|
||||
@Option(name: .long, help: "Runs per segment (default 3).")
|
||||
var runs = 3
|
||||
|
||||
@Option(name: .long, help: "Sampling temperature override.")
|
||||
var temperature: Double?
|
||||
|
||||
@Option(name: .long, help: "Ollama keep-alive during the run.")
|
||||
var keepAlive = HyMT3ModelPreset.defaultKeepAlive
|
||||
|
||||
@Option(name: .long, help: "Output directory for raw outputs and reports.")
|
||||
var out: String?
|
||||
|
||||
@OptionGroup var endpoint: EndpointOptions
|
||||
|
||||
func validate() throws {
|
||||
guard (1 ... 5).contains(runs) else {
|
||||
throw ValidationError("--runs must be between 1 and 5.")
|
||||
}
|
||||
if let temperature, !(0 ... 2).contains(temperature) {
|
||||
throw ValidationError("--temperature must be between 0 and 2.")
|
||||
}
|
||||
guard HyMT3Languages.resolve(target) != nil else {
|
||||
throw ValidationError("Unknown target language '\(target)'.")
|
||||
}
|
||||
guard !modelTags().isEmpty else {
|
||||
throw ValidationError("Pass at least one model tag.")
|
||||
}
|
||||
}
|
||||
|
||||
func run() async throws {
|
||||
try await CLIError.perform {
|
||||
try await execute()
|
||||
}
|
||||
}
|
||||
|
||||
private func execute() async throws {
|
||||
let manifestURL = URL(fileURLWithPath: manifest)
|
||||
guard let language = HyMT3Languages.resolve(target) else {
|
||||
throw ValidationError("Unknown target language '\(target)'.")
|
||||
}
|
||||
let resolved = try EvaluationManifestLoader.load(manifestURL: manifestURL, target: language.code)
|
||||
let environment = try endpoint.makeEnvironment()
|
||||
let settings = makeSettings(environment: environment, target: language)
|
||||
let configuration = EvaluationConfiguration(
|
||||
models: modelTags(),
|
||||
runs: runs,
|
||||
keepAlive: keepAlive,
|
||||
sampling: settings.samplingOptions,
|
||||
outputDirectory: outputDirectory()
|
||||
)
|
||||
let evaluationEnvironment = try await makeEnvironmentBlock(environment, settings: settings)
|
||||
let evaluation = makeRunner(
|
||||
resolved: resolved,
|
||||
configuration: configuration,
|
||||
environment: evaluationEnvironment,
|
||||
settings: settings,
|
||||
endpointEnvironment: environment
|
||||
)
|
||||
let report = try await evaluation.run()
|
||||
printSummary(report, directory: configuration.outputDirectory)
|
||||
}
|
||||
|
||||
private func makeSettings(environment: CLIEnvironment, target: ModelLanguage) -> AppSettings {
|
||||
var draft = AppSettings()
|
||||
draft.endpoint = environment.baseURL
|
||||
draft.allowRemoteEndpoint = environment.allowRemote
|
||||
draft.targetLanguage = target.code
|
||||
draft.model = modelTags().first ?? HyMT3ModelPreset.defaultModel
|
||||
draft.warmUpOnLaunch = false
|
||||
draft.keepModelLoaded = keepAlive
|
||||
if let temperature {
|
||||
draft.temperature = temperature
|
||||
}
|
||||
return draft
|
||||
}
|
||||
|
||||
private func makeEnvironmentBlock(
|
||||
_ environment: CLIEnvironment,
|
||||
settings: AppSettings
|
||||
) async throws -> EvaluationEnvironment {
|
||||
let catalog = try environment.makeCatalog()
|
||||
let version = try await catalog.serverVersion()
|
||||
let installed = try? await catalog.installedModels()
|
||||
var digests: [String: String] = [:]
|
||||
for model in installed ?? [] {
|
||||
digests[model.name] = String(model.digest.prefix(12))
|
||||
}
|
||||
return EvaluationEnvironment(
|
||||
serverVersion: version,
|
||||
ollamaVersion: version,
|
||||
hardware: hardware(),
|
||||
macOS: ProcessInfo.processInfo.operatingSystemVersionString,
|
||||
models: digests
|
||||
)
|
||||
}
|
||||
|
||||
private func makeRunner(
|
||||
resolved: ResolvedManifest,
|
||||
configuration: EvaluationConfiguration,
|
||||
environment: EvaluationEnvironment,
|
||||
settings: AppSettings,
|
||||
endpointEnvironment: CLIEnvironment
|
||||
) -> EvaluationRunner {
|
||||
let registry = AdapterRegistry(adapters: [HyMT3Adapter()])
|
||||
return EvaluationRunner(
|
||||
manifest: resolved,
|
||||
configuration: configuration,
|
||||
environment: environment,
|
||||
pipelineFactory: { model in
|
||||
var snapshot = settings
|
||||
snapshot.model = model
|
||||
return try TranslationPipeline(
|
||||
chat: endpointEnvironment.makeChatClient(),
|
||||
registry: registry,
|
||||
chunker: snapshot.chunker
|
||||
)
|
||||
},
|
||||
warmUp: { model in
|
||||
let chat = try endpointEnvironment.makeChatClient()
|
||||
try await OllamaWarmUpRunner(chat: chat).run(
|
||||
HyMT3Adapter().warmUpRequest(model: model, keepAlive: keepAlive)
|
||||
)
|
||||
},
|
||||
unload: { model in
|
||||
let chat = try endpointEnvironment.makeChatClient()
|
||||
try await OllamaWarmUpRunner(chat: chat).run(
|
||||
HyMT3Adapter().unloadRequest(model: model)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private func printSummary(_ report: EvaluationReport, directory: URL) {
|
||||
print("Report: \(directory.path)")
|
||||
for model in report.models {
|
||||
for category in model.categories {
|
||||
print(
|
||||
"\(model.model)\t\(category.category.rawValue)\t"
|
||||
+ String(
|
||||
format: "fail %.1f%%\tchrF %.2f\tBLEU %.2f",
|
||||
category.failureRate,
|
||||
category.chrF,
|
||||
category.bleu
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func modelTags() -> [String] {
|
||||
models.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty }
|
||||
}
|
||||
|
||||
private func outputDirectory() -> URL {
|
||||
if let out {
|
||||
return URL(fileURLWithPath: out)
|
||||
}
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd"
|
||||
return URL(fileURLWithPath: "evaluation/results/\(formatter.string(from: Date()))")
|
||||
}
|
||||
|
||||
private func hardware() -> String {
|
||||
let memory = ProcessInfo.processInfo.physicalMemory / 1_073_741_824
|
||||
return "Apple Silicon \(memory) GB, \(ProcessInfo.processInfo.processorCount) cores"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SprachmittlerEngines
|
||||
|
||||
struct LanguagesCommand: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "languages",
|
||||
abstract: "List the 102 supported target languages."
|
||||
)
|
||||
|
||||
@Flag(name: .long, help: "Emit JSON.")
|
||||
var json = false
|
||||
|
||||
func run() throws {
|
||||
if json {
|
||||
let data = try JSONEncoder().encode(HyMT3Languages.all)
|
||||
print(String(data: data, encoding: .utf8) ?? "[]")
|
||||
return
|
||||
}
|
||||
for language in HyMT3Languages.all {
|
||||
print("\(language.code)\t\(language.modelName)\t\(language.localizedDisplayName)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ struct SprachmittlerCLI: AsyncParsableCommand {
|
||||
commandName: "sprachmittler-cli",
|
||||
abstract: "Headless translator and test harness for Sprachmittler.",
|
||||
subcommands: [
|
||||
LanguagesCommand.self,
|
||||
DetectCommand.self,
|
||||
ModelsCommand.self,
|
||||
ShowCommand.self,
|
||||
TranslateCommand.self,
|
||||
EvalCommand.self,
|
||||
]
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user