A Neural Network Based Intelligent Support Model for Program Code Completion

In recent years, millions of source codes are generated in different languages on a daily basis all over the world. A deep neural network-based intelligent support model for source code completion would be a great advantage in software engineering and programming education fields. Vast numbers of syntax, logical, and other critical errors that cannot be detected by normal compilers continue to exist in source codes, and the development of an intelligent evaluation methodology that does not rely on manual compilation has become essential. Even experienced programmers often find it necessary to analyze an entire program in order to find a single error and are thus being forced to waste valuable time debugging their source codes. With this point in mind, we proposed an intelligent model that is based on long short-term memory (LSTM) and combined it with an attention mechanism for source code completion.,us, the proposedmodel can detect source code errors with locations and then predict the correct words. In addition, the proposedmodel can classify the source codes as to whether they are erroneous or not.We trained our proposedmodel using the source code and then evaluated the performance. All of the data used in our experiments were extracted from Aizu Online Judge (AOJ) system. ,e experimental results obtained show that the accuracy in terms of error detection and prediction of our proposed model approximately is 62% and source code classification accuracy is approximately 96% which outperformed a standard LSTM and other state-of-the-art models. Moreover, in comparison to state-of-the-art models, our proposed model achieved an interesting level of success in terms of error detection, prediction, and classification when applied to long source code sequences. Overall, these experimental results indicate the usefulness of our proposed model in software engineering and programming education arena.


Introduction
Programming is one of mankind's most creative and effective endeavors, and vast numbers of studies have been dedicated to improving the modeling and understanding of software code [1]. e outcomes of many such studies are now supporting a wide variety of core software engineering (SE) purposes, such as error detection, error prediction, error location identification, snippet suggestions, code patch generation, developer modeling, and source code classification [1]. Since learners and professionals around the world are constantly creating large numbers of new programs to improve our lives, it is a general truism that no program is ever released without undergoing a comprehensive postdevelopment debugging process. Almost every software product goes through different testing phases in the SE cycle. In fact, once errors are detected in the source code at the production or testing phases, the debugging process begins immediately to find and fix the errors. is means that learners and professionals are spending vast amounts of time attempting to find errors in source codes. To find a single error, it is often necessary to verify an entire program, which is a very lengthy process and time-consuming. is adverse situation has resulted in the emergence of a new SE research window [2].
ere are significant numbers of errors that are commonly made by students, programmers, and developers. ese include missing semicolons, delimiters, irrelevant symbols, variables, missing braces, incomplete parentheses, operators, missing methods, classes, inappropriate classes, inappropriate methods, irrelevant parameters, logic errors, and other critical errors. Although such errors often indicate inexperience, insufficient concentration to detail, and other unsuitable behaviors, a Google study on programming showed that such errors can creep into the works of even the most experienced programmers [3]. Normally, programming is a very sensitive and error-prone task and a single mistake can eventually be harmful to software endusers. Furthermore, the source code is highly error-prone during development, so the intelligent support model for code completion has become an interesting research area. Among the solutions now being explored, the use of artificial intelligence (AI) offers fascinating potential for solving source coderelated complications. In the past few years, natural language processing (NLP) developers have produced some extraordinary outcomes in different domains such as language processing, machine translation, and speech recognition. e reasons for the wide-ranging success of NLP are found in its corpus-based methods, statistical applications, messenger suggestions, handwriting recognition, and increasing large corpora of text. For example, n-gram models are among the stochastic language model forms that can be used for predicting the next item based on the corpus. Different n-gram models such as bigram, trigram, skip-gram [4], and GloVe [5] are all statistical language models that are very useful in language modeling tasks.
is burgeoning usage has stimulated the availability of a large text corpus and is helping NLP techniques to become more effective on a day-by-day basis. e NLP language model is not particularly effective when used in complex SE endeavors but still useful for the intuitive language model. As a result, numerous researchers have focused their efforts on source code completion tasks using neural networkbased language models. In [6], the authors proposed a local cache model that dealt with localness of software code but still encountered problems with small-context source code using an n-gram model. at study determined that neural network-based language models could provide robust substitutes for source code illustrations. Additionally, another study showed that the recurrent neural network (RNN) model, which is capable of retaining longer source code context than traditional n-gram and other language models, has achieved mentionable success in language modeling [7]. However, the RNN model faces limitations when it comes to representing the context of longer source codes due to gradient vanishing or exploding [8], which makes it hard to be trained using long dependent source code sequences. As a result, it is only effective for a small corpus of source codes. To minimize gradient vanishing or exploding problems, the RNN model has been extended to create long short-term memory (LSTM) networks [8]. An LSTM network is a special kind of RNN that can remember longer source code sequences due to its extraordinary internal structure.
In this paper, we are presenting an intelligent support model for source code completion that was designed using an LSTM in combination with an attention mechanism (then known as LSTM-AM) which increases the performances than a standard LSTM model. e attention mechanism is a useful technique that takes into account the results of all past hidden states for prediction. e attention mechanism can improve the accuracy of neural network-based intelligent models. We trained LSTM, RNN, CNN, and LSTM-AM networks with different hidden units (neurons) such as 50, 100, 200, and 300 using a bunch of source codes taken from an AOJ system. Erroneous source codes were then inputted into all models to determine their relative capabilities in regard to predicting and detecting source code errors. e obtained results show that our LSTM-AM network extends the capabilities of the standard LSTM network in terms of detecting and predicting such errors correctly. Even some source codes contain logical errors and other critical errors that cannot be detected by the usual compilers whereas our proposed intelligent support model can detect these errors. Additionally, the LSTM-AM network can retain a longer sequence of source code inputs and thus generate more accurate output than the standard LSTM and other state-of-the-art networks. In addition, we diversified with different settings and hidden units to create the most suitable model for our research in terms of cross-entropy, training time, accuracy, and other performance measurements. Also, the proposed model can classify the source codes based on the defects in codes. We expect that our proposed model will be useful for students, programmers, developers, and professionals as well as other persons involved in overall programming education and other aspects of SE.
e main contributions of this study are described as follows: (i) e proposed intelligent support model can help students and programmers for the source code completion (ii) e intelligent support model detects such errors (logical) that cannot be identified using conventional compilers (iii) e proposed intelligent support model accuracy is approximately 62% which outperformed other benchmark models (iv) Our proposed model can classify the source codes based on the detected errors. e classification accuracy is 96% which is much better than other models (v) e proposed model highlights defective spots with location/line number in source codes (vi) e proposed model improves the ability of learners to fix errors in source code easily by using the location/line numbers e remainder of the paper is structured as follows. In Section 2, we present the background of our study and discuss prior research. Section 3 describes the overview of natural language processing and artificial neural networks. In Section 4, we present our proposed approach. Data collection and problem description issues are presented in Section 5. e experimental results are described in Section 6. In Section 7, we discuss the results. To that end, Section 8 concludes this paper with some future work proposals.

