An opinion topic identification method based on a large language model
Patent Information
- Application Number
- CN202611117767.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-27
- Publication Date
- 2026-10-30
AI Technical Summary
1.文本预处理的不足:BERTopic的默认配置中,用于主题关键词提取的CountVectorizer对社交媒体噪声鲁棒性较弱
1)显著提升了对复杂社交媒体舆情文本的预处理能力,有效降低了数据噪声对主题识别的干扰:本发明设计了轻量级与深度级两级文本预处理策略。轻量级预处理通过去除网络链接、特殊字符、表情符号转换及冗余文本过滤,为嵌入模型提供了干净的输入;深度级预处理通过构建包含目标领域术语(如城市火灾领域的“轰燃”、“破拆排烟”)和网络热词的自定义词典,结合OOV规则实现精准分词,并构建包含领域高频停用词同时保留“不、未、非、无”等否定功能词的混合停用词表,再经词性过滤剔除噪声。该策略相较于BERTopic默认的CountVectorizer,显著增强了对社交媒体噪声(空值、重复、特殊字符)的鲁棒性,解决了中文分词及领域词汇切分错误的问题,并避免了关键否定词的误删,从而为主题建模提供了高质量的词向量空间,从根本上提升了主题识别的准确性。
Smart Images

Figure CN123012635A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of public opinion recognition technology, and in particular to a method for identifying public opinion topics based on a Large Language Model (LLM). Background Technology
[0002] Urban fires, as typical public safety emergencies, are characterized by their suddenness, destructiveness, and wide-ranging impact, easily triggering social panic and fueling public opinion, resulting in complex online public sentiment. With social media becoming a core channel for public information dissemination and expression of demands, a large volume of urban fire commentary texts has emerged on various social media platforms. These social media texts are generally characterized by informality, colloquialism, fragmentation, short length, and high noise levels, containing hot topics of public concern and serving as crucial information for emergency response departments to formulate response strategies. Therefore, identifying hot topics from large-scale unstructured public opinion texts is both significant and challenging.
[0003] The core objective of topic modeling is to parse text in an unsupervised manner, mine latent topics from text datasets, and infer topic distributions. Topic modeling can analyze topics of public concern in social media texts, helping to identify key topics in online public opinion regarding urban fires. Early Latent Dirichlet Allocation (LDA) and Nonnegative Matrix Factorization (NFF) were pioneering topic models, representing documents as a mixture of latent topics using a Bag-of-Words (BoW) model. However, these traditional topic modeling techniques, represented by BoW models, ignore the semantic relationships between words, thus failing to accurately represent documents.
[0004] To address this issue, the Neural Topic Model (NTM) has emerged. This model achieves optimization by integrating neural components into its modeling framework. Compared to traditional topic modeling methods, it overcomes the limitation of ignoring semantic connections between words, offering significant advantages. Unlike traditional LDA, NTM learns richer latent representations of text through neural networks, thereby improving topic consistency and relevance.
[0005] By searching relevant literature and patents on text topic modeling methods and investigating some industry cases, the mainstream topic modeling method BERTopic still has the following shortcomings: 1. Insufficient Text Preprocessing: In BERTopic's default configuration, the CountVectorizer used for topic keyword extraction is not robust to social media noise. For example, social media texts contain a lot of sentiment data without actual content, including null values, duplicate data, or data consisting only of reposts of non-user-edited content, as well as web links, special characters, etc. If this content is not effectively cleaned, it will pollute the word vector space, resulting in a large number of meaningless keywords in the topics, which will affect the performance of subsequent topic modeling.
[0006] Furthermore, CountVectorizer uses English word segmentation logic by default and does not support Chinese word segmentation or Chinese character processing. If only a common stop word list is used without considering the specific application scenario of urban fires, it will be unable to effectively remove some high-frequency stop words that do not substantially help semantic understanding in specific domains, as well as retain important functional stop words (such as "not" and "not"), which will interfere with the topic modeling process.
[0007] Furthermore, when generating a keyword list in BERTopic, directly calling word segmentation tools such as THULAC, Jieba, and HanLP based on built-in basic dictionaries without considering professional terms in the field of urban fire (such as "flashover", "demolition and smoke extraction", "burned area"), as well as other OOV (Out-of-Vocabulary) words (such as internet slang / popular terms, user-created words / abbreviations / pinyin puns, compound words) can easily lead to errors in domain-specific word segmentation and failure to recognize OOV words.
[0008] 2. Limitations of Text Embedded Vector Representation: BERTopic defaults to using Sentence-BERT (S-BERT) as its embedded vector generation model, achieving text vectorization through pre-trained semantic encoding capabilities. However, the inherent architectural characteristics of S-BERT result in the following significant bottlenecks when processing complex social media text: (1) Input length limitation leads to semantic loss. The maximum input length of S-BERT is limited to 512 tokens, but social media texts often exhibit fragmented, colloquial and excessive length. The model will truncate the excess part, which may lead to the loss of key semantic information and affect the accuracy of topic modeling.
[0009] (2) Encoding dimensionality limits semantic expressive power. S-BERT outputs a hidden layer vector of 768 dimensions by default. Although this dimension is sufficient to capture basic semantic features, when dealing with complex semantic differences, the limited encoding dimension may be insufficient to fully express the subtle semantic differences in the text, affecting deep semantic understanding.
[0010] (3) Insufficient adaptability of architectural features. The pre-training corpus of S-BERT is mainly composed of normal text, which is not very robust when processing social media text containing a lot of noise. Its static coding paradigm is difficult to adapt to the dynamic, diverse and noisy characteristics of social media text, which limits its effective analysis capability in complex social media scenarios.
[0011] 3. Drawbacks of excessive and highly overlapping topics: Although BERTopic does not require a preset number of topics, as the internal HDBSCAN clustering algorithm automatically identifies topics, it is prone to having too many topics, and semantic overlap between topics. To fix the number of topics and improve topic interpretability, the problems of fragmented and highly overlapping topics in the initial clustering need to be addressed.
[0012] This invention addresses the shortcomings of existing mainstream topic modeling technology BERTopic in complex urban fire scenarios. It proposes a public opinion topic identification method based on a large language model to effectively identify hot topics in online public opinion related to urban fires, thereby providing comprehensive auxiliary information for emergency response decision-makers and assisting emergency management departments in effectively controlling public opinion. This invention mainly solves the following three types of problems: (1) Solve the problem that BERTopic’s topic recognition performance deteriorates in complex urban fire scenarios because text preprocessing cannot effectively remove data noise.
[0013] (2) Solve the problem that the default embedding vector representation of BERTopic is difficult to capture deep semantics.
[0014] (3) Solve the problem that the number of initial topics generated by BERTopic is too large, the semantic redundancy is high, and the fragmentation is obvious, making it difficult to meet the needs of downstream tasks. Summary of the Invention
[0015] The purpose of this invention is to overcome the shortcomings of the prior art and provide a public opinion topic identification method based on a large language model.
[0016] The objective of this invention is achieved through the following technical solution: a method for identifying public opinion topics based on a large language model, comprising the following steps: Text preprocessing stage: Lightweight and deep text preprocessing are performed on the public opinion text to be identified in order to remove data noise and standardize vocabulary. Embedding vector encoding stage: Select an LLM pre-trained on a social media text corpus and encode the preprocessed public opinion text into a high-dimensional embedding vector; Embedded vector dimensionality reduction stage: The high-dimensional embedded vector is reduced by uniform manifold approximation and projection UMAP algorithm to generate a low-dimensional embedded vector that preserves the local semantic structure; Topic clustering stage: The HDBSCAN algorithm based on hierarchical density spatial clustering is used to perform hierarchical density clustering on low-dimensional embedded vectors to divide discrete topics and assign topic labels to each public opinion text. Topic representation generation stage: Based on the clustered topic labels, the c-TF-IDF algorithm is used to extract keywords for each topic, and LLM is called to generate natural language description topic semantic labels for each topic; Topic merging phase: Based on LLM, the semantic similarity between initial topics is determined, and semantically overlapping topics are iteratively merged until the number of topics reaches the preset target value.
[0017] Preferably, the lightweight text preprocessing is performed before the embedding vector encoding stage, including: removing web links, removing mention symbols, removing special characters and whitespace characters, unifying capitalization, converting emojis into text descriptions and performing lemmatization to unify vocabulary morphology, calculating hash values or cosine similarity based on the segmented word sequence, setting similarity thresholds to remove duplicate or highly similar text; and filtering low-value text that is too short and has no substantial semantic meaning. The deep-level text preprocessing is performed during the topic representation generation stage, including: constructing a custom domain dictionary containing target public opinion domain terms, online hot words, and abbreviations; performing standardization and contextual error correction based on the custom domain dictionary combined with OOV rules to achieve word segmentation; constructing a hybrid stop word list containing high-frequency stop words and general stop words in the target public opinion domain; removing stop words based on the hybrid stop word list while retaining negative function words, which are not included in the stop word list; and then filtering function words by part-of-speech tagging to retain content words while removing single-character words and corpus-level high-frequency noise words.
[0018] Preferably, the target public opinion domain terminology is urban fire domain terminology, the target public opinion domain high-frequency stop words are urban fire domain high-frequency stop words, and the negative function words include not, not, non, and none.
[0019] Preferably, the embedding vector encoding stage further includes the following steps: The preprocessed public opinion text is converted into a sequence of LLM tokens, which is then input into the LLM Transformer encoder. The output of the last layer CLS tokens or the average pooling of all token outputs is taken as the embedding vector, and L2 normalization is performed on the embedding vector.
[0020] Preferably, the large language model is a pre-trained large language model based on the Transformer or GLM architecture, possessing functions such as text lexical transformation, semantic embedding encoding, natural language generation, and semantic similarity discrimination. It supports long context input, with a hidden layer dimension greater than or equal to 3584, a native context window length greater than or equal to 8k words, and outputs high-dimensional embedding vectors. Furthermore, it has been pre-trained on social media texts. In one specific implementation, the LLM is version 8B of the Qwen3 model, and the training corpus integrates various social media and online public opinion texts. The hidden layer dimension is 4096, and the native context window size is 32k words, which can be extended to 128k words using YaRN technology.
[0021] Preferably, the embedding vector dimensionality reduction stage further includes the following steps: In high-dimensional space, the k-nearest neighbor algorithm is used to find the nearest neighbor data point for each high-dimensional embedding vector, and a weighted nearest neighbor graph is constructed based on the nearest neighbor data points. The weights of the edges are calculated using a Gaussian kernel function. w ij The calculation formula is: in, d ij Data points in high-dimensional space i and data points j Distance between data points j Data points i k-nearest neighbor; It is a distance threshold for controlling local density. It is a local scale parameter used to control the nearest neighbor range; A nearest neighbor graph is constructed in a low-dimensional space, and the edge weights are approximated using a binomial distribution. The calculation formula is: in, Data points in low-dimensional space i and data points j The distance between them; a It is the first hyperparameter, used to adjust the distance distribution in the low-dimensional space; b It is the second hyperparameter, used to control how quickly the weight decreases as the distance between two points increases; Using cross-entropy as the optimization objective function, the low-dimensional embedding is optimized by minimizing the objective function, so that the topological structure of the low-dimensional space matches that of the high-dimensional space. The optimization objective function is shown in the following equation: .
[0022] Preferably, the topic clustering stage further includes the following steps: In a low-dimensional embedding space, compute any two points and Euclidean distance And calculate the distance from each point to its respective k nearest neighbor as the core distance. and This is used to characterize local density, and the reachability distance between two points is defined as: ; Based on high-dimensional embedding vectors, the reachability distance between data points is calculated, a weighted fully connected graph is constructed, and the density connectivity structure of the data is characterized by a minimum spanning tree. Then, a hierarchical clustering tree is constructed on the basis of the minimum spanning tree. Using a top-down splitting method, the hierarchical tree is compressed into multiple stable and non-overlapping clusters by combining the minimum cluster size and the number of core neighbors. Finally, a topic cluster label is assigned to each public opinion text.
[0023] Preferably, the topic representation generation stage further includes the following steps: The word sequence output from deep text preprocessing is input into BERTopic's CountVectorizer component for document vectorization, generating a document-term frequency sparse matrix; The c-TF-IDF algorithm is used to calculate weights based on the document-term frequency sparse matrix and cluster labels. The calculation formula is as follows: in, w To represent a word; t Represent a clustering topic; tf w,t Indicator w A is the total number of occurrences in all documents assigned to cluster topic t; A is the average number of words for each cluster topic. tf w, The total number of times word w appears in all clustered documents; Select a predetermined number of words as topic keywords in descending order of c-TF-IDF weights; and call LLM to generate natural language description topic semantic tags to optimize topic representation.
[0024] Preferably, the topic merging stage further includes the following steps: Extract the identification features for each initial topic, which include topic keywords and representative documents ranked based on c-TF-IDF scores; Assign a unique ID to each initial topic and call LLM to generate semantic tags that summarize the core of the topic; Perform the iterative merging process: Input the semantic tags and topic keywords of all remaining topics into the LLM. The LLM will identify and return the two topic IDs that are most semantically similar. If the highest similarity exceeds the topic similarity threshold or the current number of topics has not reached the target number, merge the similar topic pairs, generate new IDs and new semantic tags for the merged topics, and update the topic tags and topic list of the document. Repeat the iterative merging until the number of topics drops to the preset target value. When the iteration terminates, output the final merged topic list.
[0025] The beneficial effects of this invention are: 1) Significantly improves the preprocessing capability for complex social media sentiment texts and effectively reduces the interference of data noise on topic recognition: This invention designs a two-level text preprocessing strategy: lightweight and deep. Lightweight preprocessing provides clean input for the embedding model by removing web links, special characters, emoticon conversions, and redundant text filtering. Deep preprocessing constructs a custom dictionary containing target domain terms (such as "flashover" and "demolition and smoke extraction" in the field of urban fires) and popular online terms, achieves accurate word segmentation by combining OOV rules, and constructs a mixed stop word list containing high-frequency stop words in the domain while retaining negative functional words such as "not," "not," "non-," and "none," and then removes noise through part-of-speech filtering. Compared with BERTopic's default CountVectorizer, this strategy significantly enhances robustness to social media noise (empty values, repetitions, special characters), solves the problem of Chinese word segmentation and domain vocabulary segmentation errors, and avoids the accidental deletion of key negative words, thereby providing a high-quality word vector space for topic modeling and fundamentally improving the accuracy of topic recognition.
[0026] 2) Employing an LLM pre-trained on social media corpora for text encoding significantly enhances the semantic representation capability of the embedding vectors: This invention overcomes the limitation of BERTopic's default use of Sentence-BERT (S-BERT), selecting an LLM pre-trained on large-scale social media texts, such as Qwen3-8B, for text encoding. It features a higher hidden layer dimension (4096 dimensions) and a larger context window (32k terms), overcoming the limitations of S-BERT's 512-term length and insufficient 768-dimensional encoding capability. It can capture a wider range of semantic patterns and nuances, exhibiting stronger robustness, especially to social media texts containing a large amount of fragmentation, colloquialisms, and noise, thereby generating more discriminative high-dimensional embedding vectors and laying a solid semantic foundation for subsequent dimensionality reduction and clustering.
[0027] 3) Efficient density clustering and noise identification are achieved through UMAP dimensionality reduction and HDBSCAN clustering: This invention employs the Uniform Manifold Approximation and Projection (UMAP) algorithm to perform nonlinear dimensionality reduction on high-dimensional LLM embedding vectors, significantly reducing computational complexity while preserving local semantic structure. Subsequently, the Hierarchical Density-Based Spatial Clustering (HDBSCAN) algorithm is used to perform hierarchical density clustering by calculating cross-distance and constructing minimum spanning trees. Compared to traditional methods that require a preset number of topics, HDBSCAN can automatically identify clusters and effectively label noisy text, avoiding the forced assignment of noise to a specific topic and improving the purity and reliability of the clustering results.
[0028] 4) Integrating c-TF-IDF and LLM to generate topic representations, balancing keyword accuracy and semantic readability: In the topic representation generation stage, this invention first uses a category-based term frequency-inverse document frequency (c-TF-IDF) algorithm to extract core keywords for each topic, ensuring keyword distinctiveness; then, it calls LLM to automatically generate natural language descriptions of topic semantic tags (such as "fire - blocked fire exits and property management responsibility") based on these keywords and representative documents. This approach overcomes the shortcomings of a pure keyword list, which suffers from semantic ambiguity and poor interpretability, making the meaning of the topic immediately clear and facilitating emergency response decision-makers to quickly understand the focus of public opinion.
[0029] 5) An LLM-based topic iterative merging strategy effectively solves the problems of topic fragmentation and semantic overlap: Addressing the issue of excessive topic numbers and high overlap caused by HDBSCAN automatic clustering in BERTopic, this invention designs an LLM-based topic merging stage. This involves extracting core keywords and representative documents for each initial topic, generating semantic tags using LLM, and iteratively merging the most similar topic pairs based on semantic similarity until a preset number of topics is reached. Compared to traditional reduction methods based on clustering or keyword overlap, this approach achieves a higher level of semantic understanding and judgment. The merged results are more consistent with human cognition, significantly improving the cohesion, interpretability, and diversity of the final topics, providing accurate and concise topic information for downstream tasks (such as public opinion analysis and emergency response decision-making). Attached Figure Description
[0030] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0031] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] See Figure 1 This invention provides a technical solution: a method for identifying public opinion topics based on a large language model, comprising the following steps: Text preprocessing stage: Lightweight and deep text preprocessing are performed on the public opinion text to be identified in order to remove data noise and standardize vocabulary. Embedding vector encoding stage: Select an LLM pre-trained on a social media text corpus and encode the preprocessed public opinion text into a high-dimensional embedding vector; Embedded vector dimensionality reduction stage: The high-dimensional embedded vector is reduced by uniform manifold approximation and projection UMAP algorithm to generate a low-dimensional embedded vector that preserves the local semantic structure; Topic clustering stage: The HDBSCAN algorithm based on hierarchical density spatial clustering is used to perform hierarchical density clustering on low-dimensional embedded vectors to divide discrete topics and assign topic labels to each public opinion text. Topic representation generation stage: Based on the clustered topic labels, the c-TF-IDF algorithm is used to extract keywords for each topic, and LLM is called to generate natural language description topic semantic labels for each topic; Topic merging phase: Based on LLM, the semantic similarity between initial topics is determined, and semantically overlapping topics are iteratively merged until the number of topics reaches the preset target value.
[0033] In some embodiments, the lightweight text preprocessing is performed before the embedding vector encoding stage, including: removing web links, removing mention symbols, removing special characters and whitespace characters, unifying capitalization, converting emojis into text descriptions and performing lemmatization to unify lexical forms, calculating hash values or cosine similarity based on the segmented word sequence, setting similarity thresholds to remove duplicate or highly similar text; and filtering low-value text that is too short and has no substantial semantic meaning. The deep-level text preprocessing is performed during the topic representation generation stage, including: constructing a custom domain dictionary containing target public opinion domain terms, online hot words, and abbreviations; performing standardization and contextual error correction based on the custom domain dictionary combined with OOV rules to achieve word segmentation; constructing a hybrid stop word list containing high-frequency stop words and general stop words in the target public opinion domain; removing stop words based on the hybrid stop word list while retaining negative function words, which are not included in the stop word list; and then filtering function words by part-of-speech tagging to retain content words while removing single-character words and corpus-level high-frequency noise words.
[0034] In some embodiments, the target public opinion domain terminology is urban fire domain terminology, the target public opinion domain high-frequency stop words are urban fire domain high-frequency stop words, and the negative function words include not, not, non, and none.
[0035] In this embodiment, in view of the characteristics of social media texts related to urban fires, a text preprocessing procedure is designed at the text preprocessing stage to reduce data noise and standardize word forms, so that the model can focus more on meaningful linguistic features and provide high-quality input for the topic modeling task. To this end, the present invention designs a two-stage text preprocessing strategy including a light-weight stage and a deep stage.
[0036] (1) Light-weight text preprocessing: performed before text embedding generation to provide clean text input for the embedding model, and the main processing contents are as follows: (a) Unify text formats and word forms. Noise data such as web links (including short links), @ mentions, meaningless special characters (e.g., ¥%), and redundant blank characters are removed, case is unified, emojis are converted into corresponding text descriptions, and lemmatization is performed to unify word forms; (b) Filter redundant information. Calculate the text hash value or cosine similarity based on the segmented word sequence, set a reasonable similarity threshold, and eliminate identically collected identical or highly similar texts; filter low-value texts that are too short and have no substantial semantics.
[0037] (2) Deep-level text preprocessing: performed in the subsequent topic representation generation stage, the clean text output by the light-weight preprocessing is further processed to achieve accurate extraction of keywords, and the main processing contents are as follows: (a) Text segmentation. Since the internal basic lexicons of segmentation tools such as NLTK, THULAC, and Jieba do not contain professional terms in the urban fire domain and some social media OOV words, a custom domain lexicon covering fire domain terms, internet buzzwords and abbreviated expressions is constructed before segmentation, and accurate segmentation is achieved based on this lexicon in combination with OOV rule standardization and context-based error correction.
[0038] (b) Stop word removal, part-of-speech filtering, single-character word deletion, etc. This module constructs a mixed stop word list, including high-frequency stop words in the urban fire domain and general stop words, and retains negative function words such as "no, not, non-, none" without including them in the stop word list. Then, content words with actual semantics such as nouns, verbs and adjectives are retained through part-of-speech tagging, and function words such as auxiliary words, conjunctions and pronouns are filtered out; finally, single-character words and corpus-level high-frequency noise words are removed.
[0039] In some embodiments, the embedding vector encoding stage described above further includes the following steps: Convert the preprocessed public opinion text into a token sequence of the LLM, input the sequence into the Transformer encoder of the LLM, take the output of the CLS token in the last layer or the mean pooling of all token outputs as the embedding vector, and perform L2 normalization on the embedding vector.
[0040] In some embodiments, the large language model is a pre-trained large language model based on the Transformer or GLM architecture, which has the functions of text lexical transformation, semantic embedding encoding, natural language generation and semantic similarity discrimination, supports long context input, has a hidden layer dimension greater than or equal to 3584, a native context window length greater than or equal to 8k words, outputs high-dimensional embedding vectors, and has been pre-trained on social media text.
[0041] In this embodiment, the introduction of LLM further enhances document processing capabilities, with its representation ability surpassing that of S-BERT. Currently, LLM based on Generative Pre-trained Transformer (GPT) offers two major advantages by processing text through text-to-embedded vectors: Firstly, higher-dimensional LLM embedding vectors can capture a wider range of language patterns and semantic nuances; existing research shows that LLM embedding vector technology can significantly improve clustering performance. Secondly, LLM can leverage generalized representations learned from extensive pre-training in tasks such as translation and question answering. Therefore, introducing the advantages of LLM in text semantic encoding will effectively improve the performance of the BERTopic embedding representation module.
[0042] To adapt to the characteristics of social media text, this invention selects an LLM pre-trained on a large-scale social media text corpus to encode the text, and its output vector representation is used as the embedding vector of the text. Taking the Qwen3 model as an example: its training corpus includes various types of social media text such as forums, social platforms, and online comments, adapting to social media text analysis application scenarios; it has a high proportion of Chinese corpus, deeply optimizing Chinese semantic understanding capabilities; the open-source 8B version has a hidden layer dimension of 4096 dimensions, and the native context window size is 32k units.
[0043] Therefore, this invention uses Qwen3 version 8B in the BERTopic embedding module as an example to illustrate the encoding process of LLM embedding vectors. Let the set of public opinion texts be... Where N is the total number of documents, first for document d i Perform text preprocessing to obtain standardized documents. Then, Convert to Qwen3 Token Sequence Where L is the token length, which cannot exceed the Qwen3 context window size of 32k. Next, ... Input the Qwen3 Transformer encoder and take the output of the last layer [CLS] terminology (or the mean pooling of all terminology outputs) as the document. Embedded vector e i Then the collection of public opinion texts.D The corresponding high-dimensional embedding matrix is ,in ,and H represents the dimension of the hidden layer in the model; for example, the dimension of Qwen3 version 8B is 4096. Finally, to improve clustering stability, the vectors can be... e i Perform L2 normalization to ensure the vector magnitude is 1, and obtain As shown in the following formula: .
[0044] In some embodiments, the embedding vector dimensionality reduction stage further includes the following steps: In high-dimensional space, the k-nearest neighbor algorithm is used to find the nearest neighbor data point for each high-dimensional embedding vector, and a weighted nearest neighbor graph is constructed based on the nearest neighbor data points. The weights of the edges are calculated using a Gaussian kernel function. w ij The calculation formula is: in, d ij Data points in high-dimensional space i and data points j Distance between data points j Data points i k-nearest neighbor; It is a distance threshold for controlling local density. It is a local scale parameter used to control the nearest neighbor range; A nearest neighbor graph is constructed in a low-dimensional space, and the edge weights are approximated using a binomial distribution. The calculation formula is:
[0045] in, Data points in low-dimensional space i and data points j The distance between them; a It is the first hyperparameter, used to adjust the distance distribution in the low-dimensional space; b It is the second hyperparameter, used to control how quickly the weight decreases as the distance between two points increases; Using cross-entropy as the optimization objective function, the low-dimensional embedding is optimized by minimizing the objective function, so that the topological structure of the low-dimensional space matches that of the high-dimensional space. The optimization objective function is shown in the following equation: .
[0046] In this embodiment, the goal of embedding vector dimensionality reduction is to reduce the high-dimensional embedding matrix output by LLM encoding: ; Dimensionality reduction to a lower-dimensional space ;in d ≪ H This module reduces computational costs while preserving semantic similarity. It employs the UMAP algorithm for dimensionality reduction, which retains the local similarity relationships between data points during dimensionality reduction. This ensures that similar data points remain close together in the lower-dimensional space, maintaining the local structure of the data. The specific steps are as follows: (1) Constructing a high- and low-dimensional space nearest neighbor graph: First, for each high-dimensional vector e i UMAP uses the k-nearest neighbor algorithm to find its nearest neighbor data points and constructs a weighted nearest neighbor graph based on these points. G =( V , E ),node V For text data points, edges E Weight w ij The similarity between two points is calculated using the Gaussian kernel function, and the formula is as follows: ; Similarly, a nearest neighbor graph is constructed in a low-dimensional space, and the edge weights of the graph are approximated by a binomial distribution; (2) Optimize the objective function: Use random initialization or other dimensionality reduction algorithms to generate low-dimensional vectors, use cross-entropy as the objective function, optimize the low-dimensional embedding by minimizing the objective function, so that the topological structure of the low-dimensional space matches the high-dimensional space.
[0047] In some embodiments, the topic clustering phase further includes the following steps: In a low-dimensional embedding space, compute any two points and Euclidean distance And calculate the distance from each point to its respective k nearest neighbor as the core distance. and This is used to characterize local density, and the reachability distance between two points is defined as: ; Based on high-dimensional embedding vectors, the reachability distance between data points is calculated, a weighted fully connected graph is constructed, and the density connectivity structure of the data is characterized by a minimum spanning tree. Then, a hierarchical clustering tree is constructed on the basis of the minimum spanning tree. Using a top-down splitting method, the hierarchical tree is compressed into multiple stable and non-overlapping clusters by combining the minimum cluster size and the number of core neighbors. Finally, a topic cluster label is assigned to each public opinion text.
[0048] In this embodiment, the topic clustering uses the HDBSCAN algorithm, whose core principle is to partition topics based on reachability distance and clustering stability. Specifically, HDBSCAN is used to perform hierarchical density clustering on the low-dimensional embedding vector matrix Z after dimensionality reduction of UMAP, dividing it into discrete topics and outputting topic tags for each text: ,in y i The value of is given by the following formula: ;in M This represents the number of topics in the text dataset. Topic clustering mainly involves two steps: (1) Calculate the reach distance between any two points: In the low-dimensional embedding space, calculate the reach distance between any two points. and Euclidean distance And calculate the distance from each point to its respective k nearest neighbor as the core distance. and , used to characterize local density; (2) Constructing a hierarchical clustering tree: First, the reach distance between data points is calculated based on the high-dimensional embedding vector, and a weighted fully connected graph is constructed. The density connectivity structure of the data is characterized by the minimum spanning tree (MST). Then, a hierarchical clustering tree is constructed based on the minimum spanning tree. A top-down splitting method is adopted. Combined with parameter constraints such as minimum cluster size and core neighborhood number, the hierarchical tree is compressed into multiple stable and non-overlapping clusters. Finally, a corresponding topic cluster label is assigned to each text.
[0049] In some embodiments, the topic representation generation stage further includes the following steps: The word sequence output from deep text preprocessing is input into BERTopic's CountVectorizer component for document vectorization, generating a document-term frequency sparse matrix; The c-TF-IDF algorithm is used to calculate weights based on the document-term frequency sparse matrix and cluster labels. The calculation formula is as follows: in, w To represent a word; t Represent a clustering topic; tf w,t Indicator w A is the total number of occurrences in all documents assigned to cluster topic t; A is the average number of words for each cluster topic. tf w, The total number of times word w appears in all clustered documents; Select a predetermined number of words as topic keywords in descending order of c-TF-IDF weights; and call LLM to generate natural language description topic semantic tags to optimize topic representation.
[0050] In this embodiment, based on the topic tags output by topic clustering, an initial list of interpretable, high-quality keywords is generated for each topic, along with topic semantic tags for natural language descriptions generated by calling LLM. The main steps are as follows: (1) Document Vectorization: The word sequence output from the deep-level preprocessing is input into the CountVectorizer component of BERTopic to achieve document vectorization. The CountVectorizer counts word frequencies based on the bag-of-words (BOW) model and outputs a document-word frequency sparse matrix. The rows of this matrix correspond to documents, and the columns correspond to feature terms in the vocabulary, which are used for subsequent c-TF-IDF weight calculation and topic keyword extraction.
[0051] (2) c-TF-IDF algorithm: The c-TF-IDF algorithm first calculates weights based on the document-term frequency sparse matrix and cluster labels; then, to reduce noise and cover the topic as comprehensively as possible, the algorithm sorts the terms in descending order of c-TF-IDF weights and selects the top-N (e.g., N is 10) words with the highest weights as topic keywords. To optimize topic representation, LLM is called to generate natural language description topic semantic labels, as shown in Table 1.
[0052] In some embodiments, the topic merging phase further includes the following steps: Extract the identification features for each initial topic, which include topic keywords and representative documents ranked based on c-TF-IDF scores; Assign a unique ID to each initial topic and call LLM to generate semantic tags that summarize the core of the topic; Perform the iterative merging process: Input the semantic tags and topic keywords of all remaining topics into the LLM. The LLM will identify and return the two topic IDs that are most semantically similar. If the highest similarity exceeds the topic similarity threshold or the current number of topics has not reached the target number, merge the similar topic pairs, generate new IDs and new semantic tags for the merged topics, and update the topic tags and topic list of the document. Repeat the iterative merging until the number of topics drops to the preset target value. When the iteration terminates, output the final merged topic list.
[0053] In this embodiment, the present invention designs a topic merging method based on LLM (Leadership Management Model). It determines the semantic similarity between initial topics, iteratively merges topics with highly overlapping semantics until the number of topics reaches a preset target value. Compared with traditional reduction methods based on clustering or keyword overlap, this method achieves semantic-level topic determination through LLM, resulting in more accurate merging results, clearer topics, and better consistency and diversity. It mainly includes the following three steps: (1) Extracting the core information of the initial topic: Let the initial topic set obtained after clustering be: Where M is the initial number of topics. First, a single topic is extracted from the clustering results. T m The "identification features" (including the top-10 keywords ranked based on c-TF-IDF scores and 3 to 5 representative documents) are used to assign a unique ID to each initial topic, providing a basis for Qwen3's judgment. See Table 1 for relevant elements.
[0054] (2) Generating topic semantic tags based on LLM: To improve the accuracy of merging, according to the design logic of the prompt words in Table 1, Qwen3 is called to generate a semantic tag that can summarize the core of the topic for each initial topic. For example, the tag for Topic_1 is "fire - fire escape blockage and property responsibility", which replaces the pure keyword list and makes it easier for Qwen3 to identify overlapping topics. Table 1. Examples of LLM-based prompt word design
[0055] (3) Qwen3 Prompt Iterative Merging of Overlapping Topics: The core of iterative merging is to enable Qwen3 to identify and merge the most similar topics. First, input the semantic labels and Top-10 keywords of all remaining topics, referring to the Prompt design logic in Table 2.
[0056] Table 2 LLM-based topic merging Prompt template table
[0057] Secondly, execute the Qwen3 call to obtain the returned similar topic pairs (e.g., [Topic_1, Topic_3]). If the similarity is greater than the threshold (e.g., 0.7) or the current number of topics has not yet reached the reduction target, then... M * (e.g., 15) will trigger a topic merging operation. Specifically, the main steps of topic merging include: outputting similar topic pairs according to the Prompt design logic in Table 2; generating new topic IDs (e.g., Topic_1_2) and semantic tags for the similar topic pairs; updating the document clustering topic tags for the similar topic pairs to the new topic IDs; and calling topic representation generation to update the current topic list. These steps are repeated until the number of topics drops to the target value.
[0058] Finally, after the iteration terminates, the final merged list of topics is output: Then, LLM is called to generate a highly readable natural language description of the topic summary.
[0059] The above description is merely a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the forms disclosed herein and should not be construed as excluding other embodiments. It can be used in various other combinations, modifications, and environments, and can be altered within the scope of the concept described herein through the above teachings or related technologies or knowledge. Modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention should be within the protection scope of the appended claims.
Claims
1. A method for identifying public opinion topics based on a large language model, characterized in that: Includes the following steps: Text preprocessing stage: Lightweight and deep text preprocessing are performed on the public opinion text to be identified in order to remove data noise and standardize vocabulary. Embedding vector encoding stage: Select a large language model pre-trained on a social media text corpus to encode the pre-processed public opinion text into high-dimensional embedding vectors; Embedded vector dimensionality reduction stage: The high-dimensional embedded vector is reduced by uniform manifold approximation and projection UMAP algorithm to generate a low-dimensional embedded vector that preserves the local semantic structure; Topic clustering stage: The HDBSCAN algorithm based on hierarchical density spatial clustering is used to perform hierarchical density clustering on low-dimensional embedded vectors to divide discrete topics and assign topic labels to each public opinion text. Topic representation generation stage: Based on the clustered topic labels, the c-TF-IDF algorithm is used to extract keywords for each topic, and a large language model is called to generate natural language descriptions of topic semantic labels for each topic; Topic merging stage: Based on the large language model, the semantic similarity between the initial topics is judged, and semantically overlapping topics are iteratively merged until the number of topics reaches the preset target value.
2. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The lightweight text preprocessing is performed before the embedding vector encoding stage, including: removing web links, removing mention symbols, removing special characters and whitespace characters, unifying capitalization, converting emojis into text descriptions and performing lemmatization to unify vocabulary morphology, calculating hash values or cosine similarity based on the segmented word sequence, setting similarity thresholds to remove duplicate or highly similar text; and filtering low-value text that is too short and has no substantial semantic meaning. The deep-level text preprocessing is performed during the topic representation generation stage, including: constructing a custom domain dictionary containing target public opinion domain terms, online hot words, and abbreviations; performing standardization and contextual error correction based on the custom domain dictionary combined with OOV rules to achieve word segmentation; constructing a hybrid stop word list containing high-frequency stop words and general stop words in the target public opinion domain; removing stop words based on the hybrid stop word list while retaining negative function words, which are not included in the stop word list; and then filtering function words by part-of-speech tagging to retain content words while removing single-character words and corpus-level high-frequency noise words.
3. The public opinion topic identification method based on a large language model according to claim 2, characterized in that: The target public opinion domain terminology is urban fire domain terminology, the target public opinion domain high-frequency stop words are urban fire domain high-frequency stop words, and the negative function words include not, not, non- and none.
4. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The embedding vector encoding stage further includes the following steps: The preprocessed public opinion text is converted into a word sequence of a large language model and input into the Transformer encoder of the large language model. The output of the last CLS word or the average pooling of all word outputs is taken as the embedding vector, and L2 normalization is performed on the embedding vector.
5. The public opinion topic identification method based on a large language model according to claim 4, characterized in that: The large language model is a pre-trained large language model based on the Transformer or GLM architecture. It has functions such as text lexical transformation, semantic embedding encoding, natural language generation and semantic similarity discrimination. It supports long context input, hidden layer dimension greater than or equal to 3584, native context window length greater than or equal to 8k words, outputs high-dimensional embedding vectors, and has been pre-trained on social media text.
6. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The aforementioned embedding vector dimensionality reduction stage also includes the following steps: In high-dimensional space, the k-nearest neighbor algorithm is used to find the nearest neighbor data point for each high-dimensional embedding vector, and a weighted nearest neighbor graph is constructed based on the nearest neighbor data points. The weights of the edges are calculated using a Gaussian kernel function. w ij The calculation formula is: in, d ij Data points in high-dimensional space i and data points j Distance between data points j Data points i k-nearest neighbor; It is a distance threshold for controlling local density. It is a local scale parameter used to control the nearest neighbor range; A nearest neighbor graph is constructed in a low-dimensional space, and the edge weights are approximated using a binomial distribution. The calculation formula is: in, Data points in low-dimensional space i and data points j The distance between them; a It is the first hyperparameter, used to adjust the distance distribution in the low-dimensional space; b It is the second hyperparameter, used to control how quickly the weight decreases as the distance between two points increases; Using cross-entropy as the optimization objective function, the low-dimensional embedding is optimized by minimizing the objective function, so that the topological structure of the low-dimensional space matches that of the high-dimensional space. The optimization objective function is shown in the following equation: 。 7. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The topic clustering phase also includes the following steps: In a low-dimensional embedding space, compute any two points and Euclidean distance And calculate the distance from each point to its respective k nearest neighbor as the core distance. and This is used to characterize local density, and the reachability distance between two points is defined as: ; Based on high-dimensional embedding vectors, the reachability distance between data points is calculated, a weighted fully connected graph is constructed, and the density connectivity structure of the data is characterized by a minimum spanning tree. Then, a hierarchical clustering tree is constructed on the basis of the minimum spanning tree. Using a top-down splitting method, the hierarchical tree is compressed into multiple stable and non-overlapping clusters by combining the minimum cluster size and the number of core neighbors. Finally, a topic cluster label is assigned to each public opinion text.
8. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The topic representation generation phase also includes the following steps: The word sequence output from deep text preprocessing is input into BERTopic's CountVectorizer component for document vectorization, generating a document-term frequency sparse matrix; The c-TF-IDF algorithm is used to calculate weights based on the document-term frequency sparse matrix and cluster labels. The calculation formula is as follows: in, w To represent a word; t Represent a clustering topic; tf w,t Indicator w A is the total number of occurrences in all documents assigned to cluster topic t; A is the average number of words for each cluster topic. tf w, The total number of times word w appears in all clustered documents; A predetermined number of words are selected as topic keywords in descending order of c-TF-IDF weights; and a large language model is invoked to generate topic semantic tags for natural language descriptions, thereby optimizing topic representation.
9. The public opinion topic identification method based on a large language model according to claim 1, characterized in that: The topic merging phase also includes the following steps: Extract the identification features for each initial topic, which include topic keywords and representative documents ranked based on c-TF-IDF scores; Assign a unique ID to each initial topic and call a large language model to generate semantic tags that summarize the core of the topic; Perform the iterative merging process: Input the semantic tags and topic keywords of all remaining topics into the LLM. The LLM will identify and return the IDs of the two topics with the most semantic similarity. If the highest similarity exceeds the topic similarity threshold or the current number of topics has not reached the target number, merge the similar topic pairs, generate new IDs and new semantic tags for the merged topics, and update the topic tags and topic list of the document. Repeat the iterative merging until the number of topics drops to the preset target value. When the iteration terminates, output the final merged topic list.
