Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

archive

LLM 파인튜닝 트레인 데이터셋 데이터 전처리 본문

AIH 학부연구생/23_2 연구 논문

LLM 파인튜닝 트레인 데이터셋 데이터 전처리

안정민 2024. 2. 10. 14:01

Data_preprocess.ipynb
0.11MB


 

데이터 전처리 프로세스는 캐글을 참고해서 처리하긴 했다

사실 처리 부분에서 참고한 부분은, 데이터 분석 부분인데, 사실 데이터를 보고 아 키 값이 아니라 밸류 값 부분을 조금 깔끔하게 정제하고, url 같은 것들은 좀 걸러내고, 길이도 줄여야겠다 싶은 부분들은 있었으나, 키값에 대한 부분을 전혀 고려하고 있지 않았는데, 다음과 같이 확인해 보니 데이터가 주어진 비율적인 부분들이 달랐다는 것도 알게 되어 생각보다 노이즈가 많은 데이터를 사용 중이었구나 느낌. 그리고 확실히 데이터를 사용하기 전에는 이것저것 분석하고 비율을 따져보며 신중하게 접근해야한다는 것을 느꼈다.


(+)아 그리고 뭔가 모델 파인튜닝을 바로 저 큰 데이터로 돌리기 무서워서

트레인 데이터 셋을 셋으로 나눠서 집어넣기로 함 

그래서 다음이 위에 올려둔 파일에 추가된 코드임

 

import os

def split_csv_to_train_sets(input_csv_file, output_directory, num_train_sets=3):
    # Ensure output directory exists
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    # Read the input CSV file
    df = pd.read_csv(input_csv_file)

    # Calculate number of rows per train set
    num_rows_per_set = len(df) // num_train_sets

    # Split the dataframe into train sets
    for i in range(num_train_sets):
        start_idx = i * num_rows_per_set
        end_idx = start_idx + num_rows_per_set if i < num_train_sets - 1 else None
        train_set = df.iloc[start_idx:end_idx]

        # Save the train set to a CSV file
        output_filename = os.path.join(output_directory, f"train_set_{i+1}.csv")
        train_set.to_csv(output_filename, index=False)

        print(f"Train set {i+1} saved to {output_filename}")

# Example usage
input_csv_file = "input_data.csv"
output_directory = "train_sets"
split_csv_to_train_sets(input_csv_file, output_directory)