Background and Prior Research
Modern society is flourishing due to advancements in the wide-ranging fields of information and communication technology (ICT), where programming is a crucial aspect of many developments. Millions of source codes are being created every day, most of which are tested through manual compiling processes. As a result, an important research field that has recently emerged involves the use of AI systems for source code completion during development rather than manual compiling processes. More specifically, artificial neural network-based models are using for source code completion in order to achieve more humanlike results. Numerous studies have been completed and a wide variety of different methods were proposed regarding the use of AI in SE fields, some of which will be reviewed below.
In [1], the authors present a language model for source code testing that uses a neural network instead of an existing language (i.e., n-gram) model. In most cases, ngram language models cannot handle long source code sequences effectively, so neural network-based language models were developed to improve source code analyses. In the cited study, RNN and LSTM language models were trained and the obtained results showed that the LSTM model performed better than the RNN model. at study used a Java project corpus to evaluate the performance of the language models.
In [4], the authors proposed a novel LSTM-based source code correction method that used segment similarities. More specifically, the study utilized the sequenceto-sequence (seq2seq) model for the source code correction process. e seq2seq model is a machine learning approach which is very effective for language modelings such as machine translator, conversational model, text translator, and image captioning.
White et al. [7] proposed a deep software language model using RNN. e obtained experimental results using a Java corpus showed that the proposed software language model outperformed conventional models like cache-based n-gram and standard n-gram. at software language model showed significant promise for use in SE fields.
In [9], the authors presented a novel Tree-LSTM-based model where each LSTM unit was used as a tree. at model assesses semantic relatedness prediction tasks based on sentence pairs and sentiment classification. Meanwhile, in [10], the authors proposed a method that classified archived source codes by language type using an LSTM. eir experimental results demonstrated that the proposed LSTM surpassed the linguist classifier, Naive Bayes (NB) classifier, and other similar networks.
In [11], the authors proposed a technique that automatically identifies and corrects source code syntax errors using an RNN. eir proposed SYNFix algorithm finds the error location of the next predicted token sequence, after which the identified error is solved by either replacing or inserting a proper word. A significant limitation of this technique is that it cannot recover or handle multiple syntax errors in a source code sequence.
Pedroni and Meyer [12] studied to find the appropriate type of compiler messages that can assist novice programmers to identify source code errors. And what actions are needed for the error messages? In that study, the authors experimentally showed that certain message types help novice programmers more than others.
In [13], the authors presented a model for source code syntax error correction that was written in the C programming language.
at model, called DeepFix, uses a multilayered sequence-to-sequence neural network combined with an attention mechanism. e authors also proposed a trained RNN that can predict an error with its location number and fix the error with a proper token. e experimental results obtained showed that, out of a total of 6971 source code errors, this approach completely fixed about 27% and partially fixed about 19%.
Rahman et al. [14] proposed a language model using LSTM for fixing source code errors. e proposed model is a combined attention mechanism with LSTM which increases the effectiveness of standard LSTM. Experimental results showed that the model significantly corrected errors in the source codes.
In [15], the authors proposed a source code bug detection technique that works by varying the hyperparameters of an LSTM in order to investigate perplexity issues and training time. e results obtained show that LSTM produces significant results for source code error detection.
Bahdanau et al. [16] proposed a language translation model that uses RNN. More specifically, the encoder-decoder technique is used as a translator when it is necessary to encode a source text into a fixed-length vector. By utilizing the vector length, the decoder can translate the sentences. e paper extends fixed-length limitations by allowing (soft) search from the source sentence to predict a target word instead of using the hard segments of the source code sentences.
Li et al. [17] points out the limitations of neural network language models. To overcome those problems, the authors proposed two new approaches: an attention mechanismenhanced LSTM and a pointer mixture network. e attention mechanism-enhanced LSTM is used to alleviate fixed-size vectors and improve memorization capability by providing a variety of ways for gradients to backpropagate. In contrast, the pointer mixture network predicts out of vocabulary (UoV) words by considering locally repeating tokens.
at study also proposed the use of an abstract syntax tree-(AST-) based code completion method.
Li et al. [18] presented a source code defect prediction model using a convolution neural network called DP-CNN. Abstract syntax tree (AST) has used to convert the source code into token vectors. Using the word embedding map, each token vector is converted into a numerical vector. CNN used a numerical vector for training. ereafter, the CNN model creates the source code's semantic and structural features. Compared with the traditional defect prediction features, DP-CNN improved the performance by 12% compared with other state-of-the-art models and 16% compared with other traditional feature basis methods.

