LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
segmentation_eigen_inference_impl.h
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DEEPLIMA_SRC_INCLUDE_SEGMENTATION_SEGMENTATION_EIGEN_INFERENCE_IMPL_H
7#define DEEPLIMA_SRC_INCLUDE_SEGMENTATION_SEGMENTATION_EIGEN_INFERENCE_IMPL_H
8
9#include <eigen3/Eigen/Dense>
10
11#include "bilstm.h"
12#include "bilstm_and_dense.h"
13
14#include "embd_dict.h"
15
18
19namespace deeplima
20{
21namespace segmentation
22{
23namespace eigen_impl
24{
25#ifdef WIN32
26#ifdef SEGM_EXPORTING
27 #define SEGM_EXPORT __declspec(dllexport)
28#elif defined(DEEPLIMA_CONVERTFROMTORCH_SHARED) // users of the DLL
29 #define SEGM_EXPORT __declspec(dllimport)
30#else // static linking
31 #define SEGM_EXPORT
32#endif
33#else
34 #define SEGM_EXPORT
35#endif
36
38{
39public:
40 typedef Eigen::MatrixXf Matrix;
41 typedef Eigen::VectorXf Vector;
42 typedef float Scalar;
43 typedef Eigen::MatrixXf tensor_t;
46
47 virtual void load(const std::string& fn)
48 {
50 }
51
52 const std::vector<impl::ngram_descr_t>& get_ngram_descr() const
53 {
54 return m_ngram_gescr;
55 }
56
57 virtual void precompute_inputs(
58 const Eigen::MatrixXf& /*inputs*/,
59 Eigen::MatrixXf& /*outputs*/,
60 int64_t /*input_size*/
61 )
62 {
63 throw std::runtime_error("Precomputing isn't supported for segmentation");
64 }
65
66 virtual void predict(
67 size_t worker_id,
68 const Eigen::MatrixXf& inputs,
69 int64_t input_begin,
70 int64_t input_end,
71 int64_t output_begin,
72 int64_t output_end,
73 std::shared_ptr< StdMatrix<uint8_t> >& output,
74 const std::vector<std::string>& /*outputs_names*/
75 )
76 {
77 auto p_op = std::dynamic_pointer_cast<deeplima::eigen_impl::Op_BiLSTM_Dense_ArgMax<Eigen::MatrixXf, Eigen::VectorXf, float>>(Parent::m_ops[0]);
78 assert(Parent::m_wb.size() > 0);
79 assert(worker_id < Parent::m_wb[0].size());
80 p_op->execute(Parent::m_wb[0][worker_id], inputs, Parent::m_params[0], output->m_tensor,
81 input_begin, input_end, output_begin, output_end);
82 }
83
84protected:
85 std::vector<impl::ngram_descr_t> m_ngram_gescr;
86
87 virtual void convert_from_torch(const std::string& fn);
88};
89
90
91} // namespace eigen_impl
92} // namespace segmentation
93} // namespace deeplima
94
95#endif
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
virtual void precompute_inputs(const Eigen::MatrixXf &, Eigen::MatrixXf &, int64_t)
virtual void predict(size_t worker_id, const Eigen::MatrixXf &inputs, int64_t input_begin, int64_t input_end, int64_t output_begin, int64_t output_end, std::shared_ptr< StdMatrix< uint8_t > > &output, const std::vector< std::string > &)
Edit rules for lemmatizing words absent from the lemma dictionary.
DictsHolderImpl< EmbdUInt64Float > EmbdUInt64FloatHolder
Definition embd_dict.h:210