50 const FeatExtractor& fe,
52 const std::string unk_str =
"<<UNK>>")
54 std::vector<std::map<std::string, uint64_t>> values(fe.size());
57 typename DataSet::const_iterator it = src.begin();
58 while (src.end() != it)
60 for (
size_t ifeat = 0; ifeat < fe.size(); ifeat++)
62 if (!fe.should_preprocess_feature(ifeat))
67 const std::string& feat_val = fe.feat_value(*it, ifeat);
68 if (0 == feat_val.size())
72 values[ifeat][feat_val]++;
79 dicts.resize(values.size());
80 for (
size_t ifeat = 0; ifeat < values.size(); ifeat++)
82 if (unk_str.size() > 0)
84 dicts[ifeat] = std::make_shared<StringDict>(unk_str,
85 values[ifeat].begin(), values[ifeat].end(),
86 [total, min_ipm](uint64_t c) {
87 return ipm(c, total) > min_ipm;
92 dicts[ifeat] = std::make_shared<StringDict>(values[ifeat].begin(),
94 [total, min_ipm](uint64_t c) {
95 return ipm(c, total) > min_ipm;