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!
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!
});
See the server and client READMEs for documentation, and the emoji or Hogwarts demos for more fully fleshed out examples.