Scientific Programming
Dam et al. [19] presented a deep learning model for software defect prediction. e model has used the abstract syntax tree (AST) incorporated in the LSTM network. Each node of the AST structure is treated as an LSTM unit. A deep tree-based LSTM model stored syntactical and structural information of source codes for accurate prediction. e learning style of the tree-based LSTM model is unsupervised. e model does not clean or replace any erroneous words by predicting correct words. It is used to generate error probability from a source code; thereafter; a classifier identifies the source code's defect by using the value of probability.
Pham et al. [20] used CNN as a language model based on Feed Forward Neural Network (FFNN). Experimental results demonstrated that the performance of the CNN language model is better than the normal FFNN. As for recurrent models, the CNN language model performs well compared with the RNN, but below the state-of-the-art LSTM model.
In [21], the authors proposed an RNN-based model for the source code fault prediction.
ere are two familiar evaluation methods such as the area under the curve (AUC) and F1-measures that are used to measure the performance. e proposed attention-based RNN model improves the accuracy of source code classification. e AUC and F1measure achieved 7% and 14% more accuracy than the other benchmark models.
In summary, a wide variety of methods and techniques have been proposed in various studies, most of which used RNN, LSTM, or convolutional neural network (CNN) models for source code manipulation and other applications. It is very difficult to explain which proposed research work is superior over other researches. RNNs perform comparatively better than conventional language models, but RNNs have limited ability to handle long source code inputs [7]. An LSTM is a special kind of RNN network that can remember longer source code sequences due to its extraordinary internal structure and thus overcome RNN shortcomings. Our proposed model is unlike the other models. Our proposed LSTM-AM network further extends the capabilities of a standard LSTM network to the point where it can be used for detecting and predicting source code errors as well as source code classification. Standard LSTM network only uses the last hidden state to make predictions. In contrast, our LSTM-AM network can take the outcomes of all previous hidden states into consideration when making predictions. erefore, it is a more promising technique for use in source code manipulations than other state-of-the-art language models.

Overview of Language Model and Artificial
Neural Networks

N-Gram Language
Model. e resources of natural text corpora are being enriched by the accumulation of text from multiple sources on a daily basis. e success behind natural language processing is based on this rich text corpus. For this reason, and because of their simplicity and scalability, n-gram models are popular in the field of natural language processing. An n-gram model predicts the upcoming word or text of a sequence based on probability, and the probability of an entire word sequence P(w 1 , w 2 , . . ., w n ) can be calculated by using the chain rule of probability.
e Markov assumption, which is used when the probability of a word depends solely upon the previous word, is described in (2) us, the general equation of an n-gram used for the conditional probability of the next word sequence is as follows: In practice, the maximum likelihood can be estimated by many smoothing techniques [22], as shown in the following equation: (4) Cross-entropy is measured to validate the prediction goodness of a language model [23]. Low cross-entropy values imply better language models.

