LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out > Class Template Reference

Handles multithreading. More...

#include <deeplima/nets/birnn_seq_cls.h>

Inheritance diagram for deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >:
deeplima::ThreadPool< RnnSequenceClassifier< Model, InputVectorizer, Out > > deeplima::tagging::impl::EntityTaggingClassifier< TaggingAuxScalar > deeplima::tagging::impl::EntityTaggingClassifier< float > deeplima::DependencyParser::GraphDpImpl deeplima::segmentation::impl::SegmentationImpl deeplima::tagging::impl::EntityTaggingClassifier< AuxScalar > deeplima::tagging::impl::TaggingImpl< TaggingAuxScalar > deeplima::tagging::impl::TaggingImpl< float >

Classes

struct  slot_t
 slot_t represents the part of the job processed by a classifier thread (tokenizer or tagger). More...
 

Public Member Functions

 RnnSequenceClassifier ()
 
virtual ~RnnSequenceClassifier ()
 
int32_t next_slot (uint32_t idx)
 
std::shared_ptr< StdMatrix< Out > > get_output ()
 
virtual void reset ()
 Need to be called to be able to reuse this classifier on several sequences.
 
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 get_classes_from_fn (const std::string &fn, std::vector< std::string > &classes_names, std::vector< std::vector< std::string > > &classes)
 
uint8_t get_output (uint64_t pos, uint8_t cls)
 
uint64_t get_slot_begin (uint32_t idx) const
 
bool get_slot_started (uint32_t idx) const
 
uint64_t get_slot_end (uint32_t idx) const
 
uint8_t get_lock_count (uint32_t idx) const
 
void increment_lock_count (uint32_t idx, uint8_t v=1)
 
void decrement_lock_count (uint32_t idx)
 
uint64_t get_start_timepoint () const
 
void increment_timepoint (uint64_t &timepoint)
 
uint32_t get_num_slots () const
 
uint32_t get_slot_size () const
 
int32_t get_slot_idx (uint64_t timepoint) const
 
void set_slot_lengths (uint32_t idx, const std::vector< size_t > &lengths)
 
void set_slot_begin (uint32_t idx, uint64_t slot_begin)
 
void set_slot_end (uint32_t idx, uint64_t slot_end)
 
void start_job (uint32_t idx, bool no_more_data=false)
 
void wait_for_slot (uint32_t idx)
 
void pretty_print () const
 
- Public Member Functions inherited from deeplima::ThreadPool< RnnSequenceClassifier< Model, InputVectorizer, Out > >
 ThreadPool (size_t num_threads=0)
 
void init (size_t num_threads)
 
size_t get_num_threads () const
 
virtual ~ThreadPool ()
 
void stop ()
 
size_t running ()
 
void push (void *job)
 

Protected Types

enum  slot_flags_t : uint8_t { none = 0x00 , left_overlap = 0x01 , right_overlap = 0x02 , max_flags }
 
typedef RnnSequenceClassifier< Model, InputVectorizer, Out > ThisClass
 
typedef ThreadPool< ThisClass > RnnSequenceClassifierThreadPool
 

Protected Member Functions

int32_t prev_slot (uint32_t idx)
 
void clear_slot (uint32_t idx)
 
void start_job_impl (uint32_t idx)
 Push the slot idx in the thread pool for starting the job on it.
 
- Protected Member Functions inherited from deeplima::ThreadPool< RnnSequenceClassifier< Model, InputVectorizer, Out > >
bool wait_for_new_job (void **job)
 This will wait until a job is available and then job parameter will be set to this available which will be removed from the list.
 
void wait_for_any_job_notification (const std::function< bool()> fn)
 
void thread_fn (size_t worker_id)
 

Static Protected Member Functions

static void run_one_job (ThisClass *this_ptr, size_t worker_id, void *p)
 

Protected Attributes

friend RnnSequenceClassifierThreadPool
 
uint32_t m_overlap
 
uint32_t m_num_slots
 
uint32_t m_slot_len
 
std::vector< slot_t > m_slots
 
std::vector< std::vector< size_t > > m_lengths
 
std::shared_ptr< StdMatrix< Out > > m_output
 
- Protected Attributes inherited from deeplima::ThreadPool< RnnSequenceClassifier< Model, InputVectorizer, Out > >
std::vector< std::thread > m_workers
 
std::atomic< bool > m_stop
 
std::queue< void * > m_jobs
 
std::mutex m_mutex
 
std::condition_variable m_cv
 
