尊敬的社区成员:,
在数据的预处理过程中,在将原始数据分割成标记之后,我使用了流行的WordNet Lemmatizer来生成词干。我正在一个拥有18953个令牌的数据集上进行实验。
我的问题是,引理化过程是否减少了语料库的大小?
我很困惑,请帮忙。感谢您的帮助!

最佳答案

引理化将句子中的每个标记(akaform)转换为其引理形式(akatype):

>>> from nltk import word_tokenize
>>> from pywsd.utils import lemmatize_sentence

>>> text = ['This is a corpus with multiple sentences.', 'This was the second sentence running.', 'For some reasons, there is a need to second foo bar ran.']

>>> lemmatize_sentence(text[0]) # Lemmatized sentence example.
['this', 'be', 'a', 'corpus', 'with', 'multiple', 'sentence', '.']
>>> word_tokenize(text[0]) # Tokenized sentence example.
['This', 'is', 'a', 'corpus', 'with', 'multiple', 'sentences', '.']
>>> word_tokenize(text[0].lower()) # Lowercased and tokenized sentence example.
['this', 'is', 'a', 'corpus', 'with', 'multiple', 'sentences', '.']

如果我们对句子进行引理化,每个标记都应该收到相应的引理形式,因此无论是form还是type,单词的数目都保持不变:
>>> num_tokens = sum([len(word_tokenize(sent.lower())) for sent in text])
>>> num_lemmas = sum([len(lemmatize_sentence(sent)) for sent in text])
>>> num_tokens, num_lemmas
(29, 29)


>>> [lemmatize_sentence(sent) for sent in text] # lemmatized sentences
[['this', 'be', 'a', 'corpus', 'with', 'multiple', 'sentence', '.'], ['this', 'be', 'the', 'second', 'sentence', 'running', '.'], ['for', 'some', 'reason', ',', 'there', 'be', 'a', 'need', 'to', 'second', 'foo', 'bar', 'ran', '.']]

>>> [word_tokenize(sent.lower()) for sent in text] # tokenized sentences
[['this', 'is', 'a', 'corpus', 'with', 'multiple', 'sentences', '.'], ['this', 'was', 'the', 'second', 'sentence', 'running', '.'], ['for', 'some', 'reasons', ',', 'there', 'is', 'a', 'need', 'to', 'second', 'foo', 'bar', 'ran', '.']]

“压缩”本身是指在对句子进行元化之后,整个语料库中表示的唯一标记的数量,例如。
>>> lemma_vocab = set(chain(*[lemmatize_sentence(sent) for sent in text]))
>>> token_vocab = set(chain(*[word_tokenize(sent.lower()) for sent in text]))
>>> len(lemma_vocab), len(token_vocab)
(21, 23)

>>> lemma_vocab
{'the', 'this', 'to', 'reason', 'for', 'second', 'a', 'running', 'some', 'sentence', 'be', 'foo', 'ran', 'with', '.', 'need', 'multiple', 'bar', 'corpus', 'there', ','}
>>> token_vocab
{'the', 'this', 'to', 'for', 'sentences', 'a', 'second', 'running', 'some', 'is', 'sentence', 'foo', 'reasons', 'with', 'ran', '.', 'need', 'multiple', 'bar', 'corpus', 'there', 'was', ','}

注:元素化是一个预处理步骤。但它不应该用引理形式覆盖你的原始语料库。

关于python - 趋词化机制是否会减少语料库的大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51943811/

10-15 23:27