<commit_before>package ml.dmlc.mxnet
import org.slf4j.LoggerFactory

/**
 * Learning rate scheduler, which adaptively changes the learning rate
 * based on the training progress.
 * @author <NAME>
 */

abstract class LRScheduler(var baseLR: Double = 0.01) {
  /**
   * Base class of a learning rate scheduler
   *
   * The training progress is presented by `num_update`, which can be roughly
   * viewed as the number of minibatches executed so far. Its value is
   * non-decreasing, and increases at most by one.
   *
   * The exact value is the upper bound of the number of updates applied to
   * a weight/index.
   *
   * @param numUpdate Int, the maximal number of updates applied to a weight.
   */
  def apply(numUpdate: Int): Double
}

/**
 * Class for reducing learning rate in factor
 *
 * Assume the weight has been updated by n times, then the learning rate will
 * be base_lr * factor^^(floor(n/step))
 *
 * @param step Int, schedule learning rate after n updates
 * @param factor Float, the factor for reducing the learning rate
 *
 */
class FactorScheduler(var step: Int, var factor: Float) extends LRScheduler {

  var count: Int = 0
  private val logger = LoggerFactory.getLogger(classOf[FactorScheduler])

  if (step < 1) {
    throw new IllegalArgumentException("Schedule step must be greater or equal than 1 round")
  }
  if (factor >= 1.0) {
    throw new IllegalArgumentException("Factor must be less than 1 to make lr reduce")
  }

  def apply(numUpdate: Int): Double = {

    if (numUpdate > this.count + this.step) {
      this.count += this.step
      this.baseLR *= this.factor
      this.logger.info(s"""Update$numUpdate: Change learning rate to ${this.baseLR}""")
    }
    this.baseLR
  }
}
<commit_msg>Change error throw to require<commit_after>package ml.dmlc.mxnet
import org.slf4j.LoggerFactory

/**
 * Learning rate scheduler, which adaptively changes the learning rate
 * based on the training progress.
 * @author Yuan Tang
 */

abstract class LRScheduler(var baseLR: Double = 0.01) {
  /**
   * Base class of a learning rate scheduler
   *
   * The training progress is presented by `num_update`, which can be roughly
   * viewed as the number of minibatches executed so far. Its value is
   * non-decreasing, and increases at most by one.
   *
   * The exact value is the upper bound of the number of updates applied to
   * a weight/index.
   *
   * @param numUpdate Int, the maximal number of updates applied to a weight.
   */
  def apply(numUpdate: Int): Double
}

/**
 * Class for reducing learning rate in factor
 *
 * Assume the weight has been updated by n times, then the learning rate will
 * be base_lr * factor^^(floor(n/step))
 *
 * @param step Int, schedule learning rate after n updates
 * @param factor Float, the factor for reducing the learning rate
 *
 */
class FactorScheduler(var step: Int, var factor: Float) extends LRScheduler {

  var count: Int = 0
  private val logger = LoggerFactory.getLogger(classOf[FactorScheduler])

  require(step < 1, "Schedule step must be greater or equal than 1 round")
  require(factor >= 1.0, "Factor must be less than 1 to make lr reduce")

  def apply(numUpdate: Int): Double = {

    if (numUpdate > this.count + this.step) {
      this.count += this.step
      this.baseLR *= this.factor
      this.logger.info(s"""Update$numUpdate: Change learning rate to ${this.baseLR}""")
    }
    this.baseLR
  }
}

{'fraction_non_alphanumeric': 0.0910960916838084, 'fraction_numerical': 0.0058771672054069935, 'mean_word_length': 3.38659793814433, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '678384', 'n_tokens_mistral': 1014, 'n_tokens_neox': 979, 'n_words': 407}