|
@@ -6,6 +6,7 @@ import torch.utils.data |
|
|
from typing import List, \
|
|
|
from typing import List, \
|
|
|
Union
|
|
|
Union
|
|
|
import decagon_pytorch.sampling
|
|
|
import decagon_pytorch.sampling
|
|
|
|
|
|
import scipy.stats
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_unigram_01():
|
|
|
def test_unigram_01():
|
|
@@ -78,9 +79,7 @@ def test_unigram_02(): |
|
|
|
|
|
|
|
|
neg_samples = decagon_pytorch.sampling.fixed_unigram_candidate_sampler(
|
|
|
neg_samples = decagon_pytorch.sampling.fixed_unigram_candidate_sampler(
|
|
|
true_classes=true_classes,
|
|
|
true_classes=true_classes,
|
|
|
num_true=num_true,
|
|
|
|
|
|
num_samples=batch_size,
|
|
|
num_samples=batch_size,
|
|
|
range_max=range_max,
|
|
|
|
|
|
distortion=distortion,
|
|
|
distortion=distortion,
|
|
|
unigrams=unigrams)
|
|
|
unigrams=unigrams)
|
|
|
|
|
|
|
|
@@ -120,22 +119,54 @@ def test_unigram_02(): |
|
|
def test_unigram_03():
|
|
|
def test_unigram_03():
|
|
|
range_max = 7
|
|
|
range_max = 7
|
|
|
distortion = 0.75
|
|
|
distortion = 0.75
|
|
|
batch_size = 500
|
|
|
|
|
|
|
|
|
batch_size = 25
|
|
|
unigrams = [ 1, 3, 2, 1, 2, 1, 3]
|
|
|
unigrams = [ 1, 3, 2, 1, 2, 1, 3]
|
|
|
num_true = 1
|
|
|
num_true = 1
|
|
|
|
|
|
|
|
|
true_classes = np.zeros((batch_size, num_true), dtype=np.int64)
|
|
|
true_classes = np.zeros((batch_size, num_true), dtype=np.int64)
|
|
|
for i in range(batch_size):
|
|
|
for i in range(batch_size):
|
|
|
true_classes[i, 0] = i % range_max
|
|
|
true_classes[i, 0] = i % range_max
|
|
|
true_classes_tf = tf.convert_to_tensor(true_classes)
|
|
|
|
|
|
|
|
|
|
|
|
neg_samples, _, _ = tf.nn.fixed_unigram_candidate_sampler(
|
|
|
|
|
|
true_classes=true_classes_tf,
|
|
|
|
|
|
num_true=num_true,
|
|
|
|
|
|
num_sampled=batch_size,
|
|
|
|
|
|
unique=False,
|
|
|
|
|
|
range_max=range_max,
|
|
|
|
|
|
distortion=distortion,
|
|
|
|
|
|
unigrams=unigrams)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true_classes_tf = tf.convert_to_tensor(true_classes)
|
|
|
true_classes_torch = torch.tensor(true_classes)
|
|
|
true_classes_torch = torch.tensor(true_classes)
|
|
|
|
|
|
|
|
|
|
|
|
counts_tf = defaultdict(list)
|
|
|
|
|
|
counts_torch = defaultdict(list)
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(100):
|
|
|
|
|
|
neg_samples, _, _ = tf.nn.fixed_unigram_candidate_sampler(
|
|
|
|
|
|
true_classes=true_classes_tf,
|
|
|
|
|
|
num_true=num_true,
|
|
|
|
|
|
num_sampled=batch_size,
|
|
|
|
|
|
unique=False,
|
|
|
|
|
|
range_max=range_max,
|
|
|
|
|
|
distortion=distortion,
|
|
|
|
|
|
unigrams=unigrams)
|
|
|
|
|
|
|
|
|
|
|
|
counts = defaultdict(int)
|
|
|
|
|
|
with tf.Session() as sess:
|
|
|
|
|
|
neg_samples = neg_samples.eval()
|
|
|
|
|
|
for x in neg_samples:
|
|
|
|
|
|
counts[x] += 1
|
|
|
|
|
|
for k, v in counts.items():
|
|
|
|
|
|
counts_tf[k].append(v)
|
|
|
|
|
|
|
|
|
|
|
|
neg_samples = decagon_pytorch.sampling.fixed_unigram_candidate_sampler(
|
|
|
|
|
|
true_classes=true_classes,
|
|
|
|
|
|
num_samples=batch_size,
|
|
|
|
|
|
distortion=distortion,
|
|
|
|
|
|
unigrams=unigrams)
|
|
|
|
|
|
|
|
|
|
|
|
counts = defaultdict(int)
|
|
|
|
|
|
for x in neg_samples:
|
|
|
|
|
|
counts[x] += 1
|
|
|
|
|
|
for k, v in counts.items():
|
|
|
|
|
|
counts_torch[k].append(v)
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(range_max):
|
|
|
|
|
|
print('counts_tf[%d]:' % i, counts_tf[i])
|
|
|
|
|
|
print('counts_torch[%d]:' % i, counts_torch[i])
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(range_max):
|
|
|
|
|
|
statistic, pvalue = scipy.stats.ttest_ind(counts_tf[i], counts_torch[i])
|
|
|
|
|
|
assert pvalue * range_max > .05
|