Drug-Drug Interactions (DDI) and Chemical-Protein Interactions (CPI) detection are crucial for patient safety, as unidentified interactions may lead to severe Adverse Drug Reactions (ADRs). While extensive DDI and CPI information exists within biomedical literature, manual extraction by experts proves time-intensive and resource-demanding. This study presents SB-AGT: Stochastic Beam Search-enhanced Attention-based Gumbel Tree an innovative approach to automated DDI and CPI extraction through an attention-based architecture incorporating a modified Gumbel-Tree method with stochastic beam search optimization. SB-AGT leverages multi-head attention mechanisms and enhanced latent tree structures to effectively capture complex syntactic features and drug relationship patterns. Also, the methodology includes comprehensive preprocessing protocols and addresses dataset imbalance through hybrid sampling techniques. Experimental validation on the DDIExtraction 2013 and CHEMPROT datasets demonstrates the model's effectiveness, achieving precision, surpassing traditional approaches and showing competitive performance compared to contemporary pre-trained models. Through parametric analysis, we establish optimal beam search configurations that maximize the model's extraction accuracy.