Poplar and PopLibs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CTCInference.hpp File Reference

Support for Connectionist Temporal Classification (CTC) Beam search decoder. More...

#include "CTCPlan.hpp"
#include <poplar/Graph.hpp>
#include <poplar/OptionFlags.hpp>
#include <poplar/Program.hpp>

Go to the source code of this file.

Namespaces

namespace  popnn
 Functions used in neural networks.
 

Functions

ctc::Plan popnn::ctc_infer::plan (const poplar::Graph &graph, const poplar::Type &inType, unsigned batchSize, unsigned maxTime, unsigned numClasses, unsigned beamwidth, const poplar::OptionFlags &options={})
 Create a plan for implementing the CTC Beam search inference function. More...
 
poplar::Tensor popnn::ctc_infer::createDataInput (poplar::Graph &graph, const poplar::Type &type, const std::size_t batchSize, const std::size_t maxTime, const std::size_t numClasses, const ctc::Plan &plan, const poplar::DebugContext &debugContext={})
 Create and map a data input [maxTime, batchSize, numClasses] tensor which the beam search function will use. More...
 
std::tuple< poplar::Tensor, poplar::Tensor, poplar::Tensorpopnn::ctc_infer::beamSearchDecoderLogProbabilities (poplar::Graph &graph, const poplar::Tensor &logProbs, const poplar::Tensor &dataLengths, poplar::program::Sequence &prog, unsigned blankClass, unsigned beamwidth, unsigned topPaths, const ctc::Plan &plan, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
 Calculate the most likely topPaths labels and their probabilities given the input logProbs with lengths dataLengths, creating and mapping the result tensors according to the plan provided. More...
 
std::tuple< poplar::Tensor, poplar::Tensor, poplar::Tensorpopnn::ctc_infer::beamSearchDecoderLogits (poplar::Graph &graph, const poplar::Tensor &logits, const poplar::Tensor &dataLengths, poplar::program::Sequence &prog, unsigned blankClass, unsigned beamwidth, unsigned topPaths, const ctc::Plan &plan, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
 Calculate the most likely topPaths labels and their probabilities given the input logits with lengths dataLengths, creating and mapping the result tensors according to the plan provided. More...
 

Detailed Description

Support for Connectionist Temporal Classification (CTC) Beam search decoder.

Function Documentation

◆ beamSearchDecoderLogits()

std::tuple< poplar::Tensor, poplar::Tensor, poplar::Tensor > popnn::ctc_infer::beamSearchDecoderLogits ( poplar::Graph graph,
const poplar::Tensor logits,
const poplar::Tensor dataLengths,
poplar::program::Sequence prog,
unsigned  blankClass,
unsigned  beamwidth,
unsigned  topPaths,
const ctc::Plan plan,
const poplar::DebugContext debugContext = {},
const poplar::OptionFlags options = {} 
)

Calculate the most likely topPaths labels and their probabilities given the input logits with lengths dataLengths, creating and mapping the result tensors according to the plan provided.

Prior to performing the beam search, applies log softmax to logits input.

Parameters
graphThe graph the operation will be added to
logitsThe data input [maxTime, batchSize, numClasses] tensor
dataLengthsA tensor of shape [batchSize] containing the number of valid timesteps in each logits batch entry
progA program sequence to append the operation to
blankClassThe value associated with the blankClass
beamWidthThe number of beams to use when decoding
topPathsThe number of most likely decoded paths to return, must be less than or equal to beamWidth
planThe plan which will specify how the output tensor is to be mapped and how the operation is to be carried out
debugContextOptional debug information
optionsAny implementation/debug options for the operation
Returns
The labelProbs[batchSize, topPaths] (negative log probability with the same type as logits), labelLengths[batchSize, topPaths] and decodedLabels [batchSize, topPaths, maxTime] tensors

◆ beamSearchDecoderLogProbabilities()

std::tuple< poplar::Tensor, poplar::Tensor, poplar::Tensor > popnn::ctc_infer::beamSearchDecoderLogProbabilities ( poplar::Graph graph,
const poplar::Tensor logProbs,
const poplar::Tensor dataLengths,
poplar::program::Sequence prog,
unsigned  blankClass,
unsigned  beamwidth,
unsigned  topPaths,
const ctc::Plan plan,
const poplar::DebugContext debugContext = {},
const poplar::OptionFlags options = {} 
)

Calculate the most likely topPaths labels and their probabilities given the input logProbs with lengths dataLengths, creating and mapping the result tensors according to the plan provided.

Parameters
graphThe graph the operation will be added to
logProbsThe data input [maxTime, batchSize, numClasses] tensor
dataLengthsA tensor of shape [batchSize] containing the number of valid timesteps in each logProbs batch entry
progA program sequence to append the operation to
blankClassThe value associated with the blankClass
beamWidthThe number of beams to use when decoding
topPathsThe number of most likely decoded paths to return, must be less than or equal to beamWidth
planThe plan which will specify how the output tensor is to be mapped and how the operation is to be carried out
debugContextOptional debug information
optionsAny implementation/debug options for the operation
Returns
The labelProbs[batchSize, topPaths] (negative log probability with the same type as logProbs), labelLengths[batchSize, topPaths] and decodedLabels [batchSize, topPaths, maxTime] tensors

◆ createDataInput()

poplar::Tensor popnn::ctc_infer::createDataInput ( poplar::Graph graph,
const poplar::Type type,
const std::size_t  batchSize,
const std::size_t  maxTime,
const std::size_t  numClasses,
const ctc::Plan plan,
const poplar::DebugContext debugContext = {} 
)

Create and map a data input [maxTime, batchSize, numClasses] tensor which the beam search function will use.

Mapping is according to the plan provided.

Parameters
graphThe graph the data tensor will be added to
typeThe data type of the tensor to be added to the graph
batchSizeThe size of the batch to be processed at once
maxTimeThe time dimension of the tensor to be created
numClassesThe number of symbols/classes in the "alphabet", including the blankClass
planThe plan which will specify how the tensor is to be mapped
debugContextOptional debug information
Returns
The data input [maxTime, batchSize, numClasses] tensor

◆ plan()

ctc::Plan popnn::ctc_infer::plan ( const poplar::Graph graph,
const poplar::Type inType,
unsigned  batchSize,
unsigned  maxTime,
unsigned  numClasses,
unsigned  beamwidth,
const poplar::OptionFlags options = {} 
)

Create a plan for implementing the CTC Beam search inference function.

CTC Beam search inference options

  • partialsType poplar::Type [=poplar::FLOAT]

    The type to use for partial results.

  • availableMemoryProportion Decimal between 0 and 1 (inclusive) [=0.6]

    The maximum proportion of available memory on each tile that this layer should consume temporarily during the course of the operation.

Parameters
graphThe graph the operation will be added to
inTypeThe data type of the probability data input
batchSizeThe size of the batch to be processed at once
maxTimeThe maximum time of any sequence input
numClassesThe number of symbols/classes in the "alphabet", including the blankClass
beamwidthThe number of beams to maintain during beamsearch
optionsAny implementation/debug options for the operation
Returns
plan The plan produced, which will specify how the operation is to be implemented