MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_context

Function get_context

nlp_class2/word2vec_tf.py:350–364  ·  view source on GitHub ↗
(pos, sentence, window_size)

Source from the content-addressed store, hash-verified

348
349
350def get_context(pos, sentence, window_size):
351 # input:
352 # a sentence of the form: x x x x c c c pos c c c x x x x
353 # output:
354 # the context word indices: c c c c c c
355
356 start = max(0, pos - window_size)
357 end_ = min(len(sentence), pos + window_size)
358
359 context = []
360 for ctx_pos, ctx_word_idx in enumerate(sentence[start:end_], start=start):
361 if ctx_pos != pos:
362 # don't include the input word itself as a target
363 context.append(ctx_word_idx)
364 return context
365
366
367

Callers 1

train_modelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected