# Persian Named Entity Recognition by Gray Wolf Optimization Algorithm

Authors: Aynaz Forouzandeh; Mohammad-Reza Feizi-Derakhshi; Pejman Gholami-Dastgerdi
Journal: Scientific Programming
 (2022)

---

## Abstract

Named entity recognition (NER) is a subfield of natural language processing (NLP). It is able to identify proper nouns, such as person names, locations, and organizations, and has been widely used in various tasks. NER can be practical in extracting information from social media data. However, the unstructured and noisy nature of social media (such as grammatical errors and typos) causes new challenges for NER, especially for low-resource languages such as Persian, and existing NER methods mainly focus on formal texts and English social media. To overcome this challenge, we consider Persian NER as an optimization problem and use the binary Gray Wolf Optimization (GWO) algorithm to segment posts into small possible phrases of named entities. Later, named entities are recognized based on their score. Also, we prove that even human opinion can differ in the NER task and compare our method with other systems with theSep_TD_Tel01 dataset and the results show that our proposed system obtains a higher F1 score in comparison with other methods.


---

## Body

## 1. Introduction

Named entity recognition (NER) is commonly accepted as one of the core tasks in natural language processing (NLP). The key purpose of NER is to identify and classify certain proper nouns, such as person names, locations, and organizations [1] which can be used in numerous text processing applications, such as information extraction, machine translation, information retrieval, and text summarization.Moreover, with the pervasiveness of social networks and social media such as Telegram and Instagram, a very large pile of information is being produced and published daily that carries useful data. This has led to fundamental changes in so many tasks carried out by service providers, business owners, factories, brands, or even governments. Thus, NER can be practical in extracting information from unstructured texts such as emails, social media, and text messages [2]. Nevertheless, social media NER is challenging due to its unstructured and noisy short texts which can contain spelling inconsistencies, improper grammatical structures, and numerous informal abbreviations. Also, in Persian, unlike in English, fewer kinds of research have been conducted due to the lack of corpus and not being widespread of this language which poses another challenge. Therefore, previous methods may be very effective in their language but not applicable in the Persian language due to differences in the structure of languages.In this work, to overcome the above-mentioned challenges, we use metaheuristic optimization algorithms which have become popular in solving many problems. We view NER as a binary optimization problem to partition Telegram posts into small possible phrases of named entities which we call them segments. To be specific, it can be a possible segmentation boundary between each pair of words which is defined by a binary value. Then, we apply the binary Gray Wolf Optimization (GWO) algorithm to obtain optimum values. Finally, we rank these segments to recognize segments that are true named entities. Our main contributions are as follows:(i)
We propose a NER system for the Persian language that is based on segmentation using the GWO algorithm. Background knowledge extracted from two corpora (Persian Wikipedia andN-Gram) is used as global contexts in the segmentation process.(ii)
We developedN-Gram from the Hamshahri corpus and Telegram large dataset(iii)
We compare our method with three other methods on theSep_TD_Tel01 datasetIn Section2, we review some related works for NER and its different categories of proposed methods. Section 3 describes our method. In Section 4, we talk about the evaluation method, dataset, parameter setting, and evaluation results. Finally, Section 5 presents some concluding notes.


## 2. Related Work

This paper describes NER systems based on the GWO algorithm for Persian data. Thus, in this section, some related works on NER will be discussed.In the past few years, NER has been researched widely. However, due to the lack of a Persian data corpus, fewer researches have been carried out in this language. In the literature, different methods of NER have been proposed, such as machine learning methods, linguistic rule-based methods, statistical methods, and hybrid methods.Early NER research studies were mostly allocated to rule-based systems. In linguistic rule-based systems, named entities are recognized based on structural and grammatical rules. However, rule-based systems suffer from poor generalization as including all linguistic rules is practically impossible [2]. Riaz in [3] proposes a hand-crafted rule-based Urdu NER algorithm. Khormuji and Bazrafkan in [1] present an approach based on local filters for Persian NER. This approach uses multiple dictionaries, which are available on the web. References [4–6] are some other rule-based NER systems that have been carried out in different languages.To date, various machine learning methods have been used to recognize named entities. The most common examples are hidden Markov models (HMMs), decision trees, maximum entropy, support vector machines (SVMs), conditional random fields (CRFs), and bidirectional LSTM [7, 8]. All these methods are based on supervised learning, which is the most common learning method in NER. There have also been semisupervised and unsupervised systems, but the results of these systems are mostly worse [9]. Konkol et al. in [9] use an unsupervised machine learning method based on semantic features, which can be used in a variety of languages. Chiu and Nichols in [8] extract named entities using bidirectional long short-term memory (BiLSTM) and convolutional neural network (CNN) architecture on an English dataset. In this model, word- and character-level features are extracted with a hybrid BiLSTM and CNN architecture. Furthermore, as lexicon is important in NER, a new lexicon encoding scheme and the matching algorithm have been proposed, making use of partial matches. Poostchi et al. in [7] propose a deep learning method based on BiLSTM-CRF for Persian NER, which is a combination of BiLSTM and a CRF. The BiLSTM processes each sentence token-by-token and produces an intermediate representation. Then, CRF uses this representation as input to predict all tokens’ labels. Before the BiLSTM process, embedding methods, which is part of the training stage, have been used to convert each token into a high-dimensional numerical vector. As well, Momtazi and Totrabi in [10] present NER for Persian text in which for entity recognition BiLSTM is used, and for the word representation, word2vec, and fastText vector representation are used and compared. Taher et al. in [11] proposed Beheshti-NER which utilizes BERT for Persian NER. In this method, they have trained CRF on the top of pretrained bidirectional transformer BERT. Also, Asgari-Chenaghlu et al. in [12] propose two approaches for NER by deep learning and transformers. In both approaches, image features have been used. In [13], Dogan et al. use deep learning models (ELMos) and an extensive knowledge base for fine-grained NER. Zali and Firoozbakht in [14] present an approach for Persian NER based on neural networks benefiting from the vector representation of words. Tafreshi and Soltanzadeh in [15] implement Persian NER based on CRF in which various linguistic features have been designed to extract appropriate features for the learning phase. Farahani et al. in [16] present ParsBERT which is a transformer-based model for Persian and evaluate the model on sentiment analysis, text classification, and NER task.Moreover, there have been some research studies that have proposed statistical systems. These studies are generally focused on language-independent machine-learning techniques that aim to learn statistical models from data [17]. Bikel et al. in [18] have built a NER system which is called “Nymble.” This system uses a slightly modified HMM in which observations are the words, and hidden states represent the labels. Nymble has been implanted in English and Spanish. Chenliang et al. in [19] propose a novel 2-step unsupervised NER system called “TwiNER” on which our proposed system is based. TwiNER focuses on a targeted Twitter stream that is used to collect users’ opinions about organizations. This system uses two global contexts, Microsoft Web N-Gram and Wikipedia, to partition tweets into valid segments. This process has been carried out with a dynamic programming algorithm. Then, named entities are extracted using both global and local contexts.Furthermore, some studies make use of hybrid methods. In hybrid approaches, ruled-based and machine-learning methods are integrated. Moradi et al. in [20] present a hybrid system for Persian NER. Because of HMM innate weaknesses, they combine it with ruled-based methods. This system uses HMM and Viterbi algorithms in its machine learning section and lexical resources and pattern bases in its rule-based section. Dashtipour et al. in [2] propose a hybrid Persian NER by combining dictionaries of Persian NER, grammar rules, and SVM. Persian-named entity dictionaries of three entities (name, location, and date) were collected manually in this system. Then, different grammar rules were added. Finally, a classifier was trained with bigram features. Kung et al. [21] present a Hybrid Mandarin NER using transfer learning for disaster management. This approach, which has three modules, combines established rules and learned sentence patterns.


