-
Notifications
You must be signed in to change notification settings - Fork 8
/
LSTMCRFMMLabeler.h
82 lines (57 loc) · 1.92 KB
/
LSTMCRFMMLabeler.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
74
75
76
77
78
79
80
81
82
/*
* Labeler.h
*
* Created on: Mar 16, 2015
* Author: mszhang
*/
#ifndef SRC_NNCRF_H_
#define SRC_NNCRF_H_
#include "N3L.h"
#include "basic/LSTMCRFMMClassifier.h"
#include "Options.h"
#include "Instance.h"
#include "Example.h"
#include "Pipe.h"
#include "Utf.h"
using namespace nr;
using namespace std;
class Labeler {
public:
std::string nullkey;
std::string unknownkey;
std::string seperateKey;
public:
Alphabet m_featAlphabet;
Alphabet m_labelAlphabet;
Alphabet m_wordAlphabet;
NRVec<Alphabet> m_tagAlphabets;
public:
Options m_options;
Pipe m_pipe;
#if USE_CUDA==1
LSTMCRFMMClassifier<gpu> m_classifier;
#else
LSTMCRFMMClassifier<cpu> m_classifier;
#endif
public:
void readWordEmbeddings(const string& inFile, Alphabet& alphabet, NRMat<dtype>& wordEmb, bool needNormalized=true);
public:
Labeler();
virtual ~Labeler();
public:
int createAlphabet(const vector<Instance>& vecInsts);
int addTestWordAlpha(const vector<Instance>& vecInsts);
int addTestCharAlpha(const vector<Instance>& vecInsts);
int addTestTagAlpha(const vector<Instance>& vecInsts);
void extractLinearFeatures(vector<string>& features, const Instance* pInstance, int idx);
void extractFeature(Feature& feat, const Instance* pInstance, int idx);
void convert2Example(const Instance* pInstance, Example& exam);
void initialExamples(const vector<Instance>& vecInsts, vector<Example>& vecExams);
public:
void train(const string& trainFile, const string& devFile, const string& testFile, const string& modelFile, const string& optionFile, const string& wordEmbFile, const string& tagEmbFile);
int predict(const vector<Feature>& features, vector<string>& outputs, const vector<string>& words);
void test(const string& testFile, const string& outputFile, const string& modelFile);
void writeModelFile(const string& outputModelFile);
void loadModelFile(const string& inputModelFile);
};
#endif /* SRC_NNCRF_H_ */