forked from larryniven/nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq2seq.h
65 lines (51 loc) · 1.71 KB
/
seq2seq.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
#ifndef SEQ2SEQ_H
#define SEQ2SEQ_H
#include "autodiff/autodiff.h"
#include "nn/tensor-tree.h"
namespace seq2seq {
std::shared_ptr<tensor_tree::vertex> make_tensor_tree(int encoder_layers);
struct seq2seq_nn_t {
std::shared_ptr<autodiff::op_t> pred;
std::vector<std::shared_ptr<autodiff::op_t>> atts;
};
struct attention {
virtual ~attention();
virtual std::shared_ptr<autodiff::op_t> operator()(
std::shared_ptr<autodiff::op_t> output,
std::shared_ptr<autodiff::op_t> hidden,
int nhidden,
int cell_dim) = 0;
};
struct bilinear_attention
: public attention {
virtual std::shared_ptr<autodiff::op_t> operator()(
std::shared_ptr<autodiff::op_t> output,
std::shared_ptr<autodiff::op_t> hidden,
int nhidden,
int cell_dim) override;
};
struct bilinear_softmax_attention
: public attention {
virtual std::shared_ptr<autodiff::op_t> operator()(
std::shared_ptr<autodiff::op_t> output,
std::shared_ptr<autodiff::op_t> hidden,
int nhidden,
int cell_dim) override;
};
seq2seq_nn_t make_training_nn(
std::vector<int> labels,
int label_set_size,
std::shared_ptr<autodiff::op_t> hidden,
int nhidden,
int cell_dim,
std::shared_ptr<tensor_tree::vertex> var_tree,
attention& att_func);
std::vector<int> decode(
std::vector<std::string> const& id_label,
std::shared_ptr<autodiff::op_t> hidden,
int nhidden,
int cell_dim,
std::shared_ptr<tensor_tree::vertex> var_tree,
attention& att_func);
}
#endif