MCPcopy Create free account
hub / github.com/awslabs/gap-text2sql / print_2d_tensor

Function print_2d_tensor

relogic/logickit/utils/utils.py:7–14  ·  view source on GitHub ↗

Print a 2D tensor

(tensor)

Source from the content-addressed store, hash-verified

5import itertools
6
7def 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
16def entropy(p):
17 """Compute the entropy of a probability distribution"""

Callers

nothing calls this directly

Calls 1

logMethod · 0.80

Tested by

no test coverage detected