<commit_before>__all__ = ["SingleLayerRegularizer_ABC", "L1", "L2"]

class SingleLayerRegularizer_ABC(object) :
	"""An abstract regularization to be applied to a layer."""

	def __init__(self, factor, *args, **kwargs) :
		self.name = self.__class__.__name__
		self.factor = factor
		self.hyperparameters = ["factor"]

	def getFormula(self, layer) :
		"""Returns the expression to be added to the cost"""
		raise NotImplemented("Must be implemented in child")

class L1(SingleLayerRegularizer_ABC) :
	"""
	Will add this to the cost
	.. math::

			factor * abs(Weights)
	"""

	def getFormula(self, layer) :
		# print "ssss L1" 
		return self.factor * ( abs(layer.W).sum() )

class L2(SingleLayerRegularizer_ABC) :
	"""
	Will add this to the cost
	.. math::

			factor * (Weights)^2
	"""

	def getFormula(self, layer) :
		# print "pppp L2" 
		return self.factor * ( (layer.W * layer.W).sum() )<commit_msg>removed factor from ABC constructor<commit_after>__all__ = ["SingleLayerRegularizer_ABC", "L1", "L2"]

class SingleLayerRegularizer_ABC(object) :
	"""An abstract regularization to be applied to a layer."""

	def __init__(self, *args, **kwargs) :
		self.name = self.__class__.__name__

	def getFormula(self, layer) :
		"""Returns the expression to be added to the cost"""
		raise NotImplemented("Must be implemented in child")

class L1(SingleLayerRegularizer_ABC) :
	"""
	Will add this to the cost
	.. math::

			factor * abs(Weights)
	"""
	def __init__(self, factor) :
		SingleLayerRegularizer_ABC.__init__(self)
		self.factor = factor
		self.hyperparameters = ["factor"]

	def getFormula(self, layer) :
		return self.factor * ( abs(layer.W).sum() )

class L2(SingleLayerRegularizer_ABC) :
	"""
	Will add this to the cost
	.. math::

			factor * (Weights)^2
	"""
	def __init__(self, factor) :
		SingleLayerRegularizer_ABC.__init__(self)
		self.factor = factor
		self.hyperparameters = ["factor"]

	def getFormula(self, layer) :
		return self.factor * ( (layer.W * layer.W).sum() )
{'fraction_non_alphanumeric': 0.13666162380231972, 'fraction_numerical': 0.006051437216338881, 'mean_word_length': 4.304812834224599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '632539', 'n_tokens_mistral': 720, 'n_tokens_neox': 656, 'n_words': 179}