函数一:tf.nn.embedding_lookup()

ERROR:

I get this error: TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [float32, float64] that don't all match. 
is it because deprecated function in Tensorflow 1.0, or this is a problem with the script or a problem of deprecation can someone help

解决办法:https://stackoverflow.com/questions/43452873/bidirectional-dynamic-rnn-function-in-tensorflow-1-0

#之前的:

tf.nn.embedding_lookup(embeddings, encoder_inputs)

#修改后的:
#will cast you're embeddings to tf.float64, which was what was caussing the concat between float32 and float64 error. I solved it by replacing above with tf.nn.embedding_lookup(embeddings, encoder_inputs)
tf.cast(encoder_inputs_embedded,tf.float32) #and also casting the embeddings variable to float32 (assuming its a numpy array).

tf.nn.embedding_lookup函数的用法主要是选取一个张量里面索引对应的元素。tf.nn.embedding_lookup(tensor, id):tensor就是输入张量,id就是张量对应的索引,其他的参数不介绍。

例如:

import tensorflow as tf;
import numpy as np; c = np.random.random([10,1])
b = tf.nn.embedding_lookup(c, [1, 3]) with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print sess.run(b)
print c

输出:

[[ 0.77505197]
 [ 0.20635818]]
[[ 0.23976515]
 [ 0.77505197]
 [ 0.08798201]
 [ 0.20635818]
 [ 0.37183035]
 [ 0.24753178]
 [ 0.17718483]
 [ 0.38533808]
 [ 0.93345168]
 [ 0.02634772]]

分析:输出为张量的第一和第三个元素。

样例2:

  • 原型:tf.nn.embedding_lookup(params, ids, partition_strategy='mod', name=None, validate_indices=True, max_norm=None)
  • 在网上搜会发现基本都是假设ids只有一行,但是假如ids有若干行,会怎样?
  • 直接上代码:
# -*- coding= utf-8 -*-
import tensorflow as tf
import numpy as np a = [[0.1, 0.2, 0.3], [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3]]
a = np.asarray(a)
idx1 = tf.Variable([0, 2, 3, 1], tf.int32)
idx2 = tf.Variable([[0, 2, 3, 1], [4, 0, 2, 2]], tf.int32)
out1 = tf.nn.embedding_lookup(a, idx1)
out2 = tf.nn.embedding_lookup(a, idx2)
init = tf.global_variables_initializer() with tf.Session() as sess:
sess.run(init)
print sess.run(out1)
print out1
print '=================='
print sess.run(out2)
print out2

输出:

[[ 0.1  0.2  0.3]
[ 2.1 2.2 2.3]
[ 3.1 3.2 3.3]
[ 1.1 1.2 1.3]]
Tensor("embedding_lookup:0", shape=(4, 3), dtype=float64)
==================
[[[ 0.1 0.2 0.3]
[ 2.1 2.2 2.3]
[ 3.1 3.2 3.3]
[ 1.1 1.2 1.3]] [[ 4.1 4.2 4.3]
[ 0.1 0.2 0.3]
[ 2.1 2.2 2.3]
[ 2.1 2.2 2.3]]]
Tensor("embedding_lookup_1:0", shape=(2, 4, 3), dtype=float64)

tensorflow笔记1:基础函数、embedding_lookup的更多相关文章

  1. (四) tensorflow笔记:常用函数说明

    tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...

  2. tensorflow笔记4:函数:tf.assign()、tf.assign_add()、tf.identity()、tf.control_dependencies()

    函数原型: tf.assign(ref, value, validate_shape=None, use_locking=None, name=None)   Defined in tensorflo ...

  3. tensorflow 笔记12:函数区别:placeholder,variable,get_variable,参数共享

    一.函数意义: 1.tf.Variable() 变量 W = tf.Variable(<initial-value>, name=<optional-name>) 用于生成一个 ...

  4. tensorflow笔记 :常用函数说明

    常用函数说明,梯度.产生变量等 http://blog.csdn.net/c2a2o2/article/details/69061539

  5. JavaScript 笔记(1) -- 基础 & 函数 & 循环 & ...

    目录(代码编写): 显示数据 语法 变量 & 变量类型 对象 函数 事件 字符串 运算符 条件语句 循环语句 Break 和 Continue 使用 JS 近两年,现整理下一些基本: HTML ...

  6. SAS学习笔记2 基础函数应用

    输入输出语句(put和input函数) put()函数:把数值型或字符型变量转为字符型变量(输出变量) input()函数:将字符型变量转化为数值型变量(输入变量) 选择与删除语句(keep.drop ...

  7. tensorflow笔记:多层LSTM代码分析

    tensorflow笔记:多层LSTM代码分析 标签(空格分隔): tensorflow笔记 tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) ten ...

  8. tensorflow笔记:使用tf来实现word2vec

    (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔 ...

  9. tensorflow笔记:模型的保存与训练过程可视化

    tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...

  10. tensorflow笔记:多层CNN代码分析

    tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...

随机推荐

  1. HDU 2217 Data Structure?

    C - Data Structure? Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  2. 你想知道的关于JavaScript作用域的一切(译)

    原文链接: Everything you wanted to know about JavaScript scope 原文作者: Todd Motto JavaScript中有许多章节是关于scope ...

  3. IDEA安装使用 VisualVM 及VisualVM 远程监视

    1. VisualVM是什么 按照VisualVM官网(http://visualvm.github.io/)上的介绍,VisualVM是一个集成命令行JDK工具和轻量级分析功能的可视化工具.专为开发 ...

  4. docker-compose 管理多个docker容器实例

    Compose 安装 运行此命令下载最新版本的Docker Compose $ curl -L https://github.com/docker/compose/releases/download/ ...

  5. 使用jupyterthemes插件定制jupyter notebook界面

    jupyter notebook界面是可以定制的,定制位置在:C:\anaconda\Lib\site-packages\notebook\static\custom. 启动jupyter noteb ...

  6. 一行Python

    只要理解了函数式编程,使用神奇的Lambda, 配合列表推导以及复杂一点的判断语句,任何的python 代码都可以转换成一行代码 1.打印九九乘法表 # 打印九九乘法表 print('\n'.join ...

  7. 常用Raspberry Pi周边传感器的使用教程(转)

    转:http://bbs.xiaomi.cn/thread-7797152-1-1.html 在Raspberry Pi 的使用和开发过程中,你可能时常需要一些硬件和传感器等来支持你的开发工作,例如, ...

  8. 【LeetCode】3. Longest Substring Without Repeating Characters (2 solutions)

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  9. numpy 基于现有数据创建ndarray(from existing data)

    1 numpy.array array(object[, dtype=None, copy=True, order='K', subok=False, ndmin=0]) 2 numpy.asarra ...

  10. linux文件系统 - 初始化(三)

    执行init程序 一.目的 内核加载完initrd文件后,为挂载磁盘文件系统做好了必要的准备工作,包括挂载了sysfs.proc文件系统,加载了磁盘驱动程序驱动程序等.接下来,内核跳转到用户空间的in ...