SprintInterface

This is a Sprint interface implementation, i.e. you would specify this module in your Sprint config. (Sprint = the RWTH ASR toolkit.) Note that there are multiple Sprint interface implementations provided. This one would be used explicitly, e.g. for forwarding in recognition or wherever else Sprint needs posteriors (a FeatureScorer). Most of the other Sprint interfaces will be used automatically, e.g. via ExternSprintDataset, when it spawns its Sprint subprocess.

SprintInterface.config = None[source]
Type:rnn.Config
SprintInterface.sprintDataset = None[source]
Type:SprintDatasetBase
SprintInterface.engine = None[source]
Type:TFEngine.Engine|Engine
SprintInterface.init(name=None, sprint_unit=None, **kwargs)[source]

This will get called by various Sprint interfaces. Depending on name and sprint_unit, we can figure out which interface it is. For all PythonControl-based interfaces, we must return an object which will be used for further callbacks.

Parameters:
  • name (str|None) –
  • sprint_unit (str|None) –
Returns:

some object or None

Return type:

None|object

SprintInterface.init_python_feature_scorer(config, **kwargs)[source]
Parameters:config (str) –
Return type:PythonFeatureScorer
class SprintInterface.PythonFeatureScorer(callback, version_number, sprint_opts, **kwargs)[source]
Parameters:
  • callback ((str,)->object) –
  • version_number (int) –
  • sprint_opts (dict[str,str]) –
init(input_dim, output_dim)[source]

Called by Sprint.

Parameters:
  • input_dim (int) –
  • output_dim (int) – number of emission classes
exit()[source]
get_feature_buffer_size()[source]

Called by Sprint.

Returns:-1 -> no limit
add_feature(feature, time)[source]

Called by Sprint.

Parameters:
  • feature (numpy.ndarray) – shape (input_dim,)
  • time (int) –
reset(num_frames)[source]

Called by Sprint. Called when we shall flush any buffers.

Parameters:num_frames (int) –
get_segment_name()[source]
get_features(num_frames=None)[source]
Parameters:num_frames (int|None) –
Returns:shape (input_dim, num_frames)
Return type:numpy.ndarray
get_posteriors(num_frames=None)[source]
Parameters:num_frames (int|None) –
Returns:shape (output_dim, num_frames)
Return type:numpy.ndarray
features_to_dataset(num_frames=None)[source]
Parameters:num_frames (int|None) –
Returns:(dataset, seq_idx)
Return type:(Dataset.Dataset, int)
engine[source]
Return type:TFEngine.Engine|Engine.Engine
config[source]
Return type:Config.Config
compute(num_frames)[source]

Called by Sprint. All the features which we received so far should be evaluated.

Parameters:num_frames (int) –
get_scores(time)[source]

Called by Sprint.

Parameters:time (int) –
Returns:shape (output_dim,)
Return type:numpy.ndarray
SprintInterface.getSegmentList(corpusName, segmentList, **kwargs)[source]

Called by Sprint PythonSegmentOrder. Set python-segment-order = true in Sprint to use this.

If this is used, this gets called really early. If it is used together with the Sprint PythonTrainer, it will get called way earlier before the init() below. It might also get called multiple times, e.g. if Sprint is in interactive mode to calc the seg count. This is optional. You can use the SprintInterface only for the PythonTrainer.

Return type:list[str]

:returns segment list. Can also be an iterator.

SprintInterface.init_python_trainer(inputDim, outputDim, config, targetMode, **kwargs)[source]

Called by Sprint when it initializes the PythonTrainer. Set trainer = python-trainer in Sprint to enable. Note that Sprint will call this, i.e. the trainer init lazily quite late, only once it sees the first data.

Parameters:
  • config (str) – config string, passed by Sprint. assumed to be “,”-separated
  • targetMode (str) – “target-alignment” or “criterion-by-sprint” or so
Returns:

not expected to return anything

Return type:

None

SprintInterface.exit()[source]
SprintInterface.feedInput(features, weights=None, segmentName=None)[source]
SprintInterface.finishDiscard()[source]
SprintInterface.finishError(error, errorSignal, naturalPairingType=None)[source]
SprintInterface.feedInputAndTarget(features, weights=None, segmentName=None, orthography=None, alignment=None, speaker_name=None, speaker_gender=None, **kwargs)[source]
SprintInterface.feedInputAndTargetAlignment(features, targetAlignment, weights=None, segmentName=None)[source]
SprintInterface.feedInputAndTargetSegmentOrth(features, targetSegmentOrth, weights=None, segmentName=None)[source]
SprintInterface.feedInputUnsupervised(features, weights=None, segmentName=None)[source]
SprintInterface.feedInputForwarding(features, weights=None, segmentName=None)[source]
SprintInterface.dumpFlags()[source]
SprintInterface.setTargetMode(mode)[source]
Parameters:mode (str) – target mode
SprintInterface.initBase(configfile=None, targetMode=None, epoch=None)[source]
Parameters:
  • configfile (str|None) – filename, via init(), this is set
  • targetMode (str|None) – “forward” or so. via init(), this is set
  • epoch (int) – via init(), this is set
SprintInterface.startTrainThread(epoch=None)[source]
SprintInterface.prepareForwarding()[source]
SprintInterface.initDataset()[source]
SprintInterface.getFinalEpoch()[source]
SprintInterface.train(segmentName, features, targets=None)[source]
Parameters:
  • segmentName (str|None) – full name
  • features (numpy.ndarray) – 2d array
  • targets (numpy.ndarray|dict[str,numpy.ndarray]|None) – 2d or 1d array
SprintInterface.features_to_dataset(features, segment_name)[source]
Parameters:
  • features (numpy.ndarray) – format (input-feature,time) (via Sprint)
  • segment_name (str) –
Returns:

(dataset, seq-idx)

Return type:

(Dataset.Dataset, int)

SprintInterface.forward(segmentName, features)[source]
Parameters:features (numpy.ndarray) – format (input-feature,time) (via Sprint)

:return numpy.ndarray, format (output-dim,time)

class SprintInterface.Criterion[source]
gotPosteriors = <threading.Event object>[source]
gotErrorSignal = <threading.Event object>[source]
posteriors = None[source]
error = None[source]
errorSignal = None[source]
make_node(posteriors, seq_lengths)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, output_storage, params=None)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
node : Apply instance

Contains the symbolic inputs and outputs.

inputs : list

Sequence of inputs (immutable).

output_storage : list

List of mutable 1-element lists (do not change the length of these lists)

Raises:
MethodNotDefined

The subclass does not override this method.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

SprintInterface.demo()[source]