日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow--embedding_lookup 和 embedding_lookup_sparse

發布時間:2024/7/5 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow--embedding_lookup 和 embedding_lookup_sparse 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

tf.nn.embedding_lookup ( tensor, id )

作用:選取一個張量里面索引對應的元素
應用場景:單值離散特征的 embedding,相當于 one-hot 編碼

用戶\水果蘋果香蕉草莓芒果西瓜木瓜火龍果
user11000000
user20001000
user30000001
import tensorflow as tf import numpy as npp = tf.Variable(np.arange(21).reshape(7,3)) u = tf.nn.embedding_lookup(p, ids=[0, 3, 6]) with tf.Session() as s:s.run(tf.global_variables_initializer())print(s.run(t))# [[ 0 1 2] --- p # [ 3 4 5] # [ 6 7 8] # [ 9 10 11] # [12 13 14] # [15 16 17] # [18 19 20]]# [[ 0 1 2] ---user1 # [ 9 10 11] ---user2 # [18 19 20]] ---user3

tf.nn.embedding_lookup_sparse(params, sp_ids)

作用:選取一個張量里面多個索引對應的元素的平均值
應用場景:多值離散特征的 embedding,相當于多次 one-hot 后取平均值

用戶\水果蘋果香蕉草莓芒果西瓜木瓜火龍果
user11110000
user21001000
user30000111
import tensorflow as tf import numpy as npp = tf.Variable(np.arange(21).reshape(7,3), dtype=tf.float32) gs = tf.SparseTensor(indices=[[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1]], values=[0,1,2,6,0,3,4,5], dense_shape=(3,3)) embedded_tags = tf.nn.embedding_lookup_sparse(p, sp_ids=tags, sp_weights=None)with tf.Session() as s:s.run([tf.global_variables_initializer(), tf.tables_initializer()])print(s.run([embedded_tags]))#[[ 3. , 4. , 5. ], ---user1 # [ 9. , 10. , 11. ], ---user2 # [13.5, 14.5, 15.5]] ---user3

比如 user1:( [ 0 1 2 ] + [ 3 4 5 ] + [ 6 7 8 ] ) / 3 = [ 3. , 4. , 5. ]

相關參考:推薦系統遇上深度學習(四)–多值離散特征的embedding解決方案

總結

以上是生活随笔為你收集整理的tensorflow--embedding_lookup 和 embedding_lookup_sparse的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。