目录

Spatial signals

序列表示方法 人工智能 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Temporal signals

序列表示方法 人工智能 第2张

# Sequence

序列表示方法 人工智能 第3张

Sequence embedding

  • [b,seq_len,feature_len] # 1个句子10个单词每个单词4个意思,[1,10,4]

  • e.g. I like it.

import tensorflow as tf

tf.convert_to_tensor([[1,0,0],[0,1,0],[0,0,1]])
<tf.Tensor: id=4, shape=(3, 3), dtype=int32, numpy=
array([[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1]], dtype=int32)>

[b,100,1]

  • [price,scalar,1] # 1-->1个点表示一个价格

序列表示方法 人工智能 第4张

[b,28,28]

序列表示方法 人工智能 第5张

  • 对图片扫描的次数变成了时间的概念

序列表示方法 人工智能 第6张

Batch

  • [b,word num,word vec]

  • [word num,b,word vec]

序列表示方法 人工智能 第7张

[words,word vec]

  • How to represent a word
    • [Rome, Italy, ...]
  • one hot

序列表示方法 人工智能 第8张

  • sparse

  • high-dim

序列表示方法 人工智能 第9张

  • semantic similarity

  • trainable

Word embedding

序列表示方法 人工智能 第10张

  • Word2Vec vs GloVe

序列表示方法 人工智能 第11张

Embedding Layer

  • Random initialized embedding
from tensorflow.keras import layers

x = tf.range(5)
x = tf.random.shuffle(x)
x
<tf.Tensor: id=10, shape=(5,), dtype=int32, numpy=array([0, 4, 3, 2, 1], dtype=int32)>
net = layers.Embedding(10,4)
net(x)
<tf.Tensor: id=26, shape=(5, 4), dtype=float32, numpy=
array([[-0.04665176, -0.00618398, -0.02745042, -0.0418861 ],
       [-0.00495533, -0.02990632, -0.04187028, -0.03159492],
       [ 0.00022942, -0.01628833, -0.00680885, -0.03196504],
       [-0.0023623 ,  0.04522124,  0.02052191, -0.02518519],
       [ 0.0211277 , -0.03581526,  0.00149528,  0.04243053]],
      dtype=float32)>
net.trainable
True
net.trainable_variables
[<tf.Variable 'embedding/embeddings:0' shape=(10, 4) dtype=float32, numpy=
 array([[-0.04665176, -0.00618398, -0.02745042, -0.0418861 ],
        [ 0.0211277 , -0.03581526,  0.00149528,  0.04243053],
        [-0.0023623 ,  0.04522124,  0.02052191, -0.02518519],
        [ 0.00022942, -0.01628833, -0.00680885, -0.03196504],
        [-0.00495533, -0.02990632, -0.04187028, -0.03159492],
        [ 0.04476041,  0.00983595,  0.01300793, -0.00486787],
        [ 0.00272337,  0.00402355, -0.04166143,  0.01867583],
        [-0.01088942,  0.02177001,  0.01363814, -0.04016535],
        [-0.04173249, -0.03866537, -0.0426992 ,  0.00479555],
        [ 0.02334514,  0.01809745, -0.03649411, -0.00876436]],
       dtype=float32)>]
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