Print a 2D tensor
(tensor)
| 5 | import itertools |
| 6 | |
| 7 | def print_2d_tensor(tensor): |
| 8 | """ Print a 2D tensor """ |
| 9 | utils.log("lv, h >\t" + "\t".join(f"{x + 1}" for x in range(len(tensor)))) |
| 10 | for row in range(len(tensor)): |
| 11 | if tensor.dtype != torch.long: |
| 12 | utils.log(f"layer {row + 1}:\t" + "\t".join(f"{x:.5f}" for x in tensor[row].cpu().data)) |
| 13 | else: |
| 14 | utils.log(f"layer {row + 1}:\t" + "\t".join(f"{x:d}" for x in tensor[row].cpu().data)) |
| 15 | |
| 16 | def entropy(p): |
| 17 | """Compute the entropy of a probability distribution""" |