Text classification method and device, computer-readable storage medium, and electronic device

By obtaining the initial encoding of the input text and the classification information of the target keywords, and using the pre-trained model to determine the input text type, the problem of insufficient text classification accuracy in the existing technology is solved, higher text classification accuracy and terminal control accuracy are achieved, and the user experience is improved.

CN114020908BActive Publication Date: 2025-09-05SHENZHEN ZHONGKE MINGWANG COMM SOFTWARE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111284916.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-01
Publication Date
2025-09-05
Estimated Expiration
2041-11-01

AI Technical Summary

Technical Problem

In the existing intelligent voice interaction technology, the text classification accuracy is poor, which causes the operation performed by the terminal to be inconsistent with the operation required by the user, thereby reducing the user experience.

Method used

By obtaining the initial encoding of the input text and the target classification information of the target keywords, the pre-trained text classification model is used to determine the target type of the input text. The classification information of the target keywords is used as a reference to improve the text classification accuracy and reduce the need for model retraining.

Benefits of technology

It improves the accuracy of text classification, reduces misoperations, and enhances the accuracy of terminal control and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114020908B_ABST
    Figure CN114020908B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of natural language processing technology, and specifically to a text classification method and apparatus, a computer-readable storage medium, and an electronic device. The method comprises: obtaining input text and determining an initial code corresponding to the input text; obtaining target keywords in the input text and obtaining target classification information for the target keywords; determining a reference code corresponding to the target keywords based on the target classification information; determining a target vector corresponding to the input text based on the initial code and the reference code; and determining a target type of the input text using a pre-trained text classification model based on the target vector. The technical solutions of the embodiments of the present disclosure improve the accuracy of text classification, thereby enhancing the control accuracy of the terminal and improving the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of natural language processing technology, and in particular to a text classification method and device, a computer-readable storage medium, and an electronic device. Background Art

[0002] With the development of artificial intelligence, the application of intelligent voice interaction technology in mobile terminals is becoming more and more extensive. In intelligent voice interaction technology, the input text is classified and the terminal is controlled to perform the operation corresponding to the input text according to the classification result.

[0003] In the prior art of intelligent voice interaction, when the processor classifies the input text, the classification accuracy is poor, which may cause the operation performed by the terminal to be inconsistent with the operation required by the user, thereby reducing the user experience.

[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the Invention

[0005] The purpose of the present disclosure is to provide a text classification method and device, a computer-readable storage medium and an electronic device, and a control method for a terminal device, thereby improving the accuracy of text classification at least to a certain extent, thereby improving the control accuracy of the terminal and improving the user experience.

[0006] According to a first aspect of the present disclosure, a text classification method is provided, which includes: obtaining an input text and determining an initial code corresponding to the input text; obtaining target keywords in the input text and obtaining target classification information of the target keywords; determining a reference code corresponding to the target keyword based on the target classification information; determining a target vector corresponding to the input text based on the initial code and the reference code; and determining a target type of the input text using a pre-trained text classification model based on the target vector.

[0007] According to a second aspect of the present disclosure, a text classification device is provided, which includes: a first acquisition module, used to acquire input text and determine the initial code corresponding to the input text; a second acquisition module, used to acquire target keywords in the input text and acquire target classification information of the target keywords; a first determination module, used to determine the reference code corresponding to the target keyword based on the target classification information; a second determination module, used to determine the target vector corresponding to the input text based on the initial code and the reference code; and a text classification module, used to determine the target type of the input text based on the target vector using a pre-trained text classification model.

[0008] According to a third aspect of the present disclosure, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above method is implemented.

[0009] According to a fourth aspect of the present disclosure, an electronic device is provided, which includes: one or more processors; and a memory for storing one or more programs, which enables the one or more processors to implement the above-mentioned method when the one or more programs are executed by the one or more processors.

[0010] An embodiment of the present disclosure provides a text classification method, which obtains input text and determines the initial code corresponding to the input text; obtains target keywords in the input text and obtains target classification information of the target keywords; determines the reference code corresponding to the target keywords based on the target classification information; obtains the target vector corresponding to the input text based on the initial code and the reference code; and determines the target type of the input text using a pre-trained text classification model based on the target vector. Compared with the prior art, when classifying text, the classification information corresponding to the target keywords in the input text is used as a reference, thereby improving the accuracy of text classification. Using this text classification method, when new words appear, the text containing the new words can be classified by adding keywords and the classification information corresponding to the keywords, without the need to retrain the text classification model, which can reduce the computational complexity of the text classification method when the words are updated. In addition, using this text classification method, accurate classification of the input text can make subsequent control of the terminal based on the input text more accurate, reduce misoperation, and improve user experience.

[0011] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and those skilled in the art can derive other drawings based on these drawings without inventive effort. In the drawings:

[0013] Figure 1 A schematic diagram showing an exemplary system architecture to which embodiments of the present disclosure may be applied;

[0014] Figure 2 A schematic diagram showing an electronic device to which the embodiments of the present disclosure may be applied;

[0015] Figure 3 A flowchart of a text classification method in an exemplary embodiment of the present disclosure is schematically shown;

[0016] Figure 4 A schematic diagram illustrating configuring reference coding for an input text in an exemplary embodiment of the present disclosure is shown;

[0017] Figure 5 Schematically illustrates a data flow diagram of a text classification method in an exemplary embodiment of the present disclosure;

[0018] Figure 6 Schematically illustrates a flow chart for obtaining a text classification model in an exemplary embodiment of the present disclosure;

[0019] Figure 7 A schematic diagram illustrating generating a control instruction when no reference code is configured for input text in an exemplary embodiment of the present disclosure;

[0020] Figure 8 The exemplary embodiment of the present disclosure shows Figure 7 A schematic diagram of the control instructions generated after the input text configuration reference encoding;

[0021] Figure 9 A schematic diagram showing the composition of a text classification device in an exemplary embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0022] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be embodied in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.

