本文共 684 字,大约阅读时间需要 2 分钟。
import tensorflow_hub as hubembed = hub.load("./nnlm-zh-dim50-with-normalization_2")
embeddings = embed(["男 人", "女 人"])embeddings.shape
embeddings[0]
embeddings[1]
v1 = embeddings[0].numpy().reshape(1,-1)v2 = embeddings[1].numpy().reshape(1,-1)
import sklearnsklearn.metrics.pairwise.cosine_similarity(v1, v2)
import tensorflow as tf
hub_layer = hub.KerasLayer("./nnlm-zh-dim50-with-normalization_2", output_shape=[50], input_shape=[], dtype=tf.string)model = tf.keras.Sequential()model.add(hub_layer)model.add(tf.keras.layers.Dense(16, activation='relu'))model.add(tf.keras.layers.Dense(1, activation='sigmoid'))model.summary()
转载地址:http://nhbtz.baihongyu.com/