Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary Tensorflow Cheat sheet--Time Saving for Clarity

Beoordeling
-
Verkocht
-
Pagina's
7
Geüpload op
27-08-2025
Geschreven in
2025/2026

1. Introduction TensorFlow: Open-source ML library from Google Brain for deep learning and general computation. Scalability: Runs on CPUs, GPUs, TPUs, mobile devices. Flexibility: Supports deep learning, traditional ML, and general computations. Visualization: TensorBoard for debugging and performance tracking. Deployment: TensorFlow Serving, TensorFlow Lite, TensorF. 2. Tensor Basics Tensors: Multi-dimensional arrays (scalars, vectors, matrices, higher-rank). Rank: Number of dimensions (scalar=0, vector=1, matrix=2, etc.). Shape: Defines elements per dimension. Operations: Addition, element-wise multiplication, matrix multiplication. Broadcasting: Expands smaller tensor dimensions automatically. Types: ant (immutable) tf.Variable (mutable, e.g. weights/biases) Placeholders (deprecated in TF 2.x). 3. Model Development with TensorFlow Pipeline: Data preprocessing → Model definition → Training → Evaluation → Deployment. Keras API: Simplified high-level API for building ML/DL models. Example: Simple Linear Regression Define with Sequential and Dense. Compile with optimizer (sgd) and loss (mse). Train with fit(), predict, and evaluate with MSE. 4. Core Learning Algorithms Supervised: Linear Regression, Logistic Regression, SVM. Unsupervised: K-Means, PCA. Deep Learning: Feedforward, CNNs, RNNs. Reinforcement Learning: Q-Learning, Deep Q-Networks. 5. Neural Networks in TensorFlow Building Blocks: Neurons, Layers (input, hidden, output). Activation functions: ReLU, Sigmoid, Tanh, Softmax. Training: Forward pass, backpropagation, loss functions (MSE, Cross-Entropy), optimizers (SGD, Adam, RMSprop). Regularization: Dropout, L1/L2, Batch Normalization. Keras Example: Stacking Dense layers with activations. 6. Convolutional Neural Networks (CNNs) Components: Conv2D (filters, kernels, strides, activation). Pooling (MaxPooling, AveragePooling). Flattening → Dense layers for classification. Dropout: Prevents overfitting by randomly deactivating neurons. Used in image recognition & computer vision. 7. Recurrent Neural Networks (RNNs) Designed for sequential data (time series, NLP). Challenges: Vanishing & exploding gradients. Solutions: Gradient clipping, advanced cells (LSTM, GRU). Seq2Seq Models: Encoder-Decoder for tasks like translation. Bidirectional RNNs: Capture forward and backward context. 8. Natural Language Processing (NLP) with TensorFlow Uses Embedding layers to convert words into vectors. Combined with RNNs, LSTMs, GRUs for sequence modeling. Applications: Sentiment analysis, machine translation, text classification. 9. Reinforcement Learning (RL) with Q-Learning Components: Agent, environment, states, actions, rewards. Exploration vs. Exploitation trade-off. Q-Table: Stores expected rewards for (state, action). Q-Network: Neural net approximation of Q-values for large spaces. 10. Glossary Highlights Key Terms: Activation, Backpropagation, Epoch, Gradient, Loss, Optimizer, Dropout, Embedding, TensorBoard, Transfer Learning. APIs: (input pipelines), ion, tf.GradientTape, s. Tools: TensorFlow Lite (mobile), TensorF (browser), XLA (accelerated linear algebra). This cheat sheet is a practical quick reference for TensorFlow, covering everything from tensors → core ML models → deep learning (CNNs, RNNs) → reinforcement learning → deployment.

Meer zien Lees minder
Instelling
Data Science MS
Vak
Data science MS

Voorbeeld van de inhoud

