#单词级的one-hot编码import numpy as np
samples=['The cat sat on tne mat.','The dog ate my homework.']#样本可以是一个句子,也可以是一篇文档#利用split方法对样本进行分词。在实际运用中还要把标点和特殊符号分开
token_index={
}#构建数据中所有标记的索引for sample
单词字符的one-hot编码one-hot编码是将标记转换为向量的最常用、最基本的方法。1、单词级的one-hot编码#单词级的one-hot编码import numpy as npsamples=['The cat sat on tne mat.','The dog ate my homework.']#样本可以是一个句子,也可以是一篇文档#利用split方法对样本进行分词。在实际运用中还要把标点和特殊符号分开token_index={}#构建数据中所有标记的索引for sample i