# ReferentialGym.modules package

## Submodules

## ReferentialGym.modules.batch_reshape_module module

`ReferentialGym.modules.batch_reshape_module.``build_BatchReshapeModule`(id: str, config: Dict[str, object], input_stream_keys: List[str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.batch_reshape_module.``BatchReshapeModule`(id: str, config: Dict[str, object], input_stream_keys: List[str])

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.batch_reshape_repeat_module module

`ReferentialGym.modules.batch_reshape_repeat_module.``build_BatchReshapeRepeatModule`(id: str, config: Dict[str, object], input_stream_keys: List[str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.batch_reshape_repeat_module.``BatchReshapeRepeatModule`(id: str, config: Dict[str, object], input_stream_keys: List[str])

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.concat_module module

`ReferentialGym.modules.concat_module.``build_ConcatModule`(id: str, config: Dict[str, object], input_stream_keys: List[str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.concat_module.``ConcatModule`(id: str, config: Dict[str, object], input_stream_keys: List[str])

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.current_agent_module module

class `ReferentialGym.modules.current_agent_module.``CurrentAgentModule`(id='current_agent', role=None)

  Bases: `ReferentialGym.modules.module.Module`

  `set_ref`(agent)
  `get_input_stream_ids`()
  `clone`(clone_id='a0')
  `save`(path)
  `_tidyup`()
  `_log`(log_dict, batch_size)
  `register_hook`(hook)
  `forward`(sentences, experiences, multi_round=False, graphtype='straight_through_gumbel_softmax', tau0=0.2)
    Parameters

      - sentences – Tensor of shape (batch_size, max_sentence_length, vocab_size) containing the padded sequence of (potentially one-hot-encoded) symbols.

      - experiences – Tensor of shape (batch_size, *self.obs_shape). Make sure to shuffle the experiences so that the order does not give away the target.

      - multi_round – Boolean defining whether to utter a sentence back or not.

      - graphtype – String defining the type of symbols used in the output sentence: - ‘categorical’: one-hot-encoded symbols. - ‘gumbel_softmax’: continuous relaxation of a categorical distribution. - ‘straight_through_gumbel_softmax’: improved continuous relaxation… - ‘obverter’: obverter training scheme…

      - tau0 – Float, temperature with which to apply gumbel-softmax estimator.

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Compute the losses and return them along with the produced outputs.

    Parameters

      input_streams_dict –

      Dict that should contain, at least, the following keys and values: - ‘sentences_logits’: Tensor of shape (batch_size, max_sentence_length, vocab_size) containing the padded sequence of logits over symbols. - ‘sentences_widx’: Tensor of shape (batch_size, max_sentence_length, 1) containing the padded sequence of symbols’ indices. - ‘sentences_one_hot’: Tensor of shape (batch_size, max_sentence_length, vocab_size) containing the padded sequence of one-hot-encoded symbols. - ‘experiences’: Tensor of shape (batch_size, *self.obs_shape). - ‘exp_latents’: Tensor of shape (batch_size, nbr_latent_dimensions). - ‘multi_round’: Boolean defining whether to utter a sentence back or not. - ‘graphtype’: String defining the type of symbols used in the output sentence:

      > - ’categorical’: one-hot-encoded symbols.

      > - ’gumbel_softmax’: continuous relaxation of a categorical distribution.

      > - ’straight_through_gumbel_softmax’: improved continuous relaxation…

      > - ’obverter’: obverter training scheme…

      - ’tau0’: Float, temperature with which to apply gumbel-softmax estimator.

      - ’sample’: Dict that contains the speaker and listener experiences as well as the target index.

      - ’config’: Dict of hyperparameters to the referential game.

      - ’mode’: String that defines what mode we are in, e.g. ‘train’ or ‘test’. Those keywords are expected.

      - ’it’: Integer specifying the iteration number of the current function call.

## ReferentialGym.modules.dsprites_per_latent_accuracy_metric_module module

`ReferentialGym.modules.dsprites_per_latent_accuracy_metric_module.``build_dSpritesPerLatentAccuracyMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.dsprites_per_latent_accuracy_metric_module.``dSpritesPerLatentAccuracyMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.factor_vae_disentanglement_metric_module module

`ReferentialGym.modules.factor_vae_disentanglement_metric_module.``build_FactorVAEDisentanglementMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.factor_vae_disentanglement_metric_module.``FactorVAEDisentanglementMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `_prune_dims`(variances)

    Mask for dimensions collapsed to the prior.

  `_generate_training_batch`(dataset, model, batch_size, nbr_points, global_variances, active_dims)

    Sample a set of training samples based on a batch of ground-truth data.

    Args:

      dataset: dataset to be sampled from. model: model that takes observations as input and

      > outputs a dim_representation sized representation for each observation.

      batch_size: Number of points to be used to compute the training_sample. nbr_points: Number of points to be sampled for training/evaluation set. global_variances: Numpy vector with variances for all dimensions of

      > representation.

      active_dims: Indexes of active dimensions.

    Returns:

      (num_factors, dim_representation)-sized numpy array with votes.

  `_generate_training_sample`(dataset, model, batch_size, global_variances, active_dims)

    Sample a single training sample based on a mini-batch of ground-truth data.

    Args: dataset: dataset to be sampled from. model: model that takes observation as input and

    > outputs a representation.

    batch_size: Number of points to be used to compute the training_sample. global_variances: Numpy vector with variances for all dimensions of

    > representation.

    active_dims: Indexes of active dimensions.

    Returns:

      factor_index: Index of factor coordinate to be used. argmin: Index of representation coordinate with the least variance.

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.flatten_module module

`ReferentialGym.modules.flatten_module.``build_FlattenModule`(id: str, input_stream_keys: List[str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.flatten_module.``FlattenModule`(id: str, input_stream_keys: List[str])

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.grad_recorder_module module

`ReferentialGym.modules.grad_recorder_module.``build_GradRecorderModule`(id: str, config: Dict[str, object] = None, input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.grad_recorder_module.``GradRecorderModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.homoscedastic_multi_task_loss_module module

`ReferentialGym.modules.homoscedastic_multi_task_loss_module.``build_HomoscedasticMultiTasksLossModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.homoscedastic_multi_task_loss_module.``HomoscedasticMultiTasksLossModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.instantaneous_coordination_metric_module module

`ReferentialGym.modules.instantaneous_coordination_metric_module.``build_InstantaneousCoordinationMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.instantaneous_coordination_metric_module.``InstantaneousCoordinationMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.module module

class `ReferentialGym.modules.module.``Module`(id: str, type: str, config: Dict[str, object], input_stream_ids: Dict[str, str])

  Bases: `torch.nn.modules.module.Module`

  `get_id`() → str
  `get_type`() → str
  `get_input_stream_ids`() → Dict[str, str]
  `compute`(inputs_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      inputs_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys -named streams.

    Returns

      - outputs_sream_dict:

## ReferentialGym.modules.multi_head_classification_from_feature_map_module module

`ReferentialGym.modules.multi_head_classification_from_feature_map_module.``build_MultiHeadClassificationFromFeatureMapModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.multi_head_classification_from_feature_map_module.``MultiHeadClassificationFromFeatureMapModule`(id: str, config: Dict[str, object], heads: torch.nn.modules.container.ModuleList, input_stream_ids: Dict[str, str], final_fn: torch.nn.modules.module.Module = Softmax(dim=- 1))

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.multi_head_classification_module module

`ReferentialGym.modules.multi_head_classification_module.``build_MultiHeadClassificationModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.multi_head_classification_module.``MultiHeadClassificationModule`(id: str, config: Dict[str, object], heads: torch.nn.modules.container.ModuleList, input_stream_ids: Dict[str, str], final_fn: torch.nn.modules.module.Module = Softmax(dim=- 1))

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.multi_head_regression_module module

`ReferentialGym.modules.multi_head_regression_module.``build_MultiHeadRegressionModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.multi_head_regression_module.``MultiHeadRegressionModule`(id: str, config: Dict[str, object], heads: torch.nn.modules.container.ModuleList, input_stream_ids: Dict[str, str], final_fn: torch.nn.modules.module.Module = Softmax(dim=- 1))

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.optimization_module module

`ReferentialGym.modules.optimization_module.``build_OptimizationModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.optimization_module.``OptimizationModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.per_epoch_logger_module module

`ReferentialGym.modules.per_epoch_logger_module.``build_PerEpochLoggerModule`(id: str, config: Dict[str, object] = None, input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.per_epoch_logger_module.``PerEpochLoggerModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.population_handler_module module

`ReferentialGym.modules.population_handler_module.``build_PopulationHandlerModule`(id: str, prototype_speaker: ReferentialGym.modules.module.Module, prototype_listener: ReferentialGym.modules.module.Module, config: Dict[str, object], input_stream_ids: Dict[str, str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.population_handler_module.``PopulationHandlerModule`(id: str, prototype_speaker: ReferentialGym.modules.module.Module, prototype_listener: ReferentialGym.modules.module.Module, config: Dict[str, object], input_stream_ids: Dict[str, str])

  Bases: `ReferentialGym.modules.module.Module`

  `_select_agents`()
  `bookkeeping`(mode, epoch)
  `_reptile_step`(learner, reptile_learner, nbr_grad_steps=1, verbose=False)
  `_apply_meta_update`(meta_learner, meta_optimizer, learner)
  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.squeeze_module module

`ReferentialGym.modules.squeeze_module.``build_SqueezeModule`(id: str, config: Dict[str, object], input_stream_keys: List[str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.squeeze_module.``SqueezeModule`(id: str, config: Dict[str, object], input_stream_keys: List[str])

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## ReferentialGym.modules.topographic_similarity_metric_module module

`ReferentialGym.modules.topographic_similarity_metric_module.``build_TopographicSimilarityMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.topographic_similarity_metric_module.``TopographicSimilarityMetricModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str] = None)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

## ReferentialGym.modules.visual_module module

`ReferentialGym.modules.visual_module.``build_VisualModule`(id: str, config: Dict[str, object], input_stream_ids: Dict[str, str]) → ReferentialGym.modules.module.Module

class `ReferentialGym.modules.visual_module.``VisualModule`(id, encoder, featout_converter, featout_normalization, config, input_stream_ids)

  Bases: `ReferentialGym.modules.module.Module`

  `compute`(input_streams_dict: Dict[str, object]) → Dict[str, object]

    Operates on inputs_dict that is made up of referents to the available stream. Make sure that accesses to its element are non-destructive.

    Parameters

      input_streams_dict – dict of str and data elements that follows self.input_stream_ids’s keywords and are extracted from self.input_stream_keys-named streams.

    Returns

      - outputs_stream_dict:

## Module contents