## 3. Model Description

In this paper, named entities of the Telegram posts have been extracted by the TwiNER [19] method and gray wolf optimization [22]. As these kinds of posts are considered informal, the process of extracting named entities in this context is challenging, and the common methods are not useful. Therefore, in this paper, a segmentation-based system is presented. The proposed system architecture can be divided into two steps: 1-segmentation and 2-named entity extraction. The architecture of the proposed system is shown in Figure 1.Figure 1
Proposed system architecture.In the first step, the posts are segmented using a stickiness function. Two global contexts, Wikipedia andN-Gram, were used to calculate the stickiness. In fact, in the segmentation phase, each Telegram post is broken down into smaller terms, each of which is a candidate for named entities in the next step. Nevertheless, due to the fact that the state space for the segmentation of each post will increase exponentially, an optimization algorithm is needed to find the optimum state. In this paper, the binary GWO [23] is used to find the optimal segmentation. This step is fully explained in Section 3.1.In the second step, after segmenting the posts, these segments must be scored, considering that not all of the segments are true named entities. To do this, a graph is created whose nodes will be the extracted segments, and the weight of its edge will be calculated using the Jaccard. The Random walk model then scores graph nodes using Wikipedia’s linguistic knowledge. The outputs of this section are scored segments. Finally, high-scored segments are considered as named entities. The full description of this step is given in Section3.2.


### 3.1. Segmentation

In the first step, posts need to be segmented based on a stickiness criterion. In this paper, segmentation means the partition of a post into smaller phrases. However, the number of segmentation states grows exponentially with respect to the length of the post, and examining all these states is impossible. If we assume that a sentence hasm words, then we will have 2m−1 state for segmenting. For instance, in order to segment the post, which can be seen in Figure 2 has 11 tokens, will have 210=1,024 states. Therefore, an optimization algorithm is needed to do the segmentation. This paper uses GWO for segmentation. In Figure 2, some examples of possible segments are represented. According to the results, the second segmentation has the better output since it considers the named entity of “Ayatollah Hashemi Rafsanjani” as a segment.Figure 2
Example of a post and its boundaries and some possible segmentation of this post.


#### 3.1.1. GWO in Segmentation

As mentioned in Section3.1, search space size exceeds exponentially. Hence, because of the huge search space, attribute reduction is a challenging task. Various search techniques have been employed to solve the attribute reduction problem, for instance, greedy search based on sequential forward selection and sequential backward selection. Nonetheless, these approaches suffer from different issues, such as increasing computational cost and stagnation in local optima [24]. Metaheuristic optimization algorithms have become more popular in various applications due to their simplicity in implementation, not requiring gradient information and bypassing local optima [25]. Metaheuristics are fundamentally based on trajectory such as simulated annealing (SA) or based on population, such as genetic algorithm (GA), ant colony algorithm (ACO), particle swarm optimization (PSO), and GWO [26].GWO is a recently developed algorithm introduced by Mirjalili et al., which mimics the leadership hierarchy (alpha, beta, omega, and delta) and haunting mechanism of gray wolfs. In this algorithm, alpha is considered the best solution. Beta and omega are, respectively, the second and third-best solutions. For more information about GWO, please refer to [22]. This algorithm is based on swarm intelligence (SI). SI algorithms have fewer parameters and are easy to implement, and GWO is one of the rapidly progressing SI algorithms drawing researchers’ attention [26].This section describes how to use the GWO to segment posts. As mentioned, GWO is based on SI, which processes the solution of the problem in vector form. In this paper, each solution is called a gray wolf vector. The segmentation problem is defined as a binary problem; nevertheless, GWO is not able to produce binary vectors. Consequently, the values of this algorithm need to be in binary form. In order to do this, the method described in [23] has been utilized in which two approaches are proposed. This article uses the second approach. In this approach, only the updated values of the gray wolf vector are converted to binary values. To be more specific, if the sigmoid value of the gray wolf vector exceeds the threshold (the threshold is generated randomly), it returns 1, and otherwise 0.To start optimization, the dimension of gray wolf vectors must be determined. If a post hasn words, then the dimension of the gray wolf vector will be n−1. Because to segment, each post, between each word can be considered as a segmentation boundary. Segment boundary is the boundary of a word or some selected words as a segment in the segmentation phase. For instance, in the post “Urgent: Ayatollah Hashemi Rafsanjani was hospitalized.” the dimension of gray wolf vectors is equal to 7.Each gray wolf vector can be generated by three values (0, 1, and −1). A value of 0 means that this point is not considered as a segmentation boundary (pink cells in Figure3), and values 1 and −1 indicate the segmentation boundary (green and blue cells in Figure 3). The difference between 1 and −1 is that −1 has been used for definite segmentation boundaries, so for each post, it remains constant in the process of optimization. Definite segmentation boundaries are stop words, punctuations, and emojis, which are not used as named entity or part of named entity in the Persian language. The points that are before and after these tokens are marked with −1 in the gray wolf vector (green cells in Figure 3). These points, to some extent, prevent the overproduction of segments that are not named entities. Therefore, it will reduce the number of states. According to this explanation, our goal is to find the optimum value for nondefinite boundaries. Algorithm 1 outlines the segment extraction algorithm.Figure 3
An example of a gray wolf vector. The pink cells with the value of 0 are not segmentation boundaries, the value of 1 in the blue cells indicates segmentation boundaries, and the green cells are definite segmentation boundaries for stop words, punctuations, and emojis.Algorithm 1: Segment extraction.
input:p: A Telegram post p=w1w2…wnwherewi is a word in the postGWV: gray wolf vectoroutput:S: set of segments for a post extracted from GWV(1)
NewSegment⟵True(2)
DetectSegment⟵False(3)
S⟵(4)
fori = 1:len(GWV) do(5)
ifGWV[i] ! = −1 then(6)
ifNewSegmentorGWV[i − 1] = = −1 then(7)
start⟵i(8)
NewSegment⟵False(9)
ifGWV[i] = = 1 ori = = len(GWV) then(10)
end⟵i(11)
NewSegment⟵True(12)
DetectSegment⟵True(13)
else ifGWV[i + 1] = = −1 then(14)
i⟵i+1(15)
end⟵i(16)
NewSegment⟵True(17)
DetectSegment⟵True(18)
else(19)
NewSegment⟵False(20)
DetectSegment⟵False(21)
ifDetectSegmentthen(22)
currentSegment⟵wstart…wend(23)
addcurrentSegment to S(24)
DetectSegment⟵False(25)
NewSegment⟵True(26)
returnSAs mentioned, a stickiness criterion is required in segmentation. As a result, a fitness function must be defined to determine the optimal value. The following section describes this function in detail.


