Starchild
F* library for verifying neural networks.
Install / Use
/learn @wenkokke/StarchildREADME
StarChild
StarChild is a library for leveraging the interactive theorem proving and SMT checking abilities of F* to verify properties of neural networks. It currently supports feedforward neural networks using ReLU, sigmoid, and softmax activation functions. Networks are written as follows:
val layer1 : layer 2 1
let layer1 = { weights = [[228300.0R /. 13.0R]; [228300.0R /. 13.0R]]
; biases = [~.337910.0R /. 13.0R]
; activation = Sigmoid
}
val model : network 2 1 1
let model = NLast layer1
Properties of the model can then be checked using F* assertions. Let’s check if the model correctly implements the AND gate:
let _ = assert (run_network model [1.0R; 1.0R] == [1.0R])
let _ = assert (run_network model [0.0R; 1.0R] == [0.0R])
let _ = assert (run_network model [1.0R; 0.0R] == [0.0R])
let _ = assert (run_network model [0.0R; 0.0R] == [0.0R])
Yes! It correctly implements the AND gate! However, is it robust? What do we mean by robust? That’s generally not an easy question. For this AND gate, let’s take robustness to mean that if the input is within some epsilon of a 0.0 or 1.0, the gate still works:
let epsilon = 0.24R
let truthy x = dist x 1.0R <=. epsilon
let falsy x = dist x 0.0R <=. epsilon
let _ = assert (forall x1 x2. truthy x1 && truthy x2 ==> run_network model [x1; x2] == [1.0R])
let _ = assert (forall x1 x2. falsy x1 && truthy x2 ==> run_network model [x1; x2] == [0.0R])
let _ = assert (forall x1 x2. truthy x1 && falsy x2 ==> run_network model [x1; x2] == [0.0R])
let _ = assert (forall x1 x2. falsy x1 && falsy x2 ==> run_network model [x1; x2] == [0.0R])
The network we defined is robust around truthy and falsy inputs!
StarChild ships with a script which can help you convert a subset of Keras models to F* files.
It’s called convert.py, and you invoke it like this:
python convert.py \
-i models/Fashion_MNIST_PCA_100_ReLU_64_Softmax_10.h5 \
-o models/Fashion_MNIST_PCA_100_ReLU_64_Softmax_10.fst
Make sure to install the requirements first!<sup>1</sup>
StarChild also comes with two example models, trained on the Fashion MNIST dataset, using the train_*.py scripts.
Currently, F* chokes up when type checking the larger of the models.
You may also be interested in StarChild’s friend, Lazuli!
<a name="pip">1</a>: Run pip install -r requirements.txt.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