Tensorflow Cheat Sheet
Introduction to Tensorflow Example: Evaluating Tensors
import tensorflow as tf In TensorFlow 2.x, eager execution is enabled by de-
What is Tensorflow?
fault, which means operations are evaluated immedia-
TensorFlow is an open-source machine learning library scalar = tf.constant(7)
tely. In TensorFlow 1.x, you would have required a ses-
developed by the Google Brain team. Its name derives vector = tf.constant([7, 7])
matrix = tf.constant([[7, 7], [7, 7]]) sion to evaluate tensors.
from the operations which neural networks perform on
multi-dimensional data arrays, termed „tensors“. While tensor = tf.constant([1, 2, 3])
print(„Rank of scalar:“, tf.rank(scalar))
TensorFlow was originally designed for deep learning print(„Rank of vector:“, tf.rank(vector)) print(tensor.numpy()) # Converts tensor to a numpy array
tasks, it‘s versatile enough to be used for a wide variety print(„Rank of matrix:“, tf.rank(matrix)) and prints it
of other complex computational tasks.
Shape of Tensors Sources of Tensors
Key Features of TensorFlow The shape of a tensor defines how many elements are tf.zeros(): Creates a tensor with all elements set to zero.
Scalability: TensorFlow can run on a single CPU, on in each dimension. Using the shape attribute, you can
zero_tensor = tf.zeros(shape=(2, 3))
multiple CPUs/GPUs, and even on mobile devices. This retrieve the shape of any tensor.
makes it suitable for both research and production.
tensor = tf.constant([[1, 2, 3], [4, 5, 6]]) tf.ones(): Creates a tensor with all elements set to one.
Flexibility: TensorFlow isn‘t just for deep learning. You
can use it for traditional machine learning algorithms print(„Shape of tensor:“, tensor.shape)
one_tensor = tf.ones(shape=(2, 3))
or even general mathematical computations. Changing the Shape of Tensors
Visualization: With TensorBoard, TensorFlow offers a Sometimes, you might need to reshape a tensor. You
suite of visualization tools to analyze and visualize your Practice with Tensors
can use the reshape function for this.
model‘s structure and performance.
Addition
Production Ready: TensorFlow models can be easily tensor = tf.constant([[1, 2], [3, 4], [5, 6]])
You can add tensors using the + operator or the tf.add()
deployed to any platform with TensorFlow Serving, reshaped_tensor = tf.reshape(tensor, (2, 3))
print(„Reshaped tensor:\n“, reshaped_tensor) function.
TensorFlow Lite, and TensorFlow.js.
tensor1 = tf.constant([1, 2, 3])
Types of Tensors: Constant, Variable, Placeholder tensor2 = tf.constant([4, 5, 6])
Tensorflow Basics Constant: Immutable tensors whose values can‘t be result = tensor1 + tensor2 # or tf.add(tensor1, tensor2)
Tensor Basics changed. print(result.numpy())
In TensorFlow, data is represented as tensors. A tensor
is a generalization of vectors and matrices to potentially constant_tensor = tf.constant([1, 2, 3]) Multiplication (Element-wise)
higher dimensions, and it‘s the fundamental data struc- Element-wise multiplication can be performed using
Variable: Tensors whose values can change. They are ty- the * operator or the tf.multiply() function.
ture in TensorFlow.
pically used for weights and biases in a neural network.
tensor1 = tf.constant([1, 2, 3])
Rank of Tensors tensor2 = tf.constant([4, 5, 6])
variable_tensor = tf.Variable([1, 2, 3])
The rank of a tensor refers to the number of dimensions result = tensor1 * tensor2 # or tf.multiply(tensor1, tensor2)
it has. For instance: Placeholder: (Deprecated in TensorFlow 2.x) They were
print(result.numpy())
A scalar has rank 0. used to feed external data into a TensorFlow graph. In
A vector has rank 1. Matrix Multiplication
TensorFlow 2.x, this approach has been replaced by
A matrix has rank 2. For matrix multiplication, you can use the tf.matmul()
using tf.data for input pipelines.
And so on for higher dimensions. function or the @ operator in Python.

1

