BERT-Based Agricultural Crop Prediction System Using Soil and Weather Parameters with Interactive Streamlit Deployment
Abstract
The proper choice of crops is a necessary aspect of enhancing agricultural performance, effective use of resources, and sustainable food production in changing climatic conditions. Conventional recommendation systems are based mostly on statistical and shallow machine learning models, in which soil and climatic parameters are used as independent variables, thereby restricting their capacity to form contextual associations among agronomic factors. The research is a BERT-based predictive agricultural crop model that uses contextual language representations to predict complex relationships among soil nutrients and weather conditions. Numerical agricultural data, such as Nitrogen (N), Phosphorus (P), Potassium (K), soil pH, temperature, humidity, rainfall, and soil type, are transformed into text-structured descriptors and input into an already-trained Bidirectional Encoder Representations from Transformers (BERT) model. The contextual embeddings obtained with the frozen BERT encoder are sent to a light model neural classification head of fully connected layers, dropout regularization, and LogSoftmax activation to make predictions that will choose the best crop among 22 classes. The model is coded in PyTorch and deployed as an interactive Streamlit application, enabling real-time user interaction and crop suggestions. It is experimentally shown that contextual embedding-based modeling enhances classification strength and is able to contribute to interpretable agricultural decision-making. The system illustrates how transformer-based architecture can be used in precision agriculture and decision support systems.