benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 70883493-c6e1-5035-8a63-f20c94d4b9d3

Problem

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

complete prompt

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


def task_func(example_str):
    """
    Extract all texts not enclosed in square brackets into a string and calculate the TF-IDF values
    which are returned as a dictionary.

    Parameters:
    example_str (str): The input string.

    Returns:
    dict: A dictionary with words as keys and TF-IDF scores as values.

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

    Example:
    >>> tfidf_scores = task_func("Josie Smith [3996 COLLEGE AVENUE, SOMETOWN, MD 21003] Mugsy Dog Smith [2560 OAK ST, GLENMEADE, WI 14098]")
    >>> print(tfidf_scores)
    {'dog': 0.3779644730092272, 'josie': 0.3779644730092272, 'mugsy': 0.3779644730092272, 'smith': 0.7559289460184544}
    """

instruct prompt

Extract all texts not enclosed in square brackets into a string and calculate the TF-IDF values which are returned as a dictionary.
The function should output with:
    dict: A dictionary with words as keys and TF-IDF scores as values.
You should write self-contained code starting with:

Code

import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
import re
def task_func(example_str):

code prompt

Code

import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
import re
def task_func(example_str):

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