[0023] In addition, the accompanying drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. Identical reference numerals in the figures denote identical or similar parts, and thus repetitive descriptions thereof will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0024] Figure 1 A schematic diagram shows a system architecture of an exemplary application environment in which a text classification method and apparatus according to an embodiment of the present disclosure can be applied.

[0025] like Figure 1As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is a medium for providing a communication link between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc. The terminal devices 101, 102, 103 may be electronic devices with text analysis functions, including but not limited to desktop computers, portable computers, smart phones, and tablet computers, etc. It should be understood that Figure 1 The number of terminal devices, networks, and servers in the embodiment is merely illustrative. Any number of terminal devices, networks, and servers may be provided as needed. For example, the server 105 may be a server cluster consisting of multiple servers.

[0026] The text classification method provided in the embodiments of the present disclosure is generally executed by the terminal devices 101, 102, and 103, and accordingly, the text classification device is generally set in the terminal devices 101, 102, and 103. However, it is easy for those skilled in the art to understand that the text classification method provided in the embodiments of the present disclosure can also be executed by the server 105, and accordingly, the text classification device can also be set in the server 105, and this exemplary embodiment does not specifically limit this. For example, in one exemplary embodiment, a user can obtain input text through the terminal devices 101, 102, and 103, and then upload the input text to the server 105. After the server generates the target type corresponding to the input text through the text classification method provided in the embodiments of the present disclosure, it transmits the target type corresponding to the input text to the terminal devices 101, 102, and 103.

[0027] The exemplary embodiment of the present disclosure provides an electronic device for implementing a text classification method, which may be Figure 1 The terminal device 101, 102, 103 or the server 105 in the embodiment of the present invention comprises at least a processor and a memory, wherein the memory is used to store executable instructions of the processor, and the processor is configured to execute the text classification method by executing the executable instructions.

[0028] Among them, the above-mentioned terminal devices 101, 102, and 103 can all be mobile terminals. Figure 2 The structure of the electronic device is exemplarily described by taking the mobile terminal 200 in FIG. 1 as an example. It should be understood by those skilled in the art that, in addition to the components specifically used for mobile purposes, Figure 2The structure in FIG. 2 can also be applied to fixed type devices. In other embodiments, the mobile terminal 200 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware. The interface connection relationship between the components is only shown schematically and does not constitute a structural limitation of the mobile terminal 200. In other embodiments, the mobile terminal 200 may also adopt the same Figure 2 Different interface connection methods, or a combination of multiple interface connection methods.

[0029] like Figure 2 As shown, the mobile terminal 200 may specifically include: a processor 210, an internal memory 221, an external memory interface 222, a Universal Serial Bus (USB) interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a speaker 271, a receiver 272, a microphone 273, an earphone interface 274, a sensor module 280, a display 290, a camera module 291, an indicator 292, a motor 293, a button 294, and a subscriber identification module (SIM) card interface 295. The sensor module 280 may include a depth sensor 2801, a pressure sensor 2802, a gyroscope sensor 2803, and the like.

[0030] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0031] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU enables intelligent cognitive applications in the mobile terminal 200, such as image recognition, face recognition, speech recognition, and text comprehension.

[0032] The processor 210 is provided with a memory that can store instructions for implementing six modular functions: detection instructions, connection instructions, information management instructions, analysis instructions, data transmission instructions, and notification instructions, and the execution of the instructions is controlled by the processor 210.

[0033] The wireless communication function of the mobile terminal 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 250, the wireless communication module 260, the modem processor, and the baseband processor.

[0034] The mobile terminal 200 implements display functions through a GPU, a display screen 290, and an application processor, etc. The processor 210 may include one or more GPUs that execute program instructions to generate or change display information.

[0035] The internal memory 221 may be used to store computer executable program codes, where the executable program codes include instructions.

[0036] The mobile terminal 200 can implement audio functions such as music playback and recording through the audio module 270 , the speaker 271 , the receiver 272 , the microphone 273 , the headphone jack 274 and the application processor.

[0037] The mobile terminal 200 may also include other devices that provide auxiliary functions. For example, the keys 294 include a power key, a volume key, etc., through which the user can input key signals related to user settings and function control of the mobile terminal 200. Another example includes the indicator 292, the motor 293, and the SIM card interface 295.

[0038] In this example embodiment, the user's voice information can be obtained through the above-mentioned microphone 273 and sent to the above-mentioned processor 210. The processor performs voice-to-text conversion on the voice information to obtain the input text, and then uses the text classification method disclosed in this disclosure to obtain the target type corresponding to the above-mentioned input text.

[0039] Word2vec is a software tool for training word vectors. It can express a word into a vector form through an optimized training model based on a given corpus. It is a tool in the field of natural language processing.

[0040] In the related art, existing text classification methods are implemented through neural networks. Word2vec technology is used to train word embeddings in a given corpus as input to the text classification model, and a general prior information text classification model is used to train the model. The general prior information can be the pre-classification results corresponding to the word embeddings. However, when using neural networks for text classification, a large amount of general prior information needs to be introduced as training samples to implement the text classification model. In specific business scenarios, it is impossible to accurately determine the specific application scenario of each word embedding, resulting in poor text classification accuracy.

[0041] Furthermore, word vectors trained on general, large-scale corpora cannot incorporate prior knowledge related to business scenarios. For example, the vectors learned by the model for "going to the train station" and "going to Haidilao" may be very similar. However, in the voice assistant scenario, going to the train station may be classified as navigation, while going to Haidilao may be classified as food. Furthermore, when new vocabulary is introduced, or when vocabulary takes on new meanings, the above word vectors cannot be used to complete the classification of the input text. For example, Haidilao (restaurant) may appear frequently, but Dadong (restaurant) may appear only rarely or not at all. Some restaurant entities may even be out-of-view (OOV) words, making it impossible for the model to use the prior information in the word vectors for classification.

[0042] Furthermore, if word vectors are directly used as input, if classification errors are found during model use, the model can only be retrained due to the lack of interaction with the model, which increases the difficulty of classification and training costs.

[0043] The text classification method and text classification device according to the exemplary embodiments of the present disclosure are described in detail below.

[0044] Figure 3 The flowchart of a text classification method in this exemplary embodiment includes the following steps:

[0045] Step S310: obtaining an input text and determining an initial code corresponding to the input text;

[0046] Step S320, obtaining target keywords in the input text, and obtaining target category information of the target keywords;

[0047] Step S330, determining a reference code corresponding to the target keyword according to the target classification information;

[0048] Step S340, determining a target vector corresponding to the input text according to the initial code and the reference code;

[0049] Step S350: Determine the target type of the input text according to the target vector using a pre-trained text classification model.

[0050] Compared to the existing technology, this embodiment uses the classification information corresponding to the target keywords in the input text as a reference when classifying the input text, thereby improving the accuracy of text classification. Furthermore, when new words appear, the text containing the new words can be classified by adding keywords and their corresponding classification information, without the need to retrain the text classification model. This can reduce the computational complexity of the text classification method when the vocabulary is updated. Furthermore, accurate classification of the input text can make subsequent control of the terminal based on the input text more precise, reduce misoperations, and improve the user experience.

[0051] In step S310, an input text is obtained, and an initial code corresponding to the input text is determined.

[0052] In an example implementation of the present disclosure, the processor may first obtain input text. When obtaining the input text, it may obtain the input text of the text input by the user, or it may obtain the voice information input by the user, and perform voice-to-text conversion on the input voice information to obtain the above-mentioned input text. The method of obtaining the input text may be customized according to user needs and is not specifically limited in this example implementation.

[0053] After obtaining the input text, the processor can obtain a character encoding table, and then the processor can obtain the initial encoding corresponding to the input text based on the character encoding table. Specifically, each character can correspond to a code, and the encoding information corresponding to each character in the input text can be determined. The encoding information corresponding to the characters in the input text can then be sorted according to the order of the Chinese characters in the input text to obtain the initial encoding.

[0054] For example, refer to Figure 4 As shown, assuming that the input text is "Xiao Bu I want to go to Haidilao", the encoding information corresponding to the characters "Xiao", "Bu", "I", "I want ...

[0055] In step S320, target keywords in the input text are obtained, and target category information of the target keywords is obtained.

[0056] In an example embodiment of the present disclosure, the processor can determine the target keyword in the above-mentioned input text. Specifically, the processor can obtain another keyword word list and traverse the above-mentioned keyword word list based on the above-mentioned input text to determine whether the keyword in the keyword word list exists in the above-mentioned input text. If so, the above-mentioned keyword is obtained as the target keyword of the input text. If not, the target keyword is set to empty.

