Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow: tf.summary.text and linebreaks

How do you use tf.summary.text to emit text that contains linebreaks?

I have tried replacing '\n' with <br> but I cannot get the output to show proper linebreaks. Without proper linebreaks makes it very hard to read yaml output as shown here:

enter image description here

like image 474
user3504575 Avatar asked Jul 10 '17 15:07

user3504575


5 Answers

Tensorboard text uses the markdown format (though it doesn't support all its features). That means you need to add 2 spaces before \n to produce a linebreak, e.g. line_1 \nline_2 \nline_3

like image 140
Jason CHAN Avatar answered Oct 06 '22 23:10

Jason CHAN


I had been encountering the same issue, so I will answer here what I found ( I put this in the issue as well).

For me I cared specifically about tables and regardless of line break type \n or \r\n ( or double space for that matter) it results in the same line-ending-less output.

| heading | heading | |--- |--- | | key | value | | key | value |

I entirely missed the part about 2d tensors will be rendered as tables but the following does create a table:

tl = [
    ["**key**","**value**"],
    ["key_2","`value_2`"],
    ["key_3","value_3"]
]
tfboard.add_summary(sess.run(tf.summary.text("eh1", tf.convert_to_tensor(tl))))

So it looks like all newlines are just stripped from single strings and if you want consecutive lines, try making a table as a list.

like image 23
ehiller Avatar answered Oct 06 '22 23:10

ehiller


In case you want to dump a pandas DataFrame, use to_markdown().

like image 36
user66081 Avatar answered Oct 06 '22 23:10

user66081


Based on the documentation:

The standard TensorBoard Text Dashboard will render markdown in the strings, and will .....

So you need to provide strings as you would provide them for markdown (<br> and \n do not work in markdown so they do not work here as well).

like image 42
Salvador Dali Avatar answered Oct 07 '22 01:10

Salvador Dali


Use \n\n. It produces too much line break though.

like image 39
user1210230 Avatar answered Oct 07 '22 01:10

user1210230