.. _program_listing_file_src_rnn_attention_constructors.h: Program Listing for File attention_constructors.h ================================================= |exhale_lsh| :ref:`Return to documentation for file ` (``src/rnn/attention_constructors.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "marian.h" #include "layers/factory.h" #include "rnn/attention.h" #include "rnn/constructors.h" #include "rnn/types.h" namespace marian { namespace rnn { class AttentionFactory : public InputFactory { protected: Ptr state_; public: // AttentionFactory(Ptr graph) : InputFactory(graph) {} Ptr construct(Ptr graph) override { ABORT_IF(!state_, "EncoderState not set"); return New(graph, options_, state_); } Accumulator set_state(Ptr state) { state_ = state; return Accumulator(*this); } int dimAttended() { ABORT_IF(!state_, "EncoderState not set"); return state_->getAttended()->shape()[1]; } }; typedef Accumulator attention; } // namespace rnn } // namespace marian