-
Notifications
You must be signed in to change notification settings - Fork 4
/
nn.h
56 lines (35 loc) · 1.29 KB
/
nn.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
#ifndef NN_H
#define NN_H
#include "autodiff/autodiff.h"
#include "nn/tensor-tree.h"
namespace nn {
struct pred_nn_t {
std::shared_ptr<autodiff::op_t> logprob;
};
pred_nn_t make_pred_nn(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input);
std::shared_ptr<tensor_tree::vertex> make_pred_tensor_tree();
struct log_loss {
la::cpu::tensor_like<double> const& gold;
la::cpu::tensor_like<double> const& pred;
log_loss(la::cpu::tensor_like<double> const& gold,
la::cpu::tensor_like<double> const& pred);
double loss();
la::cpu::tensor<double> grad(double scale=1);
};
struct l2_loss {
la::cpu::tensor_like<double> const& gold;
la::cpu::tensor_like<double> const& pred;
l2_loss(la::cpu::tensor_like<double> const& gold,
la::cpu::tensor_like<double> const& pred);
double loss();
la::cpu::tensor<double> grad(double scale=1);
};
struct seq_pred_nn_t {
std::vector<std::shared_ptr<autodiff::op_t>> logprob;
};
seq_pred_nn_t make_seq_pred_nn(
std::shared_ptr<tensor_tree::vertex> var_tree,
std::vector<std::shared_ptr<autodiff::op_t>> const& feat);
}
#endif