Install Neural Structured Learning

There are several ways to set up your environment to use Neural Structured Learning (NSL) in TensorFlow:

  • The easiest way to learn and use NSL requires no installation: run the NSL tutorials directly in your browser using Google Colaboratory.
  • To use NSL on a local machine, install the NSL package with Python's pip package manager.
  • If you have a unique machine configuration, build NSL from source.

Install Neural Structured Learning using pip

1. Install the Python development environment.

On Ubuntu:

sudo apt update
sudo apt install python3-dev python3-pip  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
brew update
brew install python  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

2. Create a virtual environment.

virtualenv --python python3 "./venv"
source "./venv/bin/activate"
pip install --upgrade pip

3. Install TensorFlow

CPU support:

pip install 'tensorflow>=1.15.0'

GPU support:

pip install 'tensorflow-gpu>=1.15.0'

4. Install the Neural Structured Learning pip package.

pip install --upgrade neural_structured_learning

5. (Optional) Test Neural Structured Learning.

python -c "import neural_structured_learning as nsl"

Build the Neural Structured Learning pip package

1. Install the Python development environment.

On Ubuntu:

sudo apt update
sudo apt install python3-dev python3-pip  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
brew update
brew install python  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

2. Install Bazel.

Install Bazel, the build tool used to compile Neural Structured Learning.

3. Clone the Neural Structured Learning repository.

git clone https://github.com/tensorflow/neural-structured-learning.git

4. Create a virtual environment.

virtualenv --python python3 "./venv"
source "./venv/bin/activate"
pip install --upgrade pip

5. Install Tensorflow

Note that NSL requires a TensorFlow version of 1.15 or higher. NSL also supports TensorFlow 2.0.

CPU support:

pip install 'tensorflow>=1.15.0'

GPU support:

pip install 'tensorflow-gpu>=1.15.0'

6. Install Neural Structured Learning dependencies.

cd neural-structured-learning
pip install --requirement neural_structured_learning/requirements.txt

7. (Optional) Unit Test Neural Structured Learning.

bazel test //neural_structured_learning/...

8. Build the pip package.

python setup.py bdist_wheel --universal --dist-dir="./wheel"

9. Install the pip package.

pip install --upgrade ./wheel/neural_structured_learning*.whl

10. Test Neural Structured Learning.

python -c "import neural_structured_learning as nsl"