Ryoo72 commited on
Commit
3292e39
·
verified ·
1 Parent(s): 4e7c6f0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +113 -0
README.md CHANGED
@@ -27,3 +27,116 @@ configs:
27
  - split: train
28
  path: data/train-*
29
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  - split: train
28
  path: data/train-*
29
  ---
30
+
31
+
32
+ ```
33
+ import json
34
+ import copy
35
+ from datasets import Dataset
36
+ from huggingface_hub import login
37
+
38
+ def create_huggingface_dataset(num_entities=10000):
39
+ # 긴 텍스트 생성을 위한 함수
40
+ def generate_long_text():
41
+ long_text = ""
42
+ for char in "abcdefghijk": # a부터 k까지
43
+ for i in range(1000): # 000부터 999까지
44
+ long_text += f"{char}{i:03d}" # 예: a000, a001, ..., k999
45
+ return long_text
46
+
47
+ # 공통으로 사용할 긴 텍스트 생성 (메모리 효율성을 위해)
48
+ long_text = generate_long_text()
49
+
50
+ # 이미지 경로 설정 - 이제 각 엔티티마다 이미지 경로 리스트 생성
51
+ image_path = "./large_image_for_debug.jpg"
52
+
53
+ # 데이터셋 구조 생성을 위한 빈 리스트
54
+ images_list = []
55
+ messages_list = []
56
+
57
+ # 10,000개의 동일한 entity 생성
58
+ for i in range(num_entities):
59
+ # 각 엔티티마다 이미지 경로 리스트 추가 (1개의 이미지 포함)
60
+ images_list.append([image_path]) # 리스트로 감싸서 추가
61
+
62
+ # 메시지 생성
63
+ message = [
64
+ {
65
+ "role": "user",
66
+ "content": [
67
+ {
68
+ "type": "image",
69
+ "index": 0,
70
+ "text": None
71
+ },
72
+ {
73
+ "type": "text",
74
+ "index": None,
75
+ "text": f"Write a000 to k999 (Entity {i+1})"
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "role": "assistant",
81
+ "content": [
82
+ {
83
+ "type": "text",
84
+ "index": None,
85
+ "text": long_text
86
+ }
87
+ ]
88
+ }
89
+ ]
90
+
91
+ messages_list.append(message)
92
+
93
+ # 최종 데이터셋 구조
94
+ dataset_dict = {
95
+ "images": images_list,
96
+ "messages": messages_list
97
+ }
98
+
99
+ return dataset_dict
100
+
101
+ # 허깅페이스 로그인 (API 토큰 필요)
102
+ login() # 이 부분에서 토큰을 요청하거나 환경 변수에서 가져옵니다
103
+
104
+ # 데이터셋 생성
105
+ print("데이터셋 생성 중...")
106
+ dataset_dict = create_huggingface_dataset()
107
+
108
+ # 생성된 데이터셋의 크기 확인
109
+ entity_count = len(dataset_dict["messages"])
110
+ print(f"생성된 entity 수: {entity_count}")
111
+ print(f"첫 번째 entity의 images 형식: {dataset_dict['images'][0]}") # 이미지가 리스트 형태인지 확인
112
+
113
+ # HuggingFace Dataset 객체로 변환
114
+ # 메모리 효율을 위해 청크로 나누어 처리
115
+ chunk_size = 100 # 한 번에 처리할 entity 수
116
+ dataset_chunks = []
117
+
118
+ for i in range(0, entity_count, chunk_size):
119
+ end_idx = min(i + chunk_size, entity_count)
120
+ chunk_dict = {
121
+ "images": dataset_dict["images"][i:end_idx],
122
+ "messages": dataset_dict["messages"][i:end_idx]
123
+ }
124
+ dataset_chunks.append(Dataset.from_dict(chunk_dict))
125
+
126
+ # 청크들을 하나의 데이터셋으로 결합
127
+ from datasets import concatenate_datasets
128
+ final_dataset = concatenate_datasets(dataset_chunks)
129
+
130
+ # 데이터셋의 실제 형식 확인
131
+ print("데이터셋 샘플 형식:")
132
+ print(final_dataset[0])
133
+
134
+ # 데이터셋 허브에 업로드
135
+ print("허깅페이스 허브에 데이터셋 업로드 중...")
136
+ final_dataset.push_to_hub(
137
+ "Ryoo72/long_for_debug", # 여기에 자신의 사용자 이름과 원하는 데이터셋 이름 입력
138
+ private=True # 비공개 설정 (선택사항)
139
+ )
140
+
141
+ print("데이터셋 업로드 완료!")
142
+ ```