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.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]

Sprint API.

Parameters:
  • callback ((str,)->object) –
  • version_number (int) –
  • sprint_opts (dict[str,str]) –
init(self, input_dim, output_dim)[source]

Called by Sprint.

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

Called by Sprint at exit.

get_feature_buffer_size(self)[source]

Called by Sprint.

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

Called by Sprint.

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

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

Parameters:num_frames (int) –
get_segment_name(self)[source]
Return type:str
get_features(self, num_frames=None)[source]
Parameters:num_frames (int|None) –
Returns:shape (input_dim, num_frames)
Return type:numpy.ndarray
get_posteriors(self, num_frames=None)[source]
Parameters:num_frames (int|None) –
Returns:shape (output_dim, num_frames)
Return type:numpy.ndarray
features_to_dataset(self, 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(self, num_frames)[source]

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

Parameters:num_frames (int) –
get_scores(self, 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]

Called by Sprint at exit.

SprintInterface.feedInput(features, weights=None, segmentName=None)[source]
Parameters:
  • features (numpy.ndarray) –
  • weights (numpy.array|None) –
  • segmentName (str|None) –
Returns:

posteriors

Return type:

numpy.ndarray

SprintInterface.finishDiscard()[source]

Discard some segment.

SprintInterface.finishError(error, errorSignal, naturalPairingType=None)[source]
Parameters:
  • error (float|numpy.ndarray) –
  • errorSignal (numpy.ndarray) –
  • naturalPairingType (str|None) – must be “softmax”
Returns:

nothing

SprintInterface.feedInputAndTarget(features, weights=None, segmentName=None, orthography=None, alignment=None, speaker_name=None, speaker_gender=None, **kwargs)[source]
Parameters:
  • features (numpy.ndarray) –
  • weights (numpy.ndarray|None) –
  • segmentName (str|None) –
  • orthography (str|None) –
  • alignment (numpy.ndarray|None) –
  • speaker_name (str|None) –
  • speaker_gender (str|None) –
Returns:

nothing

SprintInterface.feedInputAndTargetAlignment(features, targetAlignment, weights=None, segmentName=None)[source]
Parameters:
  • features (numpy.ndarray) –
  • targetAlignment (numpy.ndarray) –
  • weights (numpy.ndarray|None) –
  • segmentName (str|None) –
Returns:

nothing

SprintInterface.feedInputAndTargetSegmentOrth(features, targetSegmentOrth, weights=None, segmentName=None)[source]
Parameters:
  • features (numpy.ndarray) –
  • targetSegmentOrth (str) –
  • weights (numpy.ndarray|None) –
  • segmentName
Returns:

SprintInterface.feedInputUnsupervised(features, weights=None, segmentName=None)[source]
Parameters:
  • features (numpy.ndarray) –
  • weights (numpy.ndarray|None) –
  • segmentName (str|None) –
Returns:

nothing

SprintInterface.feedInputForwarding(features, weights=None, segmentName=None)[source]
Parameters:
  • features (numpy.ndarray) –
  • weights (numpy.ndarray|None) –
  • segmentName (str|None) –
Return type:

numpy.ndarray

SprintInterface.dump_flags()[source]

Dump some relevant env flags.

SprintInterface.set_target_mode(mode)[source]
Parameters:mode (str) – target mode
SprintInterface.get_final_epoch()[source]
Return type:int
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.make_criterion_class()[source]

Make Criterion Theano class.

SprintInterface.demo()[source]

Demo for SprintInterface.