# Conversational AI over Military Scenarios Using Intent Detection and Response Generation
## 3 Methodology
### Response Generation  
After extracting the user intent and filling the slots, the second step is to answer the user using a retrieval-based response module. Suppose no intent or relevant entity was identified in the previous step. In that case, the system uses a template-based query generation module to ask the user for additional information to retrieve an appropriate answer. In practice, we use the Elasticsearch full-text search tool to build a retrieval model in the Chinese military domain. The model is built using the Okapi BM25 algorithm. The model determines the most appropriate response based on the correlation between query Q and database document D, as shown in Equation (4). \[Score(D,Q)=\sum\
olimits_{i=1}^{n}IDF(q_{i})\frac{f(q_{i},D)(K_{1}+1)}{f(q_{i}, D)+K_{1}(1-b+b\frac{|D|}{avgdl})} \tag{4}\]  
where _IDF_ denotes the inverse document frequency in this equation, and \(avgdl\) is the average length of all texts. In the retrieval system, the entities extracted from the user query are used as the keywords to perform full-text retrieval. The top 10 most relevant results were then selected using the Learning-To-Rank Answering (LTRA) approach, as shown in Algorithm 1. The input to the retrieval model is the searched sentences \(S=\{s_{1},\dots,s_{n}\}\), query intent \(i_{Q}\), and entities \(E=\{e_{1},\dots,e_{m}\}\). First, intent prediction is performed for each sentence. If a sentence \(j\) intends \(i_{j}\) to be the same as \(i_{Q}\), the candidate sentence \(j\) is kept; otherwise, it is discarded. The LTR model ranks the candidate sentences and considers the top \(k\) candidate sentences as the most suitable replies. The LTR model was implemented using the LambdaMART algorithm [68]. LambdaMART is a listwise LTR that combines the LambdaRank and Multiple Additive Regression Tree (MART) algorithms, transforming the search candidate ranking problem into a regression tree problem. To train candidate sentences for ranking, we prepared 10 features, as shown in Table 5. Features 1-5 represent the five NER models for extracting entities from candidate sentences. Features 6 and 7 are used to determine if the candidate sentence matches the military document names and units in the Military Dictionary; the results are displayed as boolean values. Feature 8 represents the longest common subsequence (LCS) between the user query and candidate sentences, as shown in Equation (5). Feature 9 denotes the similarity between the user query and candidate sentence, as shown in Equation (6). Feature 10 denotes the term frequency-inverse document frequency (TFIDF), which is used to calculate the word importance for user's query and sytem answers based on the corpus, as shown in Equation (7). \begin{table}
\begin{tabular}{c l l} \hline \hline
**No.** & **Feature** & **Description** \\ \hline
1 & Location & Military location or organization \\
2 & Person & Name, rank and title entities \\
3 & Time & Time descriptor \\
4 & Event & Military event \\
5 & Weapon & Weapon or transport entity \\
6 & Document & Military document name \\
7 & Session & Phase name of combat missions \\
8 & Unit & Commonly used quantifiers in military affairs \\
9 & Who & An interrogative term about a person \\
10 & Where & An interrogative term about a location \\
11 & When & An interrogative term about time \\
12 & What & An interrogative term about all other matters \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Features of intent detection. \[LCS(i,j)=\left\{ \begin{aligned} 0\text{ if }i=0\text{ or }j=0\\ \text{LCS }(i-1,j-1)+1\text{ if }i,j>0\text{ and }\alpha_{i}=\beta_{j}\\ \max[\text{LCS}(i-1,j),\text{LCS}(i,j-1)]\text{ if }i,j>0\text{ and }\alpha_{i}\
eq\beta_{j}\end{aligned} \right. \tag{5}\]  
The above calculates the LCS for input sequences \(A=\alpha_{1},\alpha_{2},\ldots,\alpha_{m}\) and \(B=\beta_{1},\beta_{2},\ldots,\beta_{m}\), where \(1\leq i\leq m\) and \(1\leq j\leq n\).