MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / contextwin

Function contextwin

code/rnnslu.py:45–63  ·  view source on GitHub ↗

win :: int corresponding to the size of the window given a list of indexes composing a sentence l :: array containing the word indexes it will return a list of list of indexes corresponding to context windows surrounding each word in the sentence

(l, win)

Source from the content-addressed store, hash-verified

43
44# start-snippet-1
45def contextwin(l, win):
46 '''
47 win :: int corresponding to the size of the window
48 given a list of indexes composing a sentence
49
50 l :: array containing the word indexes
51
52 it will return a list of list of indexes corresponding
53 to context windows surrounding each word in the sentence
54 '''
55 assert (win % 2) == 1
56 assert win >= 1
57 l = list(l)
58
59 lpadded = win // 2 * [-1] + l + win // 2 * [-1]
60 out = [lpadded[i:(i + win)] for i in range(len(l))]
61
62 assert len(out) == len(l)
63 return out
64# end-snippet-1
65
66

Callers 2

trainMethod · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected