Day1 (9.27, 월)
AI Stage 로 부터 서버 생성
VSCode, Filezilla, xshell에 서버 연결
baseline 코드 이해하기
huggingface에 wandb 연동하기
Baseline 코드 바로 실행해서 제출하기
제출
1차 제출
Baseline에서
num_train_epochs
만 5로 줄임.
training_args = TrainingArguments(
output_dir='./results', # output directory
save_total_limit=5, # number of total save model.
save_steps=500, # model saving step.
num_train_epochs=5, # total number of training epochs
learning_rate=5e-5, # learning_rate
per_device_train_batch_size=16, # batch size per device during training
per_device_eval_batch_size=16, # batch size for evaluation
warmup_steps=500, # number of warmup steps for learning rate scheduler
weight_decay=0.01, # strength of weight decay
logging_dir='./logs', # directory for storing logs
logging_steps=100, # log saving step.
evaluation_strategy='steps', # evaluation strategy to adopt during training
# `no`: No evaluation during training.
# `steps`: Evaluate every `eval_steps`.
# `epoch`: Evaluate every end of epoch.
eval_steps = 500, # evaluation step.
load_best_model_at_end = True,
report_to = "wandb",
run_name = "Roberta-base-KSW"
)
{
"_name_or_path": "klue/bert-base",
"architectures": [
"BertForSequenceClassification"
],
"attention_probs_dropout_prob": 0.1,
"classifier_dropout": null,
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"id2label": {
"0": "LABEL_0",
"1": "LABEL_1",
"2": "LABEL_2",
"3": "LABEL_3",
"4": "LABEL_4",
"5": "LABEL_5",
"6": "LABEL_6",
"7": "LABEL_7",
"8": "LABEL_8",
"9": "LABEL_9",
"10": "LABEL_10",
"11": "LABEL_11",
"12": "LABEL_12",
"13": "LABEL_13",
"14": "LABEL_14",
"15": "LABEL_15",
"16": "LABEL_16",
"17": "LABEL_17",
"18": "LABEL_18",
"19": "LABEL_19",
"20": "LABEL_20",
"21": "LABEL_21",
"22": "LABEL_22",
"23": "LABEL_23",
"24": "LABEL_24",
"25": "LABEL_25",
"26": "LABEL_26",
"27": "LABEL_27",
"28": "LABEL_28",
"29": "LABEL_29"
},
"initializer_range": 0.02,
"intermediate_size": 3072,
"label2id": {
"LABEL_0": 0,
"LABEL_1": 1,
"LABEL_10": 10,
"LABEL_11": 11,
"LABEL_12": 12,
"LABEL_13": 13,
"LABEL_14": 14,
"LABEL_15": 15,
"LABEL_16": 16,
"LABEL_17": 17,
"LABEL_18": 18,
"LABEL_19": 19,
"LABEL_2": 2,
"LABEL_20": 20,
"LABEL_21": 21,
"LABEL_22": 22,
"LABEL_23": 23,
"LABEL_24": 24,
"LABEL_25": 25,
"LABEL_26": 26,
"LABEL_27": 27,
"LABEL_28": 28,
"LABEL_29": 29,
"LABEL_3": 3,
"LABEL_4": 4,
"LABEL_5": 5,
"LABEL_6": 6,
"LABEL_7": 7,
"LABEL_8": 8,
"LABEL_9": 9
},
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"problem_type": "single_label_classification",
"torch_dtype": "float32",
"transformers_version": "4.10.0",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 32000
}
아직 다들 baseline 정도로만 작업해서인지 운좋게 점수가 잘나와서 3등 점수가 되었다.
2차 제출
baseline 그대로 20 epoch 사용
roberta-base 모델을 사용
training_args = TrainingArguments(
output_dir='./results', # output directory
save_total_limit=5, # number of total save model.
save_steps=500, # model saving step.
num_train_epochs=20, # total number of training epochs
learning_rate=5e-5, # learning_rate
per_device_train_batch_size=16, # batch size per device during training
per_device_eval_batch_size=16, # batch size for evaluation
warmup_steps=500, # number of warmup steps for learning rate scheduler
weight_decay=0.01, # strength of weight decay
logging_dir='./logs', # directory for storing logs
logging_steps=100, # log saving step.
evaluation_strategy='steps', # evaluation strategy to adopt during training
# `no`: No evaluation during training.
# `steps`: Evaluate every `eval_steps`.
# `epoch`: Evaluate every end of epoch.
eval_steps = 500, # evaluation step.
load_best_model_at_end = True,
report_to = "wandb",
run_name = "Roberta-base-KSW"
)
{
"_name_or_path": "roberta-base",
"architectures": [
"RobertaForSequenceClassification"
],
"attention_probs_dropout_prob": 0.1,
"bos_token_id": 0,
"classifier_dropout": null,
"eos_token_id": 2,
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"id2label": {
"0": "LABEL_0",
"1": "LABEL_1",
"2": "LABEL_2",
"3": "LABEL_3",
"4": "LABEL_4",
"5": "LABEL_5",
"6": "LABEL_6",
"7": "LABEL_7",
"8": "LABEL_8",
"9": "LABEL_9",
"10": "LABEL_10",
"11": "LABEL_11",
"12": "LABEL_12",
"13": "LABEL_13",
"14": "LABEL_14",
"15": "LABEL_15",
"16": "LABEL_16",
"17": "LABEL_17",
"18": "LABEL_18",
"19": "LABEL_19",
"20": "LABEL_20",
"21": "LABEL_21",
"22": "LABEL_22",
"23": "LABEL_23",
"24": "LABEL_24",
"25": "LABEL_25",
"26": "LABEL_26",
"27": "LABEL_27",
"28": "LABEL_28",
"29": "LABEL_29"
},
"initializer_range": 0.02,
"intermediate_size": 3072,
"label2id": {
"LABEL_0": 0,
"LABEL_1": 1,
"LABEL_10": 10,
"LABEL_11": 11,
"LABEL_12": 12,
"LABEL_13": 13,
"LABEL_14": 14,
"LABEL_15": 15,
"LABEL_16": 16,
"LABEL_17": 17,
"LABEL_18": 18,
"LABEL_19": 19,
"LABEL_2": 2,
"LABEL_20": 20,
"LABEL_21": 21,
"LABEL_22": 22,
"LABEL_23": 23,
"LABEL_24": 24,
"LABEL_25": 25,
"LABEL_26": 26,
"LABEL_27": 27,
"LABEL_28": 28,
"LABEL_29": 29,
"LABEL_3": 3,
"LABEL_4": 4,
"LABEL_5": 5,
"LABEL_6": 6,
"LABEL_7": 7,
"LABEL_8": 8,
"LABEL_9": 9
},
"layer_norm_eps": 1e-05,
"max_position_embeddings": 514,
"model_type": "roberta",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 1,
"position_embedding_type": "absolute",
"problem_type": "single_label_classification",
"torch_dtype": "float32",
"transformers_version": "4.10.0",
"type_vocab_size": 1,
"use_cache": true,
"vocab_size": 50265
}
roberta-base 모델을 사용시에 유의사항
[load_data.py]
tokenized_sentences = tokenizer(
concat_entity,
list(dataset['sentence']),
return_tensors="pt",
padding=True,
truncation=True,
max_length=256,
add_special_tokens=True,
return_token_type_ids=False,
)
return_token_type_ids=False
outputs = model(
input_ids=data['input_ids'].to(device),
attention_mask=data['attention_mask'].to(device)#,
#token_type_ids=data['token_type_ids'].to(device)
)
token_type_ids=data['token_type_ids'].to(device)
삭제
왜 이렇게 되는지에 대해서는 찾아봐야할 것 같다.
이걸 몰라서 아슬아슬하게 제출을 못해본게 아쉽다.
WandB
첫 날 제출은 못했지만, 밤 동안에 돌아갈 수 있도록 20epoch으로 학습을 진행하였다. 하지만 과적합 되서인지 1차때 제출한 만큼의 성능을 얻을 수 없었다.
2회 때는 실수로 제대로 추론이 되지 않았고, 20epoch으로 제출하자 37.6으로 낮은 점수를 얻은 것을 확인 할 수 있었다. 종혁님 이야기처럼 4epoch 이상 돌리면 오히려 점수가 나오지 않을 수 있을 것 같다.
후기
이미지 분류 대회를 했을 때도 일단 제출을 해봐야 감이 좀 오는 것 같아서 이번에도 기본 코드를 실행해서 제출하는 프로세스를 시도해보았다. 사실 epoch만 좀 줄이고 python train.csv / python inference.py 한게 전부지만 코드를 돌려보면서 흐름을 어느정도 볼 수 있었다.
내일은 train set과 validation set 분리해서 점수를 매길수 있도록 세팅하는 작업을 해야겠다. 팀 제출이다보니 조심스럽게 되고, 한번 돌리는데 소요되는 시간이 너무 길어서 밤에 돌릴 수 있도록 세팅도 필요할 것으로 보인다.
Last updated