博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tfhub简介
阅读量:599 次
发布时间:2019-03-11

本文共 684 字,大约阅读时间需要 2 分钟。

t f h u b 简 介 tfhub简介 tfhub

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/

你可能感兴趣的文章