生成一個基於單詞等級的概率抽樣表。
用法
tf.keras.preprocessing.sequence.make_sampling_table(
size, sampling_factor=1e-05
)
參數
-
size
Int,要采樣的可能單詞數。 -
sampling_factor
word2vec 公式中的采樣因子。
返回
-
一個長度為
size
的一維 Numpy 數組,其中第 i 個條目是應該對排名為 i 的單詞進行采樣的概率。
用於為 skipgrams
生成 sampling_table
參數。 sampling_table[i]
是對數據集中最常見的單詞i-th 進行采樣的概率(為了平衡,更常見的單詞應該不那麽頻繁地采樣)。
采樣概率是根據 word2vec 中使用的采樣分布生成的:
p(word) = (min(1, sqrt(word_frequency / sampling_factor) /
(word_frequency / sampling_factor)))
我們假設詞頻遵循 Zipf 定律 (s=1) 以得出頻率(秩)的數值近似:
frequency(rank) ~ 1/(rank * (log(rank) + gamma) + 1/2 - 1/(12*rank))
其中 gamma
是 Euler-Mascheroni 常數。
相關用法
- Python tf.keras.preprocessing.sequence.TimeseriesGenerator用法及代碼示例
- Python tf.keras.preprocessing.sequence.pad_sequences用法及代碼示例
- Python tf.keras.preprocessing.image.ImageDataGenerator用法及代碼示例
- Python tf.keras.preprocessing.image.smart_resize用法及代碼示例
- Python tf.keras.preprocessing.image.DirectoryIterator.__len__用法及代碼示例
- Python tf.keras.preprocessing.text.text_to_word_sequence用法及代碼示例
- Python tf.keras.applications.inception_resnet_v2.preprocess_input用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
- Python tf.keras.layers.InputLayer用法及代碼示例
- Python tf.keras.callbacks.ReduceLROnPlateau用法及代碼示例
- Python tf.keras.layers.serialize用法及代碼示例
- Python tf.keras.metrics.Hinge用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.compute_loss用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalAccuracy.merge_state用法及代碼示例
- Python tf.keras.metrics.RootMeanSquaredError用法及代碼示例
- Python tf.keras.applications.resnet50.preprocess_input用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalCrossentropy.merge_state用法及代碼示例
- Python tf.keras.metrics.sparse_categorical_accuracy用法及代碼示例
- Python tf.keras.layers.Dropout用法及代碼示例
- Python tf.keras.activations.softplus用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.preprocessing.sequence.make_sampling_table。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。