Skip to content

Federated learning experiment using TensorFlow.js

License

Notifications You must be signed in to change notification settings

PAIR-code/federated-learning

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date
Aug 10, 2018
Jul 15, 2019
Jun 28, 2018
Aug 17, 2018
Jul 11, 2023
Jul 10, 2019
Jul 16, 2018
Jun 5, 2018
Jun 5, 2018
Jun 5, 2018
Apr 5, 2019
Jun 5, 2018
May 31, 2019

Repository files navigation

Federated Learning in TensorFlow.js

This is not an official federated learning framework for TensorFlow. This is an experimental library for TensorFlow.js that is currently unmaintained. If you would like to use an official federated learning library, check out tensorflow/federated.

This is the parent repository for an (experimental and demonstration-only) implementation of Federated Learning in Tensorflow.js. Federated Learning is a method for training machine learning models in a distributed fashion. Although it involves a central server, that server never needs to see any data or even compute a gradient. Instead, clients perform all of the inference and training locally (which they already do in Tensorflow.js), and just periodically send the server updated weights (rather than data). The server's only job is to aggregate and redistribute them, which means it can be extremely lightweight!

Basic Usage

On the server (NodeJS) side:

import * as http from 'http';
import * as federated from 'federated-learning-server';

const INIT_MODEL = 'file:///initial/model.json';
const webServer = http.createServer(); // can also use https
const fedServer = new federated.Server(webServer, INIT_MODEL);

fedServer.setup().then(() => {
  webServer.listen(80);
});

On the client (browser) side:

import * as federated from 'federated-learning-client';

const INIT_MODEL = 'http://my.initial/model.json';
const SERVER_URL = 'http://federated.learning.server'; // URL of server above
const client = new federated.Client(SERVER_URL, INIT_MODEL);

client.setup().then(() => {
  const yhat = client.predict(x); // make predictions!
  client.federatedUpdate(x, y);   // train and update the server!
});

Documentation and Examples

See the server and client READMEs for documentation, and the emoji or Hogwarts demos for more fully fleshed out examples.