Recurrent Neural Network (RNN).
An RNN is a neural network variant that is frequently used in natural language processing, classification, regression, etc. In a traditional neural network, inputs are processed through multiple hidden layers and then output via the output layer. In the case of sequential dependent input, a general neural network cannot manufacture accurate results. For example, in the case of the dependent sentence "Rose is a beautiful flower," a general neural network takes the "Rose" input to produce an output based solely on "Rose." en, when the word "is" input is considered, the network does not use the previous of "Rose" result. Instead, it simply produces the result using the word "is." Similarly, a simple neural network takes other words "a," "beautiful," and "flower" to generate results without considering the previous result of inputs. To address this problem, RNN has emerged with an internal memory that retains previous time step results. A simple RNN structure is shown in Figure 1.
Mathematically, an RNN can be presented using equation (6). e current state of the RNN can be expressed as where h t is the current state, h t−1 is the previous state, x t is the current state input, w hh is the weight of the recurrent neuron, and w hx is the weight of the input neuron. Equation (8) is used as an activation function (tanh) of RNN: Finally, the output function can be written as follows: where w yh is the weight for the output layer and y t is the output. RNN has multiple input and output types such as one to one, one to many, many to one, and many to many. Despite all the advantages, RNN is susceptible to the major drawbacks of gradient vanishing or exploding.

Gradient Vanishing and Exploding.
In this section, we discuss the RNN gradient vanishing and exploding problems. It seems simple to train the RNN network, but it is very hard because of its recurrent connection. In the case of forward propagation, we multiply all the weight metrics and a similar procedure needs to apply the backpropagation. For the backpropagation, the signal may be strong or weak which causes exploding and vanishing. Gradient vanishing makes a complex situation to determine the direction of model parameters to improve the loss function. On the other hand, exploding gradients make the learning condition unstable. Training of the hidden RNN network is passed through different time steps using backpropagation. e sum of a distinct gradient at every time step is equal to the total error gradient. e error can be expressed by considering total time steps T in the following equation: Now, we apply the chain rule to calculate the overall error gradients: e term zh t /zh k is involved with the product of Jacobians zh i /zh i−1 as shown in the following equation: e term zh t /zh t−1 in equation (12) is evaluated by equation (7).
Now, by the Eigen decomposition on the Jacobian matrix zh t /zh t−1 given by If the direction of a hidden state Δh t is moved to v i by any modifications, then the gradient will be λ i Δh t . From equation (14) the product of the Jacobians of the hidden state sequences is It is easy to visualize the term λ t i dominating Δh t . In summary, if the greatest eigenvalue is λ 1 < 1, then the gradient will vanish and λ 1 > 1 causes the gradient exploding [24]. To alleviate the Scientific Programming gradient vanishing or exploding problems, the gradient clipping, input reversal, identity initialization, weight regularization, LSTM, etc. techniques can be used.

LSTM
Network. An LSTM neural network is a special kind of RNN network that is often used to process long inputs. An LSTM is not limited to a single input but can also process complete input sequences. Usually, an LSTM is structured with four gates such as forget, input, cell state, and output. Each gate has a separate activity where the cell state keeps complete information of the input sequences and others are used to manage the input and output activities. Figure 2 shows the structure of a basic LSTM unit.
At the very beginning, processing starts with the forget gate to determine which information has to be discarded from (or retain in) the cell state. e forget gate in cell state c t−1 can be expressed by the following equation (15) where h t−1 is the hidden state and x t is the current input. e output (0 or 1) of the forget gate is produced through a sigmoid function. If the result of the forget gate is 1, then we keep the data in the cell state; otherwise, we discard the data.
e input gate determines which cell state value should be updated when new data appears.
rough the tanh function, the candidate value c t for the cell state is now created.
Now, we update the old cell state c t−1 by the c t e filtered version of the cell state will be output o t via the sigmoid function and the weight will also be updated.
Recognizing the strength of LSTM, we were motivated to apply this network model to error detection, prediction, correction, and classification in source codes.

Proposed Approach
Our proposed LSTM-AM network has an effective deep learning architecture that is used as an intelligent support model for source code completion. Accordingly, we trained our model using correct source codes and then used it successfully to detect errors and predict correct words in erroneous source codes based on the trained corpus. Moreover, the proposed model can classify the source codes using the prediction results. Our model generates a complete feedback package for each source code after being examined where learners and professionals can benefit from the model. e workflow of our proposed model is depicted in Figure 3.

Proposed LSTM-AM Network.
Over the years, attention mechanisms have been adapted to a wide variety of diverse tasks [25][26][27][28][29][30], the most popular and effective of which is sequence-to-sequence modeling. Typically, in sequence-tosequence modeling, the output of the last hidden state is used as the context vector for further consideration. It is very difficult to process long sequenced inputs using the sequence-to-sequence model [31]. e attention mechanism makes it possible to map all previously hidden state outputs, including the latest hidden state output, to produce the most relevant and accurate results.
With this point in mind, we incorporated an attention mechanism into a standard LSTM to make LSTM-AM, as shown in Figure 4. is strengthens our model's ability to predict longer source code sequences. Attention usually improves the performance of the language and translator model by merging all hidden state outputs with the softmax function; sometimes, attention mechanisms work as a dense layer. Recently, attention mechanisms have been used in machine translation tasks with great success. Furthermore, sometimes it is necessary for a machine translator model to compress entire input sequences into a smaller size vector, so there is a possibility of information loss. e use of attention mechanisms has fixed this problem. In our proposed model, an attention mechanism is combined with an LSTM. Although the abilities of a standard LSTM to capture longrange dependencies are far superior to those of an RNN. It still encounters problems when a hidden state has to carry all the necessary data in a small-sized vector [31]. e introduction of attention mechanisms and their alignment with neural language models such as LSTM are aimed at overcoming these problems [16]. e attention mechanism offers neural language models to bring and use appropriate information in all secret states of the past. As a result, the network's retention ability is improved and diverse paths are provided for gradients to backpropagate. More detailed mathematical illustrations of attention mechanisms can be found in [17].
For our attention mechanism, we took the external memory of E for the previous hidden states, which is   Scientific Programming used attention layer by considering h t and M t at the time t, attention weight α t , and context vector c t .
To predict the next word at time step t, judgment is based not only on current hidden states h t but also on context vector c t . At that point, the focus turns to the vocabulary spaces to produce the final probability y t ϵR v via softmax function. Here, G t is an output vector.
where w g ϵR k * 2k and w v ϵR v * k are trainable projection matrices, b v ϵR v is a bias, and v is a vocabulary/dictionary size.
Based on the above aspects, we can see that the use of an attention mechanism helps to effectively extract the exact features from input sequences. As such, the use of LSTM-AM will increase the capability of our model.

Data Acquisition and Problem Description
An online judge (OJ) system is a web-based programming environment that compiles and executes submitted source codes and returns judgments based on test data sets. OJ system is an open platform for programming practice as well as competition. To conduct our experimental work, we ["i", "=", "j", "+", "k", ";"] Input layer Hidden layer Scientific Programming collected source code from the AOJ system [32,33]. Currently, the AOJ system is effortlessly performing for various programming competitions and academies. As of May 2020, about 75,000 users are regularly playing their programming activities on the AOJ platform, with 2100 autonomous problem sets. All problem sets are classified based on different algorithms and branches of computer science [14]. As a result, about 4.5 million massive solution source codes have been archived on the AOJ platform, encouraging better research in the field of software engineering. We used all source codes from the AOJ system for training and testing purposes to avoid threats or difficulties in our proposed model. For model training, we selected all of the correct solutions written in C language of the three problems such as the greatest common divisor (GCD), insertion sort (IS), and prime numbers (PN). ere are a total of 2285 correct source codes for the IS problem and the overall solution success rate is 35.16%. e total number of correct source codes for the GCD problem is 1821 and the overall solution success rate is 49.86%. Considering the GCD problem, we see that there are two inputs (a and b) given in a line, after which the greatest common divisor of a and b will be output, as shown in Figure 5(a).
In contrast, the total number of correct source codes for the PN problem is 1538 and the overall solution success rate is 30.8%. In the PN problem description, the first line contains an integer N. e code needs to count the number of prime numbers in the list of N elements, as shown in Figure 5(b).

Data Preprocessing and
Training. Before we conducted training, raw source codes were filtered by removing unnecessary elements. To accomplish this, we followed the procedure applied to [14] for source code embedding and tokenization. First, we removed all irrelevant elements from codes like lines (n), comments, and tabs (\t). After that, all the remaining elements of the code were converted into word sequences where numbers, functions, tokens, keywords, variables, classes, and characters were treated as simple words. e whole code transformation process is called tokenization and vocabulary creation. en, each word was encoded with IDs in which the function names, keywords, variable names, and characters were encoded as listed in Table 1. e flowchart of the training and evaluation process of our model is shown in Figure 6.
At the early stage of the training phase, the source codes were first converted into word sequences and then encoded into token IDs as shown in Figure 7. is conversion process is called word embedding and tokenization.
Upon completion of the embedding and tokenization process, we trained our proposed model and other related state-of-the-art models with the correct source codes of IS, GCD, and PN problems. e simple training process of an LSTM-based language model is shown in Figure 8.
At the end of the training process, the next step is to check the performance of the model for the source code completion task. How accurately it identifies errors and predicts corrections? Our proposed model created the probability for each word. We considered a word will be an error candidate whose probability is below 0.1 [14]. Additionally, to test the model loss function, we calculated the cross-entropy for each epoch at the softmax layer. Crossentropy is defined as the difference between actual and predicted results. Softmax is an activation function that creates probabilities. Typically, softmax is used as the last layer of neural networks. e output range of the softmax function is between 0 and 1. e softmax layer received x � [x 1 , x 2 , x 3 , x 4 , . . ., x n ] and returns probability p � [p 1 , p 2 , p 3 , p 4 , . . ., p n ], as defined in the following equation: Cross-entropy is an effective performance measurement indicator for the probability-based model. Low-valued cross-entropy indicates a good model.
A simple example of the prediction process used by our model is shown in Figure 9. An input sequence example is {" � ," "x," "+," "y"}; then the model calculates the next probable correct word based on the source code corpus. Finally, the word with the highest probability is the winner of the next predicted word. Based on the input sequence in the example above, the correct predicted word is {";"}.

