MCPcopy Index your code
hub / github.com/pytorch/tutorials / lineToTensor

Function lineToTensor

intermediate_source/char_rnn_classification_tutorial.py:132–136  ·  view source on GitHub ↗
(line)

Source from the content-addressed store, hash-verified

130# Turn a line into a <line_length x 1 x n_letters>,
131# or an array of one-hot letter vectors
132def lineToTensor(line):
133 tensor = torch.zeros(len(line), 1, n_letters)
134 for li, letter in enumerate(line):
135 tensor[li][0][letterToIndex(letter)] = 1
136 return tensor
137
138#########################
139# Here are some examples of how to use ``lineToTensor()`` for a single and multiple character string.

Callers 2

__init__Method · 0.85

Calls 1

letterToIndexFunction · 0.85

Tested by

no test coverage detected