语言模型能做很多事情。
它们可以写作、总结、翻译并调用工具。
但它们只是机器学习所能做的事情中的一小部分。
假设客户致电你的支持热线。
首先,你需要知道他们说了什么(语音识别)。
然后,你需要决定将他们转接给谁(决策)。
你可以将这两项任务都交给语言模型,
但针对每种任务都有专门构建的模型,它们更优、更快且成本更低。
在《AnyLanguageModel 1.0 回顾》中,
我们回顾了 Swift 中本地和托管模型的一年历程。
随着 AnyLanguageModel 和 swift-huggingface 现已进入 1.x 版本,
我们将同样的方法扩展到语音和决策领域:
提供熟悉的 Swift API,并允许选择模型。
今天我们宣布两个软件包:
AnySpeechRecognizer
通过 Apple 新的语音转文本 API 实现,并提供多种识别引擎的选择,
包括在 Core ML 上本地运行的 NVIDIA Parakeet 和阿里巴巴 Qwen3-ASR,
并增加了说话人日志功能以追踪谁在何时发言。
AnyDecisionModel
针对是/否、多项选择和评分量表问题提供答案,
并附带类型化的结果和概率。
它根据模型的概率推导每个答案,
而不是生成文本,
使用你设备上的 MLX、Core AI 或 llama.cpp 中的模型,
或者来自 Jev 或 Ollama 的决策模型。
这两个软件包都可以从 Hugging Face Hub 下载开源模型,
并在设备上运行它们。
AnySpeechRecognizer
计算机转录语音已有数十年历史,
而在过去几年里,它们在这一点上表现得非常出色。
Apple 平台已经为此提供了一个 API。
macOS 26 和 iOS 26 引入了 SpeechAnalyzer ,
这是 Apple 新的语音转文本 API。
你将 SpeechTranscriber 和 SpeechDetector 等模块添加到分析器中,
给它一个文件或音频缓冲区流,
并从异步序列中读取随到达的结果。
AssetInventory 负责安装模型,
因此你的应用可以决定何时进行下载。
这是一个设计精良的 API,
但其背后的引擎只有 Apple 自家的。
AnySpeechRecognizer 保留了该 API 并让你选择引擎:
该软件包镜像了 SpeechAnalyzer 、 SpeechTranscriber 、 DictationTranscriber 、
SpeechDetector 和 AssetInventory ,
并将 Apple 的 Speech 框架作为默认引擎。
如果你的代码使用了这个共享 API,只需更改导入即可。
若要改用 Parakeet,
只需更改创建转录器的方式:
let transcriber = SpeechTranscriber (
model: ParakeetSpeechModel (variant: .v3),
transcriptionOptions: [],
reportingOptions: [.volatileResults],
attributeOptions: [.audioTimeRange]
)
安装资源、运行分析器以及读取结果的步骤保持不变。
README
包含一个完整的示例,
并列出了与 Apple 框架的差异。
认识这些模型
Parakeet v3 是 NVIDIA 的 Parakeet TDT 0.6B v3 。
它是一个多语言模型:
它能识别 25 种欧洲语言并判断出正在听的是哪种语言,
因此你无需传递区域设置。
Parakeet Ultra 是 Moondream 对 v3 进行后训练的版本。
在我们的多数测量中,它的准确率更高。
Parakeet Unified 是 NVIDIA 的
仅支持英语的 Parakeet 。
所有三种 Parakeet 模型都在该软件包自己的 Core ML 运行时上运行,
该运行时支持文件和实时输入、易失性结果、单词时间戳和单词置信度。
Qwen3-ASR 是阿里巴巴的语音模型,
具有 0.6B
和 1.7B 两种尺寸。
它能识别 30 种语言和 22 种中文方言,
包括普通话、粤语、日语和韩语,这些是 Parakeet 所不覆盖的。
它可以自动检测语言,或者你可以手动设置一种:
let transcriber = SpeechTranscriber (
model: QwenSpeechModel (variant: .large, language: Locale . Language (identifier: "yue" )),
transcriptionOptions: [],
reportingOptions: [],
attributeOptions: []
)
Qwen3-ASR 会为每个长达 40 秒的片段提供一个最终结果,
不支持易失性结果、单词时间戳或置信度。
它在 GPU 上运行,速度比 Parakeet 慢,
因此更适合转录文件而非实时输入。
要添加另一个引擎,请为其配置实现 SpeechRecognitionModel,并为其中一个模块的会话实现 SpeechRecognitionExecutor。
README 中包含一个小型提供程序,它会报告占位符文本以帮助您入门。
Hub 上的 Core ML 模型
要在应用中运行这些模型,
我们将它们转换为 Core ML 并发布在 Hub 上:
每个仓库都记录了其源检查点
以及每个文件的校验和,
并且该包将其固定到特定修订版本。
Parakeet 仓库添加了一个用于实时输入的 8 秒编码器,
它将实时分析时间缩短了约三分之一,
代价是词错误率略有升高。
该仓库还包含转换工作流,
其中大多数遵循 FluidInference 的 mobius 脚本,
并将每次转换与原始模型进行比对检查。
下载仅在您的应用请求时发生:
每个 Parakeet 约 600 MB,加上实时编码器约 590 MB,
Qwen3-ASR 为 0.9 到 2.4 GB,Sortformer 约 250 MB。
文件存储在标准的 Hugging Face 缓存中,
因此沙盒外的 Mac 应用可以与 Python 和其他 Hugging Face 工具共享这些文件。
说话人日志记录(Diarization)
当您转录对话时,
您通常想知道谁说了什么。
这就是说话人日志记录,
而 Apple 的 Speech 框架没有为此提供模块,
因此 AnySpeechRecognizer 添加了一个。
SpeakerDiarizer 在 Core ML 上与 Apple 或 Parakeet 转录器并行运行 NVIDIA 的
Streaming Sortformer,
并在相同的时间线上:
let diarizer = SpeakerDiarizer (model: SortformerDiarizationModel ())
if let request = try await AssetInventory .assetInstallationRequest(
supporting: [transcriber, diarizer]
) {
try await request.downloadAndInstall()
}
let analyzer = SpeechAnalyzer (modules: [transcriber, diarizer])
该日志记录器可追踪多达四名说话人,
即使他们互相重叠说话。
SpeakerTimeline 收集其结果
并将每个带时间戳的词归因于特定的说话人,
因此您可以按说话人轮次打印转录文本。
与 AnyLanguageModel 中的图像支持类似,
这超越了 Apple API 目前提供的功能。
该日志记录器默认使用 Sortformer v2。
您还可以选择 v2.1,
NVIDIA 使用更多的会议数据对其进行了训练,
在我们的测量中,它在会议场景下的准确性也更高。
它的表现如何?
我们使用其 hear 命令行工具在搭载 macOS 27.0.1 的 M4 Max Mac Studio 上对该包进行了测量。
以下是 LibriSpeech 文件中 3 到 8 分钟片段的词错误率:
转录器
test-clean
test-other
Parakeet v3,文件
1.55%
2.78%
Parakeet v3,实时
4.73%
4.29%
Parakeet Ultra,文件
1.66%
2.55%
Parakeet Ultra,实时
2.65%
3.28%
Parakeet Unified,文件
1.43%
2.19%
Parakeet Unified,实时
1.45%
2.42%
Apple 的转录器,文件
2.12%
3.97%
Parakeet 从文件中转录一小时音频
大约需要 20 到 40 秒,
或者实时转录大约需要 1.5 到 2.5 分钟,
在 Core ML 编译模型后,内存占用约为 100 MB。
Qwen3-ASR 要慢得多,并且需要几 GB 的内存。
会议对所有人来说都很困难:
在 AMI 录音中,人们互相重叠说话,
我们测试的每个引擎的词错误率都超过 23%。
这些数字来自一台机器和几个数据集,
因此请使用您自己的硬件和音频进行测量。
hear evaluate 可在您自己的文件上工作,
并且仓库中的 natural-speech-eval.py 工具
可重现这些测量结果。到目前为止,我们仅在 macOS 27 上进行了测试,未在 iPhone 上进行测试。
接下来,我们希望添加更多引擎,包括 macOS 27 和 iOS 27 上的 Core AI。
AnyDecisionModel
AnyDecisionModel 是另一回事。
没有可供映射的 Apple 框架,
而且决策模型本身并不新颖。
只有来自法国 Décision 地区的模型才是决策模型;
否则,它就是零样本分类中的“起泡”(sparkling)现象。
新的是名称、大量的炒作,
以及一批经过训练以做出决策的模型。
我们认为这是未来的发展方向,
因此我们想要一个为它们准备好的 Swift API。
应用经常要求语言模型做出决策。
这条消息是否紧急?
哪个团队应该处理这个工单?
这位客户有多沮丧?
通常的方法是提示语言模型,并解析它生成的文本。
这能给你一个答案,但不会显示它分配给其他选项的概率。
以下是 Swift 中的决策示例:
import AnyDecisionModel
enum Department : String , Choosable {
case billing, technical, sales
}
let ticket = "I was charged twice for my order, and now the app logs me out when I try to ask for a refund."
let model = MLXDecisionModel (modelID: "mlx-community/Qwen3-4B-Instruct-2507-4bit" )
let session = DecisionSession (model: model, state: .text(ticket))
let urgent = try await session.probability(of: "Does this convey urgency?" )
let team = try await session.choice( "Which team?" , from: Department . self )
let anger = try await session.score(
"How frustrated?" ,
levels: [ "Calm" , "Frustrated" , "Very angry" ]
)
urgent 是一个 Double。
team 是一个 Choice
anger 是一个 Score,包含预期等级、每个等级的概率以及置信度值。
由于 Department 遵循 Choosable 协议,
team.value 是一个你可以在穷举 switch 中使用的 Department。
如果你使用过 Foundation Models 或 AnyLanguageModel,
这种模型和会话模式看起来很熟悉。
DecisionSession 保存单一状态,可以是文本或 JSON,
每个问题都是关于该状态的。
问题是独立的:
答案永远不会成为后续问题的输入。
要同时询问多个问题,
将它们作为批次传递给 decide(_:)。
对于每个问题,MLX 后端构建一个提示,
为每个允许的答案提供一个 token 标签,
然后从一次前向传播中读取每个标签的概率。
试试看:Emoji Magnet
Emoji Magnet 是一个 macOS 应用,在343个表情符号堆上方有一个文本字段。
输入一个短语,例如“你穿戴的东西”,
匹配的表情符号会从堆中升起。
将其细化为“你冬天穿戴的东西”,
不再匹配的表情符号会落回。
该应用没有内置的关键字规则;
模型在推理时决定一切。
当你暂停打字时,它会向模型询问每个表情符号的是非问题,
例如:
陈述:一件厚重的冬衣符合描述“你穿戴的东西”。此陈述为真吗?
会话的状态保存着该短语。
上面的演示使用了托管的 Jev 后端,
它在一次请求中回答所有343个问题,
因此每个短语的表情符号在约半秒内确定位置。
如果没有 TYPESAFE_AI_API_KEY,该应用会在你的 Mac 上使用 MLX 后端运行 Qwen3 4B。
该后端使用前缀缓存来评估状态一次,
然后每次前向传播回答16个问题。
在 M4 Max 上,模型加载后,一组16个问题的处理时间约为0.45秒。
遍历所有343个表情符号的全程大约需要10秒,
每组的结果一旦到达就会显示。
Emoji Magnet 位于 AnyDecisionModel-Examples 仓库中。
决策头和 Clef
读取下一个 token 的概率适用于通用语言模型,
但这些模型并非为做出决策而训练。
Cloudflare 的 Clef 模型
是更新方法的一个例子:
一个带有经过训练的决策头的模型,
它将状态和类型化问题的模式转化为决策,
在一次前向传播中返回所有允许选项的概率。
Clef-Flash 是9B变体。
AnyDecisionModel 在配备 MLX 的 Mac 上运行 Clef-Flash:
let model = MLXHeadDecisionModel (
modelID: "mlx-community/clef-flash-4bit" ,
head: .jointSchema
)
你使用相同的会话和问题,但 MLXHeadDecisionModel 从 Clef 训练好的决策头中读取每个决策,而不是从下一个 token 的概率中读取。该 4-bit 模型的下载大小为 6.2 GB,其模型卡建议 Mac 至少配备 16 GB 内存。Clef 可以读取图像和视频,但该后端仅接受文本和 JSON 状态。
校准与检查概率
语言模型产生的原始概率往往过于自信。本地后端接受 Calibration(校准),它对每个答案应用温度参数,对是/否答案应用偏差。请使用独立的数据集来拟合校准并评估结果。
语言模型也可能因为选项在列表中的位置而偏向某个选项。在 MLX、Core AI 和 llama.cpp 的 next-token 后端中,开启 rotationDebiasing(旋转去偏),针对选项的每种轮换顺序分别询问一次选择题,并对概率取平均值。这将导致每次轮换都需要进行一次提示评估。
每个本地选择和评分都包含一个基于其概率熵的置信度值。它衡量的是概率的集中程度,而不是答案是否正确,因此在确定阈值之前,请先在自己的数据上检查错误率。next-token 后端的诊断报告模型分配给允许答案的概率量。低值意味着它将大部分概率分配给了其他地方。
后端
AnyDecisionModel 有六个后端:
MLX 通过 mlx-swift-lm 在 Apple silicon 上运行小型语言模型,并从 Hub 下载它。
MLX 决策头使用带有其自身训练好的决策头的模型,例如 Clef。
Core AI 在 macOS 27 和 iOS 27 上使用 Core AI 模型执行与 MLX 相同的操作。
llama.cpp 通过 llama.swift 从本地 GGUF 模型读取决策。
Jev 通过 System One API 调用 TypeSafe 的 Jev,或任何实现该 API 的服务器,例如 Kev。
Ollama 调用本地 Ollama 服务器或 Ollama 云中的 System One 决策模型。它需要 Ollama 0.35.0 或更高版本,对于云端模型则需要 0.40.5 或更高版本。
next-token 后端将答案标记为“是”和“否”、A 到 Z 或 0 到 9,因此选择题最多可有 26 个选项,评分题最多可有 10 个等级。决策头没有此类限制。
与 AnyLanguageModel 一样,该软件包使用 Swift package traits(特性)。在没有特性的情况下,它没有第三方依赖。你可以获得核心类型以及 Jev 和 Ollama 后端,它们也支持在 Linux 上构建。启用 MLX、CoreAI 或 Llama 特性以获取本地后端。
入门指南
这两个软件包都需要 Swift 6.2 或更高版本,以及 macOS 26 或 iOS 26 或更高版本。Parakeet 和 Sortformer 运行时以及 MLX 后端需要 Apple silicon。AnyDecisionModel 的 MLX 构建任务使用 Xcode 的 Swift 6.4 或更高版本以及 Metal 工具链;Core AI 需要 Xcode 27 和 OS 27 运行时。
将软件包添加到你的 Package.swift:
dependencies: [
.package(url: "https://github.com/mattt/AnySpeechRecognizer" , from: "0.1.0" ),
.package(
url: "https://github.com/mattt/AnyDecisionModel" ,
from: "0.6.0" ,
traits: [ "MLX" ]
),
]
目前,AnyDecisionModel 的 CoreAI 特性无法与 AnySpeechRecognizer 结合使用,因为 coreai-kit 0.7.3 需要 swift-huggingface 低于 1.0 版本,而 AnySpeechRecognizer 需要 1.x 版本。
每个 README 都包含更多示例以及有关要求和后端的详细信息。AnySpeechRecognizer 还包含一个名为 hear 的命令行工具,它可以转录本地文件、标记说话人并评估结果。每个 hear 命令都需要 --backend apple 、 --backend parakeet 或 --backend qwen ;在分析之前,使用相同的后端和模型选项运行 hear prepare 以安装所需的资源。
在你的应用中尝试它们,并告诉我们哪些有效,哪些无效。欢迎在两个仓库中提交问题和拉取请求。
链接
感谢 NVIDIA 为 Parakeet、Sortformer 和 NeMo 做出的贡献,感谢 Moondream 为 Parakeet Ultra 做出的贡献,感谢 FluidInference,其 FluidAudio 和 mobius 项目记录了 Parakeet 运行时和 Core ML 转换所遵循的规范,感谢 Cloudflare 为 Clef 做出的贡献,以及感谢所有为 AnyLanguageModel 做出贡献的人,这两个软件包都借鉴了其中的模式。
Language models can do a lot.
They write, summarize, translate, and call tools.
But they're only a small part of what machine learning can do.
Say a customer calls your support line.
First, you want to know what they said (speech recognition).
Then, you want to decide where to send them (decision).
You could hand both to a language model,
but there are models built for each that are
better, faster, and less expensive.
In our AnyLanguageModel 1.0 recap ,
we looked at a year of local and hosted models in Swift.
With AnyLanguageModel and swift-huggingface now on their 1.x releases,
we're extending the same approach to speech and decisions:
familiar Swift APIs with a choice of model.
Today we're announcing two packages:
AnySpeechRecognizer
implements Apple's new speech-to-text API with a choice of recognition engine,
including NVIDIA's Parakeet and Alibaba's Qwen3-ASR running locally on Core ML,
and adds speaker diarization to track who speaks when.
AnyDecisionModel
answers yes-or-no, multiple-choice, and rating-scale questions
with typed results and probabilities.
It derives each answer from the model's probabilities
instead of generating text,
using a model on your device with MLX, Core AI, or llama.cpp,
or a decision model from Jev or Ollama.
Both packages can download open models from the Hugging Face Hub
and run them on device.
AnySpeechRecognizer
Computers have been transcribing speech for decades,
and in the past few years, they've gotten very good at it.
Apple platforms already have an API for it.
macOS 26 and iOS 26 introduced SpeechAnalyzer ,
Apple's new speech-to-text API.
You add modules such as SpeechTranscriber and SpeechDetector to an analyzer,
give it a file or a stream of audio buffers,
and read results from async sequences as they arrive.
AssetInventory installs the models,
so your app decides when downloads happen.
It's a well-designed API,
but the only engine behind it is Apple's.
AnySpeechRecognizer keeps the API and lets you choose the engine:
The package mirrors SpeechAnalyzer , SpeechTranscriber , DictationTranscriber ,
SpeechDetector , and AssetInventory ,
with Apple's Speech framework as the default engine.
If your code uses that shared API, changing the import is enough.
To use Parakeet instead,
change only how you create the transcriber:
let transcriber = SpeechTranscriber (
model: ParakeetSpeechModel (variant: .v3),
transcriptionOptions: [],
reportingOptions: [.volatileResults],
attributeOptions: [.audioTimeRange]
)
The steps for installing assets, running the analyzer,
and reading results stay the same.
The README
has a complete example
and lists the differences
from Apple's framework.
Meet the models
Parakeet v3 is NVIDIA's Parakeet TDT 0.6B v3 .
It's a polyglot:
it recognizes 25 European languages and works out which one it's hearing,
so you don't pass a locale.
Parakeet Ultra is Moondream's post-trained take on v3 .
It was more accurate in most of our measurements.
Parakeet Unified is NVIDIA's
English-only Parakeet .
All three Parakeets run on the package's own Core ML runtime,
which supports file and live input, volatile results, word timing,
and word confidence.
Qwen3-ASR is Alibaba's speech model,
in 0.6B
and 1.7B sizes.
It recognizes 30 languages and 22 Chinese dialects,
including Mandarin, Cantonese, Japanese, and Korean, which Parakeet doesn't cover.
It detects the language automatically, or you can set one:
let transcriber = SpeechTranscriber (
model: QwenSpeechModel (variant: .large, language: Locale . Language (identifier: "yue" )),
transcriptionOptions: [],
reportingOptions: [],
attributeOptions: []
)
Qwen3-ASR gives one final result for each segment of up to 40 seconds,
without volatile results, word timing, or confidence.
It runs on the GPU and is slower than Parakeet,
so it's better suited to transcribing files than live input.
To add another engine, implement SpeechRecognitionModel for its configuration
and SpeechRecognitionExecutor for one module's session.
The README includes a small provider
that reports placeholder text to help you get started.
Core ML models on the Hub
To run these models in apps,
we converted them to Core ML and published them on the Hub:
Each repository records its source checkpoint
and a checksum for every file,
and the package pins it to a fixed revision.
The Parakeet repositories add an 8-second encoder for live input,
which cuts live analysis time by about a third
at the cost of a somewhat higher word error rate.
The repository also has the conversion workflows,
most of which follow FluidInference's mobius scripts,
and checks each conversion against the original model.
Downloads happen only when your app asks for them:
about 600 MB for each Parakeet, plus about 590 MB for the live encoder,
0.9 to 2.4 GB for Qwen3-ASR, and about 250 MB for Sortformer.
Files go in the standard Hugging Face cache,
so a Mac app outside the sandbox shares them with Python and other Hugging Face tools.
Speaker diarization
When you transcribe a conversation,
you often want to know who said what.
That's speaker diarization,
and Apple's Speech framework doesn't have a module for it,
so AnySpeechRecognizer adds one.
SpeakerDiarizer runs NVIDIA's
Streaming Sortformer
on Core ML alongside an Apple or Parakeet transcriber,
on the same timeline:
let diarizer = SpeakerDiarizer (model: SortformerDiarizationModel ())
if let request = try await AssetInventory .assetInstallationRequest(
supporting: [transcriber, diarizer]
) {
try await request.downloadAndInstall()
}
let analyzer = SpeechAnalyzer (modules: [transcriber, diarizer])
The diarizer tracks up to four speakers,
even when they talk over each other.
A SpeakerTimeline collects its results
and attributes each timed word to a speaker,
so you can print a transcript by speaker turn.
Like image support in AnyLanguageModel,
this goes beyond what Apple's API offers today.
The diarizer uses Sortformer v2 by default.
You can also choose v2.1 ,
which NVIDIA trained with more meeting data
and which was more accurate on meetings in our measurements, too.
How well does it work?
We measured the package with its hear command-line tool
on an M4 Max Mac Studio with macOS 27.0.1.
Here are the word error rates on LibriSpeech files of 3 to 8 minutes:
Transcriber
test-clean
test-other
Parakeet v3, file
1.55%
2.78%
Parakeet v3, live
4.73%
4.29%
Parakeet Ultra, file
1.66%
2.55%
Parakeet Ultra, live
2.65%
3.28%
Parakeet Unified, file
1.43%
2.19%
Parakeet Unified, live
1.45%
2.42%
Apple's transcriber, file
2.12%
3.97%
Parakeet transcribes an hour of audio
in about 20 to 40 seconds from a file,
or about 1.5 to 2.5 minutes live,
with about 100 MB of memory once Core ML has compiled the model.
Qwen3-ASR is much slower and needs a few gigabytes of memory.
Meetings are hard for everyone:
on AMI recordings, where people talk over each other,
every engine we tested had a word error rate above 23%.
These numbers come from one machine and a few datasets,
so measure with your own hardware and audio.
hear evaluate works on your own files,
and the repository's natural-speech-eval.py tool
reproduces these measurements .
So far, we've tested only on macOS 27, not on an iPhone.
Next, we'd like to add more engines, including Core AI on macOS 27 and iOS 27.
AnyDecisionModel
AnyDecisionModel is a different story.
There's no Apple framework to map onto,
and decision models aren't new, exactly.
It's only a decision model if it comes from the Décision region of France;
otherwise, it's sparkling zero-shot classification.
What's new is the name, a lot of hype,
and a crop of models trained to make decisions.
We think that's where things are going,
so we wanted a Swift API that's ready for them.
Apps often ask language models to make decisions.
Is this message urgent?
Which team should handle this ticket?
How frustrated is this customer?
The usual approach is to prompt a language model
and parse the text that it generates.
That gives you one answer,
but doesn't show the probabilities it assigned to the alternatives.
Here's what a decision looks like in Swift:
import AnyDecisionModel
enum Department : String , Choosable {
case billing, technical, sales
}
let ticket = "I was charged twice for my order, and now the app logs me out when I try to ask for a refund."
let model = MLXDecisionModel (modelID: "mlx-community/Qwen3-4B-Instruct-2507-4bit" )
let session = DecisionSession (model: model, state: .text(ticket))
let urgent = try await session.probability(of: "Does this convey urgency?" )
let team = try await session.choice( "Which team?" , from: Department . self )
let anger = try await session.score(
"How frustrated?" ,
levels: [ "Calm" , "Frustrated" , "Very angry" ]
)
urgent is a Double .
team is a Choice
a probability for each option, and a confidence value.
anger is a Score containing the expected level,
a probability for each level, and a confidence value.
Because Department conforms to Choosable ,
team.value is a Department that you can use in an exhaustive switch .
If you've used Foundation Models or AnyLanguageModel,
the model-and-session pattern will look familiar.
A DecisionSession holds a single state, which can be text or JSON,
and every question is about that state.
Questions are independent:
an answer never becomes input to a later question.
To ask several questions at once,
pass them to decide(_:) as a batch.
For each question, the MLX backend builds a prompt
with a one-token label for each allowed answer,
then reads the probability of each label from one forward pass.
Try it out: Emoji Magnet
Emoji Magnet is a macOS app with a text field above a pile of 343 emoji.
Type a phrase, such as "things you wear",
and the emoji that match rise out of the pile.
Refine it to "things you wear in winter",
and the emoji that no longer match fall back.
The app has no built-in keyword rules;
the model decides everything at inference time.
When you pause typing, it asks the model one yes-or-no question for each emoji,
for example:
Statement: a heavy winter coat fits the description "things you wear". Is this statement true?
The session's state holds the phrase.
The demo above uses the hosted Jev backend,
which answers all 343 questions in one request,
so the emoji settle in about half a second for each phrase.
Without a TYPESAFE_AI_API_KEY , the app runs Qwen3 4B on your Mac with the MLX backend.
That backend uses prefix caching to evaluate the state once,
then answers 16 questions per forward pass.
On an M4 Max, a group of 16 takes about 0.45 seconds after the model loads.
A full pass over all 343 emoji takes about 10 seconds,
and each group's results appear as soon as they arrive.
Emoji Magnet is in the AnyDecisionModel-Examples repository.
Decision heads and Clef
Reading next-token probabilities works with general-purpose language models,
but those models weren't trained to make decisions.
Cloudflare's Clef models
are an example of a newer approach:
a model with a trained decision head
that turns a state and a schema of typed questions into decisions,
returning probabilities for all allowed options across the questions
in one forward pass.
Clef-Flash is the 9B variant.
AnyDecisionModel runs Clef-Flash on a Mac with MLX:
let model = MLXHeadDecisionModel (
modelID: "mlx-community/clef-flash-4bit" ,
head: .jointSchema
)
You use the same sessions and questions,
but MLXHeadDecisionModel reads each decision from Clef's trained decision head
instead of from next-token probabilities.
The 4-bit model is a 6.2 GB download,
and its model card recommends a Mac with at least 16 GB of memory.
Clef can read images and video,
but this backend accepts only text and JSON states.
Calibrating and checking probabilities
Raw probabilities from language models are often overconfident.
The local backends accept a Calibration ,
which applies a temperature to every answer and a bias to yes-or-no answers.
Use separate datasets to fit the calibration and evaluate the results.
Language models can also favor an option because of its position in a list.
On the MLX, Core AI, and llama.cpp next-token backends,
turn on rotationDebiasing to ask a choice question
once for each rotation of the options and average the probabilities.
That costs one prompt evaluation per rotation.
Each local choice and score also includes a confidence value
based on the entropy of its probabilities.
It measures how concentrated the probabilities are,
not whether the answer is right,
so check the error rate on your own data before you pick a threshold.
The next-token backends' diagnostics report how much probability
the model assigned to the allowed answers.
A low value means it assigned most of the probability elsewhere.
Backends
AnyDecisionModel has six backends:
MLX runs a small language model on Apple silicon
with mlx-swift-lm
and downloads it from the Hub.
MLX decision heads run a model with its own trained decision head,
such as Clef.
Core AI does the same as MLX with a Core AI model on macOS 27 and iOS 27.
llama.cpp reads decisions from a local GGUF model
through llama.swift .
Jev calls TypeSafe's Jev through the System One API ,
or any server that implements it, such as Kev .
Ollama calls a System One decision model on a local Ollama server
or in Ollama's cloud.
It requires Ollama 0.35.0 or later, or 0.40.5 or later for cloud models.
The next-token backends label answers "yes" and "no", A to Z, or 0 to 9,
so a choice can have at most 26 options, and a score at most 10 levels.
Decision heads have no such limit.
Like AnyLanguageModel, the package uses Swift package traits.
Without traits, it has no third-party dependencies.
You get the core types and the Jev and Ollama backends,
which also build on Linux.
Enable the MLX , CoreAI , or Llama trait for the local backends.
Get started
Both packages require Swift 6.2 or later and macOS 26 or iOS 26 or later.
The Parakeet and Sortformer runtimes and the MLX backend require Apple silicon.
AnyDecisionModel's MLX build tasks use Xcode's Swift 6.4 or later
and the Metal toolchain; Core AI requires Xcode 27 and an OS 27 runtime.
Add the packages to your Package.swift :
dependencies: [
.package(url: "https://github.com/mattt/AnySpeechRecognizer" , from: "0.1.0" ),
.package(
url: "https://github.com/mattt/AnyDecisionModel" ,
from: "0.6.0" ,
traits: [ "MLX" ]
),
]
For now, AnyDecisionModel's CoreAI trait can't be combined with AnySpeechRecognizer,
because coreai-kit 0.7.3 requires swift-huggingface below 1.0
and AnySpeechRecognizer requires 1.x.
Each README has more examples and details about requirements and backends.
AnySpeechRecognizer also includes a command-line tool, hear ,
that transcribes local files, labels their speakers, and evaluates the results.
Every hear command requires --backend apple , --backend parakeet , or --backend qwen ;
run hear prepare with the same backend and model options before analysis
to install the needed assets.
Try them in your apps and tell us what works and what doesn't.
Issues and pull requests are welcome on both repositories.
Links
Thanks to NVIDIA for Parakeet, Sortformer, and NeMo, to Moondream for Parakeet Ultra,
to FluidInference, whose FluidAudio and mobius projects
documented the conventions that the Parakeet runtime and the Core ML conversions follow,
to Cloudflare for Clef,
and to everyone who contributed to AnyLanguageModel,
whose patterns both packages borrow.
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-11-02 | 8.49 | 20 | 入选 |
| 2026-11-01 | 8.77 | 34 | 未入选 |
| 2026-10-31 | 9.22 | 44 | 未入选 |
| 2026-10-30 | 9.95 | 28 | 未入选 |