TensorFlow 2.10上线:Windows上扩展GPU支持,TF-DF 1.0发布
机器之心报道
TensorFlow 2.10 已发布,还没有更新的小伙伴现在可以更新了。
import tensorflow as tf
embedding = tf.keras.layers.Embedding(
input_dim=10,
output_dim=3,
mask_zero=True) # Infer a correct padding mask.
# Instantiate a Keras multi-head attention (MHA) layer,
# a layer normalization layer, and an `Add` layer object.
mha = tf.keras.layers.MultiHeadAttention(key_dim=4, num_heads=1)
layernorm = tf.keras.layers.LayerNormalization()
add = tf.keras.layers.Add()
# Test input.
x = tf.constant([[1, 2, 3, 4, 5, 0, 0, 0, 0],
[1, 2, 1, 0, 0, 0, 0, 0, 0]])
# The embedding layer sets the mask.
x = embedding(x)
# The MHA layer uses and propagates the mask.
a = mha(query=x, key=x, value=x, use_causal_mask=True)
x = add([x, a]) # The `Add` layer propagates the mask.
x = layernorm(x)
# The mask made it through all layers.
print(x._keras_mask)
> tf.Tensor(
> [[ True True True True True False False False False]
> [ True True True False False False False False False]], shape=(2, > 9), dtype=bool)
掌握「声纹识别技术」:前20小时交给我,后9980小时……
© THE END
转载请联系本公众号获得授权
投稿或寻求报道:content@jiqizhixin.com
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号
随时掌握互联网精彩
随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 中俄关系的“五个坚持” 4973486
- 2 央行下调个人住房公积金贷款利率 4916895
- 3 老人300万房产赠水果摊主 二审宣判 4838048
- 4 重塑“诗和远方” 4747245
- 5 B太被加油站举报 4629461
- 6 京哈高速辽宁段一桥梁垮塌 4561376
- 7 戚薇二公排名第一 4444331
- 8 #电影朝云暮雨# 4359489
- 9 重庆辟谣有人从飞机上掉落 4262386
- 10 新一轮房产新政触发“抢人潮” 4189533