benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf cb49af52-b7a0-582d-a162-012bf37e443e

Problem

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

complete prompt

from nltk.tokenize import word_tokenize
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd


def task_func(documents):
    """
    Calculate the TF-IDF score of the words in a list of documents.
    
    Parameters:
    - documents (list of str): A list of text documents.
    
    Returns:
    pandas.DataFrame: A DataFrame with words as columns and documents as rows, containing the TF-IDF scores.
    
    Requirements:
    - nltk.tokenize.word_tokenize
    - sklearn.feature_extraction.text.TfidfVectorizer
    - pandas
    
    Example:
    >>> docs = ['This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?']
    >>> tfidf = task_func(docs)
    >>> print(tfidf.shape)
    (4, 11)
    """

instruct prompt

Calculate the TF-IDF score of the words in a list of documents.
The function should output with:
    pandas.DataFrame: A DataFrame with words as columns and documents as rows, containing the TF-IDF scores.
You should write self-contained code starting with:

Code

from nltk.tokenize import word_tokenize
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
def task_func(documents):

code prompt

Code

from nltk.tokenize import word_tokenize
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
def task_func(documents):

entry point

task_func

libs

  • nltk
  • 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