Datasets documentation

텍스트 데이터 로드

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

텍스트 데이터 로드

이 가이드에서는 텍스트 데이터셋을 로드하는 방법을 보여줍니다. 모든 유형의 데이터셋을 로드하는 방법을 배우려면 일반 로드 가이드를 참고하세요.

Text 파일은 데이터를 저장하는 가장 일반적인 파일 형식 중 하나입니다. 기본적으로 🤗 Datasets는 Text 파일을 줄 단위로 샘플링하여 dataset을 구성합니다.

>>> from datasets import load_dataset
>>> dataset = load_dataset("text", data_files={"train": ["my_text_1.txt", "my_text_2.txt"], "test": "my_test_file.txt"})

# Load from a directory
>>> dataset = load_dataset("text", data_dir="path/to/text/dataset")

문단 또는 전체 문서 단위로 텍스트 파일을 샘플링하려면 sample_by 매개변수를 사용하세요:

# Sample by paragraph
>>> dataset = load_dataset("text", data_files={"train": "my_train_file.txt", "test": "my_test_file.txt"}, sample_by="paragraph")

# Sample by document
>>> dataset = load_dataset("text", data_files={"train": "my_train_file.txt", "test": "my_test_file.txt"}, sample_by="document")

grep 패턴을 사용하여 특정 파일을 로드할 수도 있습니다:

>>> from datasets import load_dataset
>>> c4_subset = load_dataset("allenai/c4", data_files="en/c4-train.0000*-of-01024.json.gz")

HTTP를 통해 원격 텍스트 파일을 로드하려면 대신 URL을 전달하세요:

>>> dataset = load_dataset("text", data_files="https://huggingface.co/datasets/hf-internal-testing/dataset_with_data_files/resolve/main/data/train.txt")

To load XML data you can use the “xml” loader, which is equivalent to “text” with sample_by=“document”:

>>> from datasets import load_dataset
>>> dataset = load_dataset("xml", data_files={"train": ["my_xml_1.xml", "my_xml_2.xml"], "test": "my_xml_file.xml"})

# Load from a directory
>>> dataset = load_dataset("xml", data_dir="path/to/xml/dataset")
Update on GitHub