Hyperparameters.
In the present research, we defined several experimental hyperparameters in order to obtain better results. To avoid overfitting, a dropout ratio (0.3) was used for our proposed model. e LSTM network was optimized using Adam, which is a stochastic optimization method [34,35]. e learning rate is an important factor for neural network training because the value of the learning rate can control the learning speed of the model. Network learning becomes faster and slower on the basis of higher and lower value of learning rates, respectively. In the present paper, we determine the learning rate l � 0.002, and the network weights during training are updated by the value of l. β 1 is the exponential decay rate for the first-moment estimate and the second-moment estimate of the exponential decay rate is β 2 . e values of the β 1 and β 2 are 0.001 and 0.999, respectively. e value of ε chosen to avoid any division by zero which is ε � 1e − 8 . We trained our network in 50, 100, 150, and 200 hidden units. Each model type was named with reference to the number of units, such as the 100-unit model and 200-unit model. After training, we assessed the ability of our proposed LSTM-AM technique to pick the best number of hidden units from the created models.

Experimental Results
Our proposed intelligent support model can be useful for source code completion. Also, it is a general model and can be adapted to any source code for model training and testing. 8 Scientific Programming In our proposed model, we defined a minimum probability value by which the model can identify error candidate words based on the training corpus. Accordingly, we randomly chose some incorrect IS, GCD, and PN source codes and used them to evaluate the models' performance levels. Here, we should note that all of our research work and language model training were performed on an Intel ® Core ™ i7-5600U central processing unit (CPU) personal computer clocked at 2.60 GHz with 8 GB of RAM in a 64-bit Windows 10 operating system.

Hidden Unit Selection and Cross-Entropy Measurement.
We used several hidden units such as 50, 100, 150, and 200 to train our proposed LSTM-AM and other state-of-the-art models. In training, the correct source codes of IS, GCD, and PN problems are used separately and all the source codes of IS, GCD, and PN are used combinedly. e number of source codes of each type of problem is listed in Table 2.
We trained our proposed LSTM-AM and different stateof-the-art models using correct source codes. Table 3 presents the cross-entropy in 30 epochs during training using PN source codes. e 50-, 100-, 150-, and 200-unit models took a total of 11483, 20909, 38043, and 59065 seconds to train the LSTM-AM model using the PN problem, respectively. Tables 4 and 5 present cross-entropy of different models during training using GCD and IS source codes, respectively. e 50-, 100-, 150-, and 200-unit models took a total of 19005, 24110, 24273, and 30420 seconds to train the LSTM-AM model using the GCD problem, respectively, and for the   To evaluate the efficiency of the proposed model, epochwise cross-entropy during the training periods using the 200-unit model was calculated which is depicted in Figure 10.
As mentioned above, the efficiency of a model strongly depends upon the value of cross-entropy. During training, the 200-unit model produced the lowest cross-entropy using each type of problem set. e cross-entropy of the 200-unit model using IS, PN, and GCD problems is shown in Figure 11.
We aimed to find the best-suited hidden units for our LSTM-AM network and other state-of-the-art models. In this regard, we put together all the source codes (about 3442) to train our proposed and other state-of-the-art models. e cross-entropies and total times are recorded at the last epoch of all the models as presented in Table 6. e cross-entropy of the 200-unit model is lower than other models.
Based on the above aspect, it is ensured that the 200-unit model provides the best results because its cross-entropy is the lowest value among all the units; thus, we selected a 200unit model for the LSTM-AM network and other state-ofthe-art networks.

