fastText  d00d36476b15
Fast text processing tool/library
fasttext::Model Class Reference

#include <model.h>

Public Member Functions

 Model (std::shared_ptr< Matrix >, std::shared_ptr< Matrix >, std::shared_ptr< Args >, int32_t)
 
 ~Model ()
 
real binaryLogistic (int32_t, bool, real)
 
real negativeSampling (int32_t, real)
 
real hierarchicalSoftmax (int32_t, real)
 
real softmax (int32_t, real)
 
void predict (const std::vector< int32_t > &, int32_t, std::vector< std::pair< real, int32_t >> &, Vector &, Vector &) const
 
void predict (const std::vector< int32_t > &, int32_t, std::vector< std::pair< real, int32_t >> &)
 
void dfs (int32_t, int32_t, real, std::vector< std::pair< real, int32_t >> &, Vector &) const
 
void findKBest (int32_t, std::vector< std::pair< real, int32_t >> &, Vector &, Vector &) const
 
void update (const std::vector< int32_t > &, int32_t, real)
 
void computeHidden (const std::vector< int32_t > &, Vector &) const
 
void computeOutputSoftmax (Vector &, Vector &) const
 
void computeOutputSoftmax ()
 
void setTargetCounts (const std::vector< int64_t > &)
 
void initTableNegatives (const std::vector< int64_t > &)
 
void buildTree (const std::vector< int64_t > &)
 
real getLoss () const
 
real sigmoid (real) const
 
real log (real) const
 
void setQuantizePointer (std::shared_ptr< QMatrix >, std::shared_ptr< QMatrix >, bool)
 

Public Attributes

std::minstd_rand rng
 
bool quant_
 

Private Member Functions

int32_t getNegative (int32_t target)
 
void initSigmoid ()
 
void initLog ()
 

Static Private Member Functions

static bool comparePairs (const std::pair< real, int32_t > &, const std::pair< real, int32_t > &)
 

Private Attributes

std::shared_ptr< Matrixwi_
 
std::shared_ptr< Matrixwo_
 
std::shared_ptr< QMatrixqwi_
 
std::shared_ptr< QMatrixqwo_
 
std::shared_ptr< Argsargs_
 
Vector hidden_
 
Vector output_
 
Vector grad_
 
int32_t hsz_
 
int32_t osz_
 
real loss_
 
int64_t nexamples_
 
realt_sigmoid
 
realt_log
 
std::vector< int32_t > negatives
 
size_t negpos
 
std::vector< std::vector< int32_t > > paths
 
std::vector< std::vector< bool > > codes
 
std::vector< Nodetree
 

Static Private Attributes

static const int32_t NEGATIVE_TABLE_SIZE = 10000000
 

Constructor & Destructor Documentation

◆ Model()

fasttext::Model::Model ( std::shared_ptr< Matrix wi,
std::shared_ptr< Matrix wo,
std::shared_ptr< Args args,
int32_t  seed 
)

◆ ~Model()

fasttext::Model::~Model ( )

Member Function Documentation

◆ binaryLogistic()

real fasttext::Model::binaryLogistic ( int32_t  target,
bool  label,
real  lr 
)

◆ buildTree()

void fasttext::Model::buildTree ( const std::vector< int64_t > &  counts)

◆ comparePairs()

bool fasttext::Model::comparePairs ( const std::pair< real, int32_t > &  l,
const std::pair< real, int32_t > &  r 
)
staticprivate

◆ computeHidden()

void fasttext::Model::computeHidden ( const std::vector< int32_t > &  input,
Vector hidden 
) const

◆ computeOutputSoftmax() [1/2]

void fasttext::Model::computeOutputSoftmax ( Vector hidden,
Vector output 
) const

◆ computeOutputSoftmax() [2/2]

void fasttext::Model::computeOutputSoftmax ( )

◆ dfs()

void fasttext::Model::dfs ( int32_t  k,
int32_t  node,
real  score,
std::vector< std::pair< real, int32_t >> &  heap,
Vector hidden 
) const

◆ findKBest()

void fasttext::Model::findKBest ( int32_t  k,
std::vector< std::pair< real, int32_t >> &  heap,
Vector hidden,
Vector output 
) const

◆ getLoss()

real fasttext::Model::getLoss ( ) const

◆ getNegative()

int32_t fasttext::Model::getNegative ( int32_t  target)
private

◆ hierarchicalSoftmax()

real fasttext::Model::hierarchicalSoftmax ( int32_t  target,
real  lr 
)

◆ initLog()

void fasttext::Model::initLog ( )
private

◆ initSigmoid()

void fasttext::Model::initSigmoid ( )
private

◆ initTableNegatives()

void fasttext::Model::initTableNegatives ( const std::vector< int64_t > &  counts)

◆ log()

real fasttext::Model::log ( real  x) const

◆ negativeSampling()

real fasttext::Model::negativeSampling ( int32_t  target,
real  lr 
)

◆ predict() [1/2]

void fasttext::Model::predict ( const std::vector< int32_t > &  input,
int32_t  k,
std::vector< std::pair< real, int32_t >> &  heap,
Vector hidden,
Vector output 
) const

◆ predict() [2/2]

void fasttext::Model::predict ( const std::vector< int32_t > &  input,
int32_t  k,
std::vector< std::pair< real, int32_t >> &  heap 
)

◆ setQuantizePointer()

void fasttext::Model::setQuantizePointer ( std::shared_ptr< QMatrix qwi,
std::shared_ptr< QMatrix qwo,
bool  qout 
)

◆ setTargetCounts()

void fasttext::Model::setTargetCounts ( const std::vector< int64_t > &  counts)

◆ sigmoid()

real fasttext::Model::sigmoid ( real  x) const

◆ softmax()

real fasttext::Model::softmax ( int32_t  target,
real  lr 
)

◆ update()

void fasttext::Model::update ( const std::vector< int32_t > &  input,
int32_t  target,
real  lr 
)

Member Data Documentation

◆ args_

std::shared_ptr<Args> fasttext::Model::args_
private

◆ codes

std::vector< std::vector<bool> > fasttext::Model::codes
private

◆ grad_

Vector fasttext::Model::grad_
private

◆ hidden_

Vector fasttext::Model::hidden_
private

◆ hsz_

int32_t fasttext::Model::hsz_
private

◆ loss_

real fasttext::Model::loss_
private

◆ NEGATIVE_TABLE_SIZE

const int32_t fasttext::Model::NEGATIVE_TABLE_SIZE = 10000000
staticprivate

◆ negatives

std::vector<int32_t> fasttext::Model::negatives
private

◆ negpos

size_t fasttext::Model::negpos
private

◆ nexamples_

int64_t fasttext::Model::nexamples_
private

◆ osz_

int32_t fasttext::Model::osz_
private

◆ output_

Vector fasttext::Model::output_
private

◆ paths

std::vector< std::vector<int32_t> > fasttext::Model::paths
private

◆ quant_

bool fasttext::Model::quant_

◆ qwi_

std::shared_ptr<QMatrix> fasttext::Model::qwi_
private

◆ qwo_

std::shared_ptr<QMatrix> fasttext::Model::qwo_
private

◆ rng

std::minstd_rand fasttext::Model::rng

◆ t_log

real* fasttext::Model::t_log
private

◆ t_sigmoid

real* fasttext::Model::t_sigmoid
private

◆ tree

std::vector<Node> fasttext::Model::tree
private

◆ wi_

std::shared_ptr<Matrix> fasttext::Model::wi_
private

◆ wo_

std::shared_ptr<Matrix> fasttext::Model::wo_
private

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