#### 3.1.2. Fitness Function

In the previous section, the process of creating gray wolf vectors and their values were described. This section describes how to calculate fitness function.In this step, a criterion that determines the amount of stickiness between the words is used to assess the optimal segmentation. The high amount of stickiness means that the cut-off point between two words should not be equal to 1 because it separates the correct expression. Thus, for each postpϵPi, the goal is to divide p into m optimal segment p=s1,s2,…,sm. Therefore, the following fitness function is used to obtain an optimal state:(1)Fp=max∑i=1mCsi.ewikisi.lsi.This equation consists of three parameters.C is a function that measures the stickiness of the words, ewikis calculates the Wikipedia score, and ls normalizes the length of the segments. In the rest of this section, each parameter will be described in more detail.As stated in [19], two stickiness functions point mutual information (PMI) and symmetric conditional probability(SCP) are used to calculate C.(1). PMI-Based Stickiness. PMI measures the probability of two words occurring together more often than by chance. PMI for bigram w1w2 is defined as follows:(2)PMIw1w2=logPrw1|w2Prw1=logPrw1w2Prw1Prw2.For a segmentss=w1…wn, PMI is extended by averaging all binary partitions as follows:(3)PMIs=logPrs1/n−1∑i=1n−1Prw1…wiPrwi+1…wn,where Prs represents the N-Gram probability of the s segment. If the segment has only one word, we have PMIs=logPrw. Finally, in order to map PMI in the range (0, 1), the stickiness of segment s is as follows:(4)Cs=11+e−PMIs.(2). SCP-Based Stickiness. SCP measures the cohesiveness of bigram w1w2 by considering both conditional probabilities for the bigram as follows:(5)SCPw1w2=Prw1w2|w1Prw1w2|w2=logPrw1w22Prw1Prw2.For a segment withn words, SCP is as follows:(6)SCPs=Prs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.To smooth SCP value logarithm calculation is used as follows:(7)SCPs=logPrs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.Similarly, for a single word segment, we haveSCPs=2logPrw. Eventually, the sigmoid function is applied as follows:(8)Cs=21+e−SCPs.According to and equations (3) and (7), a big corpus is necessary to calculate Prs more accurately. In this paper, Hamshahri corpus and Telegram data have been used to calculate N-Gram.ObtainedPrs from Hamshahri corpus and Telegram data is only based on frequent patterns. Therefore, another parameter is required that increases the probability of partitioning a post into segments which are named entities. To do this, Wikipedia has been used in a global context. Generally, in Wikipedia, links title are named entities, and with the emergence of new named entities, a web page in Wikipedia is dedicated to them, from which a large dictionary is produced. This dictionary can be used in segmentation. Hence, if Wikis be the probability of occurring segment s in Wikipedia links title, the stickiness function will be as follows:(9)C′s=Cs.ewikis,(10)wikis=N_anchorsN_totals,where N_anchors is the occurrence number of segment s in Wikipedia links, and N_totals indicates the total occurrence number of segment s.So far, segments of different lengths have been treated the same. However, observations show that segments with longer lengths are more likely to be named entities. Therefore, the length of the segments must be normalized. To do this,ls is added to equation (9).(11)C′s=Cs.ewikis.ls,where ls is defined as follows:(12)fx=s−1s,ifs>1,13,ifs=1.On the other hand, since, in most cases, the length of named entities does not exceed some amount, a threshold valueu should be considered for the maximum number of words for each segment, which in this paper is 5. If the number of words exceeds this threshold, the fitness function will get a penalty which is 15 in this paper. Thus, the optimization algorithm eliminates vectors that have segments of more than 5 words. In fact, it prevents the existence of more than 4 zeroes consecutively. Algorithm 2 shows this process where it gets extracted segments from Algorithm 1 as input and calculates fitness.Algorithm 2: Fitness calculation.
input:S: set of segments for a postextracted from GWVu: The maximum length of a segmentpenalty: penalty for the segments with more than u wordsoutput: Fitness for each vector(1)
fitness⟵0(2)
foreachsegment inSdo(3)
iflen(segment) > uthen(4)
fitness⟵fitness−penalty(5)
else(6)
segmentFitness ⟵ calculate fitness for the segment using equation (1)(7)
fitness⟵fitness+segmentFitness(8)
return fitnessAlso, to increase the speed of the system, when more than two −1 occur in a row (boundaries of stop words, punctuations, and emojis), the cells in between are not included in the fitness function because they add a constant value to fitness function and do not affect the result.


### 3.2. Named Entity Extraction

At this stage, after the segmentation was performed, the segments are scored to identify named entities because not all the segments obtained from the previous stage are named entities. At first, before scoring the segments, those segments that are stop words, punctuations, hashtags, and emojis have been removed. Furthermore, some of the conversational words and abbreviations also have been removed from the segments.In Telegram posts, named entities related to a specific topic will likely occur together. For example, “Trump” and “America” are more likely to happen together, while “Trump” and “message of condolence” are less likely to happen together. Consequently, this local context is used to form a graph of segments, in which the nodes are the segments extracted from a set of telegram posts, and the Jaccard criterion obtains the weight of its edges. Ifeab is the edge passing through sa to sb, then we will have the following:(13)weab=Msa∩MsbMsa∪Msb.Ms is the set of posts in Pi that contains segment s. In this way, local context is obtained, which is based on the connection between segments.Then, the random walk model is applied to the graph. Assuming that the graph is bidirectional, the probability of transiting from nodea to node b is as follows:(14)Pab=weab∑cϵVweab.In this section, the title of Wikipedia links is used as local context. Therefore, the transition ofes for segment s is defined as follows:(15)es=wiki′s∑sjϵVwiki′sj,wherewiki′s=ewikis.Then, the stationary eigenvectorπT of P is calculated iteratively as follows:(16)π=γPT+1−γe1Tπ,where γ controls the probability of teleportation, finally, to create a balance between local and global context, equation (17) has been used.(17)ys=es.πs.Equation (17) is used to score segments, and finally, top k segments are selected as named entities.


## 3.1. Segmentation

In the first step, posts need to be segmented based on a stickiness criterion. In this paper, segmentation means the partition of a post into smaller phrases. However, the number of segmentation states grows exponentially with respect to the length of the post, and examining all these states is impossible. If we assume that a sentence hasm words, then we will have 2m−1 state for segmenting. For instance, in order to segment the post, which can be seen in Figure 2 has 11 tokens, will have 210=1,024 states. Therefore, an optimization algorithm is needed to do the segmentation. This paper uses GWO for segmentation. In Figure 2, some examples of possible segments are represented. According to the results, the second segmentation has the better output since it considers the named entity of “Ayatollah Hashemi Rafsanjani” as a segment.Figure 2
Example of a post and its boundaries and some possible segmentation of this post.


### 3.1.1. GWO in Segmentation

As mentioned in Section3.1, search space size exceeds exponentially. Hence, because of the huge search space, attribute reduction is a challenging task. Various search techniques have been employed to solve the attribute reduction problem, for instance, greedy search based on sequential forward selection and sequential backward selection. Nonetheless, these approaches suffer from different issues, such as increasing computational cost and stagnation in local optima [24]. Metaheuristic optimization algorithms have become more popular in various applications due to their simplicity in implementation, not requiring gradient information and bypassing local optima [25]. Metaheuristics are fundamentally based on trajectory such as simulated annealing (SA) or based on population, such as genetic algorithm (GA), ant colony algorithm (ACO), particle swarm optimization (PSO), and GWO [26].GWO is a recently developed algorithm introduced by Mirjalili et al., which mimics the leadership hierarchy (alpha, beta, omega, and delta) and haunting mechanism of gray wolfs. In this algorithm, alpha is considered the best solution. Beta and omega are, respectively, the second and third-best solutions. For more information about GWO, please refer to [22]. This algorithm is based on swarm intelligence (SI). SI algorithms have fewer parameters and are easy to implement, and GWO is one of the rapidly progressing SI algorithms drawing researchers’ attention [26].This section describes how to use the GWO to segment posts. As mentioned, GWO is based on SI, which processes the solution of the problem in vector form. In this paper, each solution is called a gray wolf vector. The segmentation problem is defined as a binary problem; nevertheless, GWO is not able to produce binary vectors. Consequently, the values of this algorithm need to be in binary form. In order to do this, the method described in [23] has been utilized in which two approaches are proposed. This article uses the second approach. In this approach, only the updated values of the gray wolf vector are converted to binary values. To be more specific, if the sigmoid value of the gray wolf vector exceeds the threshold (the threshold is generated randomly), it returns 1, and otherwise 0.To start optimization, the dimension of gray wolf vectors must be determined. If a post hasn words, then the dimension of the gray wolf vector will be n−1. Because to segment, each post, between each word can be considered as a segmentation boundary. Segment boundary is the boundary of a word or some selected words as a segment in the segmentation phase. For instance, in the post “Urgent: Ayatollah Hashemi Rafsanjani was hospitalized.” the dimension of gray wolf vectors is equal to 7.Each gray wolf vector can be generated by three values (0, 1, and −1). A value of 0 means that this point is not considered as a segmentation boundary (pink cells in Figure3), and values 1 and −1 indicate the segmentation boundary (green and blue cells in Figure 3). The difference between 1 and −1 is that −1 has been used for definite segmentation boundaries, so for each post, it remains constant in the process of optimization. Definite segmentation boundaries are stop words, punctuations, and emojis, which are not used as named entity or part of named entity in the Persian language. The points that are before and after these tokens are marked with −1 in the gray wolf vector (green cells in Figure 3). These points, to some extent, prevent the overproduction of segments that are not named entities. Therefore, it will reduce the number of states. According to this explanation, our goal is to find the optimum value for nondefinite boundaries. Algorithm 1 outlines the segment extraction algorithm.Figure 3
An example of a gray wolf vector. The pink cells with the value of 0 are not segmentation boundaries, the value of 1 in the blue cells indicates segmentation boundaries, and the green cells are definite segmentation boundaries for stop words, punctuations, and emojis.Algorithm 1: Segment extraction.
input:p: A Telegram post p=w1w2…wnwherewi is a word in the postGWV: gray wolf vectoroutput:S: set of segments for a post extracted from GWV(1)
NewSegment⟵True(2)
DetectSegment⟵False(3)
S⟵(4)
fori = 1:len(GWV) do(5)
ifGWV[i] ! = −1 then(6)
ifNewSegmentorGWV[i − 1] = = −1 then(7)
start⟵i(8)
NewSegment⟵False(9)
ifGWV[i] = = 1 ori = = len(GWV) then(10)
end⟵i(11)
NewSegment⟵True(12)
DetectSegment⟵True(13)
else ifGWV[i + 1] = = −1 then(14)
i⟵i+1(15)
end⟵i(16)
NewSegment⟵True(17)
DetectSegment⟵True(18)
else(19)
NewSegment⟵False(20)
DetectSegment⟵False(21)
ifDetectSegmentthen(22)
currentSegment⟵wstart…wend(23)
addcurrentSegment to S(24)
DetectSegment⟵False(25)
NewSegment⟵True(26)
returnSAs mentioned, a stickiness criterion is required in segmentation. As a result, a fitness function must be defined to determine the optimal value. The following section describes this function in detail.


### 3.1.2. Fitness Function

In the previous section, the process of creating gray wolf vectors and their values were described. This section describes how to calculate fitness function.In this step, a criterion that determines the amount of stickiness between the words is used to assess the optimal segmentation. The high amount of stickiness means that the cut-off point between two words should not be equal to 1 because it separates the correct expression. Thus, for each postpϵPi, the goal is to divide p into m optimal segment p=s1,s2,…,sm. Therefore, the following fitness function is used to obtain an optimal state:(1)Fp=max∑i=1mCsi.ewikisi.lsi.This equation consists of three parameters.C is a function that measures the stickiness of the words, ewikis calculates the Wikipedia score, and ls normalizes the length of the segments. In the rest of this section, each parameter will be described in more detail.As stated in [19], two stickiness functions point mutual information (PMI) and symmetric conditional probability(SCP) are used to calculate C.(1). PMI-Based Stickiness. PMI measures the probability of two words occurring together more often than by chance. PMI for bigram w1w2 is defined as follows:(2)PMIw1w2=logPrw1|w2Prw1=logPrw1w2Prw1Prw2.For a segmentss=w1…wn, PMI is extended by averaging all binary partitions as follows:(3)PMIs=logPrs1/n−1∑i=1n−1Prw1…wiPrwi+1…wn,where Prs represents the N-Gram probability of the s segment. If the segment has only one word, we have PMIs=logPrw. Finally, in order to map PMI in the range (0, 1), the stickiness of segment s is as follows:(4)Cs=11+e−PMIs.(2). SCP-Based Stickiness. SCP measures the cohesiveness of bigram w1w2 by considering both conditional probabilities for the bigram as follows:(5)SCPw1w2=Prw1w2|w1Prw1w2|w2=logPrw1w22Prw1Prw2.For a segment withn words, SCP is as follows:(6)SCPs=Prs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.To smooth SCP value logarithm calculation is used as follows:(7)SCPs=logPrs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.Similarly, for a single word segment, we haveSCPs=2logPrw. Eventually, the sigmoid function is applied as follows:(8)Cs=21+e−SCPs.According to and equations (3) and (7), a big corpus is necessary to calculate Prs more accurately. In this paper, Hamshahri corpus and Telegram data have been used to calculate N-Gram.ObtainedPrs from Hamshahri corpus and Telegram data is only based on frequent patterns. Therefore, another parameter is required that increases the probability of partitioning a post into segments which are named entities. To do this, Wikipedia has been used in a global context. Generally, in Wikipedia, links title are named entities, and with the emergence of new named entities, a web page in Wikipedia is dedicated to them, from which a large dictionary is produced. This dictionary can be used in segmentation. Hence, if Wikis be the probability of occurring segment s in Wikipedia links title, the stickiness function will be as follows:(9)C′s=Cs.ewikis,(10)wikis=N_anchorsN_totals,where N_anchors is the occurrence number of segment s in Wikipedia links, and N_totals indicates the total occurrence number of segment s.So far, segments of different lengths have been treated the same. However, observations show that segments with longer lengths are more likely to be named entities. Therefore, the length of the segments must be normalized. To do this,ls is added to equation (9).(11)C′s=Cs.ewikis.ls,where ls is defined as follows:(12)fx=s−1s,ifs>1,13,ifs=1.On the other hand, since, in most cases, the length of named entities does not exceed some amount, a threshold valueu should be considered for the maximum number of words for each segment, which in this paper is 5. If the number of words exceeds this threshold, the fitness function will get a penalty which is 15 in this paper. Thus, the optimization algorithm eliminates vectors that have segments of more than 5 words. In fact, it prevents the existence of more than 4 zeroes consecutively. Algorithm 2 shows this process where it gets extracted segments from Algorithm 1 as input and calculates fitness.Algorithm 2: Fitness calculation.
input:S: set of segments for a postextracted from GWVu: The maximum length of a segmentpenalty: penalty for the segments with more than u wordsoutput: Fitness for each vector(1)
fitness⟵0(2)
foreachsegment inSdo(3)
iflen(segment) > uthen(4)
fitness⟵fitness−penalty(5)
else(6)
segmentFitness ⟵ calculate fitness for the segment using equation (1)(7)
fitness⟵fitness+segmentFitness(8)
return fitnessAlso, to increase the speed of the system, when more than two −1 occur in a row (boundaries of stop words, punctuations, and emojis), the cells in between are not included in the fitness function because they add a constant value to fitness function and do not affect the result.


## 3.1.1. GWO in Segmentation

As mentioned in Section3.1, search space size exceeds exponentially. Hence, because of the huge search space, attribute reduction is a challenging task. Various search techniques have been employed to solve the attribute reduction problem, for instance, greedy search based on sequential forward selection and sequential backward selection. Nonetheless, these approaches suffer from different issues, such as increasing computational cost and stagnation in local optima [24]. Metaheuristic optimization algorithms have become more popular in various applications due to their simplicity in implementation, not requiring gradient information and bypassing local optima [25]. Metaheuristics are fundamentally based on trajectory such as simulated annealing (SA) or based on population, such as genetic algorithm (GA), ant colony algorithm (ACO), particle swarm optimization (PSO), and GWO [26].GWO is a recently developed algorithm introduced by Mirjalili et al., which mimics the leadership hierarchy (alpha, beta, omega, and delta) and haunting mechanism of gray wolfs. In this algorithm, alpha is considered the best solution. Beta and omega are, respectively, the second and third-best solutions. For more information about GWO, please refer to [22]. This algorithm is based on swarm intelligence (SI). SI algorithms have fewer parameters and are easy to implement, and GWO is one of the rapidly progressing SI algorithms drawing researchers’ attention [26].This section describes how to use the GWO to segment posts. As mentioned, GWO is based on SI, which processes the solution of the problem in vector form. In this paper, each solution is called a gray wolf vector. The segmentation problem is defined as a binary problem; nevertheless, GWO is not able to produce binary vectors. Consequently, the values of this algorithm need to be in binary form. In order to do this, the method described in [23] has been utilized in which two approaches are proposed. This article uses the second approach. In this approach, only the updated values of the gray wolf vector are converted to binary values. To be more specific, if the sigmoid value of the gray wolf vector exceeds the threshold (the threshold is generated randomly), it returns 1, and otherwise 0.To start optimization, the dimension of gray wolf vectors must be determined. If a post hasn words, then the dimension of the gray wolf vector will be n−1. Because to segment, each post, between each word can be considered as a segmentation boundary. Segment boundary is the boundary of a word or some selected words as a segment in the segmentation phase. For instance, in the post “Urgent: Ayatollah Hashemi Rafsanjani was hospitalized.” the dimension of gray wolf vectors is equal to 7.Each gray wolf vector can be generated by three values (0, 1, and −1). A value of 0 means that this point is not considered as a segmentation boundary (pink cells in Figure3), and values 1 and −1 indicate the segmentation boundary (green and blue cells in Figure 3). The difference between 1 and −1 is that −1 has been used for definite segmentation boundaries, so for each post, it remains constant in the process of optimization. Definite segmentation boundaries are stop words, punctuations, and emojis, which are not used as named entity or part of named entity in the Persian language. The points that are before and after these tokens are marked with −1 in the gray wolf vector (green cells in Figure 3). These points, to some extent, prevent the overproduction of segments that are not named entities. Therefore, it will reduce the number of states. According to this explanation, our goal is to find the optimum value for nondefinite boundaries. Algorithm 1 outlines the segment extraction algorithm.Figure 3
An example of a gray wolf vector. The pink cells with the value of 0 are not segmentation boundaries, the value of 1 in the blue cells indicates segmentation boundaries, and the green cells are definite segmentation boundaries for stop words, punctuations, and emojis.Algorithm 1: Segment extraction.
input:p: A Telegram post p=w1w2…wnwherewi is a word in the postGWV: gray wolf vectoroutput:S: set of segments for a post extracted from GWV(1)
NewSegment⟵True(2)
DetectSegment⟵False(3)
S⟵(4)
fori = 1:len(GWV) do(5)
ifGWV[i] ! = −1 then(6)
ifNewSegmentorGWV[i − 1] = = −1 then(7)
start⟵i(8)
NewSegment⟵False(9)
ifGWV[i] = = 1 ori = = len(GWV) then(10)
end⟵i(11)
NewSegment⟵True(12)
DetectSegment⟵True(13)
else ifGWV[i + 1] = = −1 then(14)
i⟵i+1(15)
end⟵i(16)
NewSegment⟵True(17)
DetectSegment⟵True(18)
else(19)
NewSegment⟵False(20)
DetectSegment⟵False(21)
ifDetectSegmentthen(22)
currentSegment⟵wstart…wend(23)
addcurrentSegment to S(24)
DetectSegment⟵False(25)
NewSegment⟵True(26)
returnSAs mentioned, a stickiness criterion is required in segmentation. As a result, a fitness function must be defined to determine the optimal value. The following section describes this function in detail.


## 3.1.2. Fitness Function

In the previous section, the process of creating gray wolf vectors and their values were described. This section describes how to calculate fitness function.In this step, a criterion that determines the amount of stickiness between the words is used to assess the optimal segmentation. The high amount of stickiness means that the cut-off point between two words should not be equal to 1 because it separates the correct expression. Thus, for each postpϵPi, the goal is to divide p into m optimal segment p=s1,s2,…,sm. Therefore, the following fitness function is used to obtain an optimal state:(1)Fp=max∑i=1mCsi.ewikisi.lsi.This equation consists of three parameters.C is a function that measures the stickiness of the words, ewikis calculates the Wikipedia score, and ls normalizes the length of the segments. In the rest of this section, each parameter will be described in more detail.As stated in [19], two stickiness functions point mutual information (PMI) and symmetric conditional probability(SCP) are used to calculate C.(1). PMI-Based Stickiness. PMI measures the probability of two words occurring together more often than by chance. PMI for bigram w1w2 is defined as follows:(2)PMIw1w2=logPrw1|w2Prw1=logPrw1w2Prw1Prw2.For a segmentss=w1…wn, PMI is extended by averaging all binary partitions as follows:(3)PMIs=logPrs1/n−1∑i=1n−1Prw1…wiPrwi+1…wn,where Prs represents the N-Gram probability of the s segment. If the segment has only one word, we have PMIs=logPrw. Finally, in order to map PMI in the range (0, 1), the stickiness of segment s is as follows:(4)Cs=11+e−PMIs.(2). SCP-Based Stickiness. SCP measures the cohesiveness of bigram w1w2 by considering both conditional probabilities for the bigram as follows:(5)SCPw1w2=Prw1w2|w1Prw1w2|w2=logPrw1w22Prw1Prw2.For a segment withn words, SCP is as follows:(6)SCPs=Prs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.To smooth SCP value logarithm calculation is used as follows:(7)SCPs=logPrs21/n−1∑i=1n−1Prw1…wiPrwi+1…wn.Similarly, for a single word segment, we haveSCPs=2logPrw. Eventually, the sigmoid function is applied as follows:(8)Cs=21+e−SCPs.According to and equations (3) and (7), a big corpus is necessary to calculate Prs more accurately. In this paper, Hamshahri corpus and Telegram data have been used to calculate N-Gram.ObtainedPrs from Hamshahri corpus and Telegram data is only based on frequent patterns. Therefore, another parameter is required that increases the probability of partitioning a post into segments which are named entities. To do this, Wikipedia has been used in a global context. Generally, in Wikipedia, links title are named entities, and with the emergence of new named entities, a web page in Wikipedia is dedicated to them, from which a large dictionary is produced. This dictionary can be used in segmentation. Hence, if Wikis be the probability of occurring segment s in Wikipedia links title, the stickiness function will be as follows:(9)C′s=Cs.ewikis,(10)wikis=N_anchorsN_totals,where N_anchors is the occurrence number of segment s in Wikipedia links, and N_totals indicates the total occurrence number of segment s.So far, segments of different lengths have been treated the same. However, observations show that segments with longer lengths are more likely to be named entities. Therefore, the length of the segments must be normalized. To do this,ls is added to equation (9).(11)C′s=Cs.ewikis.ls,where ls is defined as follows:(12)fx=s−1s,ifs>1,13,ifs=1.On the other hand, since, in most cases, the length of named entities does not exceed some amount, a threshold valueu should be considered for the maximum number of words for each segment, which in this paper is 5. If the number of words exceeds this threshold, the fitness function will get a penalty which is 15 in this paper. Thus, the optimization algorithm eliminates vectors that have segments of more than 5 words. In fact, it prevents the existence of more than 4 zeroes consecutively. Algorithm 2 shows this process where it gets extracted segments from Algorithm 1 as input and calculates fitness.Algorithm 2: Fitness calculation.
input:S: set of segments for a postextracted from GWVu: The maximum length of a segmentpenalty: penalty for the segments with more than u wordsoutput: Fitness for each vector(1)
fitness⟵0(2)
foreachsegment inSdo(3)
iflen(segment) > uthen(4)
fitness⟵fitness−penalty(5)
else(6)
segmentFitness ⟵ calculate fitness for the segment using equation (1)(7)
fitness⟵fitness+segmentFitness(8)
return fitnessAlso, to increase the speed of the system, when more than two −1 occur in a row (boundaries of stop words, punctuations, and emojis), the cells in between are not included in the fitness function because they add a constant value to fitness function and do not affect the result.


## 3.2. Named Entity Extraction

At this stage, after the segmentation was performed, the segments are scored to identify named entities because not all the segments obtained from the previous stage are named entities. At first, before scoring the segments, those segments that are stop words, punctuations, hashtags, and emojis have been removed. Furthermore, some of the conversational words and abbreviations also have been removed from the segments.In Telegram posts, named entities related to a specific topic will likely occur together. For example, “Trump” and “America” are more likely to happen together, while “Trump” and “message of condolence” are less likely to happen together. Consequently, this local context is used to form a graph of segments, in which the nodes are the segments extracted from a set of telegram posts, and the Jaccard criterion obtains the weight of its edges. Ifeab is the edge passing through sa to sb, then we will have the following:(13)weab=Msa∩MsbMsa∪Msb.Ms is the set of posts in Pi that contains segment s. In this way, local context is obtained, which is based on the connection between segments.Then, the random walk model is applied to the graph. Assuming that the graph is bidirectional, the probability of transiting from nodea to node b is as follows:(14)Pab=weab∑cϵVweab.In this section, the title of Wikipedia links is used as local context. Therefore, the transition ofes for segment s is defined as follows:(15)es=wiki′s∑sjϵVwiki′sj,wherewiki′s=ewikis.Then, the stationary eigenvectorπT of P is calculated iteratively as follows:(16)π=γPT+1−γe1Tπ,where γ controls the probability of teleportation, finally, to create a balance between local and global context, equation (17) has been used.(17)ys=es.πs.Equation (17) is used to score segments, and finally, top k segments are selected as named entities.


## 4. Evaluation

To evaluate the performance of our proposed system, we have used the NER evaluation method introduced in [27]. This method measures precision, recall, and F1score based on Message Understanding Conference (MUC) [28] metrics. These metrics, which consider different categories of errors, are listed as follows:(i)
Correct (COR). The output of the system and gold-standard are the same.(ii)
Incorrect (INC). The output of the system and gold-standard do not match.(iii)
Partial (PAR). The system output and gold-standard are somewhat similar but not the same.(iv)
Missing (Mis). A gold-standard is not captured by the system.(v)
Spurious (SPU). The output of the system does not exist in gold-standard.Precision is the percentage of correct named entities extracted by the NER system, and recall shows the percentage of gold-standard named entities that are found by the system. In order to compute precision, recall, andF1score, two different scenarios can be used.(vi)
Exact Match. The exact match is stricter and considers partial matches as (INC).(vii)
Partial Match. This match considers partial matches as (PAR) and is less strict.For calculating precision and recall, two quantities need to be defined. (1) Possible (POS), which is the number of gold-standard annotations contributing to the final score, and (2) actual (ACT), which is the number of NER system annotations. These two quantities are calculated as follows:(18)POS=COR+INC+PAR+MIS=TP+FN,ACT=COR+INC+PAR+SPU=TP+FP.The exact match is computed as follows:(19)Precision=CORACT=TPTP+FP,Recall=CORPOS=TPTP+FN.For the partial match, precision and recall would be as follows:(20)Precision=COR+0.5×PARACT=TPTP+FP,Recall=COR+0.5×PARPOS=TPTP+FN.Finally, theF1score, which is the harmonic mean of precision and recall, can be calculated as follows:(21)F1=2×Prcision×RecallPrecision+Recall.


### 4.1. Dataset

