<commit_before>module Atlas
  class Dataset::DerivedDataset < Dataset
    GRAPH_FILENAME = 'graph.yml'.freeze

    attribute :base_dataset, String
    attribute :scaling,      Preset::Scaling
    attribute :init,         Hash

    validates :scaling, presence: true

    validate :base_dataset_exists
    validate :scaling_valid

    def graph
      @graph ||= GraphDeserializer.build(YAML.load_file(graph_path))
    end

    def graph_path
      File.join(directory, key.to_s, GRAPH_FILENAME)
    end

    # Overwrite
    def dataset_dir
      @dataset_dir ||= Atlas.data_dir.join(DIRECTORY, base_dataset)
    end

    private

    def base_dataset_exists
      unless Dataset::FullDataset.exists?(base_dataset)
        errors.add(:base_dataset, 'does not exist')
      end
    end

    def scaling_valid
      if scaling
        scaling.valid?<commit_msg>Add type coercion for initializer inputs<commit_after>module Atlas
  class Dataset::DerivedDataset < Dataset
    GRAPH_FILENAME = 'graph.yml'.freeze

    attribute :base_dataset, String
    attribute :scaling,      Preset::Scaling
    attribute :init,         Hash[Symbol => Float]

    validates :scaling, presence: true

    validate :base_dataset_exists
    validate :scaling_valid

    def graph
      @graph ||= GraphDeserializer.build(YAML.load_file(graph_path))
    end

    def graph_path
      File.join(directory, key.to_s, GRAPH_FILENAME)
    end

    # Overwrite
    def dataset_dir
      @dataset_dir ||= Atlas.data_dir.join(DIRECTORY, base_dataset)
    end

    private

    def base_dataset_exists
      unless Dataset::FullDataset.exists?(base_dataset)
        errors.add(:base_dataset, 'does not exist')
      end
    end

    def scaling_valid
      if scaling
        scaling.valid?
{'fraction_non_alphanumeric': 0.07622298065984073, 'fraction_numerical': 0.0, 'mean_word_length': 2.908888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '1195593', 'n_tokens_mistral': 558, 'n_tokens_neox': 519, 'n_words': 121}