maddie
maddie

Reputation: 1954

Difference btwn high and low level libraries

What is the difference btwn high level and low level libraries?

I understand that keras is a high level library and tensorflow is a low level library but I'm still not familiar enough with these frameworks to understand what that means for high vs low libraries.

Upvotes: 1

Views: 1700

Answers (3)

Manoj Mohan
Manoj Mohan

Reputation: 6044

Keras is a high level Deep learning(DL) 'API'. Key components of the API are:

  • Model - to define the Neural network(NN).

  • Layers - building blocks of the NN model (e.g. Dense, Convolution).

  • Optimizers - different methods for doing gradient descent to learn weights of NN (e.g. SGD, Adam).

  • Losses - objective functions that the optimizer should minimize for use cases like classification, regression (e.g. categorical_crossentropy, MSE).

Moreover, it provides reasonable defaults for the APIs e.g. learning rates for Optimizers, which would work for the common use cases. This reduces the cognitive load on the user during the learning phase.

The 'Guiding Principles' section here is very informative:

https://keras.io/

The mathematical operations involved in running the Neural networks themselves like Convolutions, Matrix Multiplications etc. are delegated to the backend. One of the backends supported by Keras is Tensorflow.

To highlight the differences with a code snippet:

Keras

# Define Neural Network
model = Sequential()  
# Add Layers to the Network
model.add(Dense(512, activation='relu', input_shape=(784,)))
....
# Define objective function and optimizer
model.compile(loss='categorical_crossentropy',
          optimizer=Adam(),
          metrics=['accuracy'])

# Train the model for certain number of epochs by feeding train/validation data
history = model.fit(x_train, y_train,
                    batch_size=batch_size,
                    epochs=epochs,
                    verbose=1,
                    validation_data=(x_test, y_test))

Tensorflow

It ain't a code snippet anymore :) since you need to define everything starting from the Variables that would store the weights, the connections between the layers, the training loop, creating batches of data to do the training etc.

You can refer the below links to understand the code complexity with training a MNIST(DL Hello world example) in Keras vs Tensorflow.

https://github.com/keras-team/keras/blob/master/examples/mnist_mlp.py

https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py

Considering the benefits that come with Keras, Tensorflow has made tf.keras the high-level API in Tensorflow 2.0.

https://www.tensorflow.org/tutorials/

Upvotes: 1

Andrew Peters
Andrew Peters

Reputation: 366

Keras sits on top of Tensorflow, and thus the framework is relatively 'higher-level' than Tensorflow itself.

A 'high' level language or framework is typically defined as one that has a greater number of dependencies or has a greater distance from core binary code, relative to a lower-level language or framework.

E.g., jQuery would be considered higher-level than JavaScript, as it depends on Javascript. Whereas Javascript would be considered higher-level than assembly code, as it's transpiled to assembly.

Upvotes: 1

herdsothom
herdsothom

Reputation: 137

High level means that your interactions are closer to writing English, and the code you write is essentially more understandable to humans.

An example of low level would be a language in which you would have to do things such as allocate memory, copy data from one memory address to another etc.

Keras is considered high level because you can make a neural network in just a few lines of code, the library will handle all the complexity for you.

In tensorflow (I haven't used it), you probably have to write many more lines of code to achieve the same thing, but probably have a greater degree of control. Reading tensorflow code for a NN would be less meaningful to a layman than reading keras code for a NN.

Upvotes: 1

Related Questions