Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
candidate-set-proto-reader.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_CANDIDATE_SET_PROTO_READER_H_
38 #define RERANKER_CANDIDATE_SET_PROTO_READER_H_
39 
40 #include <unordered_map>
41 #include <vector>
42 
43 #include "candidate.H"
44 #include "candidate-set.H"
45 #include "string-canonicalizer.H"
46 #include "tokenizer.H"
47 #include "../proto/data.pb.h"
48 #include "../proto/model.pb.h"
49 
50 namespace reranker {
51 
52 using std::unordered_map;
53 
54 using confusion_learning::CandidateSetMessage;
55 
62  public:
65 
73  void Read(const CandidateSetMessage &m, CandidateSet &set) {
74  Read(m, -1, set);
75  }
76 
87  void Read(const CandidateSetMessage &m, int max_candidates,
88  CandidateSet &set);
89 
90  void ClearStrings() {
92  }
93  private:
94  int CountTokens(const string &s, const char *delimiters = " \t") const {
95  int count = 0;
96  size_t end_pos = 0;
97  size_t begin_pos = 0;
98  while (begin_pos != string::npos) {
99  begin_pos = s.find_first_not_of(delimiters, end_pos);
100  end_pos = s.find_first_of(delimiters, begin_pos);
101  if (end_pos == string::npos) {
102  end_pos = s.length();
103  }
104  if (begin_pos != string::npos) {
105  ++count;
106  begin_pos = end_pos;
107  }
108  }
109  return count;
110  }
111 
112  double ComputeLoss(CandidateSet &set, const string &candidate_raw_data);
113 
114  // data members
115  Tokenizer tokenizer_;
116 };
117 
118 } // namespace reranker
119 
120 #endif
void Read(const CandidateSetMessage &m, CandidateSet &set)
Fills in the specified CandidateSet based on the specified CandidateSetMessage, crucially constructin...
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
Provides the Tokenizer class.
static void Clear()
Clears the strings from the internal data structure.
A class to hold a set of candidates, either for training or test.
Definition: candidate-set.H:62
A class to fill in a CandidateSet based on a CandidateSetMessage, crucially constructing new Candidat...
Provides the reranker::StringCanonicalizer class.
Class to hold a single training instance for a reranker, which is a set of examples, typically the n-best output of some input process, posibly including a gold-standard feature vector.