Create a random binary tensor of shape `shape`. `sparsity` is a value between 0 and 1 controlling the ratio of 0s to 1s in the output tensor.
(shape, sparsity=0.5)
| 89 | |
| 90 | |
| 91 | def random_binary_tensor(shape, sparsity=0.5): |
| 92 | """ |
| 93 | Create a random binary tensor of shape `shape`. `sparsity` is a value |
| 94 | between 0 and 1 controlling the ratio of 0s to 1s in the output tensor. |
| 95 | """ |
| 96 | return (np.random.rand(*shape) >= (1 - sparsity)).astype(float) |
| 97 | |
| 98 | |
| 99 | def random_paragraph(n_words, vocab=None): |
nothing calls this directly
no outgoing calls
no test coverage detected