Python字符串转为列表
发布时间
阅读量:
阅读量
本文主要讲述了如何将一段中文字符串转换为列表的形式,在其中部分中采用了keras preprocessing库中的text_to_word_sequence函数,在处理中文数据时表现出色。值得注意的是通常情况下,在处理中文语料时,默认情况下各个字符之间是没有空格分割的 这种分隔方式与英语不同 例如 如果我们直接进行转换 由于没有空格分词 ACHIEVING this directly would not yield the desired results 如果我们 proceed without proper Chinese word segmentation the string would be treated as a single token
from tensorflow.keras.preprocessing.text import text_to_word_sequence
text = '我是人'
token = text_to_word_sequence(text)
print(token)
print(type(token))
print(token[0])
运行结果如下 :
['我是人']
<class 'list'>
我是人
为了解决这一问题,
全部评论 (0)
还没有任何评论哟~
