Concrete ML


Concrete ML is an open-source toolkit built on top of Concrete Framework. It enables data scientists to automatically turn their machine learning models into their homomorphic equivalent.


FHE is a powerful cryptographic tool that allows cloud service providers to perform computations directly on encrypted data without needing to decrypt first. With FHE, developers can build applications which ensure full privacy of users and are, at the same time, the complete equivalent of their insecure counterparts.

With Concrete ML, we aim to make it as simple as possible for users of machine learning frameworks to understand and use FHE. To that end, we provide APIs which are as close as possible to what data scientists are already using.

Concrete Numpy

Concrete Numpy underpins Concrete ML. It is a python package that contains the tools data scientists need to compile various numpy functions into their FHE equivalents. Concrete Numpy goes on top of the Concrete Library and its Compiler.


See More Use Cases Here
Copy

import concrete.numpy as hnp

def add(x, y):
    return x + y

inputset = [(2, 3), (0, 0), (1, 6), (7, 7), (7, 1), (3, 2), (6, 1), (1, 7), (4, 5), (5, 4)]
compiler = hnp.NPFHECompiler(add, {"x": "encrypted", "y": "encrypted"})

print(f"Compiling...")
circuit = compiler.compile_on_inputset(inputset)

examples = [(3, 4), (1, 2), (7, 7), (0, 0)]
for example in examples:
    result =  circuit.encrypt_run_decrypt(*example)
    print(f"Evaluation of {' + '.join(map(str, example))} homomorphically = {result}")

Concrete ML Makes Use Cases Easy

With Concrete ML, we are able to show some very appealing examples of how the tool can be used with models that are already familiar to data scientists.

Logistic regressions, for example, are a popular class of algorithm in Machine Learning. With Concrete ML, we can build a simple logistic regression using scikit-learn to show that they can be executed homomorphically. Converting this algorithm over quantized data to its FHE equivalent takes only a few lines of code thanks to Concrete ML.



from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from concrete.ml.sklearn import LogisticRegression
# Create a synthetic dataset
N_EXAMPLE_TOTAL = 100
N_TEST = 20
x, y = make_classification(n_samples=N_EXAMPLE_TOTAL, class_sep=2, n_features=4, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(
    x, y, test_size=N_TEST / N_EXAMPLE_TOTAL, random_state=42)
# Fix the quantization to 3 bits
model = LogisticRegression(n_bits=3)
# Fit the model
model.fit(X_train, y_train)
# We run prediction on non-encrypted data as a reference
y_pred_clear = model.predict(X_test, execute_in_fhe=False)
# We compile into an FHE model
model.compile(x)
# We then run the inference in FHE
y_pred_fhe = model.predict(X_test, execute_in_fhe=True)
print("In clear  :", y_pred_clear)
print("In FHE    :", y_pred_fhe)
print("Comparison:", (y_pred_fhe == y_pred_clear))
Copy

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

Lorem Ipsum Dolor Sit Amet

Lorem ipsum dolor sit amet, et zacarius consectetur adipiscing elit, tempor ut labore et dolore magna aliqua mussum...

ML toolkit

Still in an early version, it allows for example to turn some torch programs into numpy, and then to use the main API stack to finally get an FHE program.

<script>

var tricksWord = document.getElementsByClassName("tricks");
for (var i = 0; i < tricksWord.length; i++) {

var wordWrap = tricksWord.item(i);
wordWrap.innerHTML = wordWrap.innerHTML.replace(/(^|<\/?[^>]+>|\s)([^\s<]+)/g, 
'$1$2');

}

var tricksLetter = document.getElementsByClassName("tricksword");
for (var i = 0; i < tricksLetter.length; i++) {

   var letterWrap = tricksLetter.item(i);
   letterWrap.innerHTML = letterWrap.textContent.replace(/\S/g, "
   $&");

}
  
</script>
Copy

Start using Concrete ML

RESOURCES

Learn more

Announcing Concrete ML v0.2

We are announcing the release of Concrete ML as a public alpha. The package is built on top of Concrete Numpy.

Read Article

Quantization of Neural Networks for Fully Homomorphic Encryption

Machine Learning and the Need for Privacy‍

Read Article

Privacy-preserving insurance quotes

A tutorial on how to build an FHE-enabled insurance incident predictor.

Read Article