MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / encode

Function encode

model-experiments/masked-language-model/infer.py:58–67  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

56
57# Turns text into list of vocabulary indices.
58def encode(text):
59 R = [0] * config.MAX_LEN # all padding
60 text = tokenize(text)
61 for i in range(len(text)):
62 w = text[i]
63 if w in token2id:
64 R[i] = token2id[w]
65 else:
66 R[i] = 1 # OOV: [UNK]
67 return np.array(R)
68
69# Opposite of encode: restores text string from token ids.
70def decode(tokens):

Callers 1

predictFunction · 0.70

Calls 1

tokenizeFunction · 0.70

Tested by

no test coverage detected