[0057] In this example embodiment, the above-mentioned keyword vocabulary can be pre-configured by the user, wherein the keyword vocabulary can include multiple keywords and classification information corresponding to each keyword; the classification information can include food, navigation, travel, etc., and can also be customized according to user needs, which is not specifically limited in this example embodiment.

[0058] In this example implementation, the target classification information obtained may include "is a food field", "is not a food field", "is a navigation field", "is not a navigation field", "is a tourism field", "is not a tourism field", etc., where the specific form of the target classification information can be customized according to user needs and is not specifically limited in this example implementation.

[0059] In this example embodiment, the keywords in the keyword vocabulary may include words with vague classification and positioning, such as "Haidilao", "Dadong", etc., and it is not clear whether they should be classified as navigation or food; specific keywords can be added according to user needs and are not specifically limited in this example embodiment.

[0060] In this example implementation, the processor can update the above-mentioned keyword vocabulary at intervals of preset time, wherein the above-mentioned preset time can be 1 day, one week, one month, or can be customized according to user needs, which is not specifically limited in this example implementation.

[0061] In this example embodiment, updating the keyword vocabulary may include adding new keywords and classification information corresponding to the keywords, and may also include adding new classification information for existing keywords, wherein one of the above keywords may correspond to multiple classification information, and the classification information corresponding to each keyword may be customized according to user needs, which is not specifically limited in this example embodiment.

[0062] For example, assuming the input text is "Xiao Bu, I want to go to Haidilao," after traversing the keyword table, we can obtain the target keyword for the input text as "Haidilao." The category information corresponding to the target keyword can be determined in the keyword table. The target category information corresponding to "Haidilao" may include "category category" and "not navigation category." Users can also add or delete target category information as needed. When the category information changes, the model can be updated directly by updating the keyword table without reclassifying it, reducing the computational complexity of the text classification method.

[0063] In step S330, a reference code corresponding to the target keyword is determined according to the target classification information.

[0064] In an exemplary embodiment of the present disclosure, the initial code and the reference code may both be matrices. After determining target classification information of the target keyword in the input text, the processor may determine the reference code of the target keyword based on the target classification information.

[0065] In this exemplary embodiment, the reference code may have the same number of columns as the initial code. The processor may determine the number of rows in the reference code based on the number of categories in the classification information of the target keyword. For example, if the input text is "Xiao Bu, I want to go to Haidilao" and the target keyword is "Haidilao," the classification information corresponding to Haidilao may include "food" and "navigation." Since the initial code of the input text has 8 columns, the reference code has 8 columns and 2 rows. The processor may then determine the value of each element in the reference code based on the classification information.

[0066] In this example implementation, each row corresponds to a type of target classification information, and each column corresponds to a character in the input text. When determining the value of each element in the above reference code, only the value of the element in the column corresponding to the target keyword is adjusted, and the value of other elements can be configured to 0. If the target keyword is the field corresponding to the classification information, the value of the element corresponding to the target keyword of the target classification information is configured to 1. If the target keyword is not the field corresponding to the target classification information, the value of the element corresponding to the target keyword of the target classification information is configured to 0. The specific element configuration method can also be customized according to the user's needs, and is not specifically limited in this example implementation.

[0067] Reference Figure 4As shown, when the input text is "Xiao Bu, I want to go to Haidilao", the classification information of "Haidilao" may include the food field, not the navigation field. At this time, the values ​​of the elements of the row corresponding to the food field of the above reference code can be 0, 0, 0, 0, 0, 1, 1, 1 respectively; the values ​​of the elements of the row corresponding to the navigation field can be 0, 0, 0, 0, 0, 0, 0, 0 respectively.

[0068] In step S340, a target vector corresponding to the input text is determined according to the initial code and the reference code.

[0069] In an example embodiment of the present disclosure, after determining the above-mentioned initial code and the above-mentioned reference code, the processor can determine the target vector corresponding to the above-mentioned input text based on the above-mentioned initial code and the above-mentioned reference code. Specifically, the processor can vectorize the above-mentioned initial code and the reference code respectively to obtain the initial vector and the reference vector, and then the processor can splice the above-mentioned initial vector and the above-mentioned reference vector to obtain the target vector.

[0070] In this example embodiment, when vectorizing the initial code and the reference code, the processor may employ an embedding lookup function for vectorization to obtain the initial vector and the reference vector, wherein the number of columns in the initial vector may be the same as the number of columns in the reference vector. When vectorizing the reference code, the processor may vectorize each row separately, and after vectorizing each row, perform row-wise splicing on the vectorized results to obtain the reference vector. The splicing method may also include column splicing, diagonal splicing, etc., and may be customized according to user needs, which is not specifically limited in this example embodiment.

