<commit_before>"""Base class for the components in other modules."""
# Standard library imports
import inspect

# Standard library imports
import cPickle
import os.path

# Third-party imports
import theano
from theano import tensor

# Local imports
from .utils import sharedX, subdict

theano.config.warn.sum_div_dimshuffle_bug = False
floatX = theano.config.floatX

if 0:
    print 'WARNING: using SLOW rng'
    RandomStreams = tensor.shared_randomstreams.RandomStreams
else:
    import theano.sandbox.rng_mrg
    RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams

class Block(object):
    """
    Basic building block for deep architectures.
    """
    def params(self):
        """
        Returns a list of *shared* learnable parameters that
        are, in your judgment, typically learned in this
        model.
        """
        # NOTE: We return list(self._params) rather than self._params
        # in order to explicitly make a copy, so that the list isn't
        # absentmindedly modified. If a user really knows what they're
        # doing they can modify self._params.
        return list(self._params)

    def __call__(self, inputs):
        raise NotImplementedError('__call__')

    def save(self, save_file):
        """
        Dumps the entire object to a pickle file.
        Individual classes should override __getstate__ and __setstate__
        to deal with object versioning in the case of API changes.
        """
        save_dir = os.path.dirname(save_file)
        if not os.path.exists(save_dir):
            os.makedirs(save_dir)
        
        fhandle = open(save_file, 'w')
        cPickle.dump(self, fhandle, -1)
        fhandle.close()

    @classmethod
    def fromdict(cls, conf):
        """ Alternative way to build a block, by using a dictionary """
        return cls(**subdict(conf, inspect.getargspec(cls.__init__)[0]))

    @classmethod
    def load(cls, load_file):
        """Load a serialized block."""
        if not os.path.isfile(load_file):
            raise IOError('File %s does not exist' % load_file)
        obj = cPickle.load(open(load_file))
        if isinstance(obj, cls):
            return obj
        else:
            raise TypeError('unpickled object was of wrong class: %s' %
                            obj.__class__)

    def function(self, name=None):<commit_msg>BUGFIX: Properly handle saving to cwd ('./').<commit_after>"""Base class for the components in other modules."""
# Standard library imports
import inspect

# Standard library imports
import cPickle
import os.path

# Third-party imports
import theano
from theano import tensor

# Local imports
from .utils import sharedX, subdict

theano.config.warn.sum_div_dimshuffle_bug = False
floatX = theano.config.floatX

if 0:
    print 'WARNING: using SLOW rng'
    RandomStreams = tensor.shared_randomstreams.RandomStreams
else:
    import theano.sandbox.rng_mrg
    RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams

class Block(object):
    """
    Basic building block for deep architectures.
    """
    def params(self):
        """
        Returns a list of *shared* learnable parameters that
        are, in your judgment, typically learned in this
        model.
        """
        # NOTE: We return list(self._params) rather than self._params
        # in order to explicitly make a copy, so that the list isn't
        # absentmindedly modified. If a user really knows what they're
        # doing they can modify self._params.
        return list(self._params)

    def __call__(self, inputs):
        raise NotImplementedError('__call__')

    def save(self, save_file):
        """
        Dumps the entire object to a pickle file.
        Individual classes should override __getstate__ and __setstate__
        to deal with object versioning in the case of API changes.
        """
        save_dir = os.path.dirname(save_file)
        if save_dir and not os.path.exists(save_dir):
            os.makedirs(save_dir)
        
        fhandle = open(save_file, 'w')
        cPickle.dump(self, fhandle, -1)
        fhandle.close()

    @classmethod
    def fromdict(cls, conf):
        """ Alternative way to build a block, by using a dictionary """
        return cls(**subdict(conf, inspect.getargspec(cls.__init__)[0]))

    @classmethod
    def load(cls, load_file):
        """Load a serialized block."""
        if not os.path.isfile(load_file):
            raise IOError('File %s does not exist' % load_file)
        obj = cPickle.load(open(load_file))
        if isinstance(obj, cls):
            return obj
        else:
            raise TypeError('unpickled object was of wrong class: %s' %
                            obj.__class__)

    def function(self, name=None):
{'fraction_non_alphanumeric': 0.08651614264612788, 'fraction_numerical': 0.0012660898923823592, 'mean_word_length': 2.5479041916167664, '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': '2504911', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1339, 'n_words': 441}