1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef _FF_TAGGER_H_
#define _FF_TAGGER_H_
#include <map>
#include "ff.h"
typedef std::map<WordID, int> Class2FID;
typedef std::map<WordID, Class2FID> Class2Class2FID;
// the reason this is a "tagger" feature is that it assumes that
// the sequence unfolds from left to right, which means it doesn't
// have to split states based on left context.
// fires unigram features as well
class Tagger_BigramIdentity : public FeatureFunction {
public:
Tagger_BigramIdentity(const std::string& param);
protected:
virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta,
const Hypergraph::Edge& edge,
const std::vector<const void*>& ant_contexts,
SparseVector<double>* features,
SparseVector<double>* estimated_features,
void* context) const;
private:
void FireFeature(const WordID& left,
const WordID& right,
SparseVector<double>* features) const;
mutable Class2Class2FID fmap_;
};
// for each pair of symbols cooccuring in a lexicalized rule, fire
// a feature (mostly used for tagging, but could be used for any model)
class LexicalPairIdentity : public FeatureFunction {
public:
LexicalPairIdentity(const std::string& param);
protected:
virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta,
const Hypergraph::Edge& edge,
const std::vector<const void*>& ant_contexts,
SparseVector<double>* features,
SparseVector<double>* estimated_features,
void* context) const;
private:
void FireFeature(WordID src,
WordID trg,
SparseVector<double>* features) const;
mutable Class2Class2FID fmap_;
};
class OutputIdentity : public FeatureFunction {
public:
OutputIdentity(const std::string& param);
protected:
virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta,
const Hypergraph::Edge& edge,
const std::vector<const void*>& ant_contexts,
SparseVector<double>* features,
SparseVector<double>* estimated_features,
void* context) const;
private:
void FireFeature(WordID trg,
SparseVector<double>* features) const;
mutable Class2FID fmap_;
};
#endif
|