本文整理汇总了C++中NRMat::ncols方法的典型用法代码示例。如果您正苦于以下问题:C++ NRMat::ncols方法的具体用法?C++ NRMat::ncols怎么用?C++ NRMat::ncols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NRMat
的用法示例。
在下文中一共展示了NRMat::ncols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
void Segmentor::train(const string& trainFile, const string& devFile, const string& testFile, const string& modelFile, const string& optionFile,
const string& wordEmbFile, const string& charEmbFile, const string& bicharEmbFile) {
if (optionFile != "")
m_options.load(optionFile);
m_options.showOptions();
vector<Instance> trainInsts, devInsts, testInsts;
m_pipe.readInstances(trainFile, trainInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (devFile != "")
m_pipe.readInstances(devFile, devInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (testFile != "")
m_pipe.readInstances(testFile, testInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
vector<vector<Instance> > otherInsts(m_options.testFiles.size());
for (int idx = 0; idx < m_options.testFiles.size(); idx++) {
m_pipe.readInstances(m_options.testFiles[idx], otherInsts[idx], m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
}
createAlphabet(trainInsts);
addTestWordAlpha(devInsts);
addTestWordAlpha(testInsts);
NRMat<dtype> wordEmb, allwordEmb;
if (wordEmbFile != "") {
allWordAlphaEmb(wordEmbFile, allwordEmb);
} else {
std::cout << "must not be here, allword must be pretrained." << std::endl;
}
wordEmb.resize(m_classifier.fe._wordAlphabet.size(), m_options.wordEmbSize);
wordEmb.randu(1000);
cout << "word emb dim is " << wordEmb.ncols() << std::endl;
NRMat<dtype> charEmb;
if (charEmbFile != "") {
readEmbeddings(m_classifier.fe._charAlphabet, charEmbFile, charEmb);
} else {
charEmb.resize(m_classifier.fe._charAlphabet.size(), m_options.charEmbSize);
charEmb.randu(2000);
}
cout << "char emb dim is " << charEmb.ncols() << std::endl;
NRMat<dtype> bicharEmb;
if (bicharEmbFile != "") {
readEmbeddings(m_classifier.fe._bicharAlphabet, bicharEmbFile, bicharEmb);
} else {
bicharEmb.resize(m_classifier.fe._bicharAlphabet.size(), m_options.bicharEmbSize);
bicharEmb.randu(2000);
}
cout << "bichar emb dim is " << bicharEmb.ncols() << std::endl;
NRMat<dtype> actionEmb;
actionEmb.resize(m_classifier.fe._actionAlphabet.size(), m_options.actionEmbSize);
actionEmb.randu(3000);
cout << "action emb dim is " << actionEmb.ncols() << std::endl;
NRMat<dtype> lengthEmb;
lengthEmb.resize(6, m_options.lengthEmbSize);
lengthEmb.randu(3000);
cout << "length emb dim is " << actionEmb.ncols() << std::endl;
m_classifier.init(wordEmb, allwordEmb, lengthEmb, m_options.wordNgram, m_options.wordHiddenSize, m_options.wordRNNHiddenSize,
charEmb, bicharEmb, m_options.charcontext, m_options.charHiddenSize, m_options.charRNNHiddenSize,
actionEmb, m_options.actionNgram, m_options.actionHiddenSize, m_options.actionRNNHiddenSize,
m_options.sepHiddenSize, m_options.appHiddenSize, m_options.delta);
m_classifier.setDropValue(m_options.dropProb);
m_classifier.setOOVFreq(m_options.wordCutOff);
m_classifier.setOOVRatio(m_options.oovRatio);
m_classifier.setWordFreq(m_word_stat);
vector<vector<CAction> > trainInstGoldactions;
getGoldActions(trainInsts, trainInstGoldactions);
double bestFmeasure = 0;
int inputSize = trainInsts.size();
std::vector<int> indexes;
for (int i = 0; i < inputSize; ++i)
indexes.push_back(i);
static Metric eval, metric_dev, metric_test;
int maxIter = m_options.maxIter * (inputSize / m_options.batchSize + 1);
int oneIterMaxRound = (inputSize + m_options.batchSize -1) / m_options.batchSize;
std::cout << "maxIter = " << maxIter << std::endl;
int devNum = devInsts.size(), testNum = testInsts.size();
static vector<vector<string> > decodeInstResults;
static vector<string> curDecodeInst;
static bool bCurIterBetter;
static vector<vector<string> > subInstances;
static vector<vector<CAction> > subInstGoldActions;
//.........这里部分代码省略.........