44 #include "../proto/dataio.h"
49 #define PROG_NAME "symbolize-model"
52 #define XSTR(arg) STR(arg)
56 using namespace reranker;
57 using confusion_learning::SymbolMessage;
61 PROG_NAME " <model file> <symbol file> <output model file>\n",
67 int usage_msg_len =
sizeof(
usage_msg)/
sizeof(
const char *);
68 for (
int i = 0; i < usage_msg_len; ++i) {
75 main(
int argc,
char **argv) {
79 string model_output_file;
87 symbol_file = argv[2];
88 model_output_file = argv[3];
90 bool compressed =
true;
91 bool use_base64 =
true;
95 if (symbol_file !=
"") {
96 ConfusionProtoIO proto_reader(symbol_file,
97 ConfusionProtoIO::READ,
98 compressed, use_base64);
99 SymbolMessage symbol_message;
100 while (proto_reader.Read(&symbol_message)) {
101 symbols->SetIndex(symbol_message.symbol(), symbol_message.index());
103 proto_reader.Close();
107 shared_ptr<Model> model =
108 model_reader.
Read(model_file, compressed, use_base64);
109 model->set_symbols(symbols.get());
113 shared_ptr<ModelProtoWriter> model_writer =
114 proto_writer_factory.
CreateOrDie(model->proto_writer_spec(),
115 "model proto writer");
116 if (model_writer.get() == NULL) {
120 cerr <<
"Writing out model to file \"" << model_output_file <<
"\"...";
122 confusion_learning::ModelMessage model_message;
123 model_writer->Write(model.get(), &model_message,
false);
125 ConfusionProtoIO *proto_writer;
126 proto_writer =
new ConfusionProtoIO(model_output_file,
127 ConfusionProtoIO::WRITE,
128 compressed, use_base64);
129 proto_writer->Write(model_message);
131 bool output_best_epoch =
true;
132 bool output_key =
false;
133 model_writer->WriteFeatures(model.get(),
134 *(proto_writer->outputstream()),
136 model->num_training_errors(),
139 cerr <<
"done." << endl;
142 google::protobuf::ShutdownProtobufLibrary();
int main(int argc, char **argv)
Provides the ModelReader class, which can create Model instances from a file.
shared_ptr< Model > Read(const string &filename, bool compressed, bool use_base64)
Provides the reranker::Symbols interface as well as the reranker::StaticSymbolTable implementation...
A symbol table that stores the mapping from symbols to int’s and vice versa in local (non-static) dat...
Factory for dynamically created instance of the specified type.
void TearDown()
A free-floating function (within the reranker namespace) that frees statically allocated objects...
shared_ptr< T > CreateOrDie(StreamTokenizer &st, Environment *env=NULL)
Dynamically creates an object, whose type and initialization are contained in a specification string...
Interface for serializer for reranker::Model instances to ModelMessage instances. ...
Knows how to create Model instances that have been serialized to a file.