15 #ifndef RUNNER_ALILATS2SPARSELATS_HPP 16 #define RUNNER_ALILATS2SPARSELATS_HPP 40 const std::string& grammarscales =
45 if (rg.
get<std::string> (featureweights) !=
"" ) {
48 = ucam::util::ParseParamString<float> (rg.
getString (featureweights) );
55 std::vector<float> fscales1, fscales2;
56 if ( rg.
exists ( grammarscales ) )
57 if ( rg.
get<std::string> ( grammarscales ) !=
"" )
58 fscales2 = ucam::util::ParseParamString<float> ( rg.
getString (
60 if ( rg.
exists ( lmscales ) )
61 if ( rg.
get<std::string> ( lmscales ) !=
"" )
62 fscales1 = ucam::util::ParseParamString<float> ( rg.
getString ( lmscales ) );
64 *offset = fscales1.size();
65 if ( fscales1.size() + fscales2.size() ) {
66 LWARN (
"env parameter is overriden by " << lmscales <<
"," << grammarscales );
69 copy ( fscales2.begin(), fscales2.end(), std::back_inserter ( fscales ) );
72 "Number of scaling factors must be greater than 0" );
74 std::string x = ucam::util::toString<float> ( fscales[0] );
75 for (
unsigned k = 1; k < fscales.size(); ++k )
76 x +=
"," + ucam::util::toString<float> ( fscales[k] );
77 LINFO (
"Number of language models =" << *offset <<
". Scales=" << x );
84 template <
template <
class>
class DataT
90 typedef DataT<TupleArc32 > Data;
121 boost::scoped_ptr < LoadSparseWeightFlowerLattice>
122 mytask (
new LoadSparseWeightFlowerLattice ( rg_ , numlms,
127 (
new LoadLanguageModel ( rg_,
kLmLoad,
"" ) )
129 (
new SparseWeightVectorLattices ( rg_
133 (
new ApplyLanguageModel ( rg_
148 mytask->chainrun ( d );
167 template <
template <
class>
class DataT
173 typedef DataT<TupleArc32 > Data;
190 unsigned threadcount_;
197 bool run ( Data& original_data ) {
201 boost::scoped_ptr < LoadSparseWeightFlowerLattice>
202 loadtask (
new LoadSparseWeightFlowerLattice ( rg_
207 (
new LoadLanguageModel ( rg_ ,
kLmLoad,
213 loadtask->chainrun ( original_data );
216 bool finished =
false;
223 d->klm = original_data.klm;
224 d->fsts = original_data.fsts;
225 d->wm = original_data.wm;
226 FORCELINFO (
"=====Extract features for sentence " << d->sidx <<
":" );
227 ReadFst *runtask =
new ReadFst ( rg_ ,
230 (
new SparseWeightVectorLattices ( rg_
234 (
new ApplyLanguageModel ( rg_
Full single-threaded Alignment lattices to Sparse lattices.
MultiThreadedAliLatsToSparseVecLatsTask(const ucam::util::RegistryPO &rg)
std::vector< std::string > getVectorString(const std::string &key) const
Convenience method that returns a vector of strings taking "," as the separator character.
const std::string kSparseweightvectorlatticeLoadalilats
T get(const std::string &key) const
Returns parsed value associated to key.
static std::vector< T > & Params()
boost::scoped_ptr< NumberRangeInterface< unsigned > > IntRangePtr
static DumpNbestFeaturesTask * init(const ucam::util::RegistryPO &rg, const unsigned offset=1, const std::string &sparseweightlatticekey=HifstConstants::kSparseweightvectorlatticeStore)
SingleThreadedAliLatsToSparseVecLatsTask(const ucam::util::RegistryPO &rg)
Constructor.
Trivial implementation of a threadpool based on boost::asio methods When initiated, creates a threadpool of n threads (n <= number of cpus). Jobs should be submitted with the templated operator(). When the object is deleted it will wait for all threads to finish.
Templated (hybrid) Interface for Task classes.
Simple functor that accepts an interface and pointer to the data object in which it will have to run ...
TaskInterface & appendTask(TaskInterface *t)
Appends a task class. If there is no task, append here, otherwise delegate in next task...
std::string const kLmFeatureweights
const std::string kRuleflowerlatticeFeatureweights
const std::string kNThreads
const std::string kSparseweightvectorlatticeWordmap
std::string getString(const std::string &key) const
Performs get<string> and checks whether the real value is to be loaded from file (–param=file://.....)
const std::string kRuleflowerlatticeStore
const std::string kSparseweightvectorlatticeStore
bool exists(const std::string &key) const
Determines whether a program option (key) has been defined by the user.
void setScales(const ucam::util::RegistryPO &rg, unsigned *offset, const std::string &lmscales=HifstConstants::kLmFeatureweights, const std::string &grammarscales=HifstConstants::kRuleflowerlatticeFeatureweights, const std::string &featureweights=HifstConstants::kFeatureweights, const std::string &lmload=HifstConstants::kLmLoad)
Sets scales using environment parameter (see sparse tuple weight semiring file), or grammar scales an...
Task that dumps nbest and feature file. Templated on specific Data object and Fst Arc...
#define USER_CHECK(exp, comment)
Tests whether exp is true. If not, comment is printed and program ends.
bool run(Data &original_data)
bool run(Data &d)
Reads an input sentence, tokenizes and integer-maps.
std::string const kLmWordmap
std::string const kLmLoad
const std::string kRangeOne
Multithreaded implementation of alilats2splats pipeline.
const std::string kFeatureweights
Creates lattices using tropical tuple weight semiring – each arc containing separate feature weight ...
const std::string kSparseweightvectorlatticeStorenolm
Implements a class that loads the grammar sparseweight flower lattice and stores a pointer on the dat...