How cliang1453/bond works
Project Type and Purpose
• BOND is a research-oriented NLP pipeline/tool for open-domain Named Entity Recognition (NER) leveraging distant/weak supervision and BERT-based models.
• It provides pre-processed datasets, training/evaluation scripts, and model definitions to reproduce the KDD2020 results.
High-Level Components
From the file tree and README, we group the code into these major modules:
a. Data Layer
• dataset/ (pre-processed JSON files for BC5CDR-chem, CoNLL03, OntoNotes, Twitter, Webpage, Wikigold)
• data_utils.py (data loading, tokenization, label mapping)
b. Model Layer
• modeling_bert.py & modeling_roberta.py (model definitions, BERT/Roberta wrappers, classification heads)
• model_utils.py (helper functions: loss computation, model saving/loading)
c. Training & Self-Training Pipeline
• run_ner.py (Stage I: baseline fine-tuning on distant data)
• run_self_training_ner.py (Stage II: iterative distillation/self-training loop – the core BOND algorithm)
• scripts/*.sh & semi_script/*.sh (shell scripts orchestrating dataset choice, hyperparameters, and two‐stage runs)
d. Evaluation
• eval.py (entity-level F1 calculation, logging results)
e. External Dependencies
• Python 3.7, PyTorch 1.3, Hugging Face Transformers v2.3.0
Relationships & Data Flow
• Raw JSON files → data_utils.py → token IDs & labels
• Tokenized data → run_ner.py (Stage I) → model_utils.py → saved Stage I checkpoints
• Stage I checkpoints & unlabeled/distant data → run_self_training_ner.py (Stage II self-training loop) → model_utils.py → final checkpoints
• Any checkpoint → eval.py → F1 scores → output logs
• scripts/*.sh drive run_ner.py and run_self_training_ner.py with dataset-specific parameters
Architectural Patterns & Principles
• Pipeline pattern: clear separation of data ingestion, model definition, training logic, and evaluation.
• Modularization: reusable utilities in data_utils.py and model_utils.py.
• Two-stage training workflow (baseline then self-training) reflects a staged pipeline.
Step-by-Step Construction
a. At the left, place your Data Layer:
[ dataset/*.json ] → [ data_utils.py ]
b. In the center, stack two processing stages:
Stage I: [ run_ner.py ] → uses → [ modeling_bert.py / modeling_roberta.py ] → [ model_utils.py ]
Stage II: [ run_self_training_ner.py ] → iterative loop using the same model definitions
e. At the bottom, note external dependencies: Python, PyTorch, Transformers
Don’t Overthink—Just Separate Everything
• To include both baseline and self-training flows to reflect the BOND framework.