Chapter 1 Introduction
Metaphor detection is a specific area of research in Natural Language Processing (NLP) that aims to automatically identify and interpret figurative language. Metaphorical expression is not direct communication; thus, the lexical meaning does not directly represent the idea, but rather, semantic attributes from a source domain are mapped onto a target domain. At the root of this process is the recognition of semantic incongruity or tension; that is, the usual meaning of a word is in conflict with the situation in which it is used. The first goal of the optimisation of algorithms in this area is to improve the computational model that identifies these tensions and thus enhance the accuracy and coverage of the classification system. It is to distinguish between figurative and literal uses, and also to understand the cognitive processes that enable such mappings.
Generally speaking, the steps for applying optimised metaphor detection are data preparation and corpus selection first. To train a good supervised learning model, we need high-quality annotated data, so first perform tokenization, part-of-speech tagging and word sense disambiguation on the input text. Feature engineering is used to obtain linguistic patterns from the data, such as semantic density, selectional preference violations and contextual embeddings. In the implementation stage, select a suitable algorithm architecture; it can be a traditional statistical model or a deep neural network, and then optimise the hyperparameters to improve performance. To reduce the error rate and avoid overfitting, some optimisation methods for gradient descent and regularisation are employed. Finally, the model is tested with the typical F1-score indicator to see if it can perform well on new data and thus be used for practical language analysis.
Optimised metaphor detection will have many more applications in technology and industry in the future. In the field of machine translation and cross-lingual communication, it is necessary to accurately identify metaphors in order to retain the original meaning of idioms and prevent confusion caused by mistranslation. Sentiment analysis and opinion mining systems can also be used to study the emotional connotations of metaphors; they are often more intense than those in plain language. By identifying the figures of speech in language, one can better understand the emotional expressions in social media posts, customer feedback and other forms of communication. Automated systems in educational technology can help students learn difficult figurative language in the process of language learning. Therefore, advancing the optimisation of algorithms for metaphor detection is not only a problem in research but also a necessary path to achieve human-level artificial intelligence and natural language understanding [1].
Chapter 2 Theoretical Foundations and State of the Art for Metaphor Detection
2.1 Conceptual delineation of computational metaphor detection
Computational metaphor detection is a specific area of Natural Language Processing that aims to automatically identify and classify non-literal language, which is a concept from one semantic domain being understood in terms of another. To set up a good technical foundation, the scope of this field needs to be clearly defined and distinguished from other related NLP tasks, such as general figurative language identification, Word Sense Disambiguation (WSD), and sarcasm detection. Figurative language identification is a general category that includes idioms, hyperboles, metonymy, etc., and computational metaphor detection specifically aims to find the systematic mapping between a source domain and a target domain as described in Conceptual Metaphor Theory. Although WSD determines the correct meaning of a word in a particular context, it is based on a list of literal senses; metaphor detection is about a lexical unit being used in a way that deviates from its usual meaning, and often needs to identify the emerging property of cross-domain mapping rather than selecting a predefined dictionary entry. It should also be noted that it is not the same as sarcasm detection; although both are based on pragmatic incongruity, sentiment polarity reversal and world knowledge, metaphor detection is about semantic anomalies and contextual compatibility.
Theoretically, the operating process of this task is based on the main ideas of conceptual metaphor theory and modern computational linguistics to create a general rule for identifying contextual metaphors. The formalisation should be able to handle both lexical-level metaphors, where individual words are used figuratively, and phrase-level metaphors, where the metaphorical meaning is derived from a group of words. The way to do it is to study the meaning of words in context and determine if there has been a violation of selectional restrictions; if so, then a metaphor is present. To build a sturdy system that can handle the various meanings in different places, it needs to be standardised.
To address the problem of inconsistent task framing in previous studies, it is necessary to standardise the task formulation. The formalism has specified the input constraints as raw, unstructured text in both general domains and low-resource domains where annotated data is lacking. At the same time, the expected outputs of the system are also clearly defined; that is to say, there will be explicit labels for metaphorical tokens, and a binary tagging scheme is often employed, such as '0' for literal and '1' for metaphorical use, along with corresponding classification confidence scores. To make the evaluation of the algorithm's performance more objective, a set of reasonable norms has been established to facilitate the comparison and improvement of detection models.
2.2 Review of existing metaphor detection algorithm frameworks and performance bottlenecks
The framework of the existing metaphor detection algorithm has been updated many times and is now a flexible deep-learning model. The first way was to build a language lexicon and rules manually. The system is based on the fact that metaphorical use often does not adhere to the selectional restrictions of literality, so it can be matched with a knowledge base to find abnormalities. Although it works well for highly conventional metaphors, the operating procedure is restricted to the scope of the lexicon and is thus fragile and cannot handle new language patterns. Therefore, traditional machine learning models such as Support Vector Machines and Conditional Random Fields had to be used. Hand-engineered lexical and syntactic features were used in the framework to turn the detection problem into a statistical classification problem. Although they have increased the robustness of the model by learning from the statistics of the data, they are still limited by the quality of feature engineering and cannot capture deep semantic relationships.
The start of the Transformer model in deep learning was a change in the field. Self-attention is employed in the model to obtain a dense context vector that can capture the long-range dependency information. The path of implementation is to pre-train on a large corpus and then fine-tune with the annotated data of VUA and MET-Metaphor. Therefore, there is a new standard for accuracy; that is to say, these models can infer implicit meanings from context without explicit feature definitions. However, in spite of the above progress, a review of the published performance indicators shows that there are still some problems with the actual application. A serious problem is the lack of generalisation in the low-resource specialised domain. Models trained on general corpora are often too accustomed to the distributional characteristics of their training data and perform poorly on niche technical or creative texts that have not been sufficiently trained.
Additionally, the current frameworks are too much based on surface-level semantic cues. Therefore, the model may fail to grasp the metaphorical meaning that the author intends to convey and is close in meaning to the literal one. Another problem is that the computation speed is too slow. Transformers have a relatively complex structure and are thus not very fast; they cannot meet the low-latency requirements of real-time production. There is still the problem of inconsistent performance in identifying non-adjacent metaphor boundaries in long sentences. With the increase in sentence length, the model's capacity to focus on the relationship between distant source and target domains declines, and thus some detections are missed or incorrect. To solve these problems and promote the development of practical applications for the theory, we need to do more work.
2.3 Core optimization dimensions identified from prior empirical studies
Through analysis of more than 30 peer-reviewed empirical studies published from 2018 to 2024, three verified, high-impact core optimisation directions that can consistently improve the performance of metaphor detection systems have been identified. Firstly, to improve the accuracy of classification, fine-grained syntactic dependency features are combined with contextual semantic representations. Literal phrases in natural language are often structured similarly to metaphors and are therefore difficult for algorithms that only use semantic embeddings to distinguish. By adding grammatical relations and dependency arcs to the computational model, the system will be able to distinguish between genuine figurative language and literal language that is only syntactically similar. Thus, the context of the meaning is fixed in a particular syntactic structure, and therefore it will not be misled by superficial linguistic features.
Secondly, in order to solve the problem of performance decline in the low-resource area, transfer learning will be introduced. The traditional machine learning method usually needs a large amount of manually labelled special data to achieve high accuracy, and it is not practical for niche genres or specific languages. Transfer learning is to address the problem that there is a lack of annotated data in the target domain by using knowledge from a general, data-rich source domain. Therefore, it will reduce the data dependency of high-performance metaphor detection and make it feasible for many areas of specialised text without the high cost of extensive manual annotation.
Thirdly, the Design of Multi-task Joint Learning Objectives can improve the model's use of complementary signals from different but related sub-tasks. Specifically, by taking metaphor classification and metaphor boundary localisation as simultaneous optimisation objectives instead of separate ones, the system can utilise the inherent correlation between identifying a metaphor and determining its exact range. Therefore, the model will have a more comprehensive understanding of the text and the confidence of classification will be supported by the accuracy of boundary detection. Collectively, the three aspects of syntactic-semantic fusion, transfer learning for data efficiency and multi-task joint optimisation provide the explicit theoretical and empirical basis for all the subsequent algorithm optimisation designs in Chapter 3, and it can be guaranteed that the proposed methods are based on proven, high-impact strategies.
Chapter 3 Design and Empirical Validation of the Optimized Metaphor Detection Algorithm
3.1 Construction of the fused syntactic-semantic feature extraction module
3.1.1 Weighted feature gating mechanism for contextual metaphor marker recognition
A new method for weighting and gating has been added to adjust the amount of information from various feature sources dynamically and improve the accuracy of contextual metaphor marker recognition. Fundamentally, this module is based on the principle of selective attention; that is, its main purpose is to distinguish between linguistic structures that have important metaphorical meanings and those that are only syntactic frameworks. The input of the mechanism is a composite vector formed by concatenating the combined part-of-speech tags, dependency relation labels and high-dimensional contextual embeddings from the upstream pre-trained BERT model. Therefore, a formal gating unit with a sigmoid activation function is employed to process the input. This function returns a set of dynamic, learnable weights in the range [0, 1], and these weights are applied element-wise to the raw input features.
First, a linear transformation is performed on the concatenated feature vector to reduce the number of parameters by projecting it into a low-dimensional space. Then, the transformed vector is passed through a sigmoid activation layer to obtain the gating coefficients. The reason is that during training, the model can learn these coefficients; for tokens that are part of literal or standard collocations, the mechanism will assign a weight close to zero to reduce the influence of irrelevant syntactic features and background noise. Tokens with high metaphorical potential are given a weight close to 1 on the other hand, and thus the signal is strengthened. This process is very sensitive to unexpected verb-noun semantic collocations, and these are often metaphors. By highlighting the particular syntactic-semantic irregularities mentioned above, it can be ensured that the features provided to the downstream classification layer are highly discriminative and suitable for the task.
Linguistically speaking, this way is based on the idea that metaphoricity often shows up as a kind of tension or abnormality in the local syntactic-semantic environment. According to the above theory, a weighted feature gating mechanism is employed to adjust the weight of the feature vector dynamically based on the context; it is no longer a fixed bag of words. The Layer-wise specification of the module is a weight matrix that can be used for both the dimensionality of BERT embeddings and the dimensionality of syntactic tags, so it is compatible. The output of this layer is a filtered and task-optimised set of features that still has the contextual richness of BERT but is more structurally rigid due to the gated syntactic input. Therefore, it is a good representation and can better identify faint metaphorical signals in the complex structure of sentences.
3.1.2 Low-resource domain feature transfer learning branch
Due to the lack of large-scale annotated datasets in some areas, transfer learning for the low-resource domain feature branch has been employed to address the problem of metaphor detection in these specific fields. Transfer learning is employed in this module to make full use of the general knowledge contained in the pre-trained transformer model and adapt it to the particular linguistic characteristics of low-resource environments, such as medical texts, legal documents and poetry. The first kind of fine-tuning is instance-based, and only a small number of 500 manually labelled metaphor examples from the target domains need to be used. Most of the parameters in the base model are frozen, and only the upper layers are updated; thus, it can be adapted to the new domain without the high cost of full retraining. This way, the strong deep semantic representations obtained in pre-training can be retained, and the model will also be aware of the special metaphorical structure in this kind of text.
In order to ensure that the learned features are truly representative of metaphorical language and not merely superficial domain-specific characteristics, a domain adversarial component is added to the module. A domain adversarial loss function is used to define this mechanism formally, and it is a minimax game in the optimisation process. Let the feature extractor be denoted as Gf and the domain classifier as Gd. Given the input features xi, it is hoped that the domain classifier will be able to distinguish between data from the source domain (general) and the target domain (specialized), and at the same time, the feature extractor should not provide information that can be used for such discrimination. The formal mathematical expression of the domain adversarial loss Ld is to minimise the following objective function with respect to the feature extractor and maximise it with respect to the domain classifier:
Ld = - E(xi~Ds)[log Gd(Gf(xi))] - E(xj~Dt)[log(1 - Gd(Gf(x_j)))]
Ds is the distribution of the source domain and Dt is the distribution of the target domain in this formulation. To minimise the loss, the feature extractor will be forced to produce domain-invariant features that can fool the domain classifier. Therefore, the model has to focus on high-level, generalisable semantic features that can indicate metaphors and ignore the specific lexical patterns or formatting peculiarities of a particular domain. The actual application of this Design is that it can still have good detection performance for new, specialised texts and be used in many areas of professional and creative work without needing to be labelled manually.
3.2 Optimization of the dual-task multi-layer transformer detection architecture
3.2.1 Joint metaphor classification and boundary labeling objective function
The joint metaphor classification and boundary labelling objective function is used to optimise the dual-task multi-layer transformer architecture, and at the same time, it can identify whether there is metaphorical language and determine its exact position in the text. Therefore, the two kinds of loss in the formal mathematical derivation are a weighted cross-entropy loss for binary classification and a Conditional Random Field (CRF) loss for sequence labelling. The weighted cross-entropy component is at the token level, and it assigns a probability score to each token indicating whether it is a metaphor or not. We assign different weights to the classes to address the problem of data imbalance and prevent the model from being biased towards the more numerous literal class during training.
In addition to classification, the CRF loss term is also used to optimise the sequence dependence of tags and determine the start and end positions of metaphorical expressions. The first is to decide whether a token is part of a metaphor, and then a CRF layer is used to model the transition probabilities of label states and ensure structural consistency. Therefore, there will be no illogical tag sequences, such as a metaphor-ending token appearing right after a literal token without a starting token. To achieve the two goals of the joint function simultaneously, a dynamic hyperparameter is introduced to adjust the weight of the classification loss and the CRF loss. The balance coefficient should be set reasonably; otherwise, one of the tasks will be too prominent in the optimisation landscape and the gradient update will focus too much on boundary precision at the expense of classification accuracy, or vice versa.
In practice, the purpose of the joint goal is to take advantage of the correlation between the type of metaphor and the location of its boundaries. In the typical architecture, these tasks are often separated, so if there is a mistake in one stage, it will affect the results of the others. Optimize both at the same time, and then use the semantic information from the classification task to guide the boundary detection and vice versa. Therefore, there are fewer errors in general; in particular, it is no longer the case that only part of a multi-token metaphorical phrase is recognised. Together, the constraints will be regarded as a single semantic unit of the metaphor, and thus the detection system will be more stable and accurate in complex language.
3.2.2 Computational complexity pruning strategy for inference acceleration
To improve the dual-task multi-layer transformer detection architecture, we need to reduce the computational cost of deep learning models and maintain their representation power. To speed up the inference process, a targeted computational complexity pruning method is employed, and only the feed-forward network layers in the top three task-specific layers of the Transformer are considered. Based on the above observations, it can be seen that the upper layers of the task-specific layer have many redundant parameters, and the weights of these parameters are small in the final result. Structured Magnitude-Based Pruning is a method to determine how important a weight parameter is by using the L2 norm as an indicator of its contribution to the model's predictive ability. By a certain method, it is determined that the parameter with a small L2 norm is redundant and can be omitted. This threshold is not fixed; instead, based on the results of rigorous tests on a separate validation set, it is set dynamically to determine how much pruning should be done for the current data and task.
The path of realisation is to compute the L2 norm of each filter or neuron in the feed-forward network. Those that are below the calculated threshold will be permanently removed from the network structure, and therefore a smaller model with fewer computations is obtained. To verify that the above method works, we can also calculate the reduction in floating-point operations theoretically. Remove the multiplication-accumulation operation for the pruned weight to reduce the total number of FLOPs and speed up the processing. At the same time, a small number of active weight parameters need to be reduced to decrease the memory consumption of the model and run it more efficiently in hardware. First and foremost, the optimisation should not reduce the performance of the program. According to the experiment, the new method can still achieve more than 98% of the detection accuracy of the original model; thus, it is able to understand the meaning of metaphors correctly. Finally, compared with the unpruned full model, this pruning strategy has reduced inference latency by more than 45% and is thus a good way to deploy large-scale natural language processing models in resource-constrained or real-time environments.
3.3 Comparative performance experiment and result analysis
3.3.1 Dataset and evaluation metric configuration
To guarantee that the experiment for verifying the optimised metaphor detection algorithm is both rigorous and reproducible, the configuration of the dataset and evaluation indicators need to be standardised and precisely defined. The sources of the data used to test the generalisation ability of the algorithm in various language areas and the particular indicators of detection performance are presented in this section. The three different corpora in the experiment are used for different purposes in the verification process. First, the standard VUA metaphor corpus is used as a reference for general-domain English text and is thus a good basis for comparison with other excellent models. Secondly, the MES metaphor dataset is used to evaluate the performance of low-resource situations and specifically targets the medical field, which has a large number of special terms and lacks labelled data. Thirdly, an annotated legal metaphor corpus is used to test how well the model can handle complicated, structurally dense language and ensure that it has not been overfit to general or medical texts.
To improve the reliability of the empirical results, a reasonable division plan for all the data is employed. The data are divided into training, validation and test sets in an 8:1:1 stratified manner. A systematic way of doing this will keep the proportion of metaphorical and literal cases the same in all subsets and prevent data leakage or statistical bias. A fixed random seed is used in the partitioning stage to ensure that the process can be replicated exactly and other researchers will obtain the same results in their experiments.
In addition to the data configuration, there is a whole system of indicators that can grasp the finer points in metaphor identification. Precision, Recall and the F1-score are used for the main task of metaphor detection in the system. Precision shows how accurate the model is by calculating the proportion of correctly identified metaphors among all predicted metaphors, and Recall indicates how comprehensive the model is by showing what proportion of all actual metaphors in the dataset have been correctly identified. F1-score is the harmonic mean of the two and can be used as one index for comparison. In addition to binary classification, the Exact Match Ratio is also used for metaphor boundary labelling. This index is stricter than detection alone; that is to say, the predicted span of the metaphor must be exactly the same as the ground truth annotation, and it is required for applications that need precise semantic localisation. Finally, in order to determine if it can be applied in practice, we will calculate the average inference delay per sentence. This time index is based on the standard consumer-grade GPU hardware platform, and it can provide an actual reference for how fast the algorithm can run and ensure that the speed-up in performance is not due to an excessively long processing time.
3.3.2 Baseline model comparison and ablation test results
To verify the effectiveness of the optimised metaphor detection algorithm we have put forward rigorously, we conducted all sorts of experiments and compared it with six representative baseline models, including rule-based systems, traditional machine learning classifiers, and advanced Transformer-based architectures. The experimental process was to train these models on the same dataset of standard metaphor corpora and low-resource domain-specific texts to ensure a fair evaluation environment. The above steps will help set up a good performance reference to determine whether the optimisation measures we have put forward can actually improve the current situation. The first is to separate the algorithm's performance from the data's advantage, and then we will see that our Design is better at handling linguistic ambiguity in structure and operation.
According to the above statistics, the new model has achieved good results in all respects and is better than the old one. The old model and the standard transformer are not good at dealing with the small amount of data, but the new algorithm is still stable and has a high detection rate. The reason for this performance gap is that the model has new architecture, and some parts of it are not needed to address the problems of sparse data and complex semantics. To find the reasons for the above gains in more detail, an ablation study was carried out. One by one, remove the weighted feature gating mechanism, the low-resource transfer learning branch, the dual-task joint objective function and the complexity pruning strategy, and then determine how much each one contributes independently. Based on the above results, all parts are necessary; otherwise, there will be a relatively large decrease in precision due to the removal of the weighted feature gating mechanism, and thus it cannot filter out noise.
According to the above statistics, all the improvements in performance are statistically significant at the p<0.05 level, and thus can be considered to have been caused by the full model. Therefore, it can be concluded that the observed improvement is not due to randomness and is reproducible. Besides the number of errors, the types of errors were also analysed. Based on the above analysis, the optimisations we have put forward will address some of the problems in the baseline model, such as incorrectly classifying literal idioms as metaphors and failing to recognise new metaphors in low-resource areas. Due to the problems listed above, this algorithm will not be used in practice for Natural Language Processing; it is neither accurate nor efficient. Finally, all the above tests have shown that the optimised algorithm can be used to detect metaphors automatically in practice.
Chapter 4 Conclusion
In short, the research on algorithm optimisation for metaphor detection has shown some progress at the intersection of computational linguistics and artificial intelligence. At the most basic level, metaphor detection is the automatic recognition of figurative language, that is to say, a word or phrase that is used to refer to an object or action but is not literally applicable. The main idea of this paper is that the traditional statistical model cannot well address the profound semantic abnormalities and changes in context that occur in metaphorical expressions. Therefore, to optimise the algorithms, we need to go beyond simple pattern matching and carry out complex semantic analysis and context embedding.
According to the operating procedure in this paper, the pre-trained language model with attention mechanism is used for detection, and it has achieved good accuracy. Specifically, it is a path that takes raw text data, performs tokenisation and vectorisation, and then uses a deep neural network to assign different weights to various words based on their context. Adjust the hyperparameters and add a special loss function to reduce the number of false positives caused by literal polysemy, and then distinguish between ordinary ambiguity and real metaphorical use. A systematic way is used to turn the vague concept of language into a problem that can be computed and solved by data processing and model training.
To know what it is, we need to understand why we need to optimise it. In actual use, to improve the performance of natural language processing tasks such as sentiment analysis, machine translation and information retrieval, accurate metaphor detection is required. Without the ability to detect metaphors, the algorithm will often misjudge the mood or purpose of the text in a message and thus make a mistake in automated customer service or cross-cultural communication. For example, in the monitoring of social media, one needs to know how to recognise sarcasm and other emotional cues in the text. Therefore, the optimised algorithms obtained in this study can offer a more reliable way for machines to grasp the nuances and flexibility of human language that are usually only possessed by people. Finally, this work has put forward a normalisation and scaling plan to address the problem of shallow processing of literal text and the need for deep semantic understanding in advanced artificial intelligence.
References
\[1\]Nergui-Szllssy, Daniel. Object Classification as Key for Algorithmic Language Processing of Metonymy and Metaphor : A Sensory Language Retrieval Approach+[J]. 会议论文, 2019, 000(9086348).
\[2\]Nergui-Szollossy, Daniel. Object Classification as Key for Algorithmic Language Processing of Metonymy and Metaphor : A Sensory Language Retrieval Approach+[J]. IEEE, 2019.