LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
deeplima::MwtSeq2Seq Class Reference

Character seq2seq fallback of the multiword-token expansion (see MwtLexicon): writes the words of a surface the segmenter flagged as multiword but that neither the dictionary nor the affix rules expand well. More...

#include <deeplima/mwt_seq2seq.h>

Public Types

typedef Eigen::MatrixXf Matrix
typedef Eigen::VectorXf Vector

Public Member Functions

 MwtSeq2Seq ()=default
bool loaded () const
bool before_rules () const
void load (const std::string &fn)
void clear ()
std::vector< std::string > expand (const std::string &surface) const

Static Public Member Functions

static std::u32string decompose (const std::u32string &s)
static std::u32string recompose (const std::u32string &s)
static std::u32string utf8_to_u32 (const std::string &s)
static std::string u32_to_utf8 (const std::u32string &s)

Detailed Description

Character seq2seq fallback of the multiword-token expansion (see MwtLexicon): writes the words of a surface the segmenter flagged as multiword but that neither the dictionary nor the affix rules expand well.

Needed where the split is not a concatenation, as in the abugidas: Amharic "ሄደ" = "ሄድ" + "ኧ" splits inside a syllable. For Ethiopic and Tamil, the surface's syllables are first decomposed into consonant + vowel letter, which turns most of these splits into concatenations, and the words are recomposed afterwards.

The model: a character embedding, a one-layer BiLSTM encoder, an LSTM cell decoder fed with the previous character and the attention context, a bilinear attention, and a copy mechanism (a learned gate mixes the generated distribution with the attention over the source characters). Greedy decoding; the output is the words separated by spaces. Expansions are cached (up to CACHE_SIZE surfaces), as the same surfaces recur.

Trained in Python by deeplima-training-scripts' tokenization/train_mwt_seq2seq.py, which writes <segmenter>.pt.mwt.s2s: "MWTS2S01", then uint32 decomposed, before_rules, V, E, H, then V-4 uint32 code points (output ids 4..V-1; 0 pad, 1 bos, 2 eos, 3 unk), then 15 matrices, each uint32 rows, cols and rows*cols float32 row-major: embedding (V x E); encoder forward W_ih (4H x E), W_hh (4H x H), bias (4H); encoder backward, the same; decoder W_ih (8H x (E+2H)), W_hh (8H x 2H), bias (8H); attention (2H x 2H); output (V x 4H) and its bias (V); copy gate (1 x (4H+E)) and its bias (1). Biases are PyTorch's b_ih + b_hh, gates in PyTorch's order (input, forget, cell, output).

Definition at line 52 of file mwt_seq2seq.h.

Member Typedef Documentation

◆ Matrix

typedef Eigen::MatrixXf deeplima::MwtSeq2Seq::Matrix

Definition at line 55 of file mwt_seq2seq.h.

◆ Vector

typedef Eigen::VectorXf deeplima::MwtSeq2Seq::Vector

Definition at line 56 of file mwt_seq2seq.h.

Constructor & Destructor Documentation

◆ MwtSeq2Seq()

deeplima::MwtSeq2Seq::MwtSeq2Seq ( )
default

Member Function Documentation

◆ before_rules()

bool deeplima::MwtSeq2Seq::before_rules ( ) const
inline

Definition at line 62 of file mwt_seq2seq.h.

◆ clear()

void deeplima::MwtSeq2Seq::clear ( )
inline

Definition at line 112 of file mwt_seq2seq.h.

◆ decompose()

std::u32string deeplima::MwtSeq2Seq::decompose ( const std::u32string & s)
inlinestatic

Definition at line 172 of file mwt_seq2seq.h.

◆ expand()

std::vector< std::string > deeplima::MwtSeq2Seq::expand ( const std::string & surface) const
inline

Definition at line 120 of file mwt_seq2seq.h.

◆ load()

void deeplima::MwtSeq2Seq::load ( const std::string & fn)
inline

Definition at line 64 of file mwt_seq2seq.h.

◆ loaded()

bool deeplima::MwtSeq2Seq::loaded ( ) const
inline

Definition at line 60 of file mwt_seq2seq.h.

◆ recompose()

std::u32string deeplima::MwtSeq2Seq::recompose ( const std::u32string & s)
inlinestatic

Definition at line 213 of file mwt_seq2seq.h.

◆ u32_to_utf8()

std::string deeplima::MwtSeq2Seq::u32_to_utf8 ( const std::u32string & s)
inlinestatic

Definition at line 279 of file mwt_seq2seq.h.

◆ utf8_to_u32()

std::u32string deeplima::MwtSeq2Seq::utf8_to_u32 ( const std::string & s)
inlinestatic

Definition at line 251 of file mwt_seq2seq.h.


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