std::mutex m_mutex_notify
 
std::condition_variable m_cv_notify
 

Detailed Description

template<class Model, class InputVectorizer, class Out>
class deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >

Handles multithreading.

buffers from elsewhere are called slots here

Starts and stops threads. Each classifier has its own threadpool Each thread has its own stack so on machines with low memory, could be a problem.

The RnnSequenceClassifier is a Model, able to infer but also a thread pool to dispatch the work between several threads. And also a vectorizer, here a matrix.

Definition at line 46 of file birnn_seq_cls.h.

Member Typedef Documentation

◆ RnnSequenceClassifierThreadPool

template<class Model , class InputVectorizer , class Out >
typedef ThreadPool< ThisClass > deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::RnnSequenceClassifierThreadPool
protected

Definition at line 84 of file birnn_seq_cls.h.

◆ ThisClass

template<class Model , class InputVectorizer , class Out >
typedef RnnSequenceClassifier<Model, InputVectorizer, Out> deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::ThisClass
protected

Definition at line 83 of file birnn_seq_cls.h.

Member Enumeration Documentation

◆ slot_flags_t

template<class Model , class InputVectorizer , class Out >
enum deeplima::RnnSequenceClassifier::slot_flags_t : uint8_t
protected
Enumerator
none 
left_overlap 
right_overlap 
max_flags 

Definition at line 87 of file birnn_seq_cls.h.

Constructor & Destructor Documentation

◆ RnnSequenceClassifier()

template<class Model , class InputVectorizer , class Out >
deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::RnnSequenceClassifier ( )
inline

Definition at line 51 of file birnn_seq_cls.h.

◆ ~RnnSequenceClassifier()

template<class Model , class InputVectorizer , class Out >
virtual deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::~RnnSequenceClassifier ( )
inlinevirtual

Definition at line 75 of file birnn_seq_cls.h.

Member Function Documentation

◆ clear_slot()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::clear_slot ( uint32_t  idx)
inlineprotected

Definition at line 168 of file birnn_seq_cls.h.

◆ decrement_lock_count()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::decrement_lock_count ( uint32_t  idx)
inline

Definition at line 407 of file birnn_seq_cls.h.

◆ get_classes_from_fn()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_classes_from_fn ( const std::string &  fn,
std::vector< std::string > &  classes_names,
std::vector< std::vector< std::string > > &  classes 
)
inline

Definition at line 360 of file birnn_seq_cls.h.

◆ get_lock_count()

template<class Model , class InputVectorizer , class Out >
uint8_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_lock_count ( uint32_t  idx) const
inline

Definition at line 391 of file birnn_seq_cls.h.

◆ get_num_slots()

template<class Model , class InputVectorizer , class Out >
uint32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_num_slots ( ) const
inline

Definition at line 438 of file birnn_seq_cls.h.

◆ get_output() [1/2]

template<class Model , class InputVectorizer , class Out >
std::shared_ptr< StdMatrix< Out > > deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_output ( )
inline

Definition at line 261 of file birnn_seq_cls.h.

◆ get_output() [2/2]

template<class Model , class InputVectorizer , class Out >
uint8_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_output ( uint64_t  pos,
uint8_t  cls 
)
inline

Definition at line 364 of file birnn_seq_cls.h.

◆ get_slot_begin()

template<class Model , class InputVectorizer , class Out >
uint64_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_slot_begin ( uint32_t  idx) const
inline

Definition at line 373 of file birnn_seq_cls.h.

◆ get_slot_end()

template<class Model , class InputVectorizer , class Out >
uint64_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_slot_end ( uint32_t  idx) const
inline

Definition at line 385 of file birnn_seq_cls.h.

◆ get_slot_idx()

template<class Model , class InputVectorizer , class Out >
int32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_slot_idx ( uint64_t  timepoint) const
inline

Definition at line 448 of file birnn_seq_cls.h.

◆ get_slot_size()

template<class Model , class InputVectorizer , class Out >
uint32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_slot_size ( ) const
inline

Definition at line 443 of file birnn_seq_cls.h.

◆ get_slot_started()

template<class Model , class InputVectorizer , class Out >
bool deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_slot_started ( uint32_t  idx) const
inline

Definition at line 379 of file birnn_seq_cls.h.

◆ get_start_timepoint()

template<class Model , class InputVectorizer , class Out >
uint64_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::get_start_timepoint ( ) const
inline

Definition at line 422 of file birnn_seq_cls.h.

