0% found this document useful (0 votes)
2 views

TensorFlow

TensorFlow is an open-source platform by Google for building and training machine learning models using tensors and computational graphs. It allows for scalable model training and deployment across various platforms, while offering advantages such as flexibility, high performance, and ease of use, but it also has drawbacks like complexity and debugging challenges. The document includes an example of a simple model built with TensorFlow to demonstrate its functionality.

Uploaded by

charlton.latham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

TensorFlow

TensorFlow is an open-source platform by Google for building and training machine learning models using tensors and computational graphs. It allows for scalable model training and deployment across various platforms, while offering advantages such as flexibility, high performance, and ease of use, but it also has drawbacks like complexity and debugging challenges. The document includes an example of a simple model built with TensorFlow to demonstrate its functionality.

Uploaded by

charlton.latham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TensorFlow

TensorFlow is an open-source platform developed by Google for building and


training machine learning and deep learning models.
TensorFlow works with tensors (multi-dimensional arrays) and automatically
manages the flow of data through mathematical operations. That’s why it’s
called Tensor + Flow.
Tensor = data (numbers, images, etc.)
Flow = how data moves through operations (like addition, multiplication, etc.)
It allows to:
• Build ML models from scratch
• Train and deploy them at scale
• Run models on various platforms: desktops, servers, browsers, mobile
devices, and even embedded systems

How TensorFlow Works


TensorFlow works by creating a computational graph that represents the
machine learning model.

Step 1: Define the Model


1. Create a graph: TensorFlow creates a computational graph that represents
the machine learning model.
2. Define operations: The graph consists of operations (e.g., matrix
multiplication, activation functions) that are connected together.

Step 2: Feed Data into the Model


1. Input data: Data is fed into the graph through placeholders or input layers.
2. Forward pass: The data flows through the graph, and the model makes
predictions.
Step 3: Train the Model
1. Compute loss: The difference between the predicted output and the actual
output is calculated using a loss function.
2. Backpropagation: The gradients of the loss function with respect to the
model's parameters are computed using backpropagation.

Step 4: Make Predictions


1. Use the trained model: Once the model is trained, it can be used to make
predictions on new, unseen data.

Advantages of TensorFlow
1. Scalability: TensorFlow can handle large-scale machine learning tasks and
can be distributed across multiple machines.
2. Flexibility: TensorFlow allows developers to build and deploy machine
learning models on various platforms, including desktops, servers, and mobile
devices.
3. High-Performance: TensorFlow is optimized for performance and can handle
complex computations efficiently.
4. Easy to Use: TensorFlow has a simple and intuitive API, making it accessible
to developers of all skill levels.
5. Accuracy: TensorFlow can help organizations build accurate machine
learning models that improve decision-making.

Drawbacks of TensorFlow
1.Complexity: TensorFlow's low-level API can be complex and require manual
management of details such as memory allocation and gradient computation.
2. Debugging Challenges: Debugging TensorFlow models can be difficult due to
the complexity of the computational graph and the asynchronous nature of the
computations.
Example

import tensorflow as tf
import numpy as np
# Training data
x = np.array([0, 1, 2, 3, 4], dtype=float)
y = 2 * x + 1 # Expected output
# Build a simple model
model = tf.keras.Sequential([
tf.keras.layers.Dense(units=1, input_shape=[1])
])
# Compile the model
model.compile(optimizer='sgd', loss='mean_squared_error')
# Train the model
model.fit(x, y, epochs=100)
# Use the model to predict
print(model.predict([10.0])) # Should be close to 2*10 + 1 = 21

output:
Epoch 100/100
[[20.95]]

You might also like