Since the proposed method is for texts extracted from social media, the golden standards corpus must be created from such texts.Sep_TD_Tel01 dataset [29] includes 10285 Telegram posts of public groups and channels collected from January 5, 2017, to July 20, 2017. This dataset has 720 windows in which every 12 hours is considered as a single window and have been utilized in [30]. Considering the volume of unusable information being shared on social media and labeling manually taking much time and effort, 300 posts of this dataset related to two topics were collected to create gold-standard for evaluating our system. We asked three people who are familiar with NER to label these posts based on IOB (inside, outside, and beginning) format in three versions.In addition, to implement the proposed method, calculating theN-gram and probability of Wikipedia for every segment is needed. For the same reason, a database is created containing tables storing 1-gram through 5-grams [31], and another table for link texts of Wikipedia [32] which is available in ComInSys Lab.As mentioned in Section3 the Hamshahri corpus and Telegram posts have been used to develop N-Gram. To start the process, after eliminating stop words and normalization, the number of words is counted. Then, N-grams, up to 5-grams, are calculated and stored in the corresponding tables in the SQL database. The available Telegram corpus is not broad enough to generate reliable N-grams, but it can resolve the problem of the Hamshahri corpus that is outdated. It has taken five days to execute the process on a computer. Table 1 shows the total number of N-Gram extracted from these two corpora for N = 1, 2, 3, 4, 5.Table 1
The number ofN-Gram extracted from Hamshahri and Telegram from N = 1 up to N = 5.
N-GramNumber ofN-Gram1-Gram99,603,3962-Gram94,305,7223-Gram89,158,2464-Gram84,110,9885-Gram79,176,683To fill the table of Wikipedia link texts, the corpus of Persian Wikipedia, until May 24, 2020, including more than 3 million articles is used. Processing this corpus has two steps. In the first step, every link is detected and the body of each, after removing the stop words and normalization, is stored in the database. Then, document frequency (DF) and term frequency (TF) is calculated. In the second step, the occurrence of every text extracted from the previous step (either a link or a mere text) is counted. In the end, 3,177,923 link texts has been extracted from the mentioned corpus. The first step has taken 30 days by a single computer. In the second step, 6 computers have executed the process part-by-part parallelly which has taken a total time of 60 days.


### 4.2. Preprocessing

Before collecting posts for creating gold-standard, we preprocessed the dataset to remove some posts that are not suitable for our use. These posts are the posts that are only a link or are repeated more than once. Duplicate posts were removed using edit distance criteria. Then, the posts were tokenized, and their token types, including stop words, punctuations, and emojis and were saved for further use.


### 4.3. Parameter Setting

Our proposed method includes five parameters that need to be adjusted. These parameters can be divided into two categories: 1-TwiNER parameters and 2-GWO parameters. TwiNER parameters are theK value, Y value, and stickiness function (PMI and SCP). GWO parameters are the number of wolves (NW) and the number of iteration (NI).In the first step, we adjust TwiNER parameters. Figure4 shows the results of the proposed system for these parameters. In these results, GWO parameters are considered to be fixed (NW=50 and NI=200) and the obtained F1 amounts are the average of 10 runs of the system. As we can see, our system has a better performance for 60<K<80 in PMI, 60<k<100 in SCP, and γ=0 or γ=0.3. Getting more detailed information determines that overall PMI functions better than SCP. Furthermore, γ=0.3 has the better result except for SCP in the partial match. Also, the results are preferable when k is around 70 except for the SCP exact match which is around 95. In the rest of the paper, we will set the TwiNER parameter to PMI, γ=0.3 and k=70.Figure 4
Results of proposed system for different values ofK and Y. (a) The results of the partial match for PMI-based stickiness, (b) the results of an exact match with PMI stickiness function, (c) using partial match for the results of SCP-based stickiness, and (d) exact match results for SCP-based stickiness.
(a)(b)(c)(d)In the second step, the parameters of GWO need adjustment. Figure5 indicates the result of the exact F1 (average of 10 runs) for different NW and NI, respectively. In order to tun NW, TwiNER parameters are fixed to PMI, K=70, γ=0.3, and NI is set to be 200. As shown in Figure 5(a), NW=20 has the best output. Similarly, for tunning NI, NW is considered 20 with the same TwiNER parameters, the best output is for NI=200.Figure 5
The result of the exactF1 for (a) different NW and (b) NI.
(a)(b)


### 4.4. Comparison with Other Methods

In this section, we compare our proposed method with three other NER systems. The first system is TwiNER [19] which our proposed method is based on it, the second system is a hybrid method for Persian NER [20], and the third one is based on monolingual BERT for the Persian language (ParsBERT) [16]. For a fair comparison with our proposed method, our dataset has been used in these systems. Moreover, we have employed modified TwiNER for Persian data that utilizes the Hamshahri corpus and Telegram posts since TwiNER is suggested for English tweets.Before comparing our system with other methods, we compare our 3 gold-standards. The outcome shows that even human opinion can differ in recognizing named entities. The results of comparing these gold-standards are shown in Table2. As indicated in this table, the average amount for F1 in all the partial matches is 0.5828, which is far from 1 (the highest possible amount). Therefore, we should not expect the system to have a high amount of precision and recall.Table 2
Comparing three gold-standards (GS 1, GS 2, and GS 3) with each other.
Gold-standardGS1GS2GS3GS-averageCompared withGS2GS3GS1GS3GS1GS2PartialPrecision0.5840.4500.7350.5410.6300.6330.595Recall0.7030.6050.5950.6210.4420.5440.585F10.6380.5160.6580.5780.5190.5850.582ExactPrecision0.4810.3200.6700.4180.5330.5300.492Recall0.5790.4300.5430.4800.3730.4550.477F10.5250.3670.60.4470.4390.4890.478The bold values show the highest and lowest results.Table3 shows the result of all these systems in terms of precision (Pr), recall (Re), and F1 for both partial (Par) and exact (Exc) match using GS2 as gold-standard. We take two stickiness functions PMI and SCP into consideration in our comparison and as can be seen in Figure 6 our method outperform in both stickiness functions. Also, the results of our method are significantly better than hybrid Persian NER and superior to ParsBERT.Table 3
Comparison of our proposed method (GWO + PMI and GWO + SCP) with other methods.
MethodParPrParReParF1ExcPrExcReExcF1GWO + PMI0.52730.41930.46710.43690.34740.387GWO + SCP0.48270.42930.45440.38370.34130.3612TwiNER + PMI [19]0.45950.37250.41150.33450.27120.2995TwiNER + SCP [19]0.45200.38790.41750.32890.28220.3038ParsBERT [16]0.540.3670.4370.4270.290.345Hybrid Persian NER [20]0.39510.22370.28570.20960.11870.1516The bold values show the best results.Figure 6
The result of partial and exactF1 for our proposed system (GWO + PMI and GWO + SCP) and other methods.Based on the experiment conducted above, we see that our method shows promising performance in both stickiness functions by incorporating an optimization algorithm. However, in overall PMI outperformance SCP in our method, comparing our method with the average results of gold-standard also shows that our system is closer to human opinion results.


## 4.1. Dataset

