Sequence representation

Spatial signals

41- sequence representation -cnn.jpg

Temporal signals

41- Method sequence representing - Signal .jpg

# Sequence

41- representation sequence - sequences .jpg

Sequence embedding

  • [B, seq_len, feature_len] # 1 sentence 10 4 words each word meaning, [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 point represents a price

41- representation sequence - a sequence diagram .jpg

[b,28,28]

41- sequence representation - Picture .jpg

  • The number of times scanned images into a concept of time

41- sequence representation - Digital 6.jpg

Batch

  • [b,word num,word vec]

  • [word num,b,word vec]

41- -batch waveform representation sequence .jpg

[words,word vec]

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

41- sequence representation - word vector .jpg

  • sparse

  • high-dim

41- sequence representation - word similarity .jpg

  • semantic similarity

  • trainable

Word embedding

41- Method sequence representing - word error .jpg

  • Word2Vec vs GloVe

41- sequence representation - word training .jpg

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)>]

Guess you like

Origin www.cnblogs.com/nickchen121/p/10960760.html