[0071] In this example implementation, the vector corresponding to each row in the above reference code can be a 128-dimensional vector, and can also be customized according to user needs, which is not specifically limited in this example implementation.

[0072] In this example implementation, the manner in which the processor vectorizes the initial vector and the reference vector may also be customized according to user needs, which is not specifically limited in this example implementation.

[0073] In step S350, a target type of the input text is determined according to the target vector using a pre-trained text classification model.

[0074] In an exemplary embodiment of the present disclosure, referring to Figure 5As shown, after obtaining the above-mentioned target vector, the processor can input the above-mentioned target vector 510 into the pre-trained text classification model 520 to determine the target type 530 of the above-mentioned input text, wherein the above-mentioned target vector is obtained by row splicing of the initial vector 511 and the reference vector 512, that is, the initial vector 511 and the reference vector 512 are spliced ​​together up and down to obtain the above-mentioned target vector 510.

[0075] In this example embodiment, reference may be made to Figure 6 As shown, first obtain a pre-trained text classification model, which can specifically include the following steps:

[0076] Step S610, obtaining an initial model;

[0077] Step S620, obtaining a plurality of text data and determining a first code corresponding to each of the text data;

[0078] Step S630, obtaining reference keywords in each of the text data, and obtaining reference classification information corresponding to the reference keywords;

[0079] Step S640, determining a second code corresponding to the reference keyword according to the reference classification information;

[0080] Step S650, obtaining a text vector corresponding to the text data according to the first code and the second code;

[0081] Step S660: Determine the reference type corresponding to each text data, and use the reference type of each text data and the text vector corresponding to each text data to train the initial model to obtain a pre-trained text classification model.

[0082] In this example embodiment, in steps S610 to S650, the processor may first obtain text data. When obtaining the text data, the processor may obtain text data of the text input by the user, or may obtain voice information input by the user, and perform voice-to-text conversion on the input voice information to obtain the above-mentioned text data. The method of obtaining text data may be customized according to user needs and is not specifically limited in this example embodiment.

[0083] After obtaining the text data, the processor can obtain a character encoding table and, based on the character encoding table, obtain a first encoding corresponding to the text data. Specifically, each character can correspond to a code, and the processor can determine the encoding corresponding to each character in the text data, and then sort the encodings corresponding to the characters in the text data according to the order of the Chinese characters in the text data to obtain the first encoding.

[0084] The processor can determine the reference keyword in the above text data. Specifically, the processor can obtain a keyword word list, traverse the above keyword word list, and determine whether the keyword in the keyword word list exists in the above text data. If so, the above keyword is obtained as the reference keyword of the text data. If not, the reference keyword is set to empty.

[0085] In an exemplary embodiment of the present disclosure, after determining the target category information of the target keyword in the input text, the processor may determine a reference code of the target keyword according to the target category information.

[0086] In this example embodiment, both the first code and the second code may be matrices. The number of columns of the second code may be the same as that of the first code. The processor may determine the number of rows of the second code based on the number of categories in the classification information in the reference keyword. For example, if the text data is "Xiao Bu I want to go to Haidilao" and the reference keyword is "Haidilao", the classification information corresponding to Haidilao may include "food" and "navigation". Since the number of columns of the first code of the text data is 8, the number of columns of the second code is 8 and the number of rows is 2. The value of each element in the second code may then be determined based on the classification information.

[0087] In this example implementation, each row corresponds to a type of reference classification information, and each column corresponds to a character in the text data. When determining the value of each element in the above-mentioned second code, only the value of the element of the column corresponding to the reference keyword is adjusted, and the value of other elements can be configured to 0. If the above-mentioned reference keyword is the field corresponding to the reference classification information, the processor configures the value of the element corresponding to the reference keyword of the classification information to 1. If the above-mentioned reference keyword is not the field corresponding to the reference classification information, the processor configures the value of the element corresponding to the reference keyword of the classification information to 0. The specific element configuration method can also be customized according to the needs of the user, and is not specifically limited in this example implementation.

[0088] In an example embodiment of the present disclosure, after determining the above-mentioned first code and the above-mentioned second code, the processor can determine that the above-mentioned text vector corresponds to the input text based on the above-mentioned first code and the above-mentioned second code. Specifically, the processor can vectorize the above-mentioned first code and the second code respectively to obtain the first vector and the second vector, and then can perform row splicing on the above-mentioned first vector and the above-mentioned second vector to obtain the text vector.

[0089] In this example embodiment, when vectorizing the first and second codes, the processor may employ an embedding lookup function to vectorize the first and second vectors, where the number of columns in the first vector may be the same as the number of columns in the second vector. When vectorizing the second code, the processor may vectorize each row separately. After vectorizing each row, the vectorized results may be concatenated row-wise to obtain the second vector.