Since the proposed method is for texts extracted from social media, the golden standards corpus must be created from such texts.Sep_TD_Tel01 dataset [29] includes 10285 Telegram posts of public groups and channels collected from January 5, 2017, to July 20, 2017. This dataset has 720 windows in which every 12 hours is considered as a single window and have been utilized in [30]. Considering the volume of unusable information being shared on social media and labeling manually taking much time and effort, 300 posts of this dataset related to two topics were collected to create gold-standard for evaluating our system. We asked three people who are familiar with NER to label these posts based on IOB (inside, outside, and beginning) format in three versions.In addition, to implement the proposed method, calculating theN-gram and probability of Wikipedia for every segment is needed. For the same reason, a database is created containing tables storing 1-gram through 5-grams [31], and another table for link texts of Wikipedia [32] which is available in ComInSys Lab.As mentioned in Section3 the Hamshahri corpus and Telegram posts have been used to develop N-Gram. To start the process, after eliminating stop words and normalization, the number of words is counted. Then, N-grams, up to 5-grams, are calculated and stored in the corresponding tables in the SQL database. The available Telegram corpus is not broad enough to generate reliable N-grams, but it can resolve the problem of the Hamshahri corpus that is outdated. It has taken five days to execute the process on a computer. Table 1 shows the total number of N-Gram extracted from these two corpora for N = 1, 2, 3, 4, 5.Table 1
The number ofN-Gram extracted from Hamshahri and Telegram from N = 1 up to N = 5.
N-GramNumber ofN-Gram1-Gram99,603,3962-Gram94,305,7223-Gram89,158,2464-Gram84,110,9885-Gram79,176,683To fill the table of Wikipedia link texts, the corpus of Persian Wikipedia, until May 24, 2020, including more than 3 million articles is used. Processing this corpus has two steps. In the first step, every link is detected and the body of each, after removing the stop words and normalization, is stored in the database. Then, document frequency (DF) and term frequency (TF) is calculated. In the second step, the occurrence of every text extracted from the previous step (either a link or a mere text) is counted. In the end, 3,177,923 link texts has been extracted from the mentioned corpus. The first step has taken 30 days by a single computer. In the second step, 6 computers have executed the process part-by-part parallelly which has taken a total time of 60 days.


## 4.2. Preprocessing

Before collecting posts for creating gold-standard, we preprocessed the dataset to remove some posts that are not suitable for our use. These posts are the posts that are only a link or are repeated more than once. Duplicate posts were removed using edit distance criteria. Then, the posts were tokenized, and their token types, including stop words, punctuations, and emojis and were saved for further use.


## 4.3. Parameter Setting

Our proposed method includes five parameters that need to be adjusted. These parameters can be divided into two categories: 1-TwiNER parameters and 2-GWO parameters. TwiNER parameters are theK value, Y value, and stickiness function (PMI and SCP). GWO parameters are the number of wolves (NW) and the number of iteration (NI).In the first step, we adjust TwiNER parameters. Figure4 shows the results of the proposed system for these parameters. In these results, GWO parameters are considered to be fixed (NW=50 and NI=200) and the obtained F1 amounts are the average of 10 runs of the system. As we can see, our system has a better performance for 60<K<80 in PMI, 60<k<100 in SCP, and γ=0 or γ=0.3. Getting more detailed information determines that overall PMI functions better than SCP. Furthermore, γ=0.3 has the better result except for SCP in the partial match. Also, the results are preferable when k is around 70 except for the SCP exact match which is around 95. In the rest of the paper, we will set the TwiNER parameter to PMI, γ=0.3 and k=70.Figure 4
Results of proposed system for different values ofK and Y. (a) The results of the partial match for PMI-based stickiness, (b) the results of an exact match with PMI stickiness function, (c) using partial match for the results of SCP-based stickiness, and (d) exact match results for SCP-based stickiness.
(a)(b)(c)(d)In the second step, the parameters of GWO need adjustment. Figure5 indicates the result of the exact F1 (average of 10 runs) for different NW and NI, respectively. In order to tun NW, TwiNER parameters are fixed to PMI, K=70, γ=0.3, and NI is set to be 200. As shown in Figure 5(a), NW=20 has the best output. Similarly, for tunning NI, NW is considered 20 with the same TwiNER parameters, the best output is for NI=200.Figure 5
The result of the exactF1 for (a) different NW and (b) NI.
(a)(b)


## 4.4. Comparison with Other Methods

In this section, we compare our proposed method with three other NER systems. The first system is TwiNER [19] which our proposed method is based on it, the second system is a hybrid method for Persian NER [20], and the third one is based on monolingual BERT for the Persian language (ParsBERT) [16]. For a fair comparison with our proposed method, our dataset has been used in these systems. Moreover, we have employed modified TwiNER for Persian data that utilizes the Hamshahri corpus and Telegram posts since TwiNER is suggested for English tweets.Before comparing our system with other methods, we compare our 3 gold-standards. The outcome shows that even human opinion can differ in recognizing named entities. The results of comparing these gold-standards are shown in Table2. As indicated in this table, the average amount for F1 in all the partial matches is 0.5828, which is far from 1 (the highest possible amount). Therefore, we should not expect the system to have a high amount of precision and recall.Table 2
Comparing three gold-standards (GS 1, GS 2, and GS 3) with each other.
Gold-standardGS1GS2GS3GS-averageCompared withGS2GS3GS1GS3GS1GS2PartialPrecision0.5840.4500.7350.5410.6300.6330.595Recall0.7030.6050.5950.6210.4420.5440.585F10.6380.5160.6580.5780.5190.5850.582ExactPrecision0.4810.3200.6700.4180.5330.5300.492Recall0.5790.4300.5430.4800.3730.4550.477F10.5250.3670.60.4470.4390.4890.478The bold values show the highest and lowest results.Table3 shows the result of all these systems in terms of precision (Pr), recall (Re), and F1 for both partial (Par) and exact (Exc) match using GS2 as gold-standard. We take two stickiness functions PMI and SCP into consideration in our comparison and as can be seen in Figure 6 our method outperform in both stickiness functions. Also, the results of our method are significantly better than hybrid Persian NER and superior to ParsBERT.Table 3
Comparison of our proposed method (GWO + PMI and GWO + SCP) with other methods.
MethodParPrParReParF1ExcPrExcReExcF1GWO + PMI0.52730.41930.46710.43690.34740.387GWO + SCP0.48270.42930.45440.38370.34130.3612TwiNER + PMI [19]0.45950.37250.41150.33450.27120.2995TwiNER + SCP [19]0.45200.38790.41750.32890.28220.3038ParsBERT [16]0.540.3670.4370.4270.290.345Hybrid Persian NER [20]0.39510.22370.28570.20960.11870.1516The bold values show the best results.Figure 6
The result of partial and exactF1 for our proposed system (GWO + PMI and GWO + SCP) and other methods.Based on the experiment conducted above, we see that our method shows promising performance in both stickiness functions by incorporating an optimization algorithm. However, in overall PMI outperformance SCP in our method, comparing our method with the average results of gold-standard also shows that our system is closer to human opinion results.


## 5. Conclusion

In this paper, we have proposed a statistical-based approach for Persian NER in which a binary GWO algorithm has been used. This system partition posts into segments of possible named entities. However, the number of segmentation states grows exponentially with respect to the length of the post. Therefore, to find the optimal segmentation, binary GWO has been employed. The fitness function for this problem is based on three criteria: (1) stickiness, (2) Wikipedia score, and (3) segment length. We have used the Hamshahri corpus and Telegram dataset to createN-Gram for calculating stickiness. Then, we score these segments with the random walk model to recognize true named entities among the segments. Additionally, to evaluate our method, the gold standard has been generated for Telegram posts by 3 individuals. The average partial F1 measure for these gold standards is 0.582 so even human opinion differs in NER. Therefore, we cannot expect NER systems to have a high amount in the F1 measure. Comparing our method with other methods with the same dataset shows that our proposed method outperforms these systems.



---

*Source: 6368709-2022-12-10.xml*