This solution implements a BERT-based relation classification model using the specified architecture: google/bert_uncased_L-4_H-256_A-4.
- Training samples: 1,919
- Public test samples: 480
- Private test samples: 407
- Number of relation labels: 18
- Cause-Effect(e1,e2) / Cause-Effect(e2,e1)
- Component-Whole(e1,e2) / Component-Whole(e2,e1)
- Content-Container(e1,e2) / Content-Container(e2,e1)
- Entity-Destination(e1,e2)
- Entity-Origin(e1,e2) / Entity-Origin(e2,e1)
- Instrument-Agency(e1,e2) / Instrument-Agency(e2,e1)
- Member-Collection(e1,e2) / Member-Collection(e2,e1)
- Message-Topic(e1,e2) / Message-Topic(e2,e1)
- Product-Producer(e1,e2) / Product-Producer(e2,e1)
- Other
- Base Model: google/bert_uncased_L-4_H-256_A-4 (Small BERT)
- Classification Head: Linear layer on top of BERT's [CLS] token
- Special Tokens: Added [E1], [/E1], [E2], [/E2] to mark entity boundaries
- Entity Marking: Replaces
<e1>,</e1>,<e2>,</e2>with special tokens - Data Split: 85% train, 15% validation (stratified by label)
- Evaluation Metric: Macro F1 score across all 18 classes
- Optimization: AdamW optimizer with learning rate 2e-5
- Max sequence length: 128
- Batch size: 16
- Epochs: 10
- Learning rate: 2e-5
- Dropout: 0.3
- Validation split: 15%
pip install -r requirements.txtpython relation_classifier.pyThis will:
- Train the model for 10 epochs
- Save the best model based on validation F1 score
- Generate predictions for both public and private test sets
- Create submission files:
public_test_submission.csvprivate_test_submission.csv
best_model.pt: Best model checkpointpublic_test_submission.csv: Public test predictionsprivate_test_submission.csv: Private test predictions
The model is evaluated using Macro-averaged F1 score across all 18 relation classes, which ensures balanced performance across both frequent and rare relation types.
- Sentences are tokenized using BERT tokenizer
- Entity tags are replaced with special tokens for better entity representation
- Sequences are padded/truncated to max length of 128 tokens
- Cross-entropy loss for multi-class classification
- Early stopping based on validation F1 score
- Progress bars for training visibility
- Batch prediction for efficiency
- Argmax over logits for final label prediction
- Label mapping back to original relation names