SprintControl

This is the Sprint interface implementation, concretely for Sprint PythonControl, Sprint PythonSegmentOrder and Sprint SprintNnPythonLayer. For reference, in Sprint code, see:

  • src/Nn/PythonControl.cc
  • src/Tools/NnTrainer/python_control_demo.py

This interface will behave similar as SprintExternInterface. See SprintErrorSignals for the other end. It can also be used as a PythonSegmentOrdering interface. It also supports SprintNnPythonLayer.

class SprintControl.PythonControl(c2p_fd, p2c_fd, **kwargs)[source]

This will send data to CRNN over a pipe. We expect that we are child process and the parent process has spawned us,

An instance of this class is also the interface for multiple Sprint interfaces, i.e.:
  • PythonControl (standalone via NnTrainer tool)
  • PythonControl (via SegmentwiseNnTrainer)
  • implicitly PythonSegmentOrder (see code above)
Parameters:
  • c2p_fd (int) – child-to-parent file descriptor
  • p2c_fd (int) – parent-to-child file descriptor
Version = 1[source]
check_control_loop_running()[source]
close()[source]
classmethod create(**kwargs)[source]
exit(**kwargs)[source]

Called by Sprint.

get_current_seg_posteriors(seg_len)[source]
Parameters:seg_len (int) – just for double checking, the length of the current segment
Returns:matrix (time,label)
handle_cmd(cmd, *args)[source]
handle_cmd_exit()[source]
handle_cmd_export_allophone_state_fsa_by_segment_name(segment_name)[source]
handle_cmd_get_loss_and_error_signal(seg_name, seg_len, posteriors)[source]
Parameters:
  • seg_name (str) – seg name
  • seg_len (int) – the segment length in frames
  • posteriors (numpy.ndarray) – 2d (time,label) float array

See SprintErrorSignals.SprintSubprocessInstance.get_loss_and_error_signal().

handle_cmd_init(name, version)[source]
handle_next()[source]

Called by self.run_control_loop. We catch some message from our parent process, handle it and send back the result.

init_processing(input_dim=None, output_dim=None, **kwargs)[source]

This is called via Sprint when we use PythonControl to iterate the corpus, i.e. we set –*.action=python-control in Sprint in the NN trainer tool. We expect that we use the Sprint callback to calculate loss and error signal. This is called on the first segment. input_dim/output_dim are set iff we extract features/alignments.

init_segment(segment_name)[source]

Called by Sprint PythonControl in FeedForwardTrainer/SegmentwiseNnTrainer.

instance = None[source]
notify_segment_loss(segment_name, loss)[source]

Called by Sprint PythonControl in FeedForwardTrainer/SegmentwiseNnTrainer.

own_tcb_get_loss_and_error_signal(seg_name, seg_len, posteriors)[source]
own_tcb_version()[source]
own_threaded_callback(cmd, *args)[source]

This is used if we run our own control loop via run_threaded_control_loop.

process_segment(name, orthography, features=None, alignment=None, soft_alignment=None, **kwargs)[source]

This is called via Sprint when we use PythonControl to iterate the corpus. :param str name: segment name :param str orthography: segment orth

run_control_loop(callback, **kwargs)[source]

Called by Sprint when we are in PythonControl run_control_loop mode. Also called by us via self.run_threaded_control_loop().

run_threaded_control_loop()[source]
segment_list_iterator()[source]
set_current_seg_error_signal(seg_len, error_signal)[source]
Parameters:
  • seg_len (int) – just for double checking, the length of the current segment
  • error_signal – matrix (time,label)
set_current_seg_loss(seg_name, loss)[source]
Parameters:
  • seg_name (str|None) – just for double checking, the name of the current segment. might be None
  • loss (float) – the loss of the current seg
class SprintControl.SprintNnPythonLayer(config, **kwargs)[source]

Sprint will directly call this class, i.e. create an instance of it. It implements the Sprint NN PythonLayer interface.

backpropagate(errorSignalIn)[source]
Parameters:errorSignalIn – matrix of format (output_size,time)
Returns:tuple of matrices of format (input_size,time)
finalize()[source]
forward(input)[source]
Parameters:input – tuple of input matrices of format (input_size,time). we ignore them.
Returns:single output matrix of format (output_size,time)
getNumberOfFreeParameters()[source]
initializeNetworkParameters()[source]
isTrainable()[source]
loadNetworkParameters(filename)[source]
saveNetworkParameters(filename)[source]
setInputDimension(stream, size)[source]
setOutputDimension(size)[source]
SprintControl.getSegmentList(corpusName, segmentList, config, **kwargs)[source]

Sprint will directly call this function.

SprintControl.init(name, reference, config, sprint_unit=None, version_number=None, callback=None, **kwargs)[source]

This will be called by Sprint PythonControl. But we also call it ourselves e.g. in getSegmentList() and SprintNnPythonLayer. :param str name: this specifies the caller. e.g. “Sprint.PythonControl” :param reference: this is any object to identify the specific instance of the caller, if there are multiple. :param str config: this will be passed over from Sprint. you can configure that via –*.pymod-config. :param str sprint_unit: if this is called by Sprint PythonControl, this will specify which specific part

of Sprint is using this PythonControl, because there can be multiple parts. E.g. there is “FeedForwardTrainer”, “SegmentwiseNnTrainer” and “NnTrainer.pythonControl”.
Parameters:
  • version_number (int|None) – if this is called by Sprint PythonControl, this will set the version number. only newer Sprint versions will set this.
  • callback (function|None) – if this is called by Sprint PythonControl, this might provide a callback. Only newer Sprint versions will provide this to init(). This callback can be used for many different actions. It’s supposed to be called like callback(action, **other_args), where action is a string. See Sprint PythonControl code about the possible actions and arguments.
  • kwargs – all remaining args are specific for each caller.

In this specific module, we expect that there is “c2p_fd” and “p2c_fd” in the config string to communicate with the parent process, which is usually handled by SprintErrorSignals.

SprintControl.print(*args, **kwargs)[source]