Commit c090457f by xiaotong

test code

parent 907f7d2a
...@@ -303,6 +303,8 @@ void XNet::TarjanVisit(XTensor * node, XList &orders, const unsigned int code) ...@@ -303,6 +303,8 @@ void XNet::TarjanVisit(XTensor * node, XList &orders, const unsigned int code)
node->visitMark = code + 2; node->visitMark = code + 2;
orders.Add(node); orders.Add(node);
} }
else if(node->visitMark == code + 2){
}
} }
/* /*
......
...@@ -217,6 +217,13 @@ void T2TTrainer::Train(const char * fn, const char * validFN, const char * model ...@@ -217,6 +217,13 @@ void T2TTrainer::Train(const char * fn, const char * validFN, const char * model
/* back-propagation */ /* back-propagation */
net.Backward(output, g, CROSSENTROPY); net.Backward(output, g, CROSSENTROPY);
/*for(int i = 0; i < net.nodes.count; i++){
XTensor * node = (XTensor*)net.nodes.Get(i);
XLink::ShowNode(stderr, node);
}
exit(0);*/
gradStep += 1; gradStep += 1;
loss += -prob; loss += -prob;
wordCount += wc; wordCount += wc;
......
...@@ -589,9 +589,24 @@ show the network encoded in a root node (tensor) ...@@ -589,9 +589,24 @@ show the network encoded in a root node (tensor)
*/ */
void XLink::ShowNetwork(FILE * file, XTensor * root) void XLink::ShowNetwork(FILE * file, XTensor * root)
{ {
fprintf(file, "node %d - ", root->id);
XLink &income = root->income; XLink &income = root->income;
for(int i = 0; i < income.tailNum; i++){
XTensor * child = income.tails[i];
ShowNetwork(file, child);
}
}
/*
show a node
>> file - file to dump information
>> root - pointer to the node
*/
void XLink::ShowNode(FILE * file, XTensor * node)
{
fprintf(file, "node %d - ", node->id);
XLink &income = node->income;
if(income.head == NULL){ if(income.head == NULL){
fprintf(file, "income[%d]: null ", income.tailNum); fprintf(file, "income[%d]: null ", income.tailNum);
} }
...@@ -607,7 +622,7 @@ void XLink::ShowNetwork(FILE * file, XTensor * root) ...@@ -607,7 +622,7 @@ void XLink::ShowNetwork(FILE * file, XTensor * root)
} }
fprintf(stderr, ", "); fprintf(stderr, ", ");
XLink &outgo = root->outgo; XLink &outgo = node->outgo;
if(outgo.head == NULL || outgo.tailNum == 0){ if(outgo.head == NULL || outgo.tailNum == 0){
fprintf(file, "outgo[%d]: null ", outgo.tailNum); fprintf(file, "outgo[%d]: null ", outgo.tailNum);
} }
...@@ -623,11 +638,6 @@ void XLink::ShowNetwork(FILE * file, XTensor * root) ...@@ -623,11 +638,6 @@ void XLink::ShowNetwork(FILE * file, XTensor * root)
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
for(int i = 0; i < income.tailNum; i++){
XTensor * child = income.tails[i];
ShowNetwork(file, child);
}
} }
} // namespace nts(NiuTrans.Tensor) } // namespace nts(NiuTrans.Tensor)
......
...@@ -178,6 +178,10 @@ struct XLink ...@@ -178,6 +178,10 @@ struct XLink
/* show the network encoded in a root node (tensor) */ /* show the network encoded in a root node (tensor) */
static static
void ShowNetwork(FILE * file, XTensor * root); void ShowNetwork(FILE * file, XTensor * root);
/* show a node */
static
void ShowNode(FILE * file, XTensor * node);
}; };
} // namespace nts(NiuTrans.Tensor) } // namespace nts(NiuTrans.Tensor)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论