@epfml/discojs 2.1.2-p20240507135008.0 → 2.1.2-p20240513140724.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @epfml/discojs
2
+
3
+ Decentralized & federated privacy-preserving ML training in TypeScript.
4
+
5
+ This is the core library of the Disco.js project.
6
+
7
+ It is platform-agnostic, and has two companions library:
8
+ - [`discojs-node`](../discojs-node) for Node.js
9
+ - [`discojs-web`](../discojs-web) for web browsers
10
+
11
+ The easiest way to start using it is through the `Disco` object.
12
+ Create your own `Task` or load one from our `default_tasks`,
13
+ setup the `Dataset` you want, and train with it.
14
+
15
+ ```ts
16
+ import { Disco } from '@epfml/discojs'
17
+
18
+ const url = ...; // url to a Disco.js server
19
+ const dataset = ...;
20
+ const task = ...;
21
+
22
+ const disco = new Disco(task, { url })
23
+ for await (const _ of disco.fit(dataset));
24
+ ```
@@ -92,7 +92,7 @@ export class DatasetBuilder {
92
92
  async build(config) {
93
93
  // Require that at least one source collection is non-empty, but not both
94
94
  if ((this._sources.length > 0) === (this.labelledSources.size > 0)) {
95
- throw new Error('Please provide dataset input files');
95
+ throw new Error('Please provide dataset input files'); // This error message is parsed in DatasetInput.vue
96
96
  }
97
97
  let dataTuple;
98
98
  if (this._sources.length > 0) {
@@ -11,11 +11,10 @@ export const cifar10 = {
11
11
  preview: 'In this challenge, we ask you to classify images into categories based on the objects shown on the image.',
12
12
  overview: 'The CIFAR-10 dataset is a collection of images that are commonly used to train machine learning and computer vision algorithms. It is one of the most widely used datasets for machine learning research.'
13
13
  },
14
- limitations: 'The training data is limited to small images of size 32x32.',
15
- tradeoffs: 'Training success strongly depends on label distribution',
16
14
  dataFormatInformation: 'Images should be of .png format and of size 32x32. <br> The label file should be .csv, where each row contains a file_name, class. <br> <br> e.g. if you have images: 0.png (of a frog) and 1.png (of a car) <br> labels.csv contains: (Note that no header is needed)<br> 0.png, frog <br> 1.png, car',
17
15
  dataExampleText: 'Below you can find 10 random examples from each of the 10 classes in the dataset.',
18
- dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/cifar10-example.png'
16
+ dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/cifar10-example.png',
17
+ sampleDatasetLink: 'https://www.kaggle.com/competitions/cifar-10/data'
19
18
  },
20
19
  trainingInformation: {
21
20
  modelID: 'cifar10-model',
@@ -27,7 +26,7 @@ export const cifar10 = {
27
26
  preprocessingFunctions: [data.ImagePreprocessing.Resize],
28
27
  IMAGE_H: 224,
29
28
  IMAGE_W: 224,
30
- LABEL_LIST: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
29
+ LABEL_LIST: ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'],
31
30
  scheme: 'decentralized',
32
31
  noiseScale: undefined,
33
32
  clippingRadius: 20,
@@ -1,8 +1,6 @@
1
1
  export { cifar10 } from './cifar10/index.js';
2
- export { geotags } from './geotags/index.js';
3
2
  export { lusCovid } from './lus_covid.js';
4
3
  export { mnist } from './mnist.js';
5
4
  export { simpleFace } from './simple_face/index.js';
6
- export { skinMnist } from './skin_mnist.js';
7
5
  export { titanic } from './titanic.js';
8
6
  export { wikitext } from './wikitext.js';
@@ -1,8 +1,6 @@
1
1
  export { cifar10 } from './cifar10/index.js';
2
- export { geotags } from './geotags/index.js';
3
2
  export { lusCovid } from './lus_covid.js';
4
3
  export { mnist } from './mnist.js';
5
4
  export { simpleFace } from './simple_face/index.js';
6
- export { skinMnist } from './skin_mnist.js';
7
5
  export { titanic } from './titanic.js';
8
6
  export { wikitext } from './wikitext.js';
@@ -11,16 +11,16 @@ export const lusCovid = {
11
11
  overview: "Don’t have a dataset of your own? Download a sample of a few cases <a class='underline' href='https://drive.switch.ch/index.php/s/zM5ZrUWK3taaIly' target='_blank'>here</a>."
12
12
  },
13
13
  model: "We use a simplified* version of the <b>DeepChest model</b>: A deep learning model developed in our lab (<a class='underline' href='https://www.epfl.ch/labs/mlo/igh-intelligent-global-health/'>intelligent Global Health</a>.). On a cohort of 400 Swiss patients suspected of LRTI, the model obtained over 90% area under the ROC curve for this task. <br><br>*Simplified to ensure smooth running on your browser, the performance is minimally affected. Details of the adaptations are below <br>- <b>Removed</b>: positional embedding (i.e. we don’t take the anatomic position into consideration). Rather, the model now does mean pooling over the feature vector of the images for each patient <br>- <b>Replaced</b>: ResNet18 by Mobilenet",
14
- tradeoffs: 'We are using a simpler version of DeepChest in order to be able to run it on the browser.',
15
14
  dataFormatInformation: 'This model takes as input an image dataset. It consists on a set of lung ultrasound images per patient with its corresponding label of covid positive or negative. Moreover, to identify the images per patient you have to follow the follwing naming pattern: "patientId_*.png"',
16
15
  dataExampleText: 'Below you can find an example of an expected lung image for patient 2 named: 2_QAID_1.masked.reshaped.squared.224.png',
17
- dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/2_QAID_1.masked.reshaped.squared.224.png'
16
+ dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/2_QAID_1.masked.reshaped.squared.224.png',
17
+ sampleDatasetLink: 'https://drive.switch.ch/index.php/s/zM5ZrUWK3taaIly'
18
18
  },
19
19
  trainingInformation: {
20
20
  modelID: 'lus-covid-model',
21
21
  epochs: 50,
22
22
  roundDuration: 2,
23
- validationSplit: 0,
23
+ validationSplit: 0.2,
24
24
  batchSize: 5,
25
25
  IMAGE_H: 100,
26
26
  IMAGE_W: 100,
@@ -11,7 +11,6 @@ export const mnist = {
11
11
  overview: 'The MNIST handwritten digit classification problem is a standard dataset used in computer vision and deep learning. Although the dataset is effectively solved, we use it to test our Decentralised Learning algorithms and platform.'
12
12
  },
13
13
  model: 'The current model is a very simple CNN and its main goal is to test the app and the Decentralizsed Learning functionality.',
14
- tradeoffs: 'We are using a simple model, first a 2d convolutional layer > max pooling > 2d convolutional layer > max pooling > convolutional layer > 2 dense layers.',
15
14
  dataFormatInformation: 'This model is trained on images corresponding to digits 0 to 9. You can upload each digit image of your dataset in the box corresponding to its label. The model taskes images of size 28x28 as input.',
16
15
  dataExampleText: 'Below you can find an example of an expected image representing the digit 9.',
17
16
  dataExampleImage: 'http://storage.googleapis.com/deai-313515.appspot.com/example_training_data/9-mnist-example.png'
@@ -11,8 +11,6 @@ export const simpleFace = {
11
11
  preview: 'Can you detect if the person in a picture is a child or an adult?',
12
12
  overview: 'Simple face is a small subset of face_task from Kaggle'
13
13
  },
14
- limitations: 'The training data is limited to small images of size 200x200.',
15
- tradeoffs: 'Training success strongly depends on label distribution',
16
14
  dataFormatInformation: '',
17
15
  dataExampleText: 'Below you find an example',
18
16
  dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/simple_face-example.png'
@@ -11,7 +11,6 @@ export const titanic = {
11
11
  overview: 'We all know the unfortunate story of the Titanic: this flamboyant new transatlantic boat that sunk in 1912 in the North Atlantic Ocean. Today, we revist this tragedy by trying to predict the survival odds of the passenger given some basic features.'
12
12
  },
13
13
  model: 'The current model does not normalize the given data and applies only a very simple pre-processing of the data.',
14
- tradeoffs: 'We are using a small model for this task: 4 fully connected layers with few neurons. This allows fast training but can yield to reduced accuracy.',
15
14
  dataFormatInformation: 'This model takes as input a CSV file with 12 columns. The features are general information about the passenger (sex, age, name, etc.) and specific related Titanic data such as the ticket class bought by the passenger, its cabin number, etc.<br><br>pclass: A proxy for socio-economic status (SES)<br>1st = Upper<br>2nd = Middle<br>3rd = Lower<br><br>age: Age is fractional if less than 1. If the age is estimated, it is in the form of xx.5<br><br>sibsp: The dataset defines family relations in this way:<br>Sibling = brother, sister, stepbrother, stepsister<br>Spouse = husband, wife (mistresses and fiancés were ignored)<br><br>parch: The dataset defines family relations in this way:<br>Parent = mother, father<br>Child = daughter, son, stepdaughter, stepson<br>Some children travelled only with a nanny, therefore parch=0 for them.<br><br>The first line of the CSV contains the header:<br> PassengerId, Survived, Pclass, Name, Sex, Age, SibSp, Parch, Ticket, Fare, Cabin, Embarked<br><br>Each susequent row contains the corresponding data.',
16
15
  dataExampleText: 'Below one can find an example of a datapoint taken as input by our model. In this datapoint, the person is young man named Owen Harris that unfortunnalty perished with the Titanic. He boarded the boat in South Hamptons and was a 3rd class passenger. On the testing & validation page, the data should not contain the label column (Survived).',
17
16
  dataExample: [
@@ -9,10 +9,9 @@ export const wikitext = {
9
9
  preview: 'In this challenge, we ask you to do next word prediction on a dataset of Wikipedia articles.',
10
10
  overview: 'Wikitext-103-raw is a dataset comprising unprocessed text excerpts from Wikipedia articles, designed for tasks related to natural language processing and language modeling.'
11
11
  },
12
- limitations: 'The dataset may contain noise, inconsistencies, and unstructured content due to its raw nature, potentially posing challenges for certain NLP tasks.',
13
- tradeoffs: 'The raw format may lack structured annotations and may require additional preprocessing for specific applications.',
14
12
  dataFormatInformation: 'The dataset is organized as a large text file, with each line representing a segment of raw text from Wikipedia articles.',
15
- dataExampleText: 'An example excerpt from the dataset could be: "The history of artificial intelligence dates back to ancient times, with philosophical discussions on the nature of thought and reasoning."'
13
+ dataExampleText: 'An example excerpt from the dataset could be: "The history of artificial intelligence dates back to ancient times, with philosophical discussions on the nature of thought and reasoning."',
14
+ sampleDatasetLink: 'https://dax-cdn.cdn.appdomain.cloud/dax-wikitext-103/1.0.1/wikitext-103.tar.gz'
16
15
  },
17
16
  trainingInformation: {
18
17
  dataType: 'text',
@@ -1,17 +1,14 @@
1
1
  import { type Summary } from './summary.js';
2
2
  import { type DataExample } from './data_example.js';
3
- import { type LabelType } from './label_type.js';
4
3
  export interface DisplayInformation {
5
- taskTitle?: string;
6
- summary?: Summary;
7
- tradeoffs?: string;
4
+ taskTitle: string;
5
+ summary: Summary;
8
6
  dataFormatInformation?: string;
9
7
  dataExampleText?: string;
10
8
  model?: string;
11
9
  dataExample?: DataExample[];
12
10
  headers?: string[];
13
11
  dataExampleImage?: string;
14
- limitations?: string;
15
- labelDisplay?: LabelType;
12
+ sampleDatasetLink?: string;
16
13
  }
17
14
  export declare function isDisplayInformation(raw: unknown): raw is DisplayInformation;
@@ -1,24 +1,37 @@
1
1
  import { isSummary } from './summary.js';
2
2
  import { isDataExample } from './data_example.js';
3
- import { isLabelType } from './label_type.js';
4
3
  export function isDisplayInformation(raw) {
5
4
  if (typeof raw !== 'object' || raw === null) {
6
5
  return false;
7
6
  }
8
- const { dataExample, dataExampleImage, dataExampleText, dataFormatInformation, headers, labelDisplay, limitations, model, summary, taskTitle, tradeoffs } = raw;
7
+ const { dataExample, dataExampleImage, dataExampleText, dataFormatInformation, sampleDatasetLink, headers, model, summary, taskTitle, } = raw;
9
8
  if (typeof taskTitle !== 'string' ||
10
9
  (dataExampleText !== undefined && typeof dataExampleText !== 'string') ||
10
+ (sampleDatasetLink !== undefined && typeof sampleDatasetLink !== 'string') ||
11
11
  (dataFormatInformation !== undefined && typeof dataFormatInformation !== 'string') ||
12
- (tradeoffs !== undefined && typeof tradeoffs !== 'string') ||
13
12
  (model !== undefined && typeof model !== 'string') ||
14
- (dataExampleImage !== undefined && typeof dataExampleImage !== 'string') ||
15
- (labelDisplay !== undefined && !isLabelType(labelDisplay)) ||
16
- (limitations !== undefined && typeof limitations !== 'string')) {
13
+ (dataExampleImage !== undefined && typeof dataExampleImage !== 'string')) {
17
14
  return false;
18
15
  }
19
- if (summary !== undefined && !isSummary(summary)) {
16
+ if (!isSummary(summary)) {
20
17
  return false;
21
18
  }
19
+ if (sampleDatasetLink !== undefined) {
20
+ try {
21
+ new URL(sampleDatasetLink);
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ if (dataExampleImage !== undefined) {
28
+ try {
29
+ new URL(dataExampleImage);
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
22
35
  if (dataExample !== undefined && !(Array.isArray(dataExample) &&
23
36
  dataExample.every(isDataExample))) {
24
37
  return false;
@@ -32,13 +45,11 @@ export function isDisplayInformation(raw) {
32
45
  dataExampleImage,
33
46
  dataExampleText,
34
47
  dataFormatInformation,
48
+ sampleDatasetLink,
35
49
  headers,
36
- labelDisplay,
37
- limitations,
38
50
  model,
39
51
  summary,
40
52
  taskTitle,
41
- tradeoffs,
42
53
  };
43
54
  const _correct = repack;
44
55
  const _total = repack;
@@ -4,4 +4,3 @@ export { isDigest, type Digest } from './digest.js';
4
4
  export { isDisplayInformation, type DisplayInformation } from './display_information.js';
5
5
  export type { TrainingInformation } from './training_information.js';
6
6
  export { pushTask, fetchTasks } from './task_handler.js';
7
- export { LabelTypeEnum } from './label_type.js';
@@ -2,4 +2,3 @@ export { isTask, isTaskID } from './task.js';
2
2
  export { isDigest } from './digest.js';
3
3
  export { isDisplayInformation } from './display_information.js';
4
4
  export { pushTask, fetchTasks } from './task_handler.js';
5
- export { LabelTypeEnum } from './label_type.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epfml/discojs",
3
- "version": "2.1.2-p20240507135008.0",
3
+ "version": "2.1.2-p20240513140724.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,2 +0,0 @@
1
- import type { TaskProvider } from '../../index.js';
2
- export declare const geotags: TaskProvider;
@@ -1,65 +0,0 @@
1
- import { Range } from 'immutable';
2
- import * as tf from '@tensorflow/tfjs';
3
- import { data, models } from '../../index.js';
4
- import { LabelTypeEnum } from '../../task/label_type.js';
5
- import baseModel from './model.js';
6
- export const geotags = {
7
- getTask() {
8
- return {
9
- id: 'geotags',
10
- displayInformation: {
11
- taskTitle: 'GeoTags',
12
- summary: {
13
- preview: 'In this challenge, we predict the geo-location of a photo given its pixels in terms of a cell number of a grid built on top of Switzerland',
14
- overview: 'The geotags dataset is a collection of images with geo-location information used to train a machine learning algorithm to predict the location of a photo given its pixels.'
15
- },
16
- limitations: 'The training data is limited to images of size 224x224.',
17
- tradeoffs: 'Training success strongly depends on label distribution',
18
- dataFormatInformation: 'Images should be of .png format and of size 224x224. <br> The label file should be .csv, where each row contains a file_name, class. The class is the cell number of a the given grid of Switzerland. ',
19
- labelDisplay: {
20
- labelType: LabelTypeEnum.POLYGON_MAP,
21
- mapBaseUrl: 'https://disco-polygon.web.app/'
22
- }
23
- },
24
- trainingInformation: {
25
- modelID: 'geotags-model',
26
- epochs: 10,
27
- roundDuration: 10,
28
- validationSplit: 0.2,
29
- batchSize: 10,
30
- dataType: 'image',
31
- IMAGE_H: 224,
32
- IMAGE_W: 224,
33
- preprocessingFunctions: [data.ImagePreprocessing.Resize],
34
- LABEL_LIST: Range(0, 127).map(String).toArray(),
35
- scheme: 'federated',
36
- noiseScale: undefined,
37
- clippingRadius: 20,
38
- decentralizedSecure: true,
39
- minimumReadyPeers: 3,
40
- maxShareValue: 100
41
- }
42
- };
43
- },
44
- async getModel() {
45
- const pretrainedModel = await tf.loadLayersModel({
46
- load: async () => Promise.resolve(baseModel),
47
- });
48
- const numLayers = pretrainedModel.layers.length;
49
- pretrainedModel.layers.forEach(layer => { layer.trainable = false; });
50
- pretrainedModel.layers[numLayers - 1].trainable = true;
51
- const model = tf.sequential({
52
- layers: [
53
- tf.layers.inputLayer({ inputShape: [224, 224, 3] }),
54
- tf.layers.rescaling({ scale: 1 / 127.5, offset: -1 }), // Rescaling input between -1 and 1
55
- pretrainedModel
56
- ]
57
- });
58
- model.compile({
59
- optimizer: 'adam',
60
- loss: 'categoricalCrossentropy',
61
- metrics: ['accuracy']
62
- });
63
- return new models.TFJS(model);
64
- }
65
- };