PyTorch#

Commands#

  • torch.Tensor.item()

    • convert tensor to standard Python number

    • only works for tensors with one element - otherwise an exception is raised

    • implicitly moves the value to the CPU

shape#

Example:

batch_size, sequence_length = attention_mask.shape