Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
model-merge-reducer.H
Go to the documentation of this file.
1 // Copyright 2012, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 // -----------------------------------------------------------------------------
30 //
31 //
36 
37 #ifndef RERANKER_MODEL_MERGE_REDUCER_H_
38 #define RERANKER_MODEL_MERGE_REDUCER_H
39 #include <string>
40 #include "../proto/dataio.h"
41 #include "../proto/model.pb.h"
42 
43 namespace reranker {
44 
45 using confusion_learning::FeatureMessage;
46 using confusion_learning::ModelMessage;
47 
48 
52 class Reducer {
53  public:
54  virtual int Reduce(const string& key, const string& value) = 0;
55  virtual int Flush(void) = 0;
56 };
57 
58 
65 class FeatureReducer : public Reducer {
66  public:
67  FeatureReducer(bool uniform_mix, double mix_denominator);
68  virtual int Reduce(const string& feat_id, const string& value);
69  virtual int Flush(void);
70 
71  private:
72  string prev_feat_;
73  FeatureMessage cur_message_;
74  int num_merged_;
75  ConfusionProtoIO messageio_;
76  int uniform_mix_;
77  int mix_denominator_;
78 };
79 
80 
86 class ModelInfoReducer : public Reducer {
87  public:
89  : new_model_message_(true) {
90  }
91  virtual int Reduce(const string& key, const string& value);
92  virtual int Flush(void);
93 
94  static const char* kModelMessageFeatureName;
95 
96  private:
97  bool new_model_message_;
98  ConfusionProtoIO messageio_;
99  ModelMessage model_message_;
100 };
101 
108 class SymbolReducer : public Reducer {
109  public:
111  virtual int Reduce(const string& key, const string& value);
112  virtual int Flush(void) {
113  return 0;
114  };
115 
116  private:
117  string prev_sym_;
118 };
119 
120 }
121 
122 #endif
virtual int Reduce(const string &key, const string &value)
FeatureReducer(bool uniform_mix, double mix_denominator)
A reducer class which processes FeatureMessage proto buffers.
virtual int Reduce(const string &feat_id, const string &value)
virtual int Reduce(const string &key, const string &value)=0
Abstract base-class for a streaming reducer.
A reducer class which processes SymbolMessage messages and returns a set of unique them into a single...
A reducer class which processes ModelMessage protocol messages and merges them into a single message...
virtual int Flush(void)=0
static const char * kModelMessageFeatureName
virtual int Reduce(const string &key, const string &value)