def skipgrams(sequence, vocabulary_size, window_size=4, negative_samples=1.0, shuffle=True, categorical=False, sampling_table=None):
 couples = []
 labels = []
 for (i, wi) in enumerate(sequence):
  if (not wi):
   continue
  if (sampling_table is not None):
   if (sampling_table[wi] < random.random()):
    continue
  window_start = max(0, (i - window_size))
  window_end = min(len(sequence), ((i + window_size) + 1))
  for j in range(window_start, window_end):
   if (j != i):
    wj = sequence[j]
    if (not wj):
     continue
    couples.append([wi, wj])
    if categorical:
     labels.append([0, 1])
    else:
     labels.append(1)
 if (negative_samples > 0):
  nb_negative_samples = int((len(labels) * negative_samples))
  words = [c[0] for c in couples]
  random.shuffle(words)
  couples += [[words[(i % len(words))], random.randint(1, (vocabulary_size - 1))] for i in range(nb_negative_samples)]
  if categorical:
   labels += ([[1, 0]] * nb_negative_samples)
  else:
   labels += ([0] * nb_negative_samples)
 if shuffle:
  seed = random.randint(0, 10000000.0)
  random.seed(seed)
  random.shuffle(couples)
  random.seed(seed)
  random.shuffle(labels)
 return (couples, labels)

def skipgrams ( sequence , vocabulary_size , window_size = 4 , negative_samples = 1.0 , shuffle = True , categorical = False , sampling_table = None ) : couples = [ ] labels = [ ] for ( i , wi ) in enumerate ( sequence ) : if ( not wi ) : continue if ( sampling_table is not None ) : if ( sampling_table [ wi ] < random . random ( ) ) : continue window_start = max ( 0 , ( i - window_size ) ) window_end = min ( len ( sequence ) , ( ( i + window_size ) + 1 ) ) for j in range ( window_start , window_end ) : if ( j != i ) : wj = sequence [ j ] if ( not wj ) : continue couples . append ( [ wi , wj ] ) if categorical : labels . append ( [ 0 , 1 ] ) else : labels . append ( 1 ) if ( negative_samples > 0 ) : nb_negative_samples = int ( ( len ( labels ) * negative_samples ) ) words = [ c [ 0 ] for c in couples ] random . shuffle ( words ) couples += [ [ words [ ( i % len ( words ) ) ] , random . randint ( 1 , ( vocabulary_size - 1 ) ) ] for i in range ( nb_negative_samples ) ] if categorical : labels += ( [ [ 1 , 0 ] ] * nb_negative_samples ) else : labels += ( [ 0 ] * nb_negative_samples ) if shuffle : seed = random . randint ( 0 , 10000000.0 ) random . seed ( seed ) random . shuffle ( couples ) random . seed ( seed ) random . shuffle ( labels ) return ( couples , labels )
returns all possible skipgrams generated from a sequence of items .