Error Detection and Prediction.
In our evaluations, we tested LSTM-AM and other state-of-the-art models using erroneous source codes. Probable error locations were marked by changing the text color and underlining the suspected erroneous portions. Also, the proposed model ["while", "(", "x", "<", "1", "0", "{", "y", "=", "x", "+", "y", ";", "x", "+", "+", ";" "return", "y", ";", "}"]        An erroneous source code sequence evaluated by the standard LSTM network is shown in Figure 12. Here, it can be seen that errors were detected in lines 2, 6, 15, and 16. In line 2, the word "a" in the "gcd" function was detected as an error candidate, after which the correct word was predicted to be ")" with a probability 0.62435395. e model decided that the "gcd" function might be without arguments, the word ")" was predicted instead of the word "a". In line 6, the error word is "if" and the predicted word is "else" with a probability 0.5808078. Additionally, in line 15, the predicted word is "blank space" in the place of "double quotation." Finally, in line 16, the model detected "c" as an error object and suggested with a high level of probability that it should be replaced by the word "b." e word "c" is irrelevant within the context of the program; it can be confirmed that the standard LSTM model successfully detected the error candidates shown in Figure 12, as listed in Table 7. e same incorrect source code was then evaluated by the LSTM-AM network, as shown in Figure 13. e error locations are in lines 2, 15, and 16. e word "a" in the "gcd" function was detected as an error candidate and the predicted word ")" was suggested. In line 15, the word "double quotation" was identified as a bug, and the predicted word "blank space" was suggested. e word "c" in line 16 was recognized as an error and the corresponding predicted word suggested was "b" with a probability of 0.9863272, as shown in Table 8.
Another interesting erroneous source code, which exists in some logical errors, was evaluated by the standard LSTM network, as shown in Figure 14. All the detected error words and their corresponding predicted corrections of Figure 14 are listed in Table 9.       Similarly, the same erroneous source code was tested by the LSTM-AM network, as shown in Figure 15. e detailed error descriptions of Figure 15 are listed in Table 10, where it can be seen that the LSTM-AM network detected all of the potential errors, including the true logical errors, successfully.

Classification of Source Codes.
We evaluated our proposed LSTM-AM and other benchmark models using both clean and erroneous source codes. For extensive experiments, we selected several benchmark models to compare classification results such as (i) Random Forest (RF) [36] method, (ii) Random Forest (RF) method trained with secret attributes by Restricted Boltzmann Machine (RBM) [37], and (iii) Random Forest (RF) method learned with secret attributes by Deep Belief Network (DBN) [38]. e precision, recall, and F-measure are expressed by equations (23)- (25), respectively, to verify the classification performances: recall(R) � tp e⟶e tp e⟶e + fn e⟶c , where tp e⟶e is called true positive, the case e ⟶ e means defective source code classifies as erroneous, and fp c⟶e is called false positive; the case c ⟶ e means that the clean source code is classified as erroneous. e term fn e⟶c is called false negative where e ⟶ c means that the erroneous source code is classified as a clean source code. F-measure is called the harmonic mean of recall and precision. Generally, we cannot achieve optimal results simultaneously for recall and precision. For example, if all the source codes are classified as defective, the resulting recall score will be 100% where the precision score will be small. erefore, F-measure is a trade-off between recall and precision. e range of the F-measure score is between 1 and 0; the higher score implies a better classification model. Under normal circumstances, our proposed language model detects all possible errors in source codes where all the detected errors are not true errors (TE). So, we considered only TE for the classification process. An error is called a TE when the predicted probability is more than 0.90. We aligned the term true positive tp e⟶e with our proposed model when the model detects TE in erroneous source codes. Again, in case of the term false positive fp c⟶e , at least a single TE is detected within correct source codes.
Finally, the term false negative fn e⟶c , not a single TE, is detected in erroneous source code which means that it classifies the erroneous source code as clean code. As mentioned above, all the models are trained by using correct source codes and tested on 500 randomly chosen source codes from each problem set (IS, GCD, and PN). e classification results are listed in Tables 11-13 for the IS, GCD, and PN source codes, respectively.
In the classification process, the F-measure scores of the LSTM-AM and other state-of-the-art models are shown in Figure 16. F-measure results show that the classification performance of our proposed model is better than other methods.

Discussion
To assess our proposed intelligent support model, we defined three performance measurement indices such as error prediction accuracy (EPA), error detection accuracy (EDA), and model accuracy (MA), shown in equations (26) to (28). In particular, we evaluated our proposed model and other benchmark models using equation (28).

EDA � True Errors(TE) Total Detected Errors(TDE)
× 100%, EPA � True Correct Words(TCW) Total Predicted Words(TPW) × 100%, In most cases, the proposed model detects potential errors in the codes. Among these errors, there are a few In the evaluation process, we discarded the RNN and other benchmark models because they obtained high crossentropies whereas standard LSTM achieved very low crossentropies. erefore, we validated both the standard LSTM and LSTM-AM networks using several randomly chosen erroneous source codes. Figure 12 and Table 7 present the details of error detection and prediction by standard LSTM. e standard LSTM detected errors in lines 2, 6, 15, and 16 and provided the corresponding candidate words "a," "if," "double quotation," and c, respectively. e predicted correct words are ")," "else," "blank space," and "b." Although these results show that the standard LSTM had detected the most probable erroneous words and locations, not all of the candidate errors are true errors (TE). In line 2, the model     detects "a" as an error candidate by guessing that "gcd" is a function without arguments. en, as a consequence, it predicts a close parenthesis ")" as the correct word. Similarly, in line 6, the model detected "if" as a candidate error word and predicted "else" as a corresponding correction. In this case, the model calculated that the word "if" started at line 3 and ended at line 5 and that the word after line 5 should be "else." As a result, the standard LSTM predicted the word "else" in line 6 instead of the word "if." However, both the error predictions in lines 2 and 6 were incorrect, even though they were hypothetically reasonable. It should be noted that the error candidate word "c" in line 16 is a true error (TE) and the predicted word "b" is correct. e evaluation results using the standard LSTM for the erroneous source code in Figure 12 are presented in Table 14.
In Figure 13, the LSTM-AM model detected a total of three errors in lines 2, 15, and 16, with the predicted corresponding correct words being ")," "blank space," and "b" respectively, as shown in Table 8. e evaluation results using the LSTM-AM for the erroneous source code in Figure 13 are presented in Table 15.
To further evaluate the performance of our proposed model, we then took a somewhat larger and more complex erroneous source code and verified it using both the standard LSTM and LSTM-AM networks, as shown in Figures 14 and 15, respectively. e erroneous source code contains a logical error in line 23. In this source code, two inputs were taken from the keyboard as "a" and "b" variables. e higher value was assigned to variable "x" and the lower value was assigned to variable "y." Initially, variable "x" was thought to be a dividend and variable "y" was designated as a divisor. However, line 23 was checked to find the initial greatest common divisor used by the modular arithmetic operator where the small valued variable "y" was considered to be a dividend, and the higher valued variable "x" was considered to be a divisor. By following the code sequence, the correct logic would be x%y. Based on that aspect, the LSTM-AM network identified the logical error correctly by considering the previous source code sequence, whereas the standard LSTM could not detect the logical error in line 23. e evaluation results for erroneous source codes in Figures 14 and 15 are listed in Table 16, where it can be seen that the LSTM-AM network performance was even better in the case of the long source codes and complex codes with logical or other errors.
In addition to the abovementioned source code evaluations and examples, we evaluated about 300 randomly chosen erroneous source codes using the LSTM and LSTM-AM models and found that their average accuracy values were approximately 31% and 62%, respectively. ose detailed statistics are shown in Table 17.
Unlike the examples used in this study, programs' lengths can vary widely, with many containing from 500 to 1000 lines of source code, or more. One thing all have in common is that when writing a program, numerous variables and functions may be declared in many lines previously.
erefore, an attention mechanism is needed to capture the long-term source code dependencies, as well as to evaluate source code errors correctly. Our experimental results have shown that the LSTM-AM model was much more successful for the longer sequenced source code than was the standard LSTM model, as shown in Figure 17.
Additionally, some syntax and logical errors in source codes cannot be identified by traditional compilers. In such cases, our proposed LSTM-AM-based language model can provide meaningful responses to learners and professionals that can be used for the source code debugging and refactoring process.
is can be expected to save time when working to detect errors from thousands of lines of source code, as well as to limit the area that must be searched to find the errors. Furthermore, the use of this intelligent support model can assist learners and professionals to more easily find the logical and other critical errors in their source codes. Moreover, the classification accuracy of our proposed model   is much better than the other state-of-the-art models. e average precision, recall, and F-measure scores of the LSTM-AM model are 97%, 96%, and 96%, respectively, which outperformed other state-of-the-art models.

Conclusion
In the present research, we proposed an AI-based model to assist students and programmers in source code completion. Our proposed model is expected to be effective in providing end-to-end solutions for programming learners and professionals in the SE fields. e experimental results obtained in this study show that the accuracy of error detection and prediction using our proposed LSTM-AM model is approximately 62%, whereas standard LSTM model accuracy is approximately 31%. In addition, our approach provides the location numbers for the predicted errors, which effectively limits the area that must be searched to find errors, thereby, reducing the time required to fix large source code sequences. Furthermore, our model generates probable correction words for each error location and detects logical and other errors that cannot be recognized by conventional compilers. Also, the LSTM-AM model shows great success in source code classification than other state-of-the-art models. As a result, it is particularly suitable for application to long source code sequences and can be expected to contribute significantly to source code debugging and refactoring process. Despite the abovementioned advantages, our proposed model also has some limitations. For example, error detection and predictions are not always perfect, and the model sometimes cannot understand the semantic meaning of the source code because of the incorrect detection and predictions that have been produced.
us, our future work will use a bidirectional LSTM neural network to improve this intelligent support model for source code completion.

Data Availability
We acquired all the training and test source codes from the AOJ system. Resources are accessed from the following websites through the API: https://onlinejudge.u-aizu.ac.jp/ and http://developers.u-aizu.ac.jp/index.

Conflicts of Interest
e authors declare that they have no conflicts of interest.