“4f38e00dc88b5b79d74a4d542c930df6b2a251d9”上不存在“git@gitcode.net:taosdata/tdengine.git”
ExpandLayer.h 1.9 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
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

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include "Layer.h"
#include "paddle/math/Matrix.h"

namespace paddle {

/**
 * A layer for "Expand Dense data or (sequence data where the length of each
 * sequence is one) to sequence data."
 *
 * It should have exactly 2 input, one for data, one for size:
 * - first one for data
 *   - If ExpandLevel = kNonSeq: dense data
 *   - If ExpandLevel = kSeq: sequence data where the length of each sequence is
 * one
 * - second one only for sequence info
 *   - should be sequence data with or without sub-sequence.
 *
 * And the output size is the batch size(not instances) of second input.
 *
 * The config file api is expand_layer.
 */

class ExpandLayer : public Layer {
protected:
  std::unique_ptr<Weight> biases_;
  /// if input[0] is dense data, ExpandLevel=kNonSeq;
  /// if input[0] is sequence data, ExpandLevel=kSeq
  enum ExpandLevel { kNonSeq = 0, kSeq = 1 };
  /// store the ExpandLevel
  int type_;
  /// expanded sequenceStartPositions or subSequenceStartPositions
  /// of input[1]
49
  ICpuGpuVectorPtr expandStartsPos_;
Z
zhangjinchao01 已提交
50 51 52 53 54 55

public:
  explicit ExpandLayer(const LayerConfig& config) : Layer(config) {}

  ~ExpandLayer() {}

Y
Yu Yang 已提交
56 57
  bool init(const LayerMap& layerMap,
            const ParameterMap& parameterMap) override;
Z
zhangjinchao01 已提交
58

Y
Yu Yang 已提交
59 60
  void forward(PassType passType) override;
  void backward(const UpdateCallback& callback = nullptr) override;
Z
zhangjinchao01 已提交
61 62 63
};

}  // namespace paddle