一句话:提出正则表达式推断的枚举算法,以位向量矩阵紧凑编码搜索空间,并实现 CPU/GPU 版本,GPU 在困难基准上平均加速超千倍。
正则表达式推断(REI)是一个从正负样例和代价度量出发,综合出精确且代价最小正则表达式的程序合成与监督学习问题。论文提出一种适用于任意字母表的枚举算法,将正则表达式的搜索空间紧凑表示为连续位向量矩阵:这些位向量作为特征序列,编码正负样例并集之 infix-closure 的全部子语言,并对应一种形式幂级数变体上的半环。该表示支持自底向上组合构造,减少数据移动和依赖数据的分支,提升数据并行性;同时 infix-closure 在搜索中不变,可将搜索分阶段,先预计算昂贵操作再执行密集搜索。作者实现 CPU 与 Nvidia GPU(CUDA)两个 C++ 版本,并在 Google Colab Pro 上评测,GPU 在最困难基准上平均比 CPU 快超过 1000 倍。
Regular expression inference (REI) is a supervised machine learning and program synthesis problem that takes a cost metric for regular expressions, and positive and negative examples of strings as input. It outputs a regular expression that is precise (i.e., accepts all positive and rejects all negative examples), and minimal w.r.t. to the cost metric. We present a novel algorithm for REI over arbitrary alphabets that is enumerative and trades off time for space. Our main algorithmic idea is to implement the search space of regular expressions succinctly as a contiguous matrix of bitvectors. Collectively, the bitvectors represent, as characteristic sequences, all sub-languages of the infix-closure of the union of positive and negative examples. Mathematically, this is a semiring of (a variant of) formal power series. Infix-closure enables bottom-up compositional construction of larger from smaller regular expressions using the operations of our semiring. This minimises data movement and data-dependent branching, hence maximises data-parallelism. In addition, the infix-closure remains unchanged during the search, hence search can be staged: first pre-compute various expensive operations, and then run the compute intensive search process. We provide two C++ implementations, one for general purpose CPUs and one for Nvidia GPUs (using CUDA). We benchmark both on Google Colab Pro: the GPU implementation is on average over 1000x faster than the CPU implementation on the hardest benchmarks.