Commit 03fed61d by xiaotong

heap of each sentence

parent fdd64fb0
...@@ -27,6 +27,19 @@ using namespace nts; ...@@ -27,6 +27,19 @@ using namespace nts;
namespace transformer namespace transformer
{ {
/* constructor */
T2TSearch::T2TSearch()
{
fullHypos = NULL;
}
/* de-constructor */
T2TSearch::~T2TSearch()
{
if(fullHypos != NULL)
delete[] fullHypos;
}
/* /*
initialize the model initialize the model
...@@ -93,13 +106,13 @@ prepare for search ...@@ -93,13 +106,13 @@ prepare for search
*/ */
void T2TSearch::Prepare(int batchSize, int beamSize) void T2TSearch::Prepare(int batchSize, int beamSize)
{ {
if (heaps != NULL) if (fullHypos != NULL)
delete[] heaps; delete[] fullHypos;
heaps = new XHeap<MIN_HEAP, float>[batchSize]; fullHypos = new XHeap<MIN_HEAP, float>[batchSize];
for (int i = 0; i < batchSize; i++) for (int i = 0; i < batchSize; i++)
heaps[i].Init(beamSize); fullHypos[i].Init(beamSize);
} }
/* /*
...@@ -254,7 +267,7 @@ void T2TSearch::Expand(T2TStateBundle * prev, T2TStateBundle * beam) ...@@ -254,7 +267,7 @@ void T2TSearch::Expand(T2TStateBundle * prev, T2TStateBundle * beam)
} }
/* /*
collect hypotheses with ending symbol. Given a beam of hypotheses, collect hypotheses with ending symbols. Given a beam of hypotheses,
we remove the finished hypotheses and keep them in a heap. we remove the finished hypotheses and keep them in a heap.
>> beam - the beam that keeps a number of states >> beam - the beam that keeps a number of states
*/ */
...@@ -264,6 +277,8 @@ void T2TSearch::Collect(T2TStateBundle * beam) ...@@ -264,6 +277,8 @@ void T2TSearch::Collect(T2TStateBundle * beam)
for (int i = 0; i < beam->stateNum; i++) { for (int i = 0; i < beam->stateNum; i++) {
T2TState & state = states[i]; T2TState & state = states[i];
state.pid = state.last->pid;
} }
} }
......
...@@ -48,14 +48,14 @@ private: ...@@ -48,14 +48,14 @@ private:
int beamSize; int beamSize;
/* we keep the final hypotheses in a heap for each sentence in the batch. */ /* we keep the final hypotheses in a heap for each sentence in the batch. */
XHeap<MIN_HEAP, float> * heaps; XHeap<MIN_HEAP, float> * fullHypos;
public: public:
/* constructor */ /* constructor */
T2TSearch() {}; T2TSearch();
/* de-constructor */ /* de-constructor */
~T2TSearch() {}; ~T2TSearch();
/* initialize the model */ /* initialize the model */
void InitModel(int argc, char ** argv); void InitModel(int argc, char ** argv);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论