◆ increment_lock_count()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::increment_lock_count ( uint32_t  idx,
uint8_t  v = 1 
)
inline

Definition at line 397 of file birnn_seq_cls.h.

◆ increment_timepoint()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::increment_timepoint ( uint64_t &  timepoint)
inline

Definition at line 429 of file birnn_seq_cls.h.

◆ init()

template<class Model , class InputVectorizer , class Out >
virtual void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::init ( uint32_t  max_feat,
uint32_t  overlap,
uint32_t  num_slots,
uint32_t  slot_len,
uint32_t  num_threads,
bool  precomputed_input = false 
)
inlinevirtual

Definition at line 312 of file birnn_seq_cls.h.

◆ load()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::load ( const std::string &  fn)
inline

Definition at line 354 of file birnn_seq_cls.h.

◆ next_slot()

template<class Model , class InputVectorizer , class Out >
int32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::next_slot ( uint32_t  idx)
inline

Definition at line 254 of file birnn_seq_cls.h.

◆ pretty_print()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::pretty_print ( ) const
inline

Definition at line 561 of file birnn_seq_cls.h.

◆ prev_slot()

template<class Model , class InputVectorizer , class Out >
int32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::prev_slot ( uint32_t  idx)
inlineprotected

Definition at line 161 of file birnn_seq_cls.h.

◆ reset()

template<class Model , class InputVectorizer , class Out >
virtual void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::reset ( )
inlinevirtual

Need to be called to be able to reuse this classifier on several sequences.

Reimplemented in deeplima::tagging::impl::TaggingImpl< TaggingAuxScalar >, and deeplima::tagging::impl::TaggingImpl< float >.

Definition at line 269 of file birnn_seq_cls.h.

◆ run_one_job()

template<class Model , class InputVectorizer , class Out >
static void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::run_one_job ( ThisClass *  this_ptr,
size_t  worker_id,
void *  p 
)
inlinestaticprotected

Definition at line 202 of file birnn_seq_cls.h.

◆ set_slot_begin()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::set_slot_begin ( uint32_t  idx,
uint64_t  slot_begin 
)
inline

Definition at line 468 of file birnn_seq_cls.h.

◆ set_slot_end()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::set_slot_end ( uint32_t  idx,
uint64_t  slot_end 
)
inline

Definition at line 490 of file birnn_seq_cls.h.

◆ set_slot_lengths()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::set_slot_lengths ( uint32_t  idx,
const std::vector< size_t > &  lengths 
)
inline

Definition at line 456 of file birnn_seq_cls.h.

◆ start_job()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::start_job ( uint32_t  idx,
bool  no_more_data = false 
)
inline

Definition at line 506 of file birnn_seq_cls.h.

◆ start_job_impl()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::start_job_impl ( uint32_t  idx)
inlineprotected

Push the slot idx in the thread pool for starting the job on it.

Definition at line 185 of file birnn_seq_cls.h.

◆ wait_for_slot()

template<class Model , class InputVectorizer , class Out >
void deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::wait_for_slot ( uint32_t  idx)
inline

Definition at line 542 of file birnn_seq_cls.h.

Member Data Documentation

◆ m_lengths

template<class Model , class InputVectorizer , class Out >
std::vector<std::vector<size_t> > deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_lengths
protected

Definition at line 577 of file birnn_seq_cls.h.

◆ m_num_slots

template<class Model , class InputVectorizer , class Out >
uint32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_num_slots
protected

Definition at line 573 of file birnn_seq_cls.h.

◆ m_output

template<class Model , class InputVectorizer , class Out >
std::shared_ptr< StdMatrix<Out> > deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_output
protected

Definition at line 578 of file birnn_seq_cls.h.

◆ m_overlap

template<class Model , class InputVectorizer , class Out >
uint32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_overlap
protected

Definition at line 572 of file birnn_seq_cls.h.

◆ m_slot_len

template<class Model , class InputVectorizer , class Out >
uint32_t deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_slot_len
protected

Definition at line 574 of file birnn_seq_cls.h.

◆ m_slots

template<class Model , class InputVectorizer , class Out >
std::vector<slot_t> deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::m_slots
protected

Definition at line 576 of file birnn_seq_cls.h.

◆ RnnSequenceClassifierThreadPool

template<class Model , class InputVectorizer , class Out >
friend deeplima::RnnSequenceClassifier< Model, InputVectorizer, Out >::RnnSequenceClassifierThreadPool
protected

Definition at line 85 of file birnn_seq_cls.h.


The documentation for this class was generated from the following file: