深度学习中的数据表示与学习机制
1. 文本数据的表示方法
在处理文本数据时,我们常常需要将其转换为神经网络能够处理的形式。这里主要介绍了独热编码(One-hot encoding)和文本嵌入(Text embeddings)两种方法。
1.1 单词的独热编码
独热编码是一种将文本转换为向量的常用方法。以下是具体的操作步骤:
- 数据预处理 :定义一个函数 clean_words 对输入的文本进行处理,将其转换为小写并去除标点符号。
def clean_words(input_str):
punctuation = '.,;:"!?”“_-'
word_list = input_str.lower().replace('\n',' ').split()
word_list = [word.strip(punctuation) for word in word_list]
return word_list
- 构建单词索引映射 :对处理后的文本中的单词进行排序并去重,构建一个单词到索引的字典
word2index_dict。
word_list = sorted(set(clean_words(text)))
word2index_dict = {word: i for (i, w
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



