72cc9dd414ee4befbadf9bd3e4804cb2e0908e9c,allennlp/nn/initializers.py,InitializerApplicator,from_params,#Any#Any#,86
Before Change
// Construct a dictionary of available initializers from the torch.nn.init package.
all_initializer_params = params.pop("initializers", {}).as_dict()
instantiated_initializers = {}
for name, initializer_params in all_initializer_params.items():
// Just a string - corresponds to the name of an initializer.
if isinstance(initializer_params, str):
instantiated_initializers[name] = Initializer.by_name(initializer_params)
else:
initializer_type = initializer_params.pop("type")
// This is to avoid passing by reference inside the curried function.
// Without creating a new dict, we would pass the value of initializer_params
// when it is called, which could be different as it is a loop variable.
init_params = {**initializer_params}
// pylint: disable=cell-var-from-loop
def curried_initializer(tensor: torch.Tensor):
return Initializer.by_name(initializer_type)(tensor, **init_params) // type: ignore
// pylint: enable=cell-var-from-loop
instantiated_initializers[name] = curried_initializer // type: ignore
try:
default = instantiated_initializers.pop("default")
except KeyError:
default = torch.nn.init.normal
After Change
initializers = {}
for name, initializer_params in all_initializer_params.items():
initializers[name] = Initializer.from_params(initializer_params)
default = initializers.pop("default", Initializer.by_name("normal")())
exclude_regexes = params.pop("exclude", [])
return InitializerApplicator(initializers, default, exclude_regexes)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances
Project Name: allenai/allennlp
Commit Name: 72cc9dd414ee4befbadf9bd3e4804cb2e0908e9c
Time: 2017-08-07
Author: mattg@allenai.org
File Name: allennlp/nn/initializers.py
Class Name: InitializerApplicator
Method Name: from_params
Project Name: dask/distributed
Commit Name: db758d0f8609dd0fa041b212ecc89a088b57291e
Time: 2018-06-23
Author: mrocklin@gmail.com
File Name: distributed/deploy/adaptive.py
Class Name: Adaptive
Method Name: _adapt
Project Name: scipy/scipy
Commit Name: f7d35c59de44cda5dad4cab3aabc098633b9374e
Time: 2014-09-09
Author: cjk34@cam.ac.uk
File Name: scipy/integrate/setup.py
Class Name:
Method Name: configuration