|
|
|
@ -725,7 +725,7 @@ def nce(input,
|
|
|
|
|
|
|
|
|
|
window_size = 5
|
|
|
|
|
words = []
|
|
|
|
|
for i in xrange(window_size):
|
|
|
|
|
for i in range(window_size):
|
|
|
|
|
words.append(fluid.data(
|
|
|
|
|
name='word_{0}'.format(i), shape=[-1, 1], dtype='int64'))
|
|
|
|
|
|
|
|
|
@ -733,7 +733,7 @@ def nce(input,
|
|
|
|
|
label_word = int(window_size / 2) + 1
|
|
|
|
|
|
|
|
|
|
embs = []
|
|
|
|
|
for i in xrange(window_size):
|
|
|
|
|
for i in range(window_size):
|
|
|
|
|
if i == label_word:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
@ -746,14 +746,14 @@ def nce(input,
|
|
|
|
|
num_total_classes=dict_size, param_attr='nce.w_0',
|
|
|
|
|
bias_attr='nce.b_0')
|
|
|
|
|
|
|
|
|
|
#or use custom distribution
|
|
|
|
|
dist = np.array([0.05,0.5,0.1,0.3,0.05])
|
|
|
|
|
loss = fluid.layers.nce(input=embs, label=words[label_word],
|
|
|
|
|
num_total_classes=5, param_attr='nce.w_1',
|
|
|
|
|
bias_attr='nce.b_1',
|
|
|
|
|
num_neg_samples=3,
|
|
|
|
|
sampler="custom_dist",
|
|
|
|
|
custom_dist=dist)
|
|
|
|
|
#or use custom distribution
|
|
|
|
|
dist = np.array([0.05,0.5,0.1,0.3,0.05])
|
|
|
|
|
loss = fluid.layers.nce(input=embs, label=words[label_word],
|
|
|
|
|
num_total_classes=5, param_attr='nce.w_1',
|
|
|
|
|
bias_attr='nce.b_1',
|
|
|
|
|
num_neg_samples=3,
|
|
|
|
|
sampler="custom_dist",
|
|
|
|
|
custom_dist=dist)
|
|
|
|
|
"""
|
|
|
|
|
helper = LayerHelper('nce', **locals())
|
|
|
|
|
check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'nce')
|
|
|
|
|