Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_initializers.h « graph « src - github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbb0734820f2e76108fa1b7093eaa6270c1578ad (plain)
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
// TODO: move to backend, into graph/
#pragma once

#include "common/config.h"
#include "tensors/tensor.h"

#include <functional>
#include <random>

namespace marian {

typedef std::function<void(Tensor)> NodeInitializer;

namespace inits {

void zeros(Tensor t);

void ones(Tensor t);

NodeInitializer from_value(float v);

NodeInitializer eye(float val = 1.f);

NodeInitializer normal(float mean = 0.f, float stddev = 1.f);

NodeInitializer uniform(float a = 0.f, float b = 1.f);

void glorot_uniform(Tensor t);
NodeInitializer glorot_uniform2(bool fanIn = true, bool fanOut = true);

void glorot_normal(Tensor t);
NodeInitializer glorot_normal2(bool fanIn = true, bool fanOut = true);

NodeInitializer bernoulli(float p, float scale = 1.f);

NodeInitializer dropout(float dropProb);

void gumbel(Tensor t);

static inline void dummy(Tensor) {}

NodeInitializer from_vector(const std::vector<float>& v);
NodeInitializer from_vector(const std::vector<IndexType>& v);

NodeInitializer from_item(const io::Item& item);

NodeInitializer from_sparse_vector(
    std::pair<std::vector<size_t>, std::vector<float>>& v);

// NodeInitializer from_numpy(const cnpy::NpyArrayPtr& np);

NodeInitializer from_word2vec(const std::string& file,
                              int dimVoc,
                              int dimEmb,
                              bool normalize = false);

/**
 * Computes Google's sinusoidal position embeddings
 * starting from position 'start' taking into account
 * batch and time dimensions of the tensor.
 *
 * Expected tensor layout {-2: time, -1: model}
 *
 * Usually gets later reshaped to {time, 1, model} and
 * added with a broadcast to learned embeddings. Positional
 * embeddings are the same for each batch entry and change
 * over time.
 */
NodeInitializer sinusoidalPositionEmbeddings(int start);

}  // namespace inits

}  // namespace marian