如何将注意力神经网络转化为可解释的硬逻辑谓词电路:忒修斯之船替换下的真值表谓词提取与状态机合并
How to Turn an Attention Neural Network into an Interpretable Hard-Logic Predicate Circuit: Truth-Table Predicate Extraction and State-Machine Merging
AI总结:
本研究提出忒修斯之船替换法,将注意力神经网络转化为可解释硬逻辑谓词电路,在 TweetEval-emotion 任务上实现高效推理,虽准确率略有下降,但速度比 GPU 快 2-3 个数量级。
摘要:
我们将训练好的注意力网络(包括注意力机制整体)转化为替代它运行的硬逻辑谓词电路。电路的每个单元是针对 token 的 0/1 谓词,谓词间的每个映射是最小化的真值表。短表(如查询编码与键编码的乘积)被精确最小化,而宽特征到特征的转换通过抗噪最小化成为蕴含规则。模块从输出端开始按忒修斯之船的方式逐个替换,每次替换后剩余的软部分会重新适应已冻结的电路。注意力选择有两种形式:整数分数的逐行比较(顺序选择)和学习到的规则(规则选择)。两者仅在普通训练集上拟合,且仅针对教师分类正确的样本,使电路在教师正确的地方模仿教师。在 TweetEval-emotion 任务上,DistilGPT2 的完整电路采用顺序选择时测试集黄金准确率为 66.5±1.3%,规则选择时为 57.4±2.5%(3 个随机种子的结果),而教师的准确率为 74.7%,基于相同推文的词袋模型准确率为 64.0%;BERT-base 的完整电路采用顺序选择时准确率为 70.0±0.5%,规则选择时为 63.7±1.2%,而教师的准确率为 77.8%。该电路无需乘法器和权重传输,其导出的硬件描述可逐位复现。基于综合估计,它在 FPGA 卡上分类一条推文约需 1-2μs(DistilGPT2)和 3-5μs(BERT),在功耗 7.5-15W 的掌上板上需 5-9μs,比 GPU 上批量大小为 1 的网络快 2-3 个数量级(实测 DistilGPT2 包括优化的 CUDA-graph 基线需 0.9-2.6ms),综合种子 0 电路的黄金准确率损失为 DistilGPT2 损失 8.5 点、BERT 损失 8.6 点。
英文摘要:
We convert a trained attention network as a whole, attention included, into a hard-logic predicate circuit that runs in its place. Every unit of the circuit is a 0/1 predicate on tokens, and every map between predicates is a minimised truth table. Each block is fitted once on the teacher's own states, with interfaces defined from the output down, and the rules of the whole chain are then refitted on the states it produces. Attention selection takes two forms, a row-wise comparison of integer scores (order selection) and a learned rule (rule selection). Both are fitted on the ordinary training set alone, and only on the examples that the teacher classifies correctly. On TweetEval-emotion, the complete circuit of DistilGPT2 reaches a test gold accuracy of 67.7 $\pm$ 0.8% with order selection and 56.4 $\pm$ 1.4% with rule selection over five seeds, against 74.7% for the teacher and 64.0% for a bag of word pieces fitted on the same tweets, and that of BERT-base truncated to 6 blocks reaches 71.1 $\pm$ 1.1% and 61.8 $\pm$ 5.0% against 80.0% (bag of words 63.8%). On four GLUE tasks, order selection reaches a mean test gold accuracy of 70.6% (DistilGPT2) and 70.9% (BERT), above the bag of words (68.6% and 68.4%). The circuit needs no multiplier and no weight traffic, and its exported hardware description reproduces it bit for bit. By a synthesis-based estimate averaged over the five tasks, it classifies one example in 1.1-2.0 $μ$s on an FPGA card, 180-420 times faster than the network on a GPU at batch 1 with CUDA graphs (measured, 0.35-0.46 ms), and in 3.3-6.4 $μ$s with 25-96 $μ$J on a palm-sized board of 7.5-15 W, 550-2,400 times less energy per example than the GPU.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。