- refactored
- create training one th e fly from file name git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@860 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "RnnTextHelper.hpp"
|
||||
#include "matutils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -74,6 +75,7 @@ char RnnTextHelper::idx2ch(int index)
|
||||
|
||||
arma::mat RnnTextHelper::createTraining(const string& filename, size_t seq_len)
|
||||
{
|
||||
const char SPACE = ' ';
|
||||
FILE *pFile;
|
||||
|
||||
pFile = fopen(filename.c_str(), "r");
|
||||
@@ -92,33 +94,31 @@ arma::mat RnnTextHelper::createTraining(const string& filename, size_t seq_len)
|
||||
|
||||
for (int i = 0; i < seq_len; i++)
|
||||
{
|
||||
pattern.row(i)[0] = 1;
|
||||
pattern.row(i) = Matutils::char2vec(SPACE, NUM_CODES);
|
||||
}
|
||||
|
||||
int last_index = ch2idx(' ');
|
||||
int last_index = ch2idx(SPACE);
|
||||
while (!feof(pFile))
|
||||
{
|
||||
char c;
|
||||
int result = fread(&c, 1, 1, pFile);
|
||||
char ch = SPACE;
|
||||
int result = fread(&ch, 1, 1, pFile);
|
||||
if (result < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int index = ch2idx(c);
|
||||
int index = ch2idx(ch);
|
||||
if (index == 0 and last_index == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
last_index = index;
|
||||
|
||||
arma::mat data = arma::zeros(1, NUM_CODES);
|
||||
data[index] = 1;
|
||||
if (seq_len > 1)
|
||||
{
|
||||
pattern = arma::shift(pattern, 1);
|
||||
}
|
||||
pattern.row(0) = data;
|
||||
pattern.row(0) = Matutils::char2vec(ch, NUM_CODES);
|
||||
arma::mat pattern_vector = pattern.as_row();
|
||||
batch.insert_rows(batch.n_rows, pattern_vector);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user