from sklearn.feature_extraction.text import CountVectorizer

# Sample corpus
corpus = [
    "I love machine learning",
    "Machine learning is great",
    "I love coding"
]

# Initialize the CountVectorizer
vectorizer = CountVectorizer()

# Fit the model and transform the corpus into BoW vectors
X = vectorizer.fit_transform(corpus)


# Convert the result to an array format
bow_array = X.toarray()

# Get the feature names (i.e., the vocabulary)
vocabulary = vectorizer.get_feature_names_out()

print("Vocabulary:", vocabulary)
print("Bag-of-Words Vectors:\n", bow_array)
