This is the code repository for
Geiger, Atticus; Alexandra Carstensen; Michael C. Frank; and Christopher Potts. 2020. 'Relational reasoning and generalization using non-symbolic neural networks'. Ms., Stanford University.
This code requires Python 3.6 or higher. Specific requirements are given in requirements.txt. For installing PyTorch, we recommend following the specific instructions provided at this project's website.
The pretraining model is torch_rep_learner.py.
-
datasets.py: Classes for creating equality datasets that do not involve pretraining. -
trained_datasets.py: Counterparts of the classes indatasets.pybut with pretrained embedding matrices. -
(The dataset code for Model 2 is included in
fuzzy_lm_experiment.py.)
-
The core model is an
sklearn.neural_network.MLPClassifier. -
equality_experiment.pyis a framework for running the experiments, including all hyperparameter tuning. -
The experiment runs are in
run_basic_equality.ipynb. -
The results are
results/equality.csv,results/equality-pretrain-3tasks.csv,results/equality-pretrain-5tasks.csv, andresults/equality-pretrain-10tasks.csv.
-
The core model is a language model with a mean-squared error loss, implemented in PyTorch. The code is
torch_fuzzy_lm.py. -
relu_lstm.pyis a PyTorch LSTM with a ReLU activation. This is used bytorch_fuzzy_lm.py. -
fuzzy_lm_experiment.pyis a framework for running the experiments, including all hyperparameter tuning. -
The experiment runs are in
run_fuzzy_lm.ipynb. -
The results are
results/fuzzy-lm-vocab20.csv,fuzzy-lm-vocab20-pretrain-3tasks.csv,fuzzy-lm-vocab20-pretrain-5tasks.csv, andfuzzy-lm-vocab20-pretrain-10tasks.csv.
-
For the train-from-scratch versions:
- The core model is an
sklearn.neural_network.MLPClassifier, as in Model 1. run_flat_premack.ipynbruns the experiments, usingequality_experiment.py.- The results are
results/flatpremack-h1.csv(one hidden later) andresults/flatpremack-h2.csv(two hidden layers). - The versions with pretraining are
flatpremack-h2-pretrain-3tasks.csv,flatpremack-h2-pretrain-5tasks.csv, andflatpremack-h2-pretrain-10tasks.csv.
- The core model is an
-
For the pretraining regime:
- The core model is
torch_input_as_output.py. run_input_as_output.ipynbruns the experiments, including all hyperparameter tuning.- The results are
results/input-as-output.csv, along with exploratory runs involving pretraining the inputs as well:input-as-output-pretrain-3tasks.csv,input-as-output-pretrain-5tasks.csv, andinput-as-output-pretrain-10tasks.csv.
- The core model is
The notebook create_visualizations.ipynb runs all the visualization, using comparative_viz.py and the results files in results. The visualizations are written to the fig directory.
-
utils.py: general shared functionality. -
view_best_hyperparameters.ipynb: can be used to see which hyperparameters are optimal for the experiments, using the files inresults. -
rmts.mplstyle: matplotlib style file for visualizations. This needs to be placed in the directory that matplotlib looks for such files, which depends somewhat on the system: https://matplotlib.org/users/style_sheets.html -
The
testdirectory contains unit tests.