How toriving/text-classification-transformers works
Project Type and Purpose
• This is a CLI‐driven NLP pipeline for sequence classification.
• It leverages Huggingface Transformers models to train, evaluate, and predict on text classification datasets (e.g., NSMC, KoNLI, SST2, SST5).
• Key features: data preprocessing, dataset loading, model instantiation, training/evaluation loops, and experiment automation via shell scripts.
Main Architectural Components
a. User & Shell Scripts Layer
– Entry point for experiments (sh/*/*.sh).
– Shell scripts invoke the Python CLI with specific arguments (model choice, data path, hyperparameters).
b. CLI & Argument Parsing
– arguments.py: Defines all CLI parameters.
– main.py: Reads arguments, orchestrates the pipeline (train/eval/predict).
c. Data Layer
– data_in/: Raw and preprocessed CSV/TSV datasets.
– utils/*_preprocess.py: Converts original TSV/text files into train.csv, dev.csv, test.csv.
– datasets.py: Implements a Dataset class that wraps torch Dataset and DataLoader.
d. Model Layer
– modeling.py: Defines how to load and configure pretrained transformers via AutoModelForSequenceClassification.
– Integrates tokenization and model configuration (num_labels, max_seq_length).
e. Runner / Trainer Layer
– runner.py: Implements training, evaluation, and prediction loops using Huggingface’s Trainer or custom loops.
– Manages logging (TensorBoard), checkpoints, and metrics.
f. External Dependencies
– Huggingface Transformers library.
– PyTorch, TensorBoard for visualization.
g. Outputs & Artifacts
– output_dir/: Model checkpoints, logs, test predictions.
– cache_dir/: Downloaded transformer weights and tokenizers.
Relationships & Data Flow
1. User runs a shell script → invokes python main.py with flags
2. main.py loads & validates CLI args (arguments.py)
3. main.py calls preprocessing utilities (if needed) to ensure train/dev/test CSVs in data_in/
4. datasets.py reads CSVs → builds PyTorch DataLoaders
5. modeling.py initializes the Transformer model (AutoModelForSequenceClassification) + tokenizer
6. runner.py trains the model, evaluates on dev set, and/or makes predictions on test set
7. Checkpoints and logs are written to output_dir; metrics to TensorBoard
8. Optionally, model_name_or_path points to existing checkpoints for reload/predict
Architectural Patterns & Design Principles
• Pipeline pattern: clear separation of concerns (preprocess → dataset → model → runner).
• Modularity: each layer (utils, data, modeling, runner) is self‐contained.
• Config-driven: all hyperparameters and paths are injected via CLI.
• Reusability: shell scripts standardize experiments; adding a new dataset/model requires minimal changes.
Must-Include Elements
• Annotations for the most important CLI args (e.g., --model, --task_name, --output_dir).