allenai / allennlp-semparse

A framework for building semantic parsers (including neural module networks) with AllenNLP, built by the authors of AllenNLP
Apache License 2.0
107 stars 24 forks source link

How do we programmatically use this framework to train a semantic parser? #4

Closed entslscheia closed 5 years ago

entslscheia commented 5 years ago

As a newbie to allennlp, my understanding of the paradigm of training a model using allennlp is that we should have a DatasetReader object to read the data from disk, an Iterator object to batch the training data (i.e., objects of Instance), and a Model object to set up the computational graphs. Then basically, we pass those objects and an optimizer (or some other options) to a Trainer object trainer = Trainer(...), and train the model using trainer.train().

However, for the semantic parsing framework, I didn't see any code related to allennlp.training.Trainer, and the behavior of DecoderTrainer seems totally different from Trainer in allennlp. Instead of taking a Model object as a parameter to train, a DecoderTrainer object is served as a parameter of a Model object (e.g., MaximumMarginalLikelihood is inside WikiTablesMmlSemanticParser) to compute the loss.

So how do we exactly train a semantic parser programmatically? Are we still using a allennlp.training.Trainer object to incorporate everything (i.e., the model, dataset and an iterator) and train the model by calling train()?

I have read part of the source codes and have a basic understanding of how the semantic parsing framework looks like but didn't see any concrete example that includes a complete pipeline to train a semantic parser. I don't know maybe my question is kind of naive or trivial, but still confused for now.

matt-gardner commented 5 years ago

We still use the Trainer. It sounds like you're writing your own script to train your model; I'd recommend using the allennlp train command instead. You can follow this tutorial to learn more about how that whole setup works. In this repo, you'll find DatasetReaders and Models, plus a bunch of code that gets used inside those for semantic-parsing-specific stuff, and that's it. The Trainer code lives in the main repo, and we train using allennlp train and a configuration file.