benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf c2c54699-d1c3-5e08-94cd-0156d155e2ea

Problem

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

complete prompt

import re
from sklearn.feature_extraction.text import CountVectorizer
import numpy as np

# Constants
SENTENCES = ['This is a sentence', 'Another sentence here', 'More sentences']

def task_func(s: str) -> np.ndarray:
    """
    Vectorize a string using the Bag-of-Words model. The string is split into words and each word is treated as an attribute. The value of each attribute is the number of occurrences of the word in the string. The function also uses some predefined sentences (SENTENCES constant) for vectorization.

    Parameters:
    - s (str): The string to vectorize.

    Returns:
    - np.ndarray: A numpy array with the vectorized string.

    Requirements:
    - re
    - sklearn.feature_extraction.text.CountVectorizer
    - numpy

    Example:
    >>> s = 'This is a test string.'
    >>> vec = task_func(s)
    >>> print(vec)
    [0 0 1 0 0 0 1 1 1]
    """

instruct prompt

Vectorize a string using the Bag-of-Words model. The string is split into words and each word is treated as an attribute. The value of each attribute is the number of occurrences of the word in the string. The function also uses some predefined sentences (SENTENCES constant) for vectorization.
The function should output with:
    np.ndarray: A numpy array with the vectorized string.
You should write self-contained code starting with:

Code

import re
from sklearn.feature_extraction.text import CountVectorizer
import numpy as np
# Constants
SENTENCES = ['This is a sentence', 'Another sentence here', 'More sentences']
def task_func(s: str) -> np.ndarray:

code prompt

Code

import re
from sklearn.feature_extraction.text import CountVectorizer
import numpy as np
# Constants
SENTENCES = ['This is a sentence', 'Another sentence here', 'More sentences']
def task_func(s: str) -> np.ndarray:

entry point

task_func

libs

  • numpy
  • re
  • 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