【发布时间】:2018-02-28 13:46:17
【问题描述】:
我目前正在处理一个包含原始文本的数据集,我应该对其进行预处理:
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem import SnowballStemmer
from nltk.stem.wordnet import WordNetLemmatizer
stop_words = set(stopwords.words('english'))
stemmer = SnowballStemmer('english')
lemma = WordNetLemmatizer()
from autocorrect import spell
for df in [train_df, test_df]:
df['comment_text'] = df['comment_text'].apply(lambda x: word_tokenize(str(x)))
df['comment_text'] = df['comment_text'].apply(lambda x: [lemma.lemmatize(spell(word)) for word in x])
df['comment_text'] = df['comment_text'].apply(lambda x: ' '.join(x))
但是,包含spell 函数会增加内存使用量,直到出现“内存错误”。如果不使用此类功能,就不会发生这种情况。我想知道是否有办法优化这个过程,保持spell 函数(数据集有很多拼写错误的单词)。
【问题讨论】:
标签: python pandas memory-management out-of-memory