[0090] In this example implementation, the vector corresponding to each row in the second code may be a 128-dimensional vector, or may be customized according to user needs, which is not specifically limited in this example implementation.

[0091] In this example implementation, the manner of vectorizing the first vector and the second vector may be customized according to user needs, and is not specifically limited in this example implementation.

[0092] In this example implementation, the above steps S610 to S650 may refer to the process of obtaining the target vector of the above input text, which will not be described in detail here.

[0093] In step S660, the reference type corresponding to each text data is determined, and the reference type of each text data and the text vector corresponding to each text data are used to train the initial model to obtain a pre-trained text classification model.

[0094] In this example implementation, the processor may determine the reference type corresponding to each of the above text data, and use the text vectors of each of the above text data and their corresponding reference types as sample data to complete the training of the initial model to obtain the above text classification model.

[0095] In this example embodiment, the initial model may be a convolutional neural network (CNN) model, a target detection convolutional neural network (Faster-RCNN) model, a recurrent neural network (RNN) model, or a generative adversarial network (GAN) model, but is not limited thereto. Other neural network models known to those skilled in the art may also be used. This is not specifically limited in this example real-time mode.

[0096] This text classification model is primarily a neural network model based on deep learning. For example, the text classification model can be based on a feedforward neural network. A feedforward network can be implemented as an acyclic graph in which nodes are arranged in layers. Typically, a feedforward network topology includes an input layer and an output layer, separated by at least one hidden layer. The hidden layer transforms the input received by the input layer into a representation useful for generating the output in the output layer. Network nodes are fully connected to nodes in adjacent layers via edges, but there are no edges between nodes within each layer. Data received at the nodes of the input layer of the feedforward network is propagated (i.e., "fed forward") to the nodes of the output layer via an activation function. The activation function calculates the state of the nodes in each successive layer of the network based on coefficients ("weights"), which are associated with each of the edges connecting these layers. The output of the text classification model can take various forms, which are not limited by this disclosure. The text classification model can also include other neural network models, such as, for example, a convolutional neural network (CNN) model, a recurrent neural network (RNN) model, and a generative adversarial network (GAN) model, but is not limited thereto. Other neural network models known to those skilled in the art can also be used.

[0097] The above-mentioned training of the text classification model using sample data may include the following steps: selecting a network topology; using a set of training data representing the problem being modeled by the network; and adjusting the weights until the network model performs with minimum error for all instances of the training data set. For example, during a supervised learning training process for a neural network, the output generated by the network in response to an input representing an instance in the training data set is compared with the "correct" labeled output of the instance; an error signal representing the difference between the output and the labeled output is calculated; and when the error signal is propagated backward through the layers of the network, the weights associated with the connection are adjusted to minimize the error. The model when the error of each output generated from the instance of the training data set is minimized is defined as a text classification model.

[0098] After obtaining the above text classification model, the processor inputs the target vector corresponding to the above input text into the above text classification model to obtain the target type corresponding to the input text.

[0099] Compared with related art text classification models that do not use keywords, the text classification model in this application has improved accuracy, recall, and F1 score, which can improve the accuracy of text classification. For details, please refer to Table 1.

[0100] Table 1

[0101]

[0102] As can be seen from Table 1, the accuracy of the text classification model in the related art is 78%, the recall rate is 83.3% and the F1 score is 80.6%, while the accuracy of the text classification model in the present disclosure is 79.2%, the recall rate is 85.5% and the F1 score is 82.4%. That is, the accuracy, recall rate and F1 score in the present disclosure are all improved. The use of the text classification model in the present disclosure can improve the accuracy of text classification.

[0103] In summary, in this exemplary embodiment, when the processor classifies text, it utilizes the target classification information corresponding to the target keywords in the input text, which can improve the accuracy of text classification. Furthermore, when new words appear, the processor can classify the text containing the new words by using keywords and the classification information corresponding to the keywords, without the need to retrain the text classification model, which can reduce the amount of calculation of the text classification method when the vocabulary is updated. Furthermore, the accurate classification of the input text can make the subsequent control of the terminal based on the input text more accurate, reduce misoperation, and improve the user experience.

[0104] It should be noted that the above figures are merely illustrative of the processes included in the methods according to exemplary embodiments of the present disclosure and are not intended to be limiting. It is readily understood that the processes illustrated in the above figures do not indicate or limit the temporal order of these processes. Furthermore, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.

[0105] In this example implementation, the processor may generate a control instruction corresponding to the input text according to the target type, so as to control the terminal device according to the control instruction.

[0106] Specifically, assuming that the input text is "near Dadong", if the input text is "near Dadong" and the target keyword "Dadong" is not configured with classification information, that is, the reference code is configured as the default value 0, such as Figure 7 As shown, at this time, the terminal will generate navigation-related instructions to find the area where "Dadong" is located. Figure 8 As shown in the example, the target classification information for "Dadong" is configured as a restaurant rather than a place name. In this case, when the processor generates control instructions based on the input text, it only generates search instructions, not navigation instructions. This allows for more accurate control instruction generation, preventing the processor from misoperating the terminal device.

