Posit AI Weblog: TensorFlow and Keras 2.9


The discharge of Deep Finding out with R, 2d
Version
coincides with new releases of
TensorFlow and Keras. Those releases deliver many refinements that let
for extra idiomatic and concise R code.

First, the set of Tensor strategies for base R generics has very much
expanded. The set of R generics that paintings with TensorFlow Tensors is now
somewhat in depth:

strategies(elegance = "tensorflow.tensor")
 [1] -           !           !=          [           [<-        
 [6] *           /           &           %/%         %%         
[11] ^           +           <           <=          ==         
[16] >           >=          |           abs         acos       
[21] all         any         aperm       Arg         asin       
[26] atan        cbind       ceiling     Conj        cos        
[31] cospi       digamma     dim         exp         expm1      
[36] flooring       Im          is.finite   is.countless is.nan     
[41] duration      lgamma      log         log10       log1p      
[46] log2        max         imply        min         Mod        
[51] print       prod        vary       rbind       Re         
[56] rep         spherical       signal        sin         sinpi      
[61] kind        sqrt        str         sum         t          
[66] tan         tanpi      

Because of this regularly you’ll write the similar code for TensorFlow Tensors
as you might for R arrays. As an example, believe this small serve as
from Bankruptcy 11 of the e book:

reweight_distribution <-
  serve as(original_distribution, temperature = 0.5) {
    original_distribution %>%
      { exp(log(.) / temperature) } %>%
      { . / sum(.) }
  }

Observe that purposes like reweight_distribution() paintings with each 1D R
vectors and 1D TensorFlow Tensors, since exp(), log(), /, and
sum() are all R generics with strategies for TensorFlow Tensors.

In the similar vein, this Keras liberate brings with it a refinement to the
manner customized elegance extensions to Keras are outlined. In part impressed by means of
the brand new R7 syntax, there’s a
new circle of relatives of purposes: new_layer_class(), new_model_class(),
new_metric_class(), and so forth. This new interface considerably
simplifies the volume of boilerplate code required to outline customized
Keras extensions—a nice R interface that serves as a facade over
the mechanics of sub-classing Python categories. This new interface is the
yang to the yin of %py_class%–a strategy to mime the Python elegance
definition syntax in R. In fact, the “uncooked” API of changing an
R6Class() to Python by way of r_to_py() remains to be to be had for customers that
require complete keep an eye on.

This liberate additionally brings with it a cornucopia of small enhancements
all through the Keras R interface: up to date print() and plot() strategies
for fashions, improvements to freeze_weights() and load_model_tf(),
new exported utilities like zip_lists() and %<>%. And let’s no longer
put out of your mind to say a brand new circle of relatives of R purposes for editing the training
charge all the way through coaching, with a collection of integrated schedules like
learning_rate_schedule_cosine_decay(), complemented by means of an interface
for developing customized schedules with new_learning_rate_schedule_class().

You’ll in finding the overall liberate notes for the R applications right here:

The discharge notes for the R applications inform most effective part the tale alternatively.
The R interfaces to Keras and TensorFlow paintings by means of embedding a complete Python
procedure in R (by way of the
reticulate package deal). Certainly one of
the most important advantages of this design is that R customers have complete get admission to to
the whole lot in each R and Python. In different phrases, the R interface
all the time has characteristic parity with the Python interface—the rest you’ll
do with TensorFlow in Python, you’ll do in R simply as simply. This implies
the discharge notes for the Python releases of TensorFlow are simply as
related for R customers:

Thank you for studying!

Picture by means of Raphael
Wild

on
Unsplash

Reuse

Textual content and figures are approved underneath Inventive Commons Attribution CC BY 4.0. The figures which have been reused from different assets do not fall underneath this license and can also be identified by means of a be aware of their caption: “Determine from …”.

Quotation

For attribution, please cite this paintings as

Kalinowski (2022, June 9). Posit AI Weblog: TensorFlow and Keras 2.9. Retrieved from https://blogs.rstudio.com/tensorflow/posts/2022-06-09-tf-2-9/

BibTeX quotation

@misc{kalinowskitf29,
  creator = {Kalinowski, Tomasz},
  identify = {Posit AI Weblog: TensorFlow and Keras 2.9},
  url = {https://blogs.rstudio.com/tensorflow/posts/2022-06-09-tf-2-9/},
  12 months = {2022}
}

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: