Can you write code to load plain text files into a hugging face data sets data set?
- User
Can you write code to load plain text files into a hugging face data sets data set?
Assistant
Here's some code to load plain text files into a Hugging Face Dataset:
pythonimport datasets dataset = datasets.Dataset.from_files('my_dataset', files=['file1.txt', 'file2.txt']) def load_text(path): with open(path, 'r') as f: text = f.read() return text dataset = dataset.map(load_text, batched=True) print(dataset['train'][0]) # { # 'text': 'This is the content of file1.txt' # } print(dataset['train'][1]) # { # 'text': 'This is the content of file2.txt' # }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.