Skip to content
State-Regularized Recurrent Neural Networks
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


The code for the ICML 2019 paper State-Regularized Recurrent Neural Networks (

Usage and Examples

1. SR-GRU on Tomita grammars

a. To train a model, please run: THEANO_FLAGS=mode=FAST_RUN,device=cuda3,floatX=float32 python --tomita_grammar=n. The parameter n indicates the grammar number (n=1,2,3,4,7) (You can also run, it is a similar implementation but the temperature parameter is taken into account.)

b. To extract the DFA for a pre-trained model run: THEANO_FLAGS=mode=FAST_RUN,device=cuda3,floatX=float32 python --tomita_grammar=n

c. In the "DFAs" folder, you can find the extracted DFA.

We used the code from [1] to generate train and valid dataset.

2. SR-LSTM-P on Balanced Parentheses (BP)

a. Use "" to generated the train and validation datasets

b. To train a model, please run: THEANO_FLAGS=mode=FAST_RUN,device=cuda3,floatX=float32 python

c. The trained model will be saved in the "models" folder

d. Run "" at inference stage, it calls "" to plot the state transitions

[1] Weiss, Gail, Yoav Goldberg, and Eran Yahav. "Extracting automata from recurrent neural networks using queries and counterexamples." arXiv preprint arXiv:1711.09576 (2017).


Please cite in your publications if it helps your research:
title = {State-Regularized Recurrent Neural Networks},
author = {Wang, Cheng and Niepert, Mathias},
booktitle = {Proceedings of the 36th International Conference on Machine Learning},
pages = {6596--6606},
year = {2019},
editor = {Chaudhuri, Kamalika and Salakhutdinov, Ruslan},
volume = {97},
series = {Proceedings of Machine Learning Research},
address = {Long Beach, California, USA},
month = {09--15 Jun},
publisher = {PMLR}

You can’t perform that action at this time.