A lightweight hybrid model for accurate ammonia prediction in pig houses - Jacqueline Musabimana; Qiuju Xie; Hong Zhou; Ping Zheng; Honggui Liu; Tiemin Ma; Jiming Liu (Smart Agricultural Technology)
In extensive pig farms, keeping good living conditions is crucial for pigs' good health, growth, and productivity, as ammonia (NH₃) negatively impacts health and reproduction. Recently, deep learning techniques have proven potential in predicting ammonia concentration by capturing complex temporal dependencies. However, the standard transformer deep learning method relies heavily on self-attention, leading to high computational complexity and long training times, limiting its use in dynamic environments and real-time applications with limited resources. To overcome these issues, this study presents a novel, lightweight hybrid transformer model that combines Convolutional Neural Networks, Long Short-Term Memory, and Transformer (CNN-LSTM-Transformer) for NH₃ prediction. The model replaces feedforward networks with separable convolutional layers to capture local and spatial dependencies more efficiently, as well as reduce computational complexity. It also replaces positional encoding with global average pooling, simplifying the architecture and improving temporal feature aggregation. The outcomes indicated that, compared to the standard transformer, the proposed model reduces memory size by 21.1 % (4.9 MB vs. 6.21 MB) and training time by 29.7 % (5 min vs. 7.11 min). It also outperforms the standard transformer in accuracy and efficiency, with Root Mean Square Error (RMSE), Mean Absolute Percentage Error (MAPE), and coefficient of determination R² of 0.3994, 0.0225, and 0.9260, respectively, compared to 0.4250, 0.0227, and 0.9162 for the standard model, reducing RMSE by 5.99 %, MAPE by 0.88 %, and increasing R² by 1.08 %. The model improves accuracy compared to other state-of-the-art and ability for NH3 prediction.