Skip to content
Snippets Groups Projects
Commit d80db354 authored by Franck Dary's avatar Franck Dary
Browse files

Fixed CNNNetwork

parent 1065b8b6
No related branches found
No related tags found
No related merge requests found
...@@ -31,19 +31,19 @@ torch::Tensor CNNNetworkImpl::forward(torch::Tensor input) ...@@ -31,19 +31,19 @@ torch::Tensor CNNNetworkImpl::forward(torch::Tensor input)
input = input.unsqueeze(0); input = input.unsqueeze(0);
auto wordIndexes = input.narrow(1, 0, columns.size()*(1+leftBorder+rightBorder)); auto wordIndexes = input.narrow(1, 0, columns.size()*(1+leftBorder+rightBorder));
auto curIndex = wordIndexes.size(1);
std::vector<torch::Tensor> cnnOutputs; auto elementsEmbeddings = wordEmbeddings(input.narrow(1, wordIndexes.size(1), input.size(1)-wordIndexes.size(1)));
std::vector<torch::Tensor> cnnOutputs;
auto curIndex = 0;
for (unsigned int i = 0; i < focusedColumns.size(); i++) for (unsigned int i = 0; i < focusedColumns.size(); i++)
{ {
long nbElements = input[0][curIndex].item<long>(); long nbElements = maxNbElements[i];
curIndex++;
for (unsigned int focused = 0; focused < focusedBufferIndexes.size()+focusedStackIndexes.size(); focused++) for (unsigned int focused = 0; focused < focusedBufferIndexes.size()+focusedStackIndexes.size(); focused++)
{ {
cnnOutputs.emplace_back(cnns[i](wordEmbeddings(input.narrow(1, curIndex, nbElements)).unsqueeze(1))); auto cnnInput = elementsEmbeddings.narrow(1, curIndex, nbElements).unsqueeze(1);
curIndex += nbElements; curIndex += nbElements;
cnnOutputs.emplace_back(cnns[i](cnnInput));
} }
} }
...@@ -60,8 +60,8 @@ std::vector<long> CNNNetworkImpl::extractContext(Config & config, Dict & dict) c ...@@ -60,8 +60,8 @@ std::vector<long> CNNNetworkImpl::extractContext(Config & config, Dict & dict) c
std::vector<long> contextIndexes = extractContextIndexes(config); std::vector<long> contextIndexes = extractContextIndexes(config);
std::vector<long> context; std::vector<long> context;
for (auto & col : columns)
for (auto index : contextIndexes) for (auto index : contextIndexes)
for (auto & col : columns)
if (index == -1) if (index == -1)
context.push_back(dict.getIndexOrInsert(Dict::nullValueStr)); context.push_back(dict.getIndexOrInsert(Dict::nullValueStr));
else else
...@@ -71,8 +71,6 @@ std::vector<long> CNNNetworkImpl::extractContext(Config & config, Dict & dict) c ...@@ -71,8 +71,6 @@ std::vector<long> CNNNetworkImpl::extractContext(Config & config, Dict & dict) c
{ {
auto & col = focusedColumns[colIndex]; auto & col = focusedColumns[colIndex];
context.push_back(maxNbElements[colIndex]);
std::vector<int> focusedIndexes; std::vector<int> focusedIndexes;
for (auto relIndex : focusedBufferIndexes) for (auto relIndex : focusedBufferIndexes)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment