Skip to content

huy0x404/NLP_Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relation Classification Challenge - Solution

Overview

This solution implements a BERT-based relation classification model using the specified architecture: google/bert_uncased_L-4_H-256_A-4.

Dataset Information

  • Training samples: 1,919
  • Public test samples: 480
  • Private test samples: 407
  • Number of relation labels: 18

Relation Labels

  1. Cause-Effect(e1,e2) / Cause-Effect(e2,e1)
  2. Component-Whole(e1,e2) / Component-Whole(e2,e1)
  3. Content-Container(e1,e2) / Content-Container(e2,e1)
  4. Entity-Destination(e1,e2)
  5. Entity-Origin(e1,e2) / Entity-Origin(e2,e1)
  6. Instrument-Agency(e1,e2) / Instrument-Agency(e2,e1)
  7. Member-Collection(e1,e2) / Member-Collection(e2,e1)
  8. Message-Topic(e1,e2) / Message-Topic(e2,e1)
  9. Product-Producer(e1,e2) / Product-Producer(e2,e1)
  10. Other

Solution Architecture

Model

  • 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

Key Features

  1. Entity Marking: Replaces <e1>, </e1>, <e2>, </e2> with special tokens
  2. Data Split: 85% train, 15% validation (stratified by label)
  3. Evaluation Metric: Macro F1 score across all 18 classes
  4. Optimization: AdamW optimizer with learning rate 2e-5

Hyperparameters

  • Max sequence length: 128
  • Batch size: 16
  • Epochs: 10
  • Learning rate: 2e-5
  • Dropout: 0.3
  • Validation split: 15%

Usage

1. Install Dependencies

pip install -r requirements.txt

2. Train Model and Generate Predictions

python relation_classifier.py

This 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.csv
    • private_test_submission.csv

Output Files

  • best_model.pt: Best model checkpoint
  • public_test_submission.csv: Public test predictions
  • private_test_submission.csv: Private test predictions

Model Performance

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.

Implementation Details

Data Preprocessing

  • 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

Training Strategy

  • Cross-entropy loss for multi-class classification
  • Early stopping based on validation F1 score
  • Progress bars for training visibility

Prediction

  • Batch prediction for efficiency
  • Argmax over logits for final label prediction
  • Label mapping back to original relation names

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors