-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a nest sequence select layer. #3297
Add a nest sequence select layer. #3297
Conversation
lcy-seso
commented
Aug 7, 2017
- Add a sub_nested_seq_layer.
- sub_nested_seq_layer accepts two inputs: the first one is a nested sequence; the second one is a set of selected indices in the nested sequence.
- sub_nest_seq_layer trims the first nested sequence input according to the selected indices to form a new output.
- This layer will be used in beam training.
21fa44d
to
ffafc5c
Compare
return true; | ||
} | ||
|
||
void SubNestedSequenceLayer::reorganizeSeqInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reorganizeSeqInfo这个感觉是一个比较通用的函数,把ICpuGpuVectorPtr seqStartPos和ICpuGpuVectorPtr subSeqStartPos
变成了vector<vector<int>>
形式,可以放到Argument.cpp中。不过可以在下一个PR中加。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
The example usage is: | ||
|
||
.. code-block:: python | ||
sub_nest_seq = sub_nested_seq_layer(input=[data, selected_indices]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6109行的格式不对。应该空一行,再缩进四格。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
const ICpuGpuVectorPtr subSeqStartPos); | ||
void calSelectedCols(const MatrixPtr selectedIndices, | ||
const std::vector<std::vector<int>> inputSeqInfo); | ||
void buildOutputSeqInfo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
34,36,38行三个函数缺乏注释
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
outSubSeqStartInfo_.push_back(outSubSeqStartInfo_.back() + subSeqLen); | ||
} | ||
outSeqStartInfo_.push_back(outSubSeqStartInfo_.back()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildOutputSeqInfo可以和calSelectedCols合并成一个函数么?这样outSeqStartInfo_和outSubSeqStartInfo_就可以作为函数内的一个临时变量了。
主要原因是:buildOutputSeqInfo没有任何的参数,从forward的代码中看不出修改了什么变量。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
selIdsCpu_->copyFrom(*selectedIndices); | ||
} else { | ||
selIdsCpu_ = selectedIndices; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
132-150行需要移入calSelectedCols函数么,selIdsCpu也是一个临时变量,除了在calSelectedCols里面用,其他地方没有用到。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
for (size_t i = 0; i < seqNum; ++i) { | ||
for (size_t j = 0; j < beamSize; ++j) { | ||
if (selectedIndices->getElement(i, j) == -1.) break; | ||
int selSubSeqIdx = selectedIndices->getElement(i, j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
95行挪到96行后面:不用访问两次selectedIndices了。
if (selSubSeqIdx == -1) break;
-1后面为什么有一个.呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里比较的是一个float。
1d48dc0
to
c192eb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow comments.
for (size_t i = 0; i < seqNum; ++i) { | ||
for (size_t j = 0; j < beamSize; ++j) { | ||
if (selectedIndices->getElement(i, j) == -1.) break; | ||
int selSubSeqIdx = selectedIndices->getElement(i, j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里比较的是一个float。
outSubSeqStartInfo_.push_back(outSubSeqStartInfo_.back() + subSeqLen); | ||
} | ||
outSeqStartInfo_.push_back(outSubSeqStartInfo_.back()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
selIdsCpu_->copyFrom(*selectedIndices); | ||
} else { | ||
selIdsCpu_ = selectedIndices; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
c192eb8
to
42c102a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM。有空可以改下注释。
* | ||
* ths output is saved to private member rowIndice_; | ||
* [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, | ||
* 16,17,18,19,20,21,22,23,24,25,26,27] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
55行的示例不太好,rowIndice是连续的输出,有更好的示例么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,这几个layer 都是为了做 beam training 添加的,一定会整体联调,再完善一遍注释。