- provide start text
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@857 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+9
-18
@@ -40,13 +40,13 @@ class RbmListener : public Rbm::IListener
|
||||
std::cout << "L1 = " << status.L1 << std::endl;
|
||||
std::cout << "L2 = " << status.L2 << std::endl;
|
||||
m_last_progress = status.progress;
|
||||
forward();
|
||||
forward("Chap");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void forward()
|
||||
void forward(std::string const &start)
|
||||
{
|
||||
RnnStack *stack = reinterpret_cast<RnnStack*>(&m_stack);
|
||||
arma::mat state;
|
||||
@@ -56,17 +56,17 @@ class RbmListener : public Rbm::IListener
|
||||
std::string next_str;
|
||||
arma::mat t_vc = stack->trainingBatch();
|
||||
|
||||
for (int i=0; i < stack->getSeqLen(); i++)
|
||||
for (int i=0; i < start.size(); i++)
|
||||
{
|
||||
curr = stack->to_curr(t_vc.row(i));
|
||||
arma::mat curr = zeros(1, RnnTextHelper::NUM_CODES);
|
||||
int idx = RnnTextHelper::ch2idx(start.at(i));
|
||||
curr[idx] = 1;
|
||||
curr_str.append(1,RnnTextHelper::idx2ch(curr.index_max()));
|
||||
arma::mat r = stack->step_forward(state, curr);
|
||||
next = stack->to_next(r);
|
||||
stack->clamp_one_hot(next);
|
||||
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
cout << "Next: " << next_str << std::endl;
|
||||
cout << "Start: " << curr_str << std::endl;
|
||||
|
||||
for (int i=stack->getSeqLen(); i < t_vc.n_rows; i++)
|
||||
{
|
||||
@@ -76,10 +76,8 @@ class RbmListener : public Rbm::IListener
|
||||
next = stack->to_next(r);
|
||||
stack->clamp_one_hot(next);
|
||||
curr = stack->to_curr(r);
|
||||
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
cout << "Next: " << next_str << std::endl;
|
||||
|
||||
}
|
||||
AStack &m_stack;
|
||||
@@ -154,20 +152,13 @@ int main(int argc, char *argv[])
|
||||
putchar(c);
|
||||
}
|
||||
printf("\n");
|
||||
printf("Next\n");
|
||||
for (int i=0; i < t_vc.n_rows; i++)
|
||||
{
|
||||
arma::mat next = stack->to_next(t_vc.row(i));
|
||||
char c = RnnTextHelper::idx2ch(next.index_max());
|
||||
putchar(c);
|
||||
}
|
||||
printf("\n");
|
||||
command = Command::Forward;
|
||||
}
|
||||
|
||||
if (command == Command::Forward)
|
||||
{
|
||||
listener.forward();
|
||||
char *start = argv[2];
|
||||
listener.forward(start);
|
||||
}
|
||||
printf("\nEnd of program\n");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user