liveBook · Manning

Tensorflow R package

As explained in Deep Learning with R, Third Edition

The tensorflow R package is an R interface that exposes the TensorFlow Python API and functionality.

The tensorflow R package exposes the TensorFlow Python module through R, letting R code create tensors, run operations, compute gradients, and compile functions. section 3.3.1

Start TensorFlow from R

Load the package, select the TensorFlow backend, and create a tensor with familiar R function-call syntax. section 3.3.1

Practical translation rules shape everyday use:

  • Call Python TensorFlow functions with R's $ notation, such as tf$ones() and tf$constant(). section 3.3.1
  • Use zero-based indexing for Python-facing operations, append L for integer values, and use tuple() or shape() for tuple-shaped arguments. section 3.3.1
  • Represent mutable model state with tf$Variable and update it using assign(), assign_add(), or R-side assignment. section 3.3.1
  • Use GradientTape for derivatives, tf_function() for graph tracing, and jit_compile = TRUE for just-in-time compilation. section 3.3.1
library(tensorflow)
library(keras3)
use_backend("tensorflow")

Runnable setup for loading tensorflow and selecting the TensorFlow backend. section 3.3.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Covers tensors, variables, operations, gradients, nested tapes, function compilation, and an end-to-end linear classifier.
Examples
Uses constant, random, and mutable tensors; matrix operations; a dense layer; gradient calculations; and a pure-TensorFlow linear classifier.
What you can do after
Apply it via R to create TensorFlow tensors, update variables, calculate gradients, and compile numerical functions.
How it connects
Connects R to the TensorFlow Python API, tensors, variables, GradientTape, automatic differentiation, and just-in-time compilation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.