[0107] For further reference, Figure 9 As shown, in the embodiment of this example, a text classification device 900 is further provided, comprising a first acquisition module 910, a second acquisition module 920, a first determination module 930, a second determination module 940 and a text classification module 950. In particular:

[0108] The first acquisition module 910 can be used to acquire input text and determine the initial encoding corresponding to the input text. Specifically, it can acquire user input voice information, perform voice-to-text conversion on the voice information to obtain the input text; then obtain a pre-configured text encoding table; and determine the initial encoding corresponding to the input text based on the input text and the text encoding table.

[0109] The second acquisition module 920 can be used to acquire target keywords from the input text and obtain target classification information for the target keywords. Specifically, a preconfigured keyword vocabulary can be first acquired, which includes multiple keywords and corresponding classification information for the keywords; the keyword vocabulary is traversed based on the input text to determine the target keywords of the input text, and the target classification information for the target keywords in the input text can be acquired. The keyword vocabulary can be updated at preset intervals.

[0110] The first determination module 930 can be used to determine the reference code corresponding to the target keyword based on the target classification information. Specifically, the number of rows of the reference code can be first determined based on the number of types in the classification information; the value of each element in the reference code can be determined based on the classification information to determine the reference code.

[0111] The second determination module 940 can be used to determine the target vector corresponding to the input text based on the initial code and the reference code; specifically, the initial code and the reference code can first be vectorized to obtain the initial vector and the reference vector respectively; then the reference vector and the target vector can be spliced ​​to obtain the target vector.

[0112] The text classification module 950 may be configured to determine the target type of the input text based on the target vector using a pre-trained text classification model.

[0113] In this example embodiment, the apparatus may further include a control module, wherein the control module may be configured to generate a control instruction corresponding to the input text according to the target type and the input text, so as to control the terminal device according to the control instruction.

[0114] In an example embodiment of the present disclosure, the text classification device may further include a model training module. Specifically, it may first obtain an initial model; obtain multiple text data and determine the first code corresponding to each text data; obtain reference keywords in each text data and obtain reference classification information corresponding to the reference keywords; determine the second code corresponding to the reference keyword based on the reference classification information; obtain a text vector corresponding to the text data based on the first code and the second code; determine the reference type corresponding to each text data, and use the reference type of each text data and the text vector corresponding to each text data to train the initial model to obtain a pre-trained text classification model.

[0115] The specific details of each module in the above device have been described in detail in the implementation method part. The undisclosed details can be found in the implementation method part, so they will not be repeated here.

[0116] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods, or program products. Therefore, various aspects of the present disclosure may be implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, which may be collectively referred to herein as "circuits," "modules," or "systems."

[0117] In this example embodiment, the electronic device may include one or more processors and a memory, and the memory may be used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the text classification method.

[0118] Specifically, the processor may obtain input text and determine an initial encoding corresponding to the input text. Specifically, the processor may obtain voice information input by the user, perform voice-to-text conversion on the voice information to obtain the input text; then the processor obtains a pre-configured text encoding table; and determines the initial encoding corresponding to the input text based on the input text and the text encoding table.

[0119] In this example embodiment, the processor can obtain target keywords from the input text and obtain target classification information for the target keywords. Specifically, the processor can first obtain a preconfigured keyword vocabulary, which includes multiple keywords and corresponding classification information for the keywords. The processor then traverses the keyword vocabulary based on the input text, determines the target keywords in the input text, and obtains the target classification information for the target keywords in the input text. The processor can update the keyword vocabulary at preset intervals.

[0120] The processor can determine the reference code corresponding to the target keyword based on the target classification information. Specifically, the processor can first determine the number of rows of the reference code based on the number of types in the classification information; and determine the value of each element in the reference code based on the classification information to determine the reference code.

[0121] The processor can determine the target vector corresponding to the input text based on the initial code and the reference code; specifically, the processor can first vectorize the above-mentioned initial code and reference code to obtain the initial vector and the reference vector respectively; then the processor splices the reference vector and the target vector to obtain the target vector.

[0122] The processor determines the target type of the input text based on the target vector using a pre-trained text classification model; after obtaining the above-mentioned target type, the processor can also generate a control instruction corresponding to the input text based on the target type and the input text to control the terminal device according to the control instruction.

[0123] The processor can first obtain an initial model; obtain multiple text data and determine the first code corresponding to each text data; obtain reference keywords in each text data and obtain reference classification information corresponding to the reference keywords; determine the second code corresponding to the reference keywords based on the reference classification information; obtain the text vector corresponding to the text data based on the first code and the second code; determine the reference type corresponding to each text data, and use the reference type of each text data and the text vector corresponding to each text data to train the initial model to obtain a pre-trained text classification model.

