Observed since 20 Oct, 18:44 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Adaptive Class Weight Adjustment (ACWA) for Imbalanced Deep Learning
ACWA is an advanced optimization algorithm designed to automatically adjust class weights during neural network training, particularly effective for imbalanced datasets. Unlike traditional approaches, ACWA dynamically adapts based on real-time performance metrics.
Traditional Methods Limitations:
ACWA Advantages:
ACWA operates through a feedback loop:
Performance Error:
error_c = target\_metric - current\_metric_c
Weight Update:
weight_c^{(t+1)} = clip(\beta \cdot weight_c^{(t)} + (1-\beta) \cdot (weight_c^{(t)} + \alpha \cdot error_c), 0.5, 2.0)
Loss Modification:
\mathcal{L} = \sum_{c=1}^C weight_c \cdot \mathcal{L}_c
| Parameter | Description | Recommended Value |
|---|---|---|
| α | Learning rate | 0.01-0.05 |
| β | Smoothing factor | 0.8-0.95 |
| K | Update frequency | 50-200 batches |
| Target | Performance goal | Class-specific |
| Method | Pros | Cons |
|---|---|---|
| ACWA | Adaptive, automatic | Slightly more compute |
| Class Weighting | Simple | Static, manual tuning |
| Resampling | Balances data | May lose information |
| Focal Loss | Handles hard samples | Fixed strategy |
pip install acwa-torch
from acwa import ACWATrainer
# Initialize
trainer = ACWATrainer(
num_classes=10,
target_metric=0.85, # Target F1-score
alpha=0.02,
beta=0.9,
update_freq=100
)
# Training loop
for batch in dataloader:
# Forward pass
outputs = model(inputs)
# ACWA-weighted loss
loss = trainer.get_weighted_loss(outputs, labels)
# Backward pass
loss.backward()
optimizer.step()
# Update metrics
trainer.update_metrics(outputs, labels)
# Custom metrics
trainer = ACWATrainer(
metric_fn=custom_f1_function,
metric_mode='max' # or 'min'
)
# Combined with Focal Loss
trainer = ACWATrainer(
loss_fn=FocalLoss(gamma=2.0),
...
)
# Initialize weights using inverse class frequency
class_counts = torch.bincount(torch.tensor(trainset.targets))
class_frequencies = class_counts.float() / (class_counts.sum() + 1e-6)
trainer = ACWATrainer(
model=model,
num_classes=10,
class_frequencies=class_frequencies
)
# Early stopping example
best_f1 = 0
early_stop_counter = 0
patience = 5
for epoch in range(num_epochs):
# ...training logic...
if val_f1 > best_f1:
best_f1 = val_f1
torch.save(model.state_dict(), 'best_model.pth')
early_stop_counter = 0
else:
early_stop_counter += 1
if early_stop_counter >= patience:
print("Early stopping triggered.")
break
from demo_cifar100 import main
main()
datasets library to load the IMDB dataset:
from demo_huggingface import main
main()
tslearn or a similar library.How to integrate Hugging Face models?
transformers library and wrap the model with ACWATrainer.What if F1-score does not improve?
update_freq is set appropriately (20-50).# Example weight evolution plot
plt.plot(weight_history)
plt.title('ACWA Weight Adjustment')
plt.xlabel('Update Steps')
plt.ylabel('Class Weight')
plt.show()
| Method | Accuracy | Macro F1 | Training Time |
|---|---|---|---|
| ACWA (Version 3) | 86.3% | 0.781 | 0.7h |
| ACWA (Final) | 87.5% | 0.799 | 0.65h |
We welcome contributions! Please see our:
Unit Testing:
Distributed Training:
torch.nn.parallel.DistributedDataParallel.Additional Frameworks:
MIT License - Free for academic and commercial use
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.0 | 10 Apr 2025 | 6 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 18:44 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5754b3ebec4a5c8b51b1a8c6439d632ed77b0d74195ab18f80dcd5173029fe54