Skip to content

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*ashttpfrom'http';import*asfederatedfrom'federated-learning-server';constINIT_MODEL='file:///initial/model.json';constwebServer=http.createServer();// can also use httpsconstfedServer=newfederated.Server(webServer,INIT_MODEL);fedServer.setup().then(()=>{webServer.listen(80);});

On the client (browser) side:

import*asfederatedfrom'federated-learning-client';constINIT_MODEL='http://my.initial/model.json';constSERVER_URL='http://federated.learning.server';// URL of server aboveconstclient=newfederated.Client(SERVER_URL,INIT_MODEL);client.setup().then(()=>{constyhat=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.

About

Federated learning experiment using TensorFlow.js

Resources

Contributing

Stars

166 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages