6#ifndef DEEPLIMA_GRAPH_DP_EIGEN_INFERENCE_IMPL_H
7#define DEEPLIMA_GRAPH_DP_EIGEN_INFERENCE_IMPL_H
9#include <eigen3/Eigen/Dense>
25#ifdef DEP_PARSING_EXPORTING
26 #define DEP_PARSING_EXPORT __declspec(dllexport)
27#elif defined(DEEPLIMA_CONVERTFROMTORCH_SHARED)
28 #define DEP_PARSING_EXPORT __declspec(dllimport)
30 #define DEP_PARSING_EXPORT
33 #define DEP_PARSING_EXPORT
49 virtual void load(
const std::string& fn)
56 auto p_params = std::dynamic_pointer_cast<typename deeplima::eigen_impl::Op_BiLSTM<Eigen::MatrixXf, Eigen::VectorXf, float>::params_t>(
Parent::m_params[0]);
57 const auto& layer = p_params->layers[0];
58 auto hidden_size = layer.fw.weight_ih.rows() + layer.bw.weight_ih.rows();
63 const Eigen::MatrixXf& inputs,
64 Eigen::MatrixXf& outputs,
68 auto p_op = std::dynamic_pointer_cast<deeplima::eigen_impl::Op_BiLSTM<Eigen::MatrixXf, Eigen::VectorXf, float>>(
Parent::m_ops[0]);
75 const Eigen::MatrixXf& ,
81 const std::vector<std::string>&
90 const Eigen::MatrixXf& inputs,
96 const std::vector<size_t>& lengths,
97 const std::vector<std::string>&
103 auto p_encoder = std::dynamic_pointer_cast<deeplima::eigen_impl::Op_BiLSTM<Eigen::MatrixXf, Eigen::VectorXf, float>>(
Parent::m_ops[0]);
111 auto wb = std::dynamic_pointer_cast<typename deeplima::eigen_impl::Op_BiLSTM<Eigen::MatrixXf, Eigen::VectorXf, float>::workbench_t>(
Parent::m_wb[0][worker_id]);
113 auto p_decoder = std::dynamic_pointer_cast<typename deeplima::eigen_impl::Op_DeepBiaffineAttnDecoder<Eigen::MatrixXf, Eigen::VectorXf, float>>(
116 const bool predict_labels =
120 size_t start = input_begin;
121 for (
size_t i = 0; i < lengths.size(); ++i)
125 start, start + lengths[i]);
129 wb->get_last_output(),
138 const Eigen::MatrixXf& enc = wb->get_last_output();
139 const Eigen::MatrixXf sent_input = enc.block(0, 0, enc.rows(), lengths[i]);
141 sent_input, (*output)[0], start, (*output)[1]);
170 std::vector<std::shared_ptr<deeplima::eigen_impl::params_deep_biaffine_attn_decoder_t<Eigen::MatrixXf, Eigen::VectorXf>>>
m_deep_biaffine_attn_decoder;
std::vector< std::vector< std::shared_ptr< Op_Base::workbench_t > > > m_wb
std::vector< std::shared_ptr< Op_Base > > m_ops
std::vector< std::shared_ptr< param_base_t > > m_params
void predict_labels(const params_t &p, const M &input, const std::vector< uint32_t > &heads, size_t input_begin, std::vector< uint32_t > &output) const
std::vector< std::string > m_rel_class_names
deeplima::eigen_impl::BiRnnInferenceBase Parent
virtual ~BiRnnAndDeepBiaffineAttentionEigenInference()=default
virtual void predict(size_t worker_id, const Eigen::MatrixXf &inputs, int64_t input_begin, int64_t, int64_t, int64_t, std::shared_ptr< StdMatrix< uint32_t > > &output, const std::vector< size_t > &lengths, const std::vector< std::string > &)
EmbdUInt64FloatHolder dicts_holder_t
virtual size_t get_precomputed_dim() const
const std::string & get_embd_fn(size_t idx) const
std::vector< std::string > m_embd_fn
bool has_label_decoder() const
virtual void convert_from_torch(const std::string &fn)
virtual void precompute_inputs(const Eigen::MatrixXf &inputs, Eigen::MatrixXf &outputs, int64_t input_size)
std::vector< std::shared_ptr< deeplima::eigen_impl::params_deep_biaffine_attn_decoder_t< Eigen::MatrixXf, Eigen::VectorXf > > > m_deep_biaffine_attn_decoder
std::vector< std::shared_ptr< deeplima::eigen_impl::params_deep_biaffine_attn_label_decoder_t< Eigen::MatrixXf, Eigen::VectorXf > > > m_deep_biaffine_attn_label_decoder
const std::vector< std::string > & get_rel_class_names() const
virtual void predict(size_t, const Eigen::MatrixXf &, int64_t, int64_t, int64_t, int64_t, std::shared_ptr< StdMatrix< uint8_t > > &, const std::vector< std::string > &)
std::map< std::string, size_t > m_deep_biaffine_attn_decoder_idx
virtual void load(const std::string &fn)
#define DEP_PARSING_EXPORT
Edit rules for lemmatizing words absent from the lemma dictionary.
DictsHolderImpl< EmbdUInt64Float > EmbdUInt64FloatHolder