Python3 Keras分词器Tokenizer
2021/10/2 20:43:31
本文主要是介绍Python3 Keras分词器Tokenizer,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import keras.preprocessing.sequence from keras.preprocessing.text import Tokenizer samples = ['我 爱 你 无畏 人海的 拥挤','用尽 余生的 力气 只为 找到 你','你'] # 创建分词器实例 # split 默认字符为空格 tokenizer = Tokenizer() tokenizer.fit_on_texts(samples) # word_counts:字典形式 出现过多少次 print(tokenizer.word_counts) # word_docs: 字典 print(tokenizer.word_docs) one_hot_results = tokenizer.texts_to_matrix(samples) print(one_hot_results) # 获得单词索引 word_index = tokenizer.word_index print(word_index) #document_count: 整数 几个字符串 print(tokenizer.document_count) print('Found %s.'% len(word_index)) print(tokenizer.texts_to_sequences(["我 爱 你 无畏 人海的 拥挤"])) print(keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences(["我 爱 你 无畏 人海的 拥挤"]),maxlen=20))
截图:
这篇关于Python3 Keras分词器Tokenizer的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python