File size: 3,872 Bytes
db6aa40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# Train NFQA Model with Automatic Data Splitting
#
# This script trains the NFQA classification model using a single combined
# dataset that will be automatically split into train/val/test sets.
#
# Usage:
#   bash run_training_auto.sh
#
# Or with custom parameters:
#   bash run_training_auto.sh --epochs 15 --batch-size 32
#

set -e  # Exit on error

# Default paths
INPUT_FILE="../output/webfaq_nfqa_combined_highquality.jsonl"
OUTPUT_DIR="../output/training/nfqa_model_auto"

# Default training parameters
MODEL_NAME="xlm-roberta-base"
EPOCHS=6
BATCH_SIZE=16
LEARNING_RATE=2e-5
MAX_LENGTH=128
WARMUP_STEPS=500
WEIGHT_DECAY=0.1
DROPOUT=0.2
TEST_SIZE=0.2
VAL_SIZE=0.1

echo "================================================================================"
echo "NFQA Model Training - Automatic Split Mode"
echo "================================================================================"
echo ""
echo "Training Configuration:"
echo "  Input file:       $INPUT_FILE"
echo "  Output directory: $OUTPUT_DIR"
echo "  Model:            $MODEL_NAME"
echo "  Epochs:           $EPOCHS"
echo "  Batch size:       $BATCH_SIZE"
echo "  Learning rate:    $LEARNING_RATE"
echo "  Max length:       $MAX_LENGTH"
echo "  Weight decay:     $WEIGHT_DECAY"
echo "  Dropout:          $DROPOUT"
echo "  Test split:       $TEST_SIZE (20%)"
echo "  Val split:        $VAL_SIZE (10%)"
echo ""
echo "================================================================================"
echo ""

# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
    echo "❌ Error: Input file not found: $INPUT_FILE"
    echo ""
    echo "Please ensure the combined dataset exists."
    echo "You can create it by running:"
    echo "  cd ../annotator"
    echo "  python combine_datasets.py"
    exit 1
fi

# Create output directory
mkdir -p "$OUTPUT_DIR"

# Run training
python train_nfqa_model.py \
    --input "$INPUT_FILE" \
    --output-dir "$OUTPUT_DIR" \
    --model-name "$MODEL_NAME" \
    --epochs "$EPOCHS" \
    --batch-size "$BATCH_SIZE" \
    --learning-rate "$LEARNING_RATE" \
    --max-length "$MAX_LENGTH" \
    --warmup-steps "$WARMUP_STEPS" \
    --weight-decay "$WEIGHT_DECAY" \
    --dropout "$DROPOUT" \
    --test-size "$TEST_SIZE" \
    --val-size "$VAL_SIZE" \
    "$@"  # Pass any additional arguments from command line

# Check if training was successful
if [ $? -eq 0 ]; then
    echo ""
    echo "================================================================================"
    echo "✅ Training completed successfully!"
    echo "================================================================================"
    echo ""
    echo "Model saved to: $OUTPUT_DIR"
    echo ""
    echo "Generated files:"
    echo "  - best_model/                  (best checkpoint based on validation F1)"
    echo "  - final_model/                 (final epoch checkpoint)"
    echo "  - training_history.json        (training metrics)"
    echo "  - training_curves.png          (loss/accuracy/F1 plots)"
    echo "  - test_results.json            (final test metrics)"
    echo "  - classification_report.txt    (per-category performance)"
    echo "  - confusion_matrix.png         (confusion matrix visualization)"
    echo ""
    echo "Next steps:"
    echo "  1. Review training curves: $OUTPUT_DIR/training_curves.png"
    echo "  2. Check test results: $OUTPUT_DIR/test_results.json"
    echo "  3. Analyze confusion matrix: $OUTPUT_DIR/confusion_matrix.png"
    echo "  4. Deploy model from: $OUTPUT_DIR/best_model/"
    echo ""
else
    echo ""
    echo "================================================================================"
    echo "❌ Training failed!"
    echo "================================================================================"
    echo ""
    echo "Please check the error messages above and try again."
    exit 1
fi