forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_frontend.h
68 lines (55 loc) · 1.81 KB
/
parser_frontend.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
#ifndef __LTP_PARSERN_PARSER_FRONTEND_H__
#define __LTP_PARSERN_PARSER_FRONTEND_H__
#include <iostream>
//#include "framework/frontend.h"
#include "parser.n/options.h"
#include "parser.n/instance.h"
#include "parser.n/parser.h"
#include "utils/logging.hpp"
namespace ltp {
namespace depparser {
struct PairGreaterBySecond {
bool operator()(std::pair<int, int> const& l,
std::pair<int, int> const& r) const {
if (l.second != r.second) { return l.second > r.second; }
return l.first < r.first;
}
};
class NeuralNetworkParserFrontend: public NeuralNetworkParser {
private:
const LearnOption* learn_opt;
const TestOption* test_opt;
std::vector<int> precomputed_features;
std::vector<Instance*> train_dat;
std::vector<Instance*> devel_dat;
std::vector<Sample> dataset;
size_t cursor;
public:
//! The learning constructor.
NeuralNetworkParserFrontend(const LearnOption& opt);
//! The testing constructor.
NeuralNetworkParserFrontend(const TestOption& opt);
~NeuralNetworkParserFrontend();
void train(void);
void test(void);
private:
bool read_training_data(void);
void check_dataset(const std::vector<Instance*>& dataset);
void build_alphabet(void);
void build_cluster(void);
void evaluate_one_instance(const Instance& data,
const std::vector<int>& heads,
const std::vector<std::string>& deprels,
size_t& corr_heads,
size_t& corr_deprels,
size_t& nr_tokens);
void evaluate(double& uas, double& las);
void collect_precomputed_features(void);
void initialize_classifier(void);
void generate_training_samples_one_batch(
std::vector<Sample>::const_iterator& begin,
std::vector<Sample>::const_iterator& end);
}; // end for class Parser
} // end for namespace depparser
} // end for namespace ltp
#endif // end for __LTP_PARSERN_PARSER_H__