This study proposes an automatic Dewey Decimal Classification (DDC) classification framework for Indonesian book metadata by integrating the IndoBERT model strengthened through weighted loss and context enhancement mechanisms. The current escalation of digital book collections poses significant challenges in classification efficiency and information retrieval, while the manual DDC classification process still relies on librarian expertise and is relatively time-consuming. The dataset used includes 2,516 book metadata obtained through the Google Books API and mapped into 14 DDC categories. The context enhancement strategy is implemented by integrating book titles and descriptions into a single text representation, while weighted cross-entropy loss, random oversampling, and simple data augmentation techniques are applied to address class imbalance issues. Model performance is evaluated based on accuracy, precision, recall, and F1-score metrics. Experimental results show that the proposed approach achieves an accuracy of 90.14% and a weighted F1-score of 90.15%, outperforming the baseline IndoBERT model, which only achieved an accuracy of 47.82% and a weighted F1-score of 47.06%. These findings indicate that the combination of weighted loss and contextual text representation can improve the semantic understanding of book metadata while reducing bias towards the majority class in Transformer-based DDC classification.