Commit 78339123 by xiaotong

correct the bug of loading samples for Tranformer training

parent ca343382
......@@ -465,6 +465,7 @@ char line[MAX_SEQUENCE_LENGTH];
struct SampleNode
{
int id;
int offset;
int * p;
int size;
int value;
......@@ -556,6 +557,7 @@ int T2TTrainer::LoadBuf(FILE * file, bool isSorted, int step)
for (int i = 0; i < seqCount; i += step) {
SampleNode &node = nodes[count];
node.id = count;
node.offset = i;
node.p = buf + offset;
node.size = 0;
for(int j = 0; j < step; j++)
......@@ -573,8 +575,8 @@ int T2TTrainer::LoadBuf(FILE * file, bool isSorted, int step)
SampleNode &node = nodes[count];
memcpy(buf2 + offset, node.p, sizeof(int) * node.size);
for(int j = 0; j < step; j++){
seqLen2[i + j] = seqLen[node.id + j];
seqOffset[i + j] = offset + (j > 0 ? seqLen[node.id + j - 1] : 0);
seqLen2[i + j] = seqLen[node.offset + j];
seqOffset[i + j] = offset + (j > 0 ? seqLen[node.offset + j - 1] : 0);
}
count += 1;
offset += node.size;
......
......@@ -1115,6 +1115,9 @@ set the value of a cell in a 3d tensor in default type
*/
bool XTensor::Set3D(DTYPE value, int d0, int d1, int d2)
{
if (!(d2 >= 0 && d2 < dimSize[2])) {
int nnn = 0;
}
CheckNTErrors(order == 3, "Cannot get a 2d cell for a tensor whose order is not 2!");
CheckNTErrors(d0 >= 0 && d0 < dimSize[0], "dimension 0 is out of range!");
CheckNTErrors(d1 >= 0 && d1 < dimSize[1], "dimension 1 is out of range!");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论