保存符号张量以备后用

huangapple go评论69阅读模式
英文:

Saving symbolic Tensor for later use

问题

我正在跟随 TensorFlow 的教程学习一个聊天机器人,想知道如何在后续步骤中保存编码器的输出?我知道符号张量的值可以用 tf.print 打印出来,也可以写入 tf.TensorArray 中。由于聊天机器人模型的结构,全局变量不会受到训练过程中对它们所做更改的影响,那么在训练期间如何将这些张量保存在诸如 tf.TensorArray 中以备后续迭代使用呢?

英文:

I am following the tutorial from TensorFlow for a chatbot and was wondering how you could save the output of the encoder later passes? I know the values of symbolic tensors can be printed out with tf.print and they can be written into tf.TensorArray's. Because of how the chatbot model is structured, global variables will not be affected by changes made to them during training, so how does one save these tensors in things like tf.TensorArray's for later iterations during training?

答案1

得分: 0

如果您使用 run_eagerly=True 编译您的模型,那么您可以在训练过程中正确使用全局变量。如果您想在批次之间保存符号张量,那就会变得有点困难,所以我选择将我的层作为不使用符号张量的类来实现。

英文:

If you compile your model with run_eagerly=True then you can properly use global variables during training. If you want to save symbolic tensors between batches, it gets a little more difficult so I opted to make my layers as classes that don't use symbolic tensors instead.

huangapple
  • 本文由 发表于 2023年5月25日 22:10:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定