# Methods for Mid-Term Forecasting of Crop Export and Production
## 3 Materials and Methods
### Modeling of Wheat Export
#### 3.2.3 Sentiment Analysis and Topic Models  
One of the prediction problems is a significant time gap between real-world events (large trade deals, economic crises, weather emergencies, etc.) and the appearance of information about them in global databases such as UN FAOSTAT. However, mass media and social networks report all those events almost immediately. Therefore, we try using that information to improve the prediction. We use Twitter for the experiments because it is available in all the top wheat exporters and importers and provides a search API. First, we collected all the tweets from 2012 to 2020 in English related to a \"wheat grain\" topic and the considered countries. Then we built a Latent Dirichlet Allocation (LDA) topic model to extract the primary topics of the tweets (Table 2). We used the Gensim library [30] and evaluated the perplexity and topic correlations to choose the topic number.  
Eventually, we utilized the Polyglot library [31] to evaluate the sentiment of the messages. With Polyglot we define a function Sent that maps every token w from a token set \(W\) and every document d from a tweets collection \(D\) into an interval \([-1..1]\), where \(-1\) stands for strong negative attitude, and \(+1\) is for the solid positive attitude (5). We  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Topic Name** & **Food Security** & **Wheat Pests** & \begin{tabular}{c} **Yield/** \\ **Production Level** \\ \end{tabular} & \begin{tabular}{c} **International** \\ **Wheat Trade** \\ \end{tabular} & \
\begin{tabular}{c} **Weather** \\ **Conditions** \\ \end{tabular} &
\begin{tabular}{c} **Organic** \\ **Agriculture** \\ \end{tabular} \\ \hline \hline \multirow{8}{*}{Keywords} & area & & & export & & \\  & Asia & & flour & trade & & \\  & bread & field & yields & international & & \\  & curb & crop & milling & importing & farmers & & \\  & prevent & bitly & farming & harvesting & drought & \\  & Europe & biggest & producers & prices & rain & great \\  & farm & impact & grains & imports & weather & organic \\  & feed & countries & crops & bought & heavy & breeding \\  & India & problem & production & buys & & fertilizer \\  & EU & & harvest & tons & & \\  & Australian & & & market & & \\  & & & exports & & \\ \hline \hline \end{tabular}
\end{table}
Table 2: Primary topics of the wheat grain related tweets (2012–2020).  
have chosen that library because it is multilingual; therefore, our approach can be scaled to process texts on other languages.  
\[Sent(w,d):W\times D\rightarrow[-1..1] \tag{5}\]  
Let \(D_{cy}\) be a set of tweets, related to particular country \(c\) and year \(y\). We define a textual feature vector \(S\), and each element of \(S\) is a weighted summary sentiment of the tweets related to a correspondent topic.  
\[S(c,y)=(s_{1},s_{2},..,s_{T}),s_{i}=\sum_{d\in D_{cy}}\sum_{w\in d}p_{d,w}p_{w, i}\Big{(}\sum_{s\in Ent(d)}Sent(s,d)\Big{)} \tag{6}\]  
where \(Ent(d)\) is the set of all named entities (organizations) from tweet \(d\), \(p_{d,w}\) is the probability estimation that tweet \(d\) contains token \(w\), and \(p_{w,i}\) is the probability estimation that token w belongs to a topic \(i\). They both are obtained from the topic model. Thus, for each country the vector direction shows sentiment of the tweets related to the topics, while the vector length reflects popularity of the topics.  
The described methodology has the following limitations. We do not distinguish between tweets from the relevant institutions and messages from individuals. Additionally, we consider only tweets in English, which limits the completeness of the results. In the future, the official messages shall have a higher weight than those from individuals. We are also going to utilize a cross-lingual pipeline, which would help us to collect that information.