Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

learning-rate-scaler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

learning-rate-scaler

Learning rate scaler callback for @tensorflow/tfjs

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Learning rate scaler callback

Learning rate scaler callback for @tensorflow/tfjs

Installation

Package available via:

  • NPM npm install learning-rate-scaler

Usage

Module exports LearningRateCallback and example function sineWaveRateScaler = (min, max, frequency, maxLearningRateDecay, earningRateDecayPerEpoch) to use with it. (also a default LearningRateCallback scaler function).

  • example 1

LearningRateCallback with defaults

import {
  LearningRateCallback,
  sineWaveRateScaler,
} from "learning-rate-scaler";

const learningRateCallback = new LearningRateCallback()

const inputs = input({
  shape: [1],
});
const y1 = dense({ units: 1, name: "y1" }).apply(inputs);
let layersModel = model({
  inputs: inputs,
  outputs: [y1],
});
layersModel.compile({
    optimizer: train.sgd(0.001),
    loss: {
      y1: "meanAbsoluteError",
    },
});
const history = await layersModel.fitDataset(trainingDataset, {
  epochs: 1,
  callbacks: [learningRateCallback],
});

This would produce a sine-wave-looking learning-rate curve for each sample in the batch (for batch size of 2048 items with default settings).

sine-wave-learning-rate

  • example 2
const frequency = 1 / 25; // a fraction - fraction lim -> 0  produces wider periods.
const maxLearningRateDecay = 1.0001 // a number slightly higher than 1
const sineWaveRateScaler = sineWaveRateScaler(0.0001, 1, frequency, )
const learningRateCallback = new LearningRateCallback({scalerFunction: sineWaveRateScaler})
[...]
const history = await layersModel.fitDataset(trainingDataset, {
  epochs: 1,
  callbacks: [learningRateCallback],
});

This would produce a sine-wave-looking learning-rate curve with decaying of the initial max learning rate for each sample in the batch (for batch size of 2048 items with default settings).

sine-wave-learning-rate

Also it's possible to decay epoch-wise also by providing

const sineWaveRateScaler = sineWaveRateScaler(0.0001, 1, frequency, 1.0001, 1.0001)

Credits

Prepared by Webplan.pro

Keywords

FAQs

Package last updated on 18 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc