我想在 python 中使用 NLTK 训练语言模型,但我遇到了几个问题。首先,我不知道为什么我的文字在我写这样的东西时变成了字符:
s = "Natural-language processing (NLP) is an area of computer science " \
"and artificial intelligence concerned with the interactions " \
"between computers and human (natural) languages."
s = s.lower();
paddedLine = pad_both_ends(word_tokenize(s),n=2);
train, vocab = padded_everygram_pipeline(2, paddedLine)
print(list(vocab))
lm = MLE(2);
lm.fit(train,vocab)
Run Code Online (Sandbox Code Playgroud)
并且打印出来的词汇是这样的,显然是不正确的(我不想使用字符!),这是输出的一部分。:
<s>', '<', 's', '>', '</s>', '<s>', 'n', 'a', 't', 'u', 'r', 'a', 'l', '-', 'l', 'a', 'n', 'g', 'u', 'a', 'g', 'e', '</s>', '<s>', 'p', 'r', 'o', 'c', 'e', 's', …Run Code Online (Sandbox Code Playgroud)