我是NLP的新手。我用木星笔记本把我的JSON文件转换成CSV。我不知道如何使用标记化和柠檬化等技术对我的数据进行预处理。在将数据转换成CSV格式之前,我对数据进行了规范化处理,所以现在我有了一个数据框架。请如何在整个数据集上应用标记化过程,并且使用split()
函数会给我一个错误?
发布于 2022-03-31 17:19:01
好吧,像这样的东西应该能用:
import json
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
with open('data_full.json','r') as f:
data0 = f.read()
rawdata = json.loads(data0)
for dataset,instances in rawdata.items():
for instance in instances:
sentence = instance[0]
label = instance[1]
tokens = word_tokenize(sentence)
print('in ',dataset,': ', '|'.join(tokens),'; label:', instance[1])
lemmas = [ lemmatizer.lemmatize(token) for token in tokens ]
print(' lemmas = ','|'.join(lemmas))
注意:您可能需要为nltk安装一些资源,遵循错误消息中的说明。
https://datascience.stackexchange.com/questions/109378
复制相似问题