[0124] The exemplary embodiments of the present disclosure further provide a computer-readable storage medium having stored thereon a program product capable of implementing the methods described above in this specification. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product comprising program code that, when executed on a terminal device, causes the terminal device to execute the steps described in the "Exemplary Methods" section above according to various exemplary embodiments of the present disclosure.

[0125] It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0126] In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the foregoing.

[0127] In addition, the program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, and the like, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a stand-alone software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0128] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow from the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the claims.

[0129] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A text classification method, characterized in that: The text classification method comprises: Obtaining input text and determining an initial encoding corresponding to the input text; Obtaining target keywords from the input text and obtaining target category information of the target keywords; Determine the reference code corresponding to the target keyword according to the target classification information; Determine a target vector corresponding to the input text according to the initial code and the reference code; Determining a target type of the input text using a pre-trained text classification model according to the target vector; Wherein, the reference code and the initial code are both matrices, Determining the reference code corresponding to the keyword according to the target classification information includes: determining the number of columns of the reference code according to the number of columns of the initial code; determining the number of rows of the reference code according to the number of types in the target classification information; determining the value of each element in the reference code according to the target classification information to determine the reference code; Determining a target vector corresponding to the input text according to the initial code and the reference code includes: vectorizing the initial code and the reference code to obtain an initial vector and a reference vector respectively; and concatenating the reference vector and the initial vector to obtain the target vector; The step of obtaining target keywords from the input text and obtaining target classification information of the target keywords includes: Obtaining a preconfigured keyword vocabulary, wherein the keyword vocabulary includes a plurality of keywords and classification information corresponding to the keywords; wherein the keyword vocabulary is updated at preset time intervals; The target keywords of the input text are determined according to the keyword vocabulary, and target classification information of the target keywords in the input text is obtained.

2. The method according to claim 1, characterized in that The obtaining of input text comprises: Acquire voice information input by the user, and perform voice-to-text conversion on the voice information to obtain the input text.

3. The method according to claim 1, characterized in that The obtaining of the initial code corresponding to the input text includes: Get the preconfigured text encoding table; An initial code corresponding to the input text is determined according to the input text and the character code table.

4. The method according to claim 1, wherein The method further includes the step of obtaining a pre-trained text classification model, including: Obtain an initial model; Acquire a plurality of text data, and determine a first code corresponding to each of the text data; Obtaining reference keywords from each of the text data, and obtaining reference classification information corresponding to the reference keywords; Determining a second code corresponding to the reference keyword according to the reference classification information; Obtaining a text vector corresponding to the text data according to the first encoding and the second encoding; The reference type corresponding to each of the text data is determined, and the reference type of each of the text data and the text vector corresponding to each of the text data are used to train the initial model to obtain a pre-trained text classification model.

5. The method according to claim 1, wherein The method further comprises: A control instruction corresponding to the input text is generated according to the target type and the input text, so as to control the terminal device according to the control instruction.

6. A text classification device, characterized in that: The text classification device comprises: A first acquisition module is used to acquire an input text and determine an initial code corresponding to the input text; A second acquisition module is used to acquire target keywords in the input text and acquire target classification information of the target keywords; A first determining module, configured to determine a reference code corresponding to the target keyword according to the target classification information; A second determining module, configured to determine a target vector corresponding to the input text according to the initial code and the reference code; A text classification module, configured to determine a target type of the input text using a pre-trained text classification model according to the target vector; Wherein, the reference code and the initial code are both matrices, Determining the reference code corresponding to the keyword according to the target classification information includes: determining the number of columns of the reference code according to the number of columns of the initial code; determining the number of rows of the reference code according to the number of types in the target classification information; determining the value of each element in the reference code according to the target classification information to determine the reference code; Determining a target vector corresponding to the input text according to the initial code and the reference code includes: vectorizing the initial code and the reference code to obtain an initial vector and a reference vector respectively; and concatenating the reference vector and the initial vector to obtain the target vector; Among them, obtaining the target keywords in the input text and obtaining the target classification information of the target keywords include: obtaining a preconfigured keyword vocabulary, the keyword vocabulary including multiple keywords and classification information corresponding to the keywords; determining the target keywords of the input text according to the keyword vocabulary, and obtaining the target classification information of the target keywords in the input text; wherein, the keyword vocabulary is updated at preset time intervals.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the text classification method according to any one of claims 1 to 5 is implemented.

8. An electronic device, characterized in that: The electronic device comprises: one or more processors; and A memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the text classification method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for judging document correlation based on PLSA algorithm

    CN103678599A

  • Human body behavior recognition method based on global characteristics and sparse representation classification

    CN107784293A

  • A human body activity type classification method and system based on a long-short term memory neural network

    CN109948665A