What is the difference between tf.Tensor( and <tf.Tensor: >


Consider below code

import pprint

import numpy as np
import tensorflow as tf
import tensorflow_datasets as tfds
ratings = tfds.load("movielens/100k-ratings", split="train")
movies = tfds.load("movielens/100k-movies", split="train")

ratings = ratings.map(lambda x: {
    "movie_title": x["movie_title"],
    "user_id": x["user_id"],
    "user_rating": x["user_rating"],
    # "timestamp": x["timestamp"],
movies = movies.map(lambda x: x["movie_title"])
for example in movies.take(2):
  # pprint.pprint(tf.reshape(example['movie_title'],[3,5,1]))

The above code will give me output as below

<tf.Tensor: shape=(), dtype=string, numpy=b'You So Crazy (1994)'>
<tf.Tensor: shape=(), dtype=string, numpy=b'Love Is All There Is (1996)'>

Now below code will give different result.

Lets say we have below data in a csv file with name songs_details.csv

0,SOAAAGQ12A8C1420C8,Orgelblut,Dolores,Bohren  Der Club Of Gore,2008,1
1,SOAACPJ12A81C21360,Cearc Agus Coileach  The Hen And Cock,CasadhTurning,Mchel  Silleabhin,1,1
2,SOAAEJI12AB0188AB5,Godlovesugly,God Loves Ugly,Atmosphere,1,1
3,SOAAFAC12A67ADF7EB,Rome Wasnt Built In A Day,Parts Of The Process,Morcheeba,2000,2
4,SOAAKPM12A58A77210,So Confused feat Butta Creame amended album version,Late Night Special,Pretty Ricky,2007,1
5,SOAAOYI12AB01831CE,Criminal,Gotan Project live,Gotan Project,2006,2

Now lets read this csv file and process it

songs = tf.data.experimental.make_csv_dataset(
songs = songs.unbatch().map(lambda x: {

for example in songs.map(lambda x: x['title']).take(2):

The above will produce output as below

tf.Tensor(b'Skip The Youth', shape=(), dtype=string)
tf.Tensor(b'Teenage Dirtbag', shape=(), dtype=string)

are there any difference between the two representation of variables, I mean between tf.Tensor() and <tf.Tensor: >

TF version used is 2.9.1


There are no significant differences between the two representations of the variables. The only difference is that you use pprint for one variable and print for the other variable. Both functions seem to print Tensorflow tensors a little differently. However, this does not affect the tensors themselves. Printing both with pprint or print will yield the same results.

Answered By – AloneTogether

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published