All examples
Machine learning

Inspect NLP CPU execution and checkpoint replay

Compare same profile continuation, independent source aligned POS predictions and local TF IDF/BM25 execution traces.

nlp_execution_cpu.aner
// Development runtime only. All input is synthetic; no network is used.
// Run in a fresh writable directory: checkpoint creation is exclusive.
import aner.nlp
import aner.parallel
import aner.nn

// One worker is valid even under a one-slot CPU allocation. Choose a larger
// admitted value to compare concurrency; worker count does not reserve cores.
let execution = parallel.local(workers: 1)
let source = nlp.corpus(List("Alice visits Paris .", "Bob visits Rome .", "Birds fly ."),
    List("execution-train-1", "execution-train-2", "execution-train-3"), role: "training")
let training = nlp.annotate(nlp.tokenize(source),
    List(List("PROPN", "VERB", "PROPN", "PUNCT"),
         List("PROPN", "VERB", "PROPN", "PUNCT"),
         List("NOUN", "VERB", "PUNCT")), task: "pos")
let held_out = nlp.corpus(List("Bob visits Paris .", "Alice visits Rome ."),
    List("execution-validation-1", "execution-validation-2"), role: "validation")
let validation_tokens = nlp.tokenize(held_out)
let gold = nlp.annotate(validation_tokens,
    List(List("PROPN", "VERB", "PROPN", "PUNCT"),
         List("PROPN", "VERB", "PROPN", "PUNCT")), task: "pos")
let model = nlp.fit_tagger(training, epochs: 5, seed: 731, execution: execution)
let prediction = model.tag(validation_tokens, execution: execution)
let report = model.evaluate_tagger(gold, execution: execution)
print("Measured synthetic POS token accuracy")
print(report.accuracy())
print("Original source tokens, labels and execution trace")
print(validation_tokens.token_texts(0))
print(prediction.tags(0))
print(prediction.execution_summary())
print(report.execution_summary())

// Learning order and averaging state continue; changing the worker count does
// not authorize a different arithmetic/backend contract at resume.
let first = nlp.fit_tagger(training, epochs: 2, seed: 731, execution: execution)
first.save("execution-pos-stage.anertagger")
let restored = nlp.load_tagger("execution-pos-stage.anertagger")
let continued = restored.resume_tagger(training, epochs: 3, execution: execution)
print("Same-profile checkpoint continuation reproduces complete training")
print(continued.fingerprint() == model.fingerprint())
print(continued.tag(validation_tokens, execution: execution).fingerprint() == prediction.fingerprint())

// Fitting lexical policy remains a host operation. Local execution selects
// only admitted numeric phases; Unicode, CSR assembly and ranking stay CPU.
let encoder = nlp.vectorizer(source)
let features = encoder.transform(held_out, execution: execution)
let matrix = features.dense(max_cells: 1000, execution: execution)
print("Sparse row IDs, OOV counts and local numeric phase trace")
print(features.ids())
print(features.oov())
print(features.execution_summary())
let memory = nlp.index(source)
let hits = memory.search("Paris visits", top_k: 2, execution: execution)
print("Ranked evidence and BM25 contribution trace")
print(hits.ids())
print(hits.scores())
print(hits.execution_summary())

Make it your experiment.

Use the matching development runtime. Save this program as examples/nlp_execution_cpu.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/nlp_execution_cpu.aner
aner run examples/nlp_execution_cpu.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires the matching unreleased native NLP execution runtime and development editor. Published Aner 0.0.5 and VS Code 0.1.48 do not provide these execution overloads. Synthetic documents are included; no data download or external service is needed. Run from a fresh writable directory because the CPU continuation case exclusively creates a checkpoint. One admitted local CPU worker is sufficient.

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner