데이터셋을 만들어보자!
학습을 위한 데이터셋 만들기
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
명령줄 인터페이스 (CLI)
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
순서대로 나열해보자
준비물
0. 허깅페이스 데이터셋 템플릿에 맞게 구조 수정하기



1. 필요한 라이브러리 다운로드 하기





2. 허깅페이스 로그인하기

huggingface-cli login --token [token 이름]
[Hugging Face API] 허깅페이스 API key 발급 및 여러 모델 사용 예제
🔹 허깅페이스 API Hugging Face는 다양한 NLP 모델과 도구를 개발하고 공유함으로써 개발자들이 쉽게 NLP 기술을 활용할 수 있도록 지원합니다. Hugging Face의 API 서비스를 사용하면 다양한 사전 훈련된 언어 모델을 활용할 수 있으며, 이러한 모델은 대규모 데이터셋에서 사전에 학습된 상태로 제공됩니다. Hugging Face Model Hub에는 다양한 종류의 언어 모델이 포함되어 있습니다. 이러한 모델들은 이미 대량의 데이터셋으로 사전 훈련되었기 때문에 일반적인 자연어 처리 작업에 사용할 수 있습니다. API를 통해 Hugging Face에서 제공하는 미리 학습된 AI 모델을 호출하고 사용할 수 있습니다. 예를 들면, 문장 분류, 감성 분석, 기계 번역, 질문-답변 등과 같은 작..

허깅페이스에 폴더 업로드하기

huggingface-cli upload [repo-id] [local-path(내 컴퓨터 내의 경로)] [path in repo(원격 레포지토리 안에서의 경로)] --repo-type=dataset(데이터셋 업로드 시 필수)
주의! 너무 1GB이상의 데이터를 업로드할 때는 업로드 시 런타임 에러가 발생할 수 있다!
대용량 데이터셋 업로드 다루기
Repository limitations and recommendations
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
Uploading datasets
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
Repository limitations and recommendations
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
import os import shutil from huggingface_hub import HfApi, HfFolder import time # Hugging Face API 키 설정 api_token = "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" # API 키를 사용하여 HfApi 객체 생성 api = HfApi(token=api_token) # 업로드할 감정 리스트 emotions = ["amusement", "anger", "awe", "contentment", "disgust", "excitement", "fear", "sadness"] # Hugging Face 리포지토리 설정 repo_id = "xodhks/Emoset118K" # 임시 폴더 경로 설정 temp_folder = "temp_upload_folder" # 파일 업로드 함수 정의 def upload_images(batch_size=500, pause_time=300): for emotion in emotions: local_image_folder = f"E:/EmoSet-118K/image/{emotion}/" # 로컬 이미지 폴더 경로 설정 folder_in_repo = f"image/{emotion}" # 리포지토리 내 경로 설정 # 이미지 파일 이름 리스트 가져오기 및 정렬 image_files = sorted([f for f in os.listdir(local_image_folder) if f.endswith('.jpg')]) if not image_files: print(f"No images found for emotion: {emotion}") continue # 업로드 작업 시작 for batch_start in range(0, len(image_files), batch_size): # batch_size 간격으로 반복 # 임시 폴더 초기화 if os.path.exists(temp_folder): shutil.rmtree(temp_folder) os.makedirs(temp_folder) # 500개의 이미지를 임시 폴더에 복사 for i in range(batch_start, min(batch_start + batch_size, len(image_files))): src_file_path = os.path.join(local_image_folder, image_files[i]) shutil.copy(src_file_path, temp_folder) # 임시 폴더를 Hugging Face에 업로드 try: api.upload_folder( folder_path=temp_folder, path_in_repo=f"{folder_in_repo}/batch_{batch_start // batch_size + 1}", repo_id=repo_id, repo_type="dataset", # 데이터셋 리포지토리에 업로드 token=api_token # API 키를 명시적으로 설정 ) print(f"Successfully uploaded batch {batch_start // batch_size + 1} for {emotion}") except Exception as e: print(f"Failed to upload batch {batch_start // batch_size + 1} for {emotion}: {e}") # 일괄 업로드 후 잠시 대기 print(f"Batch {batch_start // batch_size + 1} for {emotion} uploaded. Waiting for {pause_time} seconds...") time.sleep(pause_time) # 함수 호출s upload_images(batch_size=50, pause_time=300)
명령줄 인터페이스 (CLI)
We’re on a journey to advance and democratize artificial intelligence through open source and open science.