我在编译此代码时遇到错误
def preprocess_text(genuine, clickbait, vocabulary):
genuine = clean(genuine)
clickbait = clean(clickbait)
words = nltk.word_tokenize(genuine) + nltk.word_tokenize(clickbait)
glove_vocabulary = open("G:\clickbait-detector-
master\data/vocabulary.glove.txt").read().split("\n")
counts = Counter(word for word in words if word in glove_vocabulary)
vocabulary = [PAD, UNK] + [word for word, count in
counts.most_common(VOCABULARY_SIZE-2)]
genuine = [mark_unknown_words(vocabulary, sentence) for sentence in
tqdm.tqdm(genuine.split("\n"), desc="genuine")]
clickbait = [mark_unknown_words(vocabulary, sentence) for sentence in
tqdm.tqdm(clickbait.split("\n"), desc="clickbait")]
return (vocabulary, "\n".join(genuine), "\n".join(clickbait))
if __name__ == "__main__":
genuine = open("G:\clickbait-detector-master\data/genuine.txt").read()
clickbait = open("G:\clickbait-detector-master\data/clickbait.txt").read()
vocabulary, genuine_preprocessed, clickbait_preprocessed =
preprocess_text(genuine, clickbait)
open("G:\clickbait-detector-master\data/vocabulary.txt",
"w").write("\n".join(vocabulary))
open("G:\clickbait-detector-master\data/genuine.preprocessed.txt",
"w").write("\n".join(genuine))
open("G:\clickbait-detector-master\data/clickbait.preprocessed.txt",
"w").write("\n".join(clickbait))
我的错误是 TypeError:preprocess_text()缺少1个必需的位置参数: “词汇”
答案 0 :(得分:0)
您的通话:preprocess_text(genuine, clickbait)
只有2个参数,您的定义:def preprocess_text(genuine, clickbait, vocabulary):
要求3个