tf.keras.preprocessing.sequence.make_sampling_table
Генерирует таблицу вероятностного выборочного отбора на основе ранга слова.
tf.keras.preprocessing.sequence.make_sampling_table(
size, sampling_factor=1e-05
)
Используется для генерации аргумента sampling_table для skipgrams. sampling_table[i] — вероятность выборки i-го по частоте слова в наборе данных (более частые слова должны выбираться реже, для баланса).
Вероятности выборки генерируются в соответствии с распределением выборки, используемым в word2vec:
p(word) = (min(1, sqrt(word_frequency / sampling_factor) /
(word_frequency / sampling_factor)))
Мы предполагаем, что частоты слов следуют закону Ципфа (s=1), чтобы получить численное приближение частоты(ранг):
frequency(rank) ~ 1/(rank * (log(rank) + gamma) + 1/2 - 1/(12*rank)) где gamma — постоянная Эйлера–Маскерони.
Аргументы
size: Int, number of possible words to sample. sampling_factor: The sampling factor in the word2vec formula.
Возвращаемые значения
A 1D Numpy array of length `size` where the ith entry is the probability that a word of rank i should be sampled.
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/preprocessing/sequence/make_sampling_table