当前位置:网站首页>tf. keras. layers. Embedding function
tf. keras. layers. Embedding function
2022-04-23 02:56:00 【Live up to your youth】
The function prototype
tf.keras.layers.Embedding(input_dim,
output_dim,
embeddings_initializer='uniform',
embeddings_regularizer=None,
activity_regularizer=None,
embeddings_constraint=None,
mask_zero=False,
input_length=None,
**kwargs
)
Function description
The embedding layer is mainly responsible for converting a feature into a vector . The embedded layer is generally placed on the first layer , It is often used in the processing of natural language sequences .

As shown in the figure above , Each word corresponds to a label , such as “late” Corresponding 3、“yeah” Corresponding 8, In this way, the word sequence can be transformed into a vector , It is convenient for data processing . The Embedding The function of layer is to map each label value in the vector into a 3 Dimension vector , In this way, a three-dimensional vector can be used to represent a word .
Embedding Function realizes the function of embedded layer . Parameters input_dim Indicates the size of the vocabulary , For example, the word sequence to be processed has 100 That's ok , Every line has 50 Word , So there's a total of 5000 Word , Assume that this 5000 Different words in a word are 2000 individual , Then the vocabulary of the input data is 2000.
Parameters output_dim Represents the vector dimension of each word mapping , If you need to use 20 A dimensional vector represents a word , that output_dim for 20. There is also a common parameter input_length, This parameter is used to specify the length of the input word sequence , If the word sequence length is 30 individual , Then the value of this parameter should be set to 30. If no parameters are set input_length, Then the length of the input sequence can be changed .
Be careful ,Embedding The layer input is a two-dimensional tensor , Shape is (batch_size, input_length), The output shape is (batch_size, input_length, output_dim), It's a three-dimensional tensor .
The usage function
model = tf.keras.models.Sequential([
# Embedded layer , The vocabulary is 256
tf.keras.layers.Embedding(256, 125),
# LSTM layer
tf.keras.layers.LSTM(125, return_sequences=True),
# LSTM layer
tf.keras.layers.LSTM(125, return_sequences=True),
# Fully connected in the time dimension Dense layer
tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(256, activation="softmax"))
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding (Embedding) (None, None, 125) 32000
lstm (LSTM) (None, None, 125) 125500
lstm_1 (LSTM) (None, None, 125) 125500
time_distributed (TimeDistr (None, None, 256) 32256
ibuted)
=================================================================
Total params: 315,256
Trainable params: 315,256
Non-trainable params: 0
_________________________________________________________________
版权声明
本文为[Live up to your youth]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220657127212.html
边栏推荐
- Rhcsa day 3 operation
- Linux redis - redis ha sentinel cluster construction details & redis master-slave deployment
- MySQL insert free column
- Log4j知识点记录
- Close the computer port
- Mosaic Routing: implement / home / news
- Navicat premium import SQL file
- 重大危险源企业如何保障年底前完成双预防机制数字化建设任务
- Codeforces Round #784 (Div. 4) (A - H)题解
- Shell script learning notes - regular expressions
猜你喜欢

基于ele封装下拉菜单等组件

机器学习(周志华) 第十四章概率图模型

1215_ Hello world used by scons

How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year

Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow

Opencv fills the rectangle with a transparent color

grain rain

Leangoo brain map - shared multi person collaborative mind mapping tool

Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet

ROP Emporium x86_64 7~8题
随机推荐
Restart redis
The problem of removing spaces from strings
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
《信息系統項目管理師總結》第六章 項目人力資源管理
It turns out that PID was born in the struggle between Lao wangtou and Lao sky
Planning code ROS migration POMDP prediction planning (I)
leangoo脑图-共享式多人协作思维导图工具分享
Codeforces Round #784 (Div. 4) (A - H)题解
MySQL / SQL Server判断表或临时表存在则删除
L2-006 树的遍历(中后序确定二叉树&层序遍历)
Niuke white moon race 5 [problem solving mathematics field]
Specific field information of MySQL export table (detailed operation of Navicat client)
ele之Table表格的封装
Android 高阶面试必问:全局业务和项目的架构设计与重构
Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
Navicat premium import SQL file
Microservices (distributed architecture)
Store consumption SMS notification template
Shell script learning notes - regular expressions
Modify the content of MySQL + PHP drop-down box