测试tensorflow-hub安装:通用语句编码器

时间:2019-05-17 14:30:00

标签: python tensorflow tensorflow-hub

我想从这里link尝试通用句子编码器

这是我在Ubuntu 18.04和Jupyter Notebook上运行的代码

 //I prefer using DidReceiveRemoteNotification because in my experience 
 //the other one is sometimes not reliable:

 public override void DidReceiveRemoteNotification(UIApplication application, 
        NSDictionary userInfo, 
        Action<UIBackgroundFetchResult> completionHandler)
    {              
        //Simply passing on all the parameters called in this method:

         IncomingNotificationHandler.Shared.HandleNotificationsIfAny(application, userInfo, completionHandler);
     }


 //WillEnterForeground also calls the handler without any parameters
 //because it doesn't automatically know anything about notifications:

  public override void WillEnterForeground(UIApplication application)
    {
        IncomingNotificationHandler.Shared.HandleNotificationsIfAny();
    }

它一直在运行,什么也没发生。正在下载内容吗?我已经等了很长时间了。它不会显示以下内容:

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder/2")
embeddings = embed([
    "The quick brown fox jumps over the lazy dog.",
    "I am a sentence for which I would like to get its embedding"])

print(session.run(embeddings))

我检查了我的tensorflow安装。看起来不错。 有任何故障排除建议吗?

1 个答案:

答案 0 :(得分:1)

你很好。此错误消息讨论仅在TensorFlow 2中使用TF Hub才有意义的符号,尤其是hub.KerasLayer。建立的TF1.x用法可以正常工作。

代码已提交(但尚未由常规的Hub版本获取)以切换到不太令人震惊的措辞。抱歉造成混乱。