benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 08eb254d-8bf7-5d7f-b958-56e88018ff53

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import pandas as pd
import regex as re
from sklearn.feature_extraction.text import CountVectorizer


def task_func(text):
    """
    Analyze a text by creating a document term matrix with CountVectorizer. The text contains several sentences, each separated by a period.
    Ignore empty sentences.

    Parameters:
    text (str): The text to analyze.

    Returns:
    DataFrame: A pandas DataFrame with the document-term matrix. Its column names should be adapted from the vectorizer feature names.

    Requirements:
    - pandas
    - regex
    - sklearn.feature_extraction.text.CountVectorizer

    Example:
    >>> text = "This is a sample sentence. This sentence contains sample words."
    >>> dtm = task_func(text)
    >>> print(dtm)
       contains  is  sample  sentence  this  words
    0         0   1       1         1     1      0
    1         1   0       1         1     1      1
    """

instruct prompt

Analyze a text by creating a document term matrix with CountVectorizer. The text contains several sentences, each separated by a period. Ignore empty sentences.
The function should output with:
    DataFrame: A pandas DataFrame with the document-term matrix. Its column names should be adapted from the vectorizer feature names.
You should write self-contained code starting with:

Code

import pandas as pd
import regex as re
from sklearn.feature_extraction.text import CountVectorizer
def task_func(text):

code prompt

Code

import pandas as pd
import regex as re
from sklearn.feature_extraction.text import CountVectorizer
def task_func(text):

entry point

task_func

libs

  • regex
  • pandas
  • sklearn

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import