Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FeatureUnion of CountVectorizers returns "empty vocabulary" error #3164

@FragLegs

Description

@FragLegs

When a CountVectorizer is used to extract n-grams and n > number of words (or characters) in the document, it will return a ValueError with the "empty vocabulary" message, which is the solution to #1207 . This is frustrating behavior when that CountVectorizer is part of a FeatureUnion whose other steps may have successfully extracted features. Here is sample code that shows the issue:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import FeatureUnion

steps = [('uni', CountVectorizer(ngram_range=(1,1))),
    ('tri', CountVectorizer(ngram_range=(3,3))),
    ('five', CountVectorizer(ngram_range=(5,5)))]

union = FeatureUnion(steps)
texts = ['This is a test']
union.fit(texts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions