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

@magenta/music

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magenta/music

This JavaScript implementation of Magenta's musical note-based models uses [TensorFlow.js](https://js.tensorflow.org) for GPU-accelerated inference.

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by27.05%
Maintainers
2
Weekly downloads
 
Created
Source

MagentaMusic.js API

This JavaScript implementation of Magenta's musical note-based models uses TensorFlow.js for GPU-accelerated inference.

We have made an effort to port our most useful models, but please file an issue if you think something is missing, or feel free to submit a Pull Request!

For the Python TensorFlow implementations, see the main Magenta repo.

Example Applications

Here are a few applications built with MagentaMusic.js:

Available Models

MusicRNN

MusicRNN implements Magenta's LSTM-based language models. These include MelodyRNN, DrumsRNN, ImprovRNN, and PerformanceRNN.

MusicVAE

MusicVAE implements several configurations of Magenta's variational autoencoder model called MusicVAE including melody and drum "loop" models, 4- and 16-bar "trio" models, and chord-conditioned "multi-track" models.

Getting started

There are two main ways to get MagentaMusic.js in your JavaScript project: via script tags or by installing it from NPM and using a build tool like yarn.

via Script Tag

Add the following code to an HTML file:

<html>
  <head>
    <!-- Load MagentaMusic.js -->
    <script src="https://cdn.jsdelivr.net/npm/@magenta/music"> </script>

    <!-- Place your code in the script tag below. You can also use an external .js file -->
    <script>
      // Notice there is no 'import' statement. 'mm' is available on the index-page
      // because of the script tag above.
      const model = new mm.MusicVAE(
          'http://download.magenta.tensorflow.org/tfjs_checkpoints/music_vae/' +
          'drums_2bar_hikl_small');
      const player = new mm.Player();

      model.initialize()
          .then(() => model.sample(1))
          .then((samples) => player.start(samples[0]));
    </script>
  </head>

  <body>
  </body>
</html>

Open up that html file in your browser and the code should run. After a few seconds you'll hear a drum beat that was randomly generated by MusicVAE!

See TODO(adarob, teropa): INSERT DEMO LINK for a complete example application with code.

via NPM

Add MagentaMusic.js to your project using yarn or npm. For example, with yarn you can simply call yarn add @magenta/music.

Then, you can use the library in your own code as in the folliwng example:

import * as mm from '@magenta/music';

const model = new mm.MusicVAE('/path/to/checkpoint');
const player = new mm.Player();

model.initialize()
    .then(() => model.sample(1))
    .then((samples) => player.start(samples[0]));

See our demos for example usage.

Example Commands

yarn install to install dependencies.

yarn test to run tests.

yarn bundle to produce a bundled version in dist/.

yarn run-demos to build and run the demo.

Pre-trained Checkpoints

Since MagentaMusic.js does not support training models, you must use weights from a model trained with the Python-based Magenta models. We are also making available our own hosted pre-trained checkpoints.

Magenta-Hosted Checkpoints

Several pre-trained MusicRNN and MusicVAE checkpoints are hosted on GCS. You can access a JSON index available checkpoints at https://goo.gl/magenta/js-checkpoints.

The JSON is formatted as a list of entries with the the following interface:

interface Checkpoint {
  id: string;  // A unique id for this checkpoint.
  model: 'MusicRNN'|'MusicVAE';  // The model class.
  description: string;  // A short human-readable description of the trained model.
  url: string;  // Path to the checkpoint directory.
}

While we do not plan to remove any of the current checkpoints, we will be adding more in the future.

If your application has a high QPS, you must mirror these files on your own server.

Your Own Checkpoints

Dumping Your Weights

To use your own checkpoints with one of our models, you must first convert the weights to the appropriate format using the provided checkpoint_converter script.

This tool is dependent on tfjs-converter, which you must first install using pip install tensorflowjs. Once installed, you can execute the script as follows:

../scripts/checkpoint_converter.py /path/to/model.ckpt /path/to/output_dir

There are additonal flags available to reduce the size of the output by removing unused (training) variables or using weight quantization. Call ../scripts/checkpoint_converter.py -h to list the avilable options.

Specifying the Model Configuration

TODO(iansimon): This will be dependent on how we end up setting up the model instantiation and config.

FAQs

Package last updated on 24 Apr 2018

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