37 #ifndef RERANKER_FEATURE_VECTOR_READER_H_
38 #define RERANKER_FEATURE_VECTOR_READER_H_
43 #include "../proto/model.pb.h"
49 using confusion_learning::FeatureMessage;
50 using confusion_learning::FeatureVecMessage;
60 template <
typename FV>
73 void Read(
const FeatureVecMessage &fv_message,
76 for (
int i = 0; i < fv_message.feature_size(); ++i) {
77 const FeatureMessage &feature_msg = fv_message.feature(i);
78 int uid = feature_msg.id();
79 if (symbols != NULL &&
80 feature_msg.has_name() && ! feature_msg.name().empty()) {
81 uid = symbols->
GetIndex(feature_msg.name());
83 double value = feature_msg.value();
84 if (std::isnan(value)) {
85 cerr <<
"FeatureVectorReader: WARNING: feature " << uid
86 <<
" has value that is NaN" << endl;
88 features.IncrementWeight(uid, value);
99 void Read(
const FeatureVecMessage &fv_message,
102 for (
int i = 0; i < fv_message.feature_size(); ++i) {
103 const FeatureMessage &feature_msg = fv_message.feature(i);
104 double value = feature_msg.value();
105 if (std::isnan(value)) {
106 cerr <<
"FeatureVectorReader: WARNING: feature " << feature_msg.name()
107 <<
" has value that is NaN" << endl;
Provides the reranker::Symbols interface as well as the reranker::StaticSymbolTable implementation...
void Read(const FeatureVecMessage &fv_message, FV &features, Symbols *symbols) const
Serializes the specified feature vector to the specified FeatureVecMessage protocol buffer message...
void Read(const FeatureVecMessage &fv_message, FeatureVector< string, V > &features, Symbols *symbols) const
virtual int GetIndex(const string &symbol)=0
Converts the specified symbol to a unique integer.
An interface specifying a converter from symbols (strings) to int indices.
V IncrementWeight(const K &uid, V by)
Increments the weight of the specified feature by the specified amount.
Defines the reranker::FeatureVector class, which, as it happens, is used to store feature vectors...
A class to de-serialize FeatureVector instances from FeatureVecMessage instances. ...
A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type.