Skip to Main Content
机器学习设计模式
book

机器学习设计模式

by Valliappa Lakshmanan, Sara Robinson, Michael Munn
September 2022
Beginner to intermediate content levelBeginner to intermediate
386 pages
7h 36m
Chinese
Southeast University Press
Content preview from 机器学习设计模式
数据表示设计模式
47
9: 'on',
10: 'with',
11: 'show',
...
然后,我们可以使用标记器的
texts_to_sequences
方法调用这个映射。这将被表示
的文本输入中的每个单词序列(这里,我们假设它们是文章的标题)映射到与每个
单词对应的词符序列,如图
2-7
所示:
integerized_titles = tokenizer.texts_to_sequences(titles_df.title)
2
-
7
:使用分词器,每个标题都被映射到一个整数索引值序列。
分词器包含我们稍后将用于创建嵌入层的其他相关信息。特别地,
VOCAB_SIZE
捕获
索引查找表的元素数量,
MAX_LEN
包含数据集中文本字符串的最大长度:
VOCAB_SIZE = len(tokenizer.index_word)
MAX_LEN = max(len(sequence) for sequence in integerized_titles)
在创建模型之前,需要对数据集中的标题进行预处理。我们需要填充标题中的元素
以输入到模型中。
Keras
在分词器方法的顶部有一个辅助函数
pad_sequence
。函数
create_sequences
将标题和句子最大长度都作为输入,并返回与填充到句子最大长
度的词符对应的整数列表:
from tensorflow.keras.preprocessing.sequence import pad_sequences
def create_sequences(texts, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PyTorch深度学习

PyTorch深度学习

Posts & Telecom Press, Vishnu Subramanian
数据科学原理

数据科学原理

Posts & Telecom Press, Sinan Ozdemir
Rust程序设计

Rust程序设计

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall

Publisher Resources

ISBN: 9787564196776