def test_skipgrams():
# test with no window size and binary labels
couples, labels = skipgrams(np.arange(3), vocabulary_size=3)
for couple in couples:
assert couple[0] in [0, 1, 2] and couple[1] in [0, 1, 2]
# test window size and categorical labels
couples, labels = skipgrams(np.arange(5), vocabulary_size=5, window_size=1,
categorical=True)
for couple in couples:
assert couple[0] - couple[1] <= 3
for l in labels:
assert len(l) == 2
python类skipgrams()的实例源码
def test_skipgrams():
# test with no window size and binary labels
couples, labels = skipgrams(np.arange(3), vocabulary_size=3)
for couple in couples:
assert couple[0] in [0, 1, 2] and couple[1] in [0, 1, 2]
# test window size and categorical labels
couples, labels = skipgrams(np.arange(5), vocabulary_size=5, window_size=1,
categorical=True)
for couple in couples:
assert couple[0] - couple[1] <= 3
for l in labels:
assert len(l) == 2
def test_skipgrams():
# test with no window size and binary labels
couples, labels = skipgrams(np.arange(3), vocabulary_size=3)
for couple in couples:
assert couple[0] in [0, 1, 2] and couple[1] in [0, 1, 2]
# test window size and categorical labels
couples, labels = skipgrams(np.arange(5), vocabulary_size=5, window_size=1,
categorical=True)
for couple in couples:
assert couple[0] - couple[1] <= 3
for l in labels:
assert len(l) == 2