, Tensorflow Cheat Sheet
methods by which they do so. The versatility of Tensor- # Visualizing the data
matrix1 = tf.constant([[1, 2], [3, 4]]) plt.scatter(X_data, y_data, label=“Original Data“)
matrix2 = tf.constant([[5, 6], [7, 8]]) Flow lies in its comprehensive collection of tools and
plt.xlabel(„X“)
result = tf.matmul(matrix1, matrix2) # or matrix1 @ matrix2 algorithms that facilitate:
plt.ylabel(„y“)
print(result.numpy()) Data Preprocessing: Transforming raw data into a plt.legend()
format suitable for training. plt.show()
Broadcasting in TensorFlow Model Development: Defining the architecture and
Broadcasting allows TensorFlow to automatically ex- parameters of the model. From the plot, we can observe a linear relationship bet-
pand the dimensions of a smaller tensor to match the Training: Optimizing the model based on data. ween X_data and y_data.
shape of a larger tensor, making certain operations fea- Evaluation: Assessing the performance of the model.
sible. Deployment: Integrating the trained model into appli- Defining, Training, and Evaluating a Model
cations or services. With the data in place, let‘s define a simple linear re-
tensor = tf.constant([[1, 2, 3], [4, 5, 6]]) gression model using TensorFlow‘s Keras API.
scalar = tf.constant(2)
result = tensor * scalar # This multiplies every element in the # Defining the model
tensor by the scalar Linear Regression with Tensorflow model = tf.keras.Sequential()
print(result.numpy()) Linear Regression is a supervised learning algorithm model.add(tf.keras.layers.Dense(units=1, input_shape=[1]))
used to predict a continuous dependent variable based
In the example above, the scalar value 2 is „broadcast“ # Compile the model with loss and optimizer
on one or more independent variables. The goal is to fit model.compile(optimizer=‘sgd‘, loss=‘mean_squared_er-
to match the shape of the tensor, allowing element-wise the best line that accurately predicts the output values ror‘)
multiplication. within a range.
# Train the model
Setting up and Importing Necessary Libraries history = model.fit(X_data, y_data, epochs=100, verbose=0)
Tensorflow Core Learning Algorithms Before diving into linear regression, you need to ensure # Training for 100 epochs
that you have TensorFlow installed and then import the
TensorFlow provides implementations for a vast array # Predicting using the trained model
necessary libraries.
of machine learning algorithms, making it an ideal tool y_pred = model.predict(X_data)
for both classical machine learning and deep learning. # Install TensorFlow (if not done already)
# Visualizing original data and the regression line
# !pip install tensorflow
plt.scatter(X_data, y_data, label=“Original Data“)
Supervised Learning Algorithms: Linear Regression, # Importing necessary libraries plt.plot(X_data, y_pred, color=‘red‘, label=“Fitted Line“)
Logistic Regression, Support Vector Machines, etc. import tensorflow as tf plt.xlabel(„X“)
Unsupervised Learning Algorithms: K-Means Clus- import numpy as np plt.ylabel(„y“)
tering, Principal Component Analysis, etc. import matplotlib.pyplot as plt plt.legend()
Deep Learning Algorithms: Neural Networks, Con- plt.show()
volutional Neural Networks, Recurrent Neural Net- Loading and Inspecting Data
# Evaluating the model‘s loss on the data
works, etc. For this example, let‘s consider a simple dataset where
loss = model.evaluate(X_data, y_data, verbose=0)
Reinforcement Learning Algorithms: Q-Learning, we‘re trying to predict y values from x values. print(f “Mean Squared Error after training: {loss}“)
Deep Q-Networks, etc.
# Sample data
The red line in the plot represents the best-fit line our
Importance in Machine Learning X_data = np.array([1, 2, 3, 4, 5], dtype=float)
linear regression model has found. The Mean Squared
Machine learning revolves around the idea of teaching y_data = np.array([2, 4, 5.8, 8.1, 10.3], dtype=float)
Error (MSE) gives us a quantitative measure of how well
computers to learn from data, and algorithms are the our model fits the data: the lower the MSE, the better.
2

Geschreven voor

Instelling
Data science MS
Vak
Data science MS

Documentinformatie

Geüpload op
27 augustus 2025
Aantal pagina's
7
Geschreven in
2025/2026
Type
SAMENVATTING

Onderwerpen

€3,10
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
c.7

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
c.7 Icahn School of Medicine at Mount Sinai
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
8 maanden
Aantal volgers
0
Documenten
26
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen