-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLatentCrfPosTagger.h
73 lines (47 loc) · 2.39 KB
/
LatentCrfPosTagger.h
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
68
69
70
71
72
73
#ifndef _LATENT_CRF_POS_TAGGER_H_
#define _LATENT_CRF_POS_TAGGER_H_
#include "../core/LatentCrfModel.h"
class LatentCrfPosTagger : public LatentCrfModel {
protected:
LatentCrfPosTagger(const std::string &textFilename,
const std::string &outputPrefix,
LearningInfo &learningInfo,
unsigned numberOfLabels,
unsigned firstLabelId,
const string &wordPairFeaturesFilename,
const string &initLambdaFilename,
const string &initThetaFilename);
~LatentCrfPosTagger();
void InitTheta();
void SetTestExample(std::vector<int64_t> &tokens);
void PrepareExample(unsigned exampleId) { /* do nothing */ }
std::vector<int64_t>& GetObservableContext(int exampleId) { /* do nothing */ return empty; }
std::vector<int64_t>& GetReconstructedObservableSequence(int exampleId);
int64_t GetContextOfTheta(unsigned sentId, int y) { return y; }
public:
static LatentCrfModel* GetInstance();
static LatentCrfModel* GetInstance(const std::string &textFilename,
const std::string &outputPrefix,
LearningInfo &learningInfo,
unsigned NUMBER_OF_LABELS,
unsigned FIRST_LABEL_ID,
const string &wordPairFeaturesFilename,
const string &initLambdaFilename,
const string &initThetaFilename);
std::vector<int64_t>& GetObservableSequence(int exampleId);
// add constrained features with hand-crafted weights
void AddConstrainedFeatures();
using UnsupervisedSequenceTaggingModel::Label;
void Label(std::vector<int64_t> &tokens, std::vector<int> &labels);
void LabelInParallel(const string &labelsFilename);
void LabelInParallel(string &inputFilename, string &outputFilename);
double ComputeNllYGivenXAndLambdaGradient(vector<double> &derivativeWRTLambda, int fromSentId, int toSentId) override;
void FireFeatures(int yI, int yIM1, unsigned sentId, int i,
FastSparseVector<double> &activeFeatures) override;
public:
std::vector<std::vector<int64_t> > data, testData;
std::vector<int64_t> empty;
std::map<int, string> labelIntToString;
std::map<string, int> labelStringToInt;
};
#endif