6#ifndef DEEPLIMA_TAGGING_IMPL_H
7#define DEEPLIMA_TAGGING_IMPL_H
49 inline bool eos()
const
55 inline const std::string&
form()
const
72 : m_data(data), m_token(stridx) { }
92template <
typename TaggingAuxScalar>
96 using Vectorizer = FeaturesVectorizerWithPrecomputing<
131 virtual void init(
size_t threads,
size_t num_buffers,
132 size_t buffer_size_per_thread,
StringIndex& stridx)
134 m_fastText->get_words([&stridx](
const std::string& word){ stridx.
get_idx(word); });
137 { Vectorizer::str_feature,
"form",
m_fastText }
143 16, num_buffers, buffer_size_per_thread, threads,
162 if (this->get_input_str_dicts().size())
164 auto z = *(this->get_input_str_dicts().begin());
165 auto p = std::make_shared<EmbdStrFloat>(z);
168 auto fastText_fn = path_resolver.
resolve(
"embd", Classifier::get_embd_fn(0), {
"bin",
"ftz"});
169 if (fastText_fn.empty())
171 throw std::runtime_error(std::string(
"Failed to resolve embedding file name with embd and ")+Classifier::get_embd_fn(0));
225 while (lock_count > 1)
262 while (lock_count > 1)
306 while (lock_count > 1)
326 virtual void handle_token_buffer(
size_t slot_no,
const typename Vectorizer::dataset_t& buffer,
int timepoints_to_analyze = -1)
333 size_t count = (timepoints_to_analyze > 0) ? timepoints_to_analyze : buffer.size();
334 for (
size_t i = 0; i < count; i++)
358 std::shared_ptr<FastTextVectorizer<typename eigen_wrp::EigenMatrixXf::matrix_t, Eigen::Index>>
m_fastText;
std::string resolve(const std::string &prefix, const std::string &path, const std::vector< std::string > &accepted_ext={}) const
bool get_slot_started(uint32_t idx) const
int32_t next_slot(uint32_t idx)
uint64_t get_slot_end(uint32_t idx) const
virtual void init(uint32_t max_feat, uint32_t overlap, uint32_t num_slots, uint32_t slot_len, uint32_t num_threads, bool precomputed_input=false)
void load(const std::string &fn)
void increment_timepoint(uint64_t &timepoint)
uint8_t get_lock_count(uint32_t idx) const
uint32_t get_slot_size() const
std::shared_ptr< StdMatrix< Out > > get_output()
void set_slot_end(uint32_t idx, uint64_t slot_end)
void increment_lock_count(uint32_t idx, uint8_t v=1)
void decrement_lock_count(uint32_t idx)
uint64_t get_slot_begin(uint32_t idx) const
void start_job(uint32_t idx, bool no_more_data=false)
void wait_for_slot(uint32_t idx)
uint64_t get_start_timepoint() const
virtual void reset()
Need to be called to be able to reuse this classifier on several sequences.
const S & get_str(const idx_t idx) const
idx_t get_idx(const char *p, size_t len)
const M & get_tensor() const
A kind of RnnSequenceClassifier, used for named entities tagging (?), but also the parent of TaggingI...
Class implementing the tagger, used as member in TokenSequenceAnalyzer, the main tagger class Son of ...
virtual void register_handler(const tagging_callback_t fn)
int32_t m_last_completed_slot
virtual void load(const std::string &fn, const PathResolver &path_resolver)
void send_results(int32_t slot_idx)
virtual void init(size_t threads, size_t num_buffers, size_t buffer_size_per_thread, StringIndex &stridx)
virtual void handle_token_buffer(size_t slot_no, const typename Vectorizer::dataset_t &buffer, int timepoints_to_analyze=-1)
void no_more_data(size_t slot_no)
uint32_t m_current_slot_timepoints
void increment_timepoint(uint64_t &timepoint)
virtual void reset()
Need to be called to be able to reuse this classifier on several sequences.
tagging_callback_t m_callback
std::function< void(std::shared_ptr< StdMatrix< uint8_t > > classes, size_t begin, size_t end, size_t slot_idx) > tagging_callback_t
std::shared_ptr< FastTextVectorizer< typename eigen_wrp::EigenMatrixXf::matrix_t, Eigen::Index > > m_fastText
void precompute_inputs(const typename Vectorizer::dataset_t &buffer)
uint64_t m_current_timepoint
void send_results_if_available()
void acquire_slot(size_t slot_no)
const enriched_token_t & operator[](size_t idx) const
token_buffer_t ::size_type size() const
enriched_token_buffer_t(const token_buffer_t<> &data, const StringIndex &stridx)
const StringIndex & m_stridx
void set_token(const token_buffer_t<>::token_t *p)
const token_buffer_t ::token_t * m_ptoken
enriched_token_t(const StringIndex &stridx)
const std::string & form() const
token_flags_t flags() const