Training method, device and electronic device for text category recognition model
By using the problem of low accuracy in judging business categories for merchants, the pre-trained text model for text mapping and keyword replacement methods is used to solve the problem of reducing accuracy of the model in learning invalid nicknames, and achieve higher recognition accuracy and speed.
Patent Information
- Application Number
- CN202311284093.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-28
- Publication Date
- 2025-04-04
AI Technical Summary
The method of judging merchant business categories in the prior art is low in accuracy, and the model may reduce the prediction accuracy when learning invalid nicknames.
By obtaining the sample data set, using the pre-trained text model for text mapping, classifying the sample text based on the prediction probability, obtaining the first and second types of sample texts, and replacing them with keywords to enrich the diversity of the training samples.
The accuracy of the text category recognition model is improved, so that the model can quickly and accurately identify keywords in the text, thereby improving the speed and accuracy of merchant nickname recognition business categories.
Smart Images

Figure CN119760131A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a training method, device and electronic device for a text category recognition model. Background Art
[0002] With the development of Internet technology, identifying merchants' real business categories has become extremely important in payment risk control.
[0003] However, in the related art, the accuracy of the method for determining the business category of a merchant is low. Summary of the invention
[0004] The embodiments of the present application provide a training method, device and electronic device for a text category recognition model, which can train a text category recognition model to accurately determine the business category of a merchant through the text category recognition model.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present invention provides a method for training a text category recognition model, the method comprising:
[0007] A sample data set is obtained, wherein the sample data set includes a plurality of sample texts; a pre-trained text model is used to perform text mapping processing on each of the sample texts, and a corresponding prediction probability of each of the sample texts is obtained; the prediction probability of the sample text is used to characterize the probability that the sample text is able to be identified as a text category; the plurality of sample texts are classified based on the prediction probability of each of the sample texts, and a first category of sample texts and a second category of sample texts are obtained; keyword replacement is performed on the first category of sample texts and the second category of sample texts, respectively, and a first category of keyword replacement texts and a second category of keyword replacement texts are obtained; and a plurality of the sample texts, the first category of keyword replacement texts and the second category of keyword replacement texts are used as training samples to perform model training on a text category recognition model to be trained, and a trained text category recognition model is obtained.
[0008] The present application embodiment provides a training device for a text category recognition model, comprising:
[0009] A data acquisition module is used to obtain a sample data set, wherein the sample data set includes multiple sample texts; a category prediction module is used to use a pre-trained text model to perform text mapping processing on each of the sample texts, and obtain a corresponding prediction probability for each of the sample texts; the prediction probability of the sample text is used to characterize the probability that the sample text is able to be identified as a text category; a text classification module is used to classify the multiple sample texts based on the prediction probability of each of the sample texts, and obtain a first category of sample texts and a second category of sample texts; a keyword replacement module is used to perform keyword replacement on the first category of sample texts and the second category of sample texts, respectively, and obtain a first category of keyword replacement texts and a second category of keyword replacement texts; a model training module is used to use the multiple sample texts, the first category of keyword replacement texts and the second category of keyword replacement texts as training samples to perform model training on a text category recognition model to be trained, and obtain a trained text category recognition model.
[0010] In the above scheme, the keyword replacement module is also used to determine the text type of the first category sample text and the text type of the second category sample text; according to the text type of the first category sample text, determine that the keywords in the first category sample text are the first category keywords; according to the text type of the second category sample text, determine that the keywords in the second category sample text are the second category keywords; perform keyword replacement on the first category keywords in the first category sample text to obtain the first category keyword replacement text; perform keyword replacement on the second category keywords in the second category sample text to obtain the second category keyword replacement text.
[0011] In the above scheme, the text type of the first category of sample text is valid text; the first category of keywords includes valid keywords and invalid keywords; the keyword replacement module is also used to obtain the first category of keyword replacement text by executing at least one of the following keyword replacement steps: determining similar keywords corresponding to the valid keywords, and using the similar keywords to replace the valid keywords in the first category of sample text to obtain the first category of keyword replacement text; randomly selecting an invalid word from a preset invalid word library to replace the invalid keyword in the first category of sample text.
[0012] In the above scheme, the text type of the second category sample text is invalid text; the second category keywords include at least one invalid keyword; the keyword replacement module is also used to randomly select an invalid word from a preset invalid word library to replace the first invalid keyword in the second category sample text, so as to obtain the second category keyword replacement text; or, randomly select an invalid word from a preset invalid word library to replace any invalid keyword in the second category sample text, so as to obtain the second category keyword replacement text.
[0013] In the above scheme, the text classification module is also used to determine, for any of the sample texts, when the predicted probability of the sample text is greater than a first probability threshold, the sample text as a first category of sample text; and when the predicted probability of the sample text is less than a second probability threshold, the sample text as a second category of sample text; and the first probability threshold is greater than the second probability threshold.
[0014] In the above scheme, the data acquisition module is also used to obtain multiple initial sample texts; perform text cleaning on the multiple initial sample texts according to the text content and text length of each of the initial sample texts to obtain multiple preprocessed sample texts; perform word segmentation on each of the preprocessed sample texts to obtain sample word segments of each of the preprocessed sample texts; perform text cleaning on the multiple preprocessed sample texts according to the word segmentation length of the sample word segmentation of each of the preprocessed sample texts to obtain the multiple sample texts that constitute the sample data set.
[0015] In the above scheme, the data acquisition module is also used to determine, for each of the initial sample texts, target text words belonging to a preset type in the initial sample text according to the text content of the initial sample text; delete the target text words to obtain a cleaned initial sample text; for any cleaned initial sample text, if the text length of the cleaned initial sample text is less than a text length threshold, delete the cleaned initial sample text to obtain multiple preprocessed sample texts.
[0016] In the above scheme, the data acquisition module is also used to delete the sample segmentation from any preprocessed sample text when the segmentation length of the sample segmentation of the preprocessed sample text is equal to the preset length, so as to obtain the multiple sample texts constituting the sample data set.
[0017] In the above scheme, the sample data set also includes a category label corresponding to each of the sample texts; the model training module is also used to input multiple sample texts, the first category keyword replacement text and the second category keyword replacement text as training samples into the text category recognition model to be trained; the sample prediction category of the sample text, the first replacement sample prediction category of the first category keyword replacement text and the second replacement sample prediction category of the second category keyword replacement text are predicted by the text category recognition model; the first category keyword replacement text and the second category keyword replacement text have the same category label as the first category sample text and the second category sample text respectively; matching loss calculation is performed according to the sample prediction category, the first replacement sample prediction category, the second replacement sample prediction category and the category label corresponding to each of the training samples to obtain a matching loss result; the parameters of the text category recognition model to be trained are updated based on the matching loss result until the matching loss result is less than a preset threshold, thereby obtaining a trained text category recognition model.
[0018] An embodiment of the present application provides an electronic device, comprising: a memory for storing computer-executable instructions; and a processor for implementing the training method of the text category recognition model provided in the embodiment of the present application when executing the computer-executable instructions stored in the memory.
[0019] An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing a training method for a text category recognition model provided in an embodiment of the present application when executed by a processor.
[0020] An embodiment of the present application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, the training method of the text category recognition model provided in the embodiment of the present application is implemented.
[0021] The embodiments of the present application have the following beneficial effects:
[0022] The embodiment of the present application first uses a pre-trained text model to obtain the predicted probabilities of multiple sample texts, selects the first category sample text and the second category sample text from the multiple sample texts according to the predicted probabilities, performs keyword replacement on the first category sample text and the second category sample text respectively, obtains the first category keyword replacement text and the second category keyword replacement text, and uses the first category sample text, the second category sample text, the first category keyword replacement text and the second category keyword replacement text as training samples to train the text category recognition model to be trained, thereby enriching the diversity of the training samples. Therefore, the text category recognition model trained by the embodiment of the present application can quickly and accurately recognize various keywords in the text, and then when the text category recognition model is applied in the scenario of merchant nickname recognition, the speed and accuracy of identifying business categories based on merchant nicknames can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a structural diagram of the training system architecture of the text category recognition model provided in the embodiment of the present application;
[0024] Figure 2 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0025] Figure 3A It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0026] Figure 3B It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0027] Figure 3C It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0028] Figure 3D It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0029] Figure 3E It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0030] Figure 3F It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0031] Figure 3G It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0032] Figure 4 It is a flowchart of a training method for a text category recognition model provided in an embodiment of the present application;
[0033] Figure 5 It is a flowchart of the training method of the text category recognition model provided in the embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0035] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0036] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0037] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0038] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0039] 1) Business category refers to the industry operated by a merchant or store, such as catering.
[0040] 2) Merchant nickname is an identifier used to represent the merchant's identity, such as the merchant manager's nickname on the communication software, the name of the physical store, etc.
[0041] 3) Bert (Bidirectional Encoder Representation from Transformers) model is a deep learning neural network model, which is an algorithm that adjusts the bidirectional encoding of the transformer model. The Bert model can map text to a high-dimensional vector representation and accurately capture semantic and contextual information.
[0042] 4) Term frequency-inverse document frequency (tf-idf) is a commonly used weighting technique used in information retrieval and text mining.
[0043] 5) word2vec is a technology in the field of natural language processing (NLP). It is the process of converting words into computable vectors.
[0044] Identifying the real business category of a merchant is extremely important in payment risk control. Among the many characteristics of a merchant, the nickname of the merchant manager is an important clue for effectively identifying the merchant. The nicknames of many merchant managers can directly identify the merchant's business category. For example, the nickname "SF Fishing Hotpot" can identify the merchant's business category as catering. The nicknames of some merchant managers cannot identify the merchant's business category, such as the nickname "Saibei Snow", which is considered an invalid nickname. There are two technical solutions for identifying business categories through nicknames: (1) Keyword matching of the merchant manager's nickname. Create a keyword vocabulary for each business category and match the merchant manager's nickname with keywords. If a keyword of a business category is matched, it is considered that the merchant manager's nickname corresponds to the business category. (2) Direct model training. All manager nicknames with merchant category labels are trained together.
[0045] However, the above technical solutions have the following shortcomings: (1) The keyword database of the business category needs to be maintained regularly, and the operation and maintenance cost is high. (2) It only relies on keywords and does not cover the nicknames of current merchant managers. (3) If the model is used for direct training, the model cannot learn enough information because there are many invalid names. At the same time, the learning of invalid nicknames may make the model's prediction accuracy lower.
[0046] Based on at least one of the above problems existing in the related art, the embodiments of the present application provide a training method, device, equipment, computer-readable storage medium and computer program product for a text category recognition model, which can quickly and accurately identify various keywords in the text, and then when the text category recognition model is applied to the scenario of merchant nickname recognition, the speed and accuracy of identifying business categories based on merchant nicknames can be improved. The following describes an exemplary application of an electronic device provided by the embodiments of the present application. The device provided by the embodiments of the present application can be implemented as various types of user terminals such as laptops, tablet computers, desktop computers, set-top boxes, mobile devices (e.g., mobile phones, portable music players, personal digital assistants, dedicated messaging devices, portable gaming devices), smart phones, smart speakers, smart watches, smart TVs, and vehicle-mounted terminals, and can also be implemented as servers. Below, an exemplary application when the device is implemented as a terminal or a server will be described.
[0047] See also Figure 1 , Figure 1 It is a schematic diagram of the architecture of the training system 100 for the text category recognition model provided in an embodiment of the present application. To implement a training application supporting a text category recognition model, the terminal 400 is connected to the server 200 via the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0048] When training the text category recognition model, the user can input a training operation for training the text category recognition model through the terminal 400. The terminal 400 generates a training request for the text category recognition model in response to the training operation, and sends the training request for the text category recognition model to the server 200 through the network 300. After receiving the training request for the text category recognition model, the server 200 responds to the training request for the text category recognition model and obtains a sample data set, which includes a plurality of sample texts; uses a pre-trained text model to perform text mapping processing on each sample text, and obtains a corresponding prediction probability of each sample text; the prediction probability of the sample text is used to characterize the probability that the sample text is a text category that can be identified; based on the prediction probability of each sample text, the plurality of sample texts are classified to obtain a first category sample text and a second category sample text; the first category sample text and the second category sample text are respectively replaced with keywords, and a first category keyword replacement text and a second category keyword replacement text are correspondingly obtained; the plurality of sample texts, the first category keyword replacement text and the second category keyword replacement text are used as training samples, and the text category recognition model to be trained is trained to obtain a trained text category recognition model.
[0049] In some embodiments, the terminal can also execute the training method of the text category recognition model of the embodiment of the present application, that is, the user can input the demand for training the text category recognition model through the terminal 400, and the terminal 400 performs the operation of training the text category recognition model in response to the demand, and obtains a sample data set, and the sample data set includes multiple sample texts; uses a pre-trained text model to perform text mapping processing on each sample text, and obtains a corresponding prediction probability for each sample text; classifies multiple sample texts based on the prediction probability of each sample text to obtain a first category of sample text and a second category of sample text; performs keyword replacement on the first category of sample text and the second category of sample text, respectively, to obtain a first category of keyword replacement text and a second category of keyword replacement text; uses multiple sample texts, the first category of keyword replacement text and the second category of keyword replacement text as training samples, and performs model training on the text category recognition model to be trained to obtain a trained text category recognition model.
[0050] In some embodiments, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal 400 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a car terminal, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0051] See also Figure 2 , Figure 2 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device is used to implement a training method for a text category recognition model, for example, the electronic device can be implemented as a terminal. Figure 2 The terminal 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the terminal 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not shown in FIG. Figure 2 Various buses are labeled as bus system 440 .
[0052] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0053] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0054] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0055] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0056] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0057] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0058] A network communication module 452, used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0059] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., display screen, speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripherals and displaying content and information);
[0060] The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions.
[0061] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 2 A training device 455 of a text category recognition model stored in a memory 450 is shown, which can be software in the form of a program and a plug-in, including the following software modules: a data acquisition module 4551, a category prediction module 4552, a text classification module 4553, a keyword replacement module 4554 and a model training module 4555. These modules are logical, so they can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be explained below.
[0062] In other embodiments, the device provided in the embodiments of the present application can be implemented in hardware. As an example, the device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the training method of the text category recognition model provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application specific integrated circuits (Application Specific Integrated Circuit, ASIC), digital signal processors (Digital Signal Processor, DSP), programmable logic devices (Programmable Logic Device, PLD), complex programmable logic devices (Complex Programmable Logic Device, CPLD), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other electronic components.
[0063] The training method of the text category recognition model provided in each embodiment of the present application can be executed by an electronic device, wherein the electronic device can be a server or a terminal, that is, the training method of the text category recognition model provided in each embodiment of the present application can be executed by a server, can be executed by a terminal, or can be executed through interaction between a server and a terminal.
[0064] See also Figure 3A , Figure 3Ais a flowchart of a training method for a text category recognition model provided in an embodiment of the present application, which will be combined with Figure 3A The steps shown are explained in detail, and the main body of the steps in Figure 3 is the server.
[0065] In step 101, a sample data set is obtained. The sample data set includes a plurality of sample texts.
[0066] In an embodiment of the present application, the sample text is historical text data with known category labels that have been cleaned using preset rules. The sample text can be a unique identification identifier (ID, Identity document) used to refer to the target object. Among them, the target object is an object that needs to be identified by category. The category label is the text category information of the target object corresponding to the sample text. The sample data set may include multiple sample texts and the category label corresponding to each sample text.
[0067] For example, in the scenario where the text category recognition model is applied to determine the business category of a merchant based on the merchant nickname, the sample text may be the remaining merchant nicknames after the nicknames of merchants whose business categories cannot be determined are filtered out using preset rules. The category label of the sample text is the business category corresponding to the merchant nickname.
[0068] In some embodiments, see Figure 3B , Figure 3A The illustrated step 101 may be implemented by following steps 1011 to 1014, which are described in detail below.
[0069] In step 1011, a plurality of initial sample texts are obtained.
[0070] In some embodiments, the initial sample text is historical text data of a known category label. Exemplarily, the initial sample text is the original nickname of the merchant.
[0071] In step 1012, text cleaning is performed on the multiple initial sample texts according to the text content and text length of each initial sample text to obtain multiple pre-processed sample texts.
[0072] In the embodiment of the present application, the text content includes each word or phrase constituting the initial sample text, and the text length is the number of words in the text content, that is, the number of characters. For each initial sample text, based on the text content and text length of the initial sample text, the words or phrases in the text content that have no impact on the business category can be filtered out to obtain a preprocessed sample text.
[0073] In some embodiments, see Figure 3C , Figure 3B The illustrated step 1012 may be implemented by following steps 10121 to 10123, which are described in detail below.
[0074] In step 10121, for each initial sample text, according to the text content of the initial sample text, determine the target text words in the initial sample text that belong to a preset type.
[0075] In some embodiments, the target text words of the preset type are words that do not affect the business category as preset. It should be noted that the embodiments of the present application do not limit the preset type.
[0076] Exemplarily, taking the initial sample text as the merchant nickname as an example, the target text words of the preset type may include special symbols, English, numbers, and stop words (such as "de", "di") and the like.
[0077] In step 10122, delete the target text words to obtain the initial sample text after cleaning.
[0078] In the embodiments of the present application, after determining the target text words, the target text words in each initial sample text can be directly deleted to obtain the initial sample text after cleaning. For example, if the initial sample text is "Xue's Tea" and the target text word is "de", the initial sample text after cleaning is "Xue Tea".
[0079] In step 10123, for any initial sample text after cleaning, when the text length of the initial sample text after cleaning is less than the text length threshold, delete the initial sample text after cleaning to obtain multiple preprocessed sample texts.
[0080] In some embodiments, for any initial sample text after cleaning, the text length of the initial sample text after cleaning can be identified and judged to obtain a length judgment result. When the length judgment result indicates that the text length of the initial sample text after cleaning is less than the text length threshold, it is considered that the initial sample text after cleaning cannot be used for text category identification, and the initial sample text after cleaning is deleted. Or, when the length judgment result indicates that the text length of the initial sample text after cleaning is greater than or equal to the text length threshold, the initial sample text after cleaning is retained. The text length of the initial sample text after cleaning can be obtained by identifying the number of characters in the text content of the initial sample text after cleaning. If the number of characters is 3, the text length of the initial sample text after cleaning is 3.
[0081] It should be noted that the embodiments of the present application do not specifically limit the text length threshold, which can be set according to actual situations.
[0082] Exemplarily, the merchant nickname may include the real name of the merchant manager or other names written by the merchant manager. The real name of the merchant manager cannot be used to determine the business category, so the real name of the merchant manager needs to be filtered out from multiple cleaned initial sample texts. Generally, the real name is 2 characters or 3 characters. Taking the text length threshold as 4, the cleaned initial sample texts with a text length less than 4 can be deleted to obtain multiple preprocessed sample texts. Taking the cleaned initial sample text "Zhang A" as an example, the number of characters is 2, that is, the text length is 2, which is less than the text length threshold of 4. It is considered that "Zhang A" is a real name and cannot be used to determine the business category, so it is deleted.
[0083] The embodiment of the present application deletes the initial sample text that cannot be identified by text category based on the text content and text length, obtains preprocessed sample text, greatly reduces meaningless data, and can improve the training speed and accuracy of the text category recognition model.
[0084] In step 1013, each preprocessed sample text is segmented to obtain sample segmentations of each preprocessed sample text.
[0085] Continue to see Figure 3B In the embodiment of the present application, for each preprocessed sample text, the text content of the preprocessed sample text can be segmented so that the text content includes one or more sample segmented words. For example, after the preprocessed sample text "Nayuki Tea" is segmented, the sample segmented words "Nayuki" and "tea" can be obtained.
[0086] It should be noted that the embodiment of the present application does not limit the means of word segmentation. It only needs to be able to divide the text into texts consisting of a small number of characters. For example, word segmentation packages can be used for word segmentation.
[0087] In step 1014, text cleaning is performed on a plurality of preprocessed sample texts according to the segmentation length of a sample segment of each preprocessed sample text, to obtain a plurality of sample texts constituting a sample data set.
[0088] In the embodiment of the present application, for each preprocessed sample text, the word segmentation length of the sample word segmentation in the preprocessed sample text can be judged to obtain a corresponding judgment result. According to the judgment result, the corresponding sample word segmentation in each preprocessed sample text is deleted to obtain multiple sample texts constituting the sample data set.
[0089] In some embodiments, Figure 3B The illustrated step 1014 can be implemented by the following steps, which are described in detail below.
[0090] For any preprocessed sample text, when the word segmentation length of the sample word segmentation in the preprocessed sample text is equal to the preset length, delete the sample word segmentation from the preprocessed sample text to obtain multiple sample texts that make up the sample dataset.
[0091] In the embodiments of the present application, for each preprocessed sample text, the word segmentation length of the sample word segmentation in the preprocessed sample text can be judged to obtain a corresponding judgment result. If the preprocessed sample text only includes one sample word segmentation, and the judgment result corresponding to the sample word segmentation indicates that the word segmentation length of the sample word segmentation is equal to the preset length, it is considered that the preprocessed sample text cannot identify the text category, and the preprocessed sample text is deleted. Or, for each preprocessed sample text, if the preprocessed sample text includes multiple sample word segmentations, and among them, there is a sample word segmentation whose judgment result indicates that the word segmentation length of the sample word segmentation is equal to the preset length, the sample word segmentation cannot identify the text category, and the sample word segmentation is deleted from the preprocessed sample text; or, when the judgment result indicates that the word segmentation length of the sample word segmentation is not equal to the preset length, the sample word segmentation is retained. The word segmentation length of the sample word segmentation can be the number of characters of the sample word segmentation.
[0092] It should be noted that the embodiments of the present application do not make specific limitations on the preset length, and it can be set according to the actual situation.
[0093] Exemplarily, taking the preprocessed sample text as the merchant nickname, the merchant nickname can include four-character idioms, and the four-character idioms cannot identify the business category of the merchant. And the sample word segmentation obtained after segmenting the four-character idiom is still the four-character idiom. The preset length can be set to 4, and the word segmentation length of each sample word segmentation is judged. If the word segmentation length is equal to 4, it is considered that the sample word segmentation is a four-character idiom and it is deleted. For example, for the preprocessed sample text "beaming with joy Nai Xue Tea", the sample word segmentations are "beaming with joy", "Nai Xue", and "Tea". The word segmentation length of the sample word segmentation "beaming with joy" is 4. Therefore, delete the sample word segmentation "beaming with joy" from the preprocessed sample text "beaming with joy Nai Xue Tea" to obtain the sample text "Nai Xue Tea". The sample text "Nai Xue Tea" includes two sample word segmentations, "Nai Xue" and "Tea".
[0094] The embodiments of the present application delete the sample word segmentations that cannot be used for text category recognition from the preprocessed sample text through the word segmentation length of the sample word segmentations to obtain multiple sample texts, reducing the data volume of the sample texts to improve the training speed of the text category recognition model.
[0095] In step 102, use the pre-trained text model to perform text mapping processing on each sample text to correspondingly obtain the prediction probability of each sample text.
[0096] The predicted probability of the sample text is used to represent the probability that the sample text can be identified as a text category.
[0097] Continue to see Figure 3A In some embodiments, for each sample text, the sample text may be input into a pre-trained text model, and the probability of the sample text under each text category is obtained through the pre-trained text model. The maximum value of the probability of the sample text under each text category is used as the predicted probability of the sample text.
[0098] It should be noted that the embodiments of the present application do not limit the pre-trained text model, as long as it can classify and predict the sample text, and can be a neural network model, a deep learning model, etc. Exemplarily, the pre-trained text model can be a Bert model.
[0099] Exemplarily, the pre-trained Bert model pre-sets three text categories: milk tea, hot pot, and barbecue. The sample text "Nayuki Tea" is input into the pre-trained Bert model, and the probability that the text category corresponding to the sample text "Nayuki Tea" is "milk tea" is 0.7, the probability of "hot pot" is 0.2, and the probability of "barbecue" is 0.1. The probability of 0.7 that the text category corresponding to the sample text "Nayuki Tea" is "milk tea" is used as the predicted probability of the sample text "Nayuki Tea".
[0100] In step 103, a plurality of sample texts are classified based on the prediction probability of each sample text to obtain first-category sample texts and second-category sample texts.
[0101] In the embodiment of the present application, multiple sample texts can be classified based on a preset probability threshold and the predicted probability of each sample text to obtain corresponding first-class sample texts and second-class sample texts. The predicted probabilities of the first-class sample texts and the second-class sample texts are different.
[0102] In some embodiments, see Figure 3D , Figure 3A The illustrated step 103 can be implemented by following the steps 1031 to 1032, which are described in detail below.
[0103] In step 1031, for any sample text, when the predicted probability of the sample text is greater than a first probability threshold, the sample text is determined as a first type of sample text.
[0104] It should be noted that the first probability threshold is not limited in the present embodiment and can be set according to the actual application scenario. For example, the first probability threshold can be 0.8, and the sample text corresponding to the predicted probability greater than 0.8 is regarded as the first type of sample text.
[0105] In step 1032, when the predicted probability of the sample text is less than the second probability threshold, the sample text is determined as a second type of sample text. The first probability threshold is greater than the second probability threshold.
[0106] In the embodiment of the present application, the first probability threshold is greater than the second probability threshold. The samples with predicted probabilities less than the second probability threshold can be used as the second type of sample texts, so that the first type of sample texts and the second type of sample texts have no intersection. The sample texts whose predicted probabilities do not meet the requirements of being greater than the first probability threshold or less than the second probability threshold are deleted.
[0107] It should be noted that the second probability threshold is not limited in the present embodiment and can be set according to the actual application scenario. For example, the second probability threshold can be 0.3, and the sample text corresponding to the predicted probability less than 0.3 is regarded as the second type of sample text.
[0108] The embodiment of the present application classifies and screens a plurality of sample texts to obtain a first category of sample texts and a second category of sample texts through a first probability threshold and a second probability threshold, and uses the first probability threshold and the second probability threshold as training samples to perform model training on a text category recognition model to be trained, thereby improving the accuracy of the trained text category recognition model.
[0109] In step 104, keyword replacement is performed on the first type of sample text and the second type of sample text respectively, and first type of keyword replacement text and second type of keyword replacement text are obtained correspondingly.
[0110] Continue to see Figure 3A In the embodiment of the present application, the first type of sample text includes at least one sample segmentation word, and the second type of sample text includes at least one sample segmentation word. The keyword includes one or more sample segmentations. For the first type of sample text, a keyword is selected from the sample segmentations in the first type of sample text to be replaced, and the first type of keyword replacement text is obtained. For the second type of sample text, a keyword is selected from the sample segmentations in the second type of sample text to be replaced, and the second type of keyword replacement text is obtained.
[0111] In some embodiments, see Figure 3E , Figure 3A The illustrated step 104 may be implemented by following steps 1041 to 1045, which are described in detail below.
[0112] In step 1041 , the text type of the first type of sample text and the text type of the second type of sample text are determined.
[0113] In the embodiment of the present application, the text type of the first type of sample text and the text type of the second type of sample text may be determined based on the prediction probability.
[0114] For example, the text type of the first type of sample text with a predicted probability greater than 0.8 is valid text, and the text category corresponding to the valid text can be obtained through the pre-trained Bert model. The text type of the second type of sample text with a predicted probability less than 0.3 is invalid text, and the text category corresponding to the invalid text cannot be obtained through the pre-trained Bert model.
[0115] In step 1042, according to the text type of the first category sample text, the keywords in the first category sample text are determined to be first category keywords.
[0116] In the embodiment of the present application, if the text type of the first type of sample text is valid text, the first type of keywords in the first type of sample text includes valid keywords and invalid keywords. If the text type of the first type of sample text is invalid text, the first type of keywords in the first type of sample text are invalid keywords.
[0117] In step 1043, the keywords in the second category of sample texts are determined to be second category keywords according to the text type of the second category of sample texts.
[0118] In the embodiment of the present application, if the text type of the second type of sample text is valid text, the second type of keywords in the second type of sample text includes valid keywords and invalid keywords. If the text type of the second type of sample text is invalid text, the first type of keywords in the second type of sample text are invalid keywords. The text type of the second type of sample text is different from the text type of the first type of sample text.
[0119] In step 1044, keyword replacement is performed on the first category keywords in the first category sample text, and corresponding first category keyword replacement text is obtained.
[0120] In the embodiment of the present application, for each first-category sample text, after determining the first-category keywords in the first-category sample text, the first-category keywords can be replaced with the pre-acquired keywords to obtain the first-category keyword replacement text corresponding to the first-category sample text. The number of first-category keyword replacement texts corresponding to the first-category sample text can be one or more.
[0121] In some embodiments, see Figure 3F , Figure 3E The shown step 1044 can be implemented by following the steps 10441 to 10442, which are described in detail below.
[0122] The text type of the first type of sample text is valid text. The first type of keywords includes valid keywords and invalid keywords.
[0123] By performing at least one of the following keyword replacement steps, a first-category keyword replacement text is obtained:
[0124] In step 10441, similar keywords corresponding to the effective keywords are determined, and the effective keywords in the first type of sample text are replaced with the similar keywords.
[0125] In the embodiment of the present application, the text type of the first category sample text is valid text, that is, each first category sample text obtains a corresponding text category after being pre-trained by the text model. The first category sample texts under the same text category are subjected to tf-idf processing, and multiple valid keywords are screened out from the sample segmentation in each first category sample text. The process of tf-idf processing is as follows: first calculate the word frequency TF, then calculate the inverse document frequency IDF, and finally calculate tf-idf, where tf-idf is the product of the word frequency TF and the inverse document frequency IDF. Sort the sample segmentation in each first category sample text according to the size of tf-idf, and select a preset number of sample segmentations with the top ranking as valid keywords. It should be noted that the formula for tf-idf processing is not repeated in the embodiment of the present application.
[0126] In some embodiments, TextRank (a graph-based ranking algorithm for text) may be used instead of tf-idf processing to extract keywords.
[0127] For example, tf-idf processing can be performed on the nicknames of merchants whose business category is predicted to be "tea". There are 500 sample segmentations such as "white tea", "black tea", and "Nayuki" in the nicknames of merchants whose business category is "tea". If "white tea" appears 40 times in total, the word frequency TF of the sample segmentation "white tea" is 40 / 500, and the inverse document frequency IDF = log(500 / 40+1). The sample segmentation "white tea" tf-idf = 40 / 500×log(500 / 40+1). By analogy, the tf-idf of each sample segmentation is calculated, and sorted by size, and the first 500 sample segmentations are selected as effective keywords. For example, sample segmentations such as 'styling', 'supermarket', and 'hotel' are all effective keywords, which can directly reflect the business category of the merchant.
[0128] After determining the effective keywords, word2vec can be used to obtain multiple similar keywords of the effective keywords. Word2vec can convert effective keywords into effective keyword vectors. In the preset keyword vector space, the vector closest to the effective keyword vector is selected as the similar keyword vector, which is converted into similar keywords by word2vec. Exemplarily, two similar keywords of each effective keyword can be obtained. For example, the similar keywords of "styling" are "hairstyle", "haircut", etc.
[0129] For the first type of sample text with valid keywords, a similar keyword to the valid keyword can be randomly used to replace the valid keyword to obtain the first type of keyword replacement text. For example, after the merchant nickname 'Han Shang Style' is segmented, the sample segmentation is 'Han Shang, Style', where 'Style' is a valid keyword, and a similar keyword can be randomly selected for replacement, and 'Style' can be replaced with 'Hair Style'. The first type of keyword replacement text of the first type of sample text 'Han Shang, Style' is 'Han Shang, Hair Style'.
[0130] In step 10442, an invalid word is randomly selected from a preset invalid word library to replace the invalid keywords in the first type of sample text.
[0131] In the embodiment of the present application, for the first type of sample text with valid keywords, the remaining sample word segments in the first type of sample text except the valid keywords are all invalid keywords. The preset invalid word library is constructed by performing tf-idf processing on the second type of sample text and selecting a preset number of sample word segments with low scores. For example, 'A place', 'Spring and Autumn', 'International', and 'Beautiful' are mostly some adjectives, place names, and some meaningless nouns, which are invalid words.
[0132] For the first type of sample text with valid keywords, an invalid word can be randomly selected from the preset invalid word library to replace the invalid keyword to obtain the first type of keyword replacement text. For example, after the merchant nickname 'Han Shang Style' is segmented, the sample segmentation is 'Han Shang, Style', where 'Han Shang' is an invalid keyword, and the invalid word 'A Land' can be used to replace it to obtain the first type of keyword replacement text 'A Land, Style'.
[0133] In some embodiments, if there are no valid keywords in the first category of sample texts, they are not replaced and are not used as training samples for model training of the text category recognition model to be trained.
[0134] In some embodiments, the number of first-category keyword replacement texts is two. Both first-category keyword replacement texts can be obtained only through step 10441. A similar keyword of an effective keyword is randomly selected to replace the effective keyword to obtain a first-category keyword replacement text; another similar keyword of the effective keyword is then selected to replace the effective keyword to obtain another first-category keyword replacement text.
[0135] In some embodiments, the number of first-category keyword replacement texts is two. Both first-category keyword replacement texts can be obtained only through step 10442. An invalid word is randomly selected from a preset invalid word library, and the invalid keyword is replaced to obtain a first-category keyword replacement text; then a different invalid word is randomly selected from the preset invalid word library, and the invalid keyword is replaced to obtain another first-category keyword replacement text.
[0136] In some embodiments, the number of first-category keyword replacement texts is two. The two first-category keyword replacement texts are obtained respectively through step 10441 and step 10442. A similar keyword of the effective keyword is randomly selected to replace the effective keyword to obtain a first-category keyword replacement text; an invalid word is randomly selected from a preset invalid word library to replace the invalid keyword to obtain another first-category keyword replacement text.
[0137] The embodiment of the present application obtains a first category of keyword replacement text by replacing valid keywords with invalid keywords in valid text, thereby enriching the training samples of the text category recognition model to be trained, so that the trained text category recognition model can more accurately identify valid keywords and invalid keywords, thereby improving the accuracy of text category recognition.
[0138] In step 1045, keyword replacement is performed on the second category keywords in the second category sample text to obtain corresponding second category keyword replacement text.
[0139] Continue to see Figure 3E In an embodiment of the present application, for each second-category sample text, after determining the second-category keywords in the second-category sample text, the second-category keywords can be replaced with the pre-acquired keywords to obtain the second-category keyword replacement text corresponding to the second-category sample text. The number of second-category keyword replacement texts corresponding to the second-category sample text can be one or more. The number of second-category keyword replacement texts corresponding to the second-category sample text is equal to the number of first-category keyword replacement texts corresponding to the first-category sample text.
[0140] In some embodiments, Figure 3E The illustrated step 1045 can be implemented by the following steps, which are described in detail below.
[0141] The text type of the second type of sample text is invalid text. The second type of keywords includes at least one invalid keyword.
[0142] An invalid word is randomly selected from a preset invalid word library to replace the first invalid keyword in the second category sample text to obtain the second category keyword replacement text; or, an invalid word is randomly selected from a preset invalid word library to replace any invalid keyword in the second category sample text to obtain the second category keyword replacement text.
[0143] In the embodiment of the present application, the text type of the second type of sample text is invalid text, that is, each of the second type of sample text cannot obtain the corresponding text category after the pre-trained text model. As invalid text, the second type of sample text does not involve valid keywords, so each sample word in the second type of sample text is an invalid keyword.
[0144] Perform tf-idf processing on each second category sample text, and select a preset number of sample segmentations with low tf-idf scores from the sample segmentations in each second category sample text as invalid words. The tf-idf processing process is similar to the processing process of the aforementioned valid keywords, and the embodiments of the present application will not be repeated here. The number of invalid words can be the same as the number of valid keywords, or it can be different.
[0145] For each second-category sample text, an invalid word can be randomly selected from a preset invalid word library to replace the first invalid keyword in the second-category sample text, thereby obtaining a first-category keyword replacement text. Alternatively, an invalid word can be randomly selected from a preset invalid word library to replace a random invalid keyword in the second-category sample text, thereby obtaining a second-category keyword replacement text.
[0146] For example, if the first-category keyword replacement text of the merchant nickname 'Han Shang Style' includes two replacement texts 'Han Shang, Style' and 'Han Shang, Hairstyle', then the number of the second-category keyword replacement texts must be consistent with the number of the first-category keyword replacement texts. The second-category keyword replacement text of the second-category sample text 'Starry Sky, Wu Ping' can be 'A Land, Wu Ping' and 'Starry Sky, Nao'.
[0147] The embodiment of the present application replaces invalid keywords with invalid text to obtain the second type of keyword replacement text, thereby enriching the training samples of the text category recognition model to be trained, so that the trained text category recognition model can more accurately identify invalid keywords and improve the accuracy of text category recognition. At the same time, the number of the second type of keyword replacement text must be consistent with the number of the first type of keyword replacement text, ensuring the consistency of the text category recognition model to be trained.
[0148] In step 105, a plurality of sample texts, first-category keyword replacement texts, and second-category keyword replacement texts are used as training samples to perform model training on a text category recognition model to be trained, thereby obtaining a trained text category recognition model.
[0149] Continue to see Figure 3A In an embodiment of the present application, multiple sample texts, first-category keyword replacement texts, and second-category keyword replacement texts can be used as training samples and input into a text category recognition model to be trained. The category label corresponding to each sample text is used as a label for verifying the predicted category of the training sample. The text category recognition model to be trained is trained to obtain a trained text category recognition model.
[0150] In some embodiments, see Figure 3G , Figure 3A The illustrated step 105 may be implemented by following steps 1051 to 1054, which are described in detail below.
[0151] The sample data set also includes the category label corresponding to each sample text;
[0152] In step 1051, a plurality of sample texts, first-category keyword replacement texts, and second-category keyword replacement texts are used as training samples and input into a text category recognition model to be trained.
[0153] In some embodiments, if the first sample text is a valid text, for each first sample text, the first sample text and the first-category keyword replacement text corresponding to the first sample text can be input as training samples to the text category recognition model to be trained. The first-category keyword replacement text corresponding to the first sample text can include the first-category keyword replacement text obtained by replacing valid keywords and the first-category keyword replacement text obtained by replacing invalid keywords.
[0154] In some embodiments, if the second sample text is invalid text, for each second sample text, the second sample text and the invalid word corresponding to the second sample text can be replaced with two second-category keyword replacement texts, which can be input together as training samples into the text category recognition model to be trained.
[0155] In some embodiments, the text category recognition model to be trained may be a model constructed based on the Bert text model.
[0156] In step 1052, the sample prediction category of the sample text, the first replacement sample prediction category of the first category keyword replacement text, and the second replacement sample prediction category of the second category keyword replacement text are predicted by the text category recognition model; the first category keyword replacement text and the second category keyword replacement text have the same category label as the first category sample text and the second category sample text, respectively.
[0157] In some embodiments, if the first sample text is a valid text, the sample prediction category of the first sample text, the first replacement sample prediction category of the first category keyword replacement text obtained by replacing valid keywords, and the first replacement sample prediction category of the first category keyword replacement text obtained by replacing invalid keywords can be predicted by a text category recognition model. The category label of the valid text is a real text category. For example, the category label of a valid merchant nickname is the real business category of the merchant. The category label of an invalid text cannot be determined. The category label of the first category keyword replacement text is the same as the category label of the first sample text, and both are real text categories. The category label of the second category keyword replacement text is the same as the category label of the second sample text, and both are impossible to determine.
[0158] In step 1053, a matching loss is calculated based on the sample prediction category, the first replacement sample prediction category, the second replacement sample prediction category, and the category label corresponding to each training sample to obtain a matching loss result.
[0159] In the embodiment of the present application, if the training sample in the text category recognition model to be trained is the first sample text, different matching losses can be calculated based on the sample prediction category of the first sample text and the category label of the first sample text, the first replacement sample prediction category of the first category keyword replacement text corresponding to the first sample text and the category label of the first sample text, and the matching loss result can be calculated based on the different matching losses.
[0160] If the training sample in the text category recognition model to be trained is the second sample text, different matching losses can be calculated based on the sample prediction category of the second sample text and the category label of the second sample text, the second replacement sample prediction category of the second category keyword replacement text corresponding to the second sample text and the category label of the second sample text, and the matching loss result can be calculated based on the different matching losses.
[0161] In some embodiments, if the input training sample is a first sample text with a prediction probability greater than 0.8, at this time, the first sample text is a valid text. The number of first-category keyword replacement texts corresponding to the first sample text can be two: first-category keyword replacement text A and first-category keyword replacement text B. The first matching loss loss1 is calculated based on the sample prediction category of the first sample text and the category label of the first sample text, the second matching loss loss2 is calculated based on the first replacement sample prediction category of the first-category keyword replacement text A and the category label of the first sample text, and the third matching loss loss3 is calculated based on the first replacement sample prediction category of the first-category keyword replacement text B and the category label of the first sample text. The calculated first matching loss loss1, second matching loss loss2 and third matching loss loss3 are added, and the average of the added sum is taken to obtain the matching loss result.
[0162] In some embodiments, the first-category keyword replacement text A can be obtained by replacing effective keywords in the first sample text with similar keywords a, and the first-category keyword replacement text B can be obtained by replacing effective keywords in the first sample text with similar keywords b.
[0163] In some embodiments, the first-category keyword replacement text A may be obtained by replacing valid keywords in the first sample text with similar keywords a, and the first-category keyword replacement text B may be obtained by replacing invalid keywords in the first sample text with invalid words.
[0164] In some embodiments, the first-category keyword replacement text A may be obtained by replacing invalid keywords in the first sample text with invalid words, and the first-category keyword replacement text B may be obtained by replacing invalid keywords in the first sample text with other invalid words.
[0165] In some embodiments, if the input training sample is a second sample text with a prediction probability less than 0.3, at this time, the second sample text is an invalid text. The number of second-category keyword replacement texts corresponding to the second sample text can be two: second-category keyword replacement text C and second-category keyword replacement text D. The first matching loss loss1 is calculated based on the sample prediction category of the second sample text and the category label of the second sample text, the second matching loss loss2 is calculated based on the second replacement sample prediction category of the second-category keyword replacement text C and the category label of the second sample text, and the third matching loss loss3 is calculated based on the second replacement sample prediction category of the second-category keyword replacement text D and the category label of the second sample text. The calculated first matching loss loss1, second matching loss loss2 and third matching loss loss3 are added, and the average of the added sum is taken to obtain the matching loss result.
[0166] In some embodiments, the second-category keyword replacement text C can be obtained by replacing the first invalid keyword or a random invalid keyword in the first sample text with an invalid word c, and the second-category keyword replacement text D can be obtained by replacing the first invalid keyword or a random invalid keyword in the second sample text with another invalid word d.
[0167] The embodiment of the present application adds training samples after keyword replacement so that each training sample can output a category by the text category recognition model to be trained. Each output category will generate a matching loss with the real category label, enriching the source of matching loss, thereby enabling the trained text category recognition model to more accurately identify valid words and invalid words, thereby improving the accuracy of text type recognition.
[0168] In step 1054, the parameters of the text category recognition model to be trained are updated based on the matching loss result until the matching loss result is less than a preset threshold, thereby obtaining a trained text category recognition model.
[0169] In the embodiment of the present application, reverse iterative propagation can be performed based on the matching loss result, and the parameters of the text category recognition model to be trained can be continuously updated and learned until the matching loss result is less than a preset threshold, thereby obtaining a trained text category recognition model. It should be noted that the embodiment of the present application does not limit the preset threshold. During the training process of the text category recognition model, the values of the three matching losses should become closer and closer and smaller, and the matching loss result should also become smaller and smaller.
[0170] The embodiment of the present application uses a pre-trained text model to obtain the predicted probabilities of multiple sample texts, selects the first category sample text and the second category sample text from the multiple sample texts according to the predicted probabilities, performs keyword replacement on the first category sample text and the second category sample text respectively, obtains the first category keyword replacement text and the second category keyword replacement text, and uses the first category sample text, the second category sample text, the first category keyword replacement text and the second category keyword replacement text as training samples to train the text category recognition model to be trained, thereby enriching the diversity of the training samples. Therefore, the text category recognition model trained by the embodiment of the present application can quickly and accurately recognize various keywords in the text, and then when the text category recognition model is applied in the scenario of merchant nickname recognition, the speed and accuracy of identifying business categories based on merchant nicknames can be improved.
[0171] The following is an explanation of an exemplary application of an embodiment of the present application in a practical application scenario.
[0172] The embodiment of the present application is implemented in the scenario of identifying the business category of the merchant nickname. Figure 4 The flowchart of the training method of the text category recognition model provided in the embodiment of the present application is as follows. Figure 4As shown in the figure: 1) Nickname text processing. First, obtain the merchant manager's nickname (initial sample text). The merchant manager's nickname includes the manager's real name and other names chosen by the manager. The manager's real name cannot be used to judge the business category. Therefore, it is necessary to clean the text of the merchant manager's nickname. The specific cleaning process is as follows: Initially clean the text of the merchant manager's nickname, removing special symbols, English, numbers, stop words, etc. (cleaned initial sample text). After cleaning, first delete the merchant manager's nicknames with a length <= 3, as these nicknames are considered the manager's real names, such as 'Sun A'. For the remaining merchant manager's nicknames (preprocessed sample text), perform word segmentation. At the same time, it is found that a large number of merchant manager's nicknames are four-character idioms, such as 'beaming with joy', and these idioms cannot identify the merchant's business category and are considered invalid names. If the length of the nickname remains 4 after word segmentation for the remaining merchant manager's nicknames, it is considered a four-character idiom. In both of the above cases, rules are used to first select the merchant manager's nicknames for which the business category cannot be judged, and these nicknames are not put into the initial version of the nickname model for training. 2) Nickname keyword library generation. Put the merchant manager's nicknames (sample text) obtained in step 1) into an initial version of a nickname model (text model) for training. If the prediction probability of the initial version of the nickname model is greater than 0.8, it is considered that the initial version of the nickname model can learn the business category from these merchant manager's nicknames. Perform tf-idf processing on these merchant manager's nicknames, and 500 words with relatively high scores can be selected as valid nickname keywords (valid keywords), such as'styling','supermarket', 'hotel', etc. These words can directly reflect the merchant's business category. Then use word2vec to select 2 similar words (similar keywords) for these valid nickname keywords. For example, the similar words for'styling' are 'hairstyle' and 'haircut'. Each valid nickname keyword has 2 similar words. If the prediction probability of the initial version of the nickname model is less than 0.3, it is considered that the initial version of the nickname model cannot learn the business category from these merchant manager's nicknames. Perform tf-idf processing on these merchant manager's nicknames, and 500 words with relatively low scores can be selected as invalid nickname keywords (invalid words). For example, 'A place', 'Spring and Autumn', 'International', 'Beautiful' are mostly adjectives, place names, and some meaningless nouns. 3) Keyword replacement of the nickname, that is, synonym replacement of the nickname. The merchant manager's nicknames (valid text) with a prediction probability greater than 0.8 and the merchant manager's nicknames (invalid text) with a prediction probability less than 0.3 of the initial version of the nickname model will undergo a second training.For the predicted probability greater than 0.8 and less than 0.3, the effective nickname keyword replacement can be performed to obtain the effective keyword replacement nickname. For example, the nickname 'Han Shang Style' is 'Han Shang, Style' after word segmentation. 'Styling' is a valid word, and a similar word can be randomly selected for replacement. 'Styling' can be replaced with 'hairstyle', and the effective keyword replacement nickname of 'Han Shang, Style' is 'Han Shang, Hairstyle'. Then the invalid word replacement is performed to obtain the invalid keyword replacement nickname. 'Han Shang, Style' is an invalid word and can be replaced with 'A place', so the invalid keyword replacement nickname of 'Han Shang, Style' is 'A place, Style'. For the merchant manager nickname with a predicted probability less than 0.3, because it does not involve effective nickname keywords, only the invalid nickname keyword replacement is performed. The first word or character after word segmentation is uniformly replaced, and an invalid nickname keyword is randomly selected from the invalid word library for replacement. For example, the invalid keyword replacement nickname of 'Starry Sky, Wu Ping' can be 'A place, Wu Ping'. In order to ensure the uniformity of the model. The predicted probability is less than 0.3 and there are two invalid keyword replacement nicknames. 4) Final version nickname model construction. The category labels with a predicted probability greater than 0.8 of the initial version nickname model are the real business categories of the merchants, and the category labels with a predicted probability less than 0.3 of the initial version nickname model are undetermined. The unreplaced merchant manager nickname is used as the original nickname, and the replaced invalid keyword replacement nickname and the valid keyword replacement nickname are used as training samples of the final version nickname model, and input into the final version nickname model (text category recognition model to be trained). The final version nickname model is based on the BERT text model. The constructed model. Figure 5 Schematic diagram of the training process of the effective final version nickname model when the original nickname is a merchant manager nickname whose prediction probability of the initial version nickname model is greater than 0.8. Figure 5As shown in the figure, the source of loss is enriched on the basis of the original loss matching loss (the difference between the original nickname prediction category and the real category label). The nicknames replaced by valid keywords and the nicknames replaced by invalid keywords are added. Each nickname can output a predicted category (predict score) by the final version nickname model. The predicted category (predict score) can be expressed as a probability value. Each predicted category and the real category label (true label) will generate a loss. The process of training the final version nickname model is the process of continuously reducing the loss. In this training process, there are three sources of loss, namely, loss1, loss2 and loss3 between the original nickname, the nickname replaced by valid keywords, the nickname replaced by invalid keywords and the real category label. The average of loss1, loss2 and loss3 is finally taken to obtain avg-loss (matching loss result). The final loss result avg-loss is used for reverse iterative propagation to continuously update the parameters of the final version nickname model. If the final version nickname model is effectively trained, loss1, loss2 and loss3 should be closer and closer and smaller, so that the final version nickname model can more accurately identify valid words and invalid words. The predicted category (predict score), matching losses loss1, loss2 and loss3, and matching loss result av g-loss can respectively satisfy the following formulas (1) to (7).
[0173] predictscore1 = softmax(classifier(BERT(x1))) Formula (I)
[0174] predictscore2 = softmax(classifier(BERT(x2))) Formula (II)
[0175] predictscore3=softmax(classifier(BERT(x3))) formula (3)
[0176]
[0177]
[0178]
[0179] avg loss =avg(loss1+loss2+loss3) formula (7)
[0180] Among them, predictscore1 is the predicted category obtained by the output of the final version nickname model for the original nickname, predictscore2 is the predicted category obtained by the output of the final version nickname model for the nickname replaced by valid keywords, and predictscore3 is the predicted category obtained by the output of the final version nickname model for the nickname replaced by invalid keywords; Bert(x1) is the Bert vector converted by the original nickname after the Bert model, Bert(x2) is the Bert vector converted by the nickname replaced by valid keywords after the Bert model, and Bert(x3) is the Bert vector converted by the nickname replaced by invalid keywords after the Bert model; classifier is a classification function used to classify the probability value of the nickname in each business category, but at this time, the sum of the probability values under each business category is not 1. Therefore, the softmax function is used to further output the predicted category. Softmax is a normalization function that can convert a set of arbitrary real values into probability values between [0, 1]. k is the kth training sample, that is, the kth original nickname input to the final version nickname model, and is the number of iterations of the final version nickname model. lable k is the probability value of the real category of the kth original nickname, the nickname replaced by a valid keyword, and the nickname replaced by an invalid keyword. loss is the final loss result avg-loss.
[0181] In the embodiment of the present application, invalid nicknames and valid nicknames are first selected through preliminary training, and synonym replacement is used to replace valid words and invalid words in the current nicknames respectively, and then put them into model training to let the model learn how to identify valid words and invalid words. This solution improves the accuracy of the model in identifying text types.
[0182] It is understandable that in the embodiments of the present application, user information is involved, such as the nickname of the merchant manager and other related data. When the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0183] The following is a description of an exemplary structure of a text category recognition model training device 455 provided in an embodiment of the present application implemented as a software module. In some embodiments, for example, Figure 2As shown, the software modules in the training device 455 of the text category recognition model may include: a data acquisition module 4551, which is used to obtain a sample data set, and the sample data set includes multiple sample texts. A category prediction module 4552, which is used to use a pre-trained text model to perform text mapping processing on each sample text, and obtain the prediction probability of each sample text; the prediction probability of the sample text is used to characterize the probability that the sample text can be identified as a text category. A text classification module 4553, which is used to classify multiple sample texts based on the prediction probability of each sample text, and obtain a first category of sample text and a second category of sample text. A keyword replacement module 4554, which is used to perform keyword replacement on the first category of sample text and the second category of sample text, respectively, and obtain a first category of keyword replacement text and a second category of keyword replacement text. A model training module 4555, which uses multiple sample texts, the first category of keyword replacement text and the second category of keyword replacement text as training samples, performs model training on the text category recognition model to be trained, and obtains a trained text category recognition model.
[0184] In some embodiments, the keyword replacement module 4554 is also used to determine the text type of the first category sample text and the text type of the second category sample text; determine that the keywords in the first category sample text are the first category keywords according to the text type of the first category sample text; determine that the keywords in the second category sample text are the second category keywords according to the text type of the second category sample text; perform keyword replacement on the first category keywords in the first category sample text to obtain corresponding first category keyword replacement text; perform keyword replacement on the second category keywords in the second category sample text to obtain corresponding second category keyword replacement text.
[0185] In some embodiments, the text type of the first category of sample text is valid text; the first category of keywords includes valid keywords and invalid keywords; the keyword replacement module 4554 is also used to obtain the first category of keyword replacement text by executing at least one of the following keyword replacement steps: determining similar keywords corresponding to the valid keywords, and using similar keywords to replace the valid keywords in the first category of sample text; randomly selecting an invalid word from a preset invalid word library to replace the invalid keywords in the first category of sample text.
[0186] In some embodiments, the text type of the second category sample text is invalid text; the second category keywords include at least one invalid keyword; the keyword replacement module 4554 is also used to randomly select an invalid word from a preset invalid word library to replace the first invalid keyword in the second category sample text to obtain the second category keyword replacement text; or, randomly select an invalid word from a preset invalid word library to replace any invalid keyword in the second category sample text to obtain the second category keyword replacement text.
[0187] In some embodiments, the text classification module 4553 is also used to determine, for any sample text, the sample text as a first category of sample text when the predicted probability of the sample text is greater than a first probability threshold; and to determine the sample text as a second category of sample text when the predicted probability of the sample text is less than a second probability threshold; the first probability threshold is greater than the second probability threshold.
[0188] In some embodiments, the data acquisition module 4551 is also used to obtain multiple initial sample texts; perform text cleaning on the multiple initial sample texts according to the text content and text length of each initial sample text to obtain multiple preprocessed sample texts; perform word segmentation on each preprocessed sample text to obtain sample word segmentation of each preprocessed sample text; perform text cleaning on the multiple preprocessed sample texts according to the word segmentation length of the sample word segmentation of each preprocessed sample text to obtain multiple sample texts constituting a sample data set.
[0189] In some embodiments, the data acquisition module 4551 is also used to determine, for each initial sample text, target text words belonging to a preset type in the initial sample text according to the text content of the initial sample text; delete the target text words to obtain a cleaned initial sample text; for any cleaned initial sample text, if the text length of the cleaned initial sample text is less than a text length threshold, delete the cleaned initial sample text to obtain multiple preprocessed sample texts.
[0190] In some embodiments, the data collection module 4551 is also used to delete the sample segmentation from any preprocessed sample text when the segmentation length of the sample segmentation of the preprocessed sample text is equal to a preset length, so as to obtain multiple sample texts constituting the sample data set.
[0191] In some embodiments, the sample data set also includes a category label corresponding to each sample text; the model training module 4555 is also used to input multiple sample texts, the first category keyword replacement text and the second category keyword replacement text as training samples into the text category recognition model to be trained; the sample prediction category of the sample text, the first replacement sample prediction category of the first category keyword replacement text and the second replacement sample prediction category of the second category keyword replacement text are predicted by the text category recognition model; the first category keyword replacement text and the second category keyword replacement text have the same category label as the first category sample text and the second category sample text respectively; according to the sample prediction category, the first replacement sample prediction category, the second replacement sample prediction category and the category label corresponding to each training sample, a matching loss calculation is performed to obtain a matching loss result; based on the matching loss result, the parameters of the text category recognition model to be trained are updated until the matching loss result is less than a preset threshold, thereby obtaining a trained text category recognition model.
[0192] The embodiment of the present application provides a computer program product, which includes a computer program or a computer executable instruction, and the computer program or the computer executable instruction is stored in a computer-readable storage medium. The processor of the electronic device reads the computer executable instruction from the computer-readable storage medium, and the processor executes the computer executable instruction, so that the electronic device executes the training method of the text category recognition model described in the embodiment of the present application.
[0193] The present application embodiment provides a computer-readable storage medium storing computer executable instructions, wherein the computer executable instructions or computer programs are stored. When the computer executable instructions or computer programs are executed by a processor, the processor will be caused to execute the training method of the text category recognition model provided by the present application embodiment, for example, Figure 3A The training method of the text category recognition model is shown.
[0194] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
[0195] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0196] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0197] As an example, computer executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0198] In summary, through the embodiments of the present application, invalid nicknames and valid nicknames are first selected through preliminary training, and synonym replacement is used to replace valid words and invalid words in the current nicknames respectively, and then put into model training to let the model learn how to identify valid words and invalid words. This scheme improves the accuracy of model recognition of text types. The embodiments of the present application propose a training of a text category recognition model. The trained text category recognition model can extract merchant categories from valid merchant manager nicknames and identify invalid nicknames. The business categories of these merchants cannot be determined, which effectively improves the effectiveness of identifying merchant categories from nicknames.
[0199] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A training method for a text category recognition model, characterized in that: The method comprises: Acquire a sample data set, wherein the sample data set includes a plurality of sample texts; Using a pre-trained text model to perform text mapping processing on each of the sample texts, and correspondingly obtaining a prediction probability of each of the sample texts; the prediction probability of the sample text is used to characterize the probability that the sample text can be identified as a text category; Classifying the plurality of sample texts based on the predicted probability of each of the sample texts to obtain a first category of sample texts and a second category of sample texts; Perform keyword replacement on the first category sample text and the second category sample text respectively, and obtain first category keyword replacement text and second category keyword replacement text respectively; The plurality of sample texts, the first category keyword replacement texts and the second category keyword replacement texts are used as training samples to perform model training on the text category recognition model to be trained, thereby obtaining a trained text category recognition model.
2. The method according to claim 1, characterized in that The keyword replacement is performed on the first type of sample text and the second type of sample text respectively, and the first type of keyword replacement text and the second type of keyword replacement text are obtained accordingly, including: Determining the text type of the first category of sample texts and the text type of the second category of sample texts; According to the text type of the first category of sample texts, determining that the keywords in the first category of sample texts are first category keywords; According to the text type of the second type of sample text, determining that the keywords in the second type of sample text are second type keywords; Performing keyword replacement on the first category of keywords in the first category of sample texts to obtain corresponding first category keyword replacement texts; The second-category keywords in the second-category sample texts are replaced with keywords to obtain corresponding second-category keyword-replaced texts.
3. The method according to claim 2, characterized in that The text type of the first type of sample text is valid text; the first type of keywords includes valid keywords and invalid keywords; The step of performing keyword replacement on the first category of keywords in the first category of sample texts to obtain the first category of keyword replacement texts includes: The first-category keyword replacement text is obtained by performing at least one of the following keyword replacement steps: Determining similar keywords corresponding to the effective keywords, and using the similar keywords to replace the effective keywords in the first type of sample texts; An invalid word is randomly selected from a preset invalid word library to replace the invalid keyword in the first type of sample text.
4. The method according to claim 2, characterized in that The text type of the second type of sample text is invalid text; the second type of keywords includes at least one invalid keyword; The step of performing keyword replacement on the second-category keywords in the second-category sample text to obtain the second-category keyword replacement text includes: Randomly select an invalid word from a preset invalid word library to replace the first invalid keyword in the second category sample text, so as to obtain the second category keyword replacement text; or, An invalid word is randomly selected from a preset invalid word library to replace any invalid keyword in the second category sample text to obtain the second category keyword replacement text.
5. The method according to claim 1, characterized in that Classifying the plurality of sample texts based on the predicted probability of each of the sample texts to obtain a first category of sample texts and a second category of sample texts, including: For any of the sample texts, when the predicted probability of the sample text is greater than a first probability threshold, determining the sample text as a first type of sample text; When the predicted probability of the sample text is less than a second probability threshold, the sample text is determined as a second type of sample text; and the first probability threshold is greater than the second probability threshold.
6. The method according to claim 1, characterized in that The obtaining of the sample data set comprises: Obtain multiple initial sample texts; According to the text content and text length of each of the initial sample texts, the multiple initial sample texts are cleaned to obtain multiple pre-processed sample texts; Performing word segmentation on each of the preprocessed sample texts to obtain sample word segmentation of each of the preprocessed sample texts; According to the word segmentation length of each sample word segment of the preprocessed sample text, the multiple preprocessed sample texts are cleaned to obtain the multiple sample texts constituting the sample data set.
7. The method according to claim 6, characterized in that The step of performing text cleaning on the multiple initial sample texts according to the text content and text length of each of the initial sample texts to obtain multiple pre-processed sample texts includes: For each of the initial sample texts, determining a target text word of a preset type in the initial sample text according to the text content of the initial sample text; Deleting the target text words to obtain a cleaned initial sample text; For any cleaned initial sample text, when the text length of the cleaned initial sample text is less than the text length threshold, the cleaned initial sample text is deleted to obtain a plurality of preprocessed sample texts.
8. The method according to claim 6, characterized in that The step of performing text cleaning on the plurality of preprocessed sample texts according to the word segmentation length of the sample word segmentation of each of the preprocessed sample texts to obtain the plurality of sample texts constituting the sample data set includes: For any preprocessed sample text, when the segmentation length of a sample segmentation of the preprocessed sample text is equal to a preset length, the sample segmentation is deleted from the preprocessed sample text to obtain the multiple sample texts constituting the sample data set.
9. The method according to any one of claims 1 to 8, characterized in that The sample data set also includes a category label corresponding to each sample text; The method of using the plurality of sample texts, the first category keyword replacement texts and the second category keyword replacement texts as training samples, performing model training on the text category recognition model to be trained, and obtaining the trained text category recognition model comprises: Input the plurality of sample texts, the first category keyword replacement texts and the second category keyword replacement texts as training samples into the text category recognition model to be trained; The sample prediction category of the sample text, the first replacement sample prediction category of the first-category keyword replacement text, and the second replacement sample prediction category of the second-category keyword replacement text are obtained by predicting the text category recognition model; the first-category keyword replacement text and the second-category keyword replacement text have the same category label as the first-category sample text and the second-category sample text respectively; Calculate the matching loss according to the sample prediction category, the first replacement sample prediction category, the second replacement sample prediction category, and the category label corresponding to each training sample to obtain a matching loss result; The parameters of the text category recognition model to be trained are updated based on the matching loss result until the matching loss result is less than a preset threshold, thereby obtaining a trained text category recognition model.
10. A training device for a text category recognition model, characterized in that: The device comprises: A data collection module, used to obtain a sample data set, wherein the sample data set includes a plurality of sample texts; A category prediction module, used to perform text mapping processing on each of the sample texts using a pre-trained text model, and obtain a corresponding prediction probability of each of the sample texts; the prediction probability of the sample text is used to characterize the probability that the sample text can be identified as a text category; A text classification module, used for classifying the plurality of sample texts based on the predicted probability of each of the sample texts to obtain a first category of sample texts and a second category of sample texts; A keyword replacement module, used to perform keyword replacement on the first category sample text and the second category sample text respectively, and obtain first category keyword replacement text and second category keyword replacement text respectively; The model training module is used to use the plurality of sample texts, the first category keyword replacement texts and the second category keyword replacement texts as training samples to perform model training on the text category recognition model to be trained, so as to obtain a trained text category recognition model.
11. An electronic device, characterized in that: The electronic device comprises: A memory for storing computer executable instructions; A processor, configured to implement the text category recognition model training method according to any one of claims 1 to 9 when executing the computer executable instructions or computer program stored in the memory.
12. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the training method of the text category recognition model described in any one of claims 1 to 9 is implemented.
13. A computer program product comprising computer executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the training method of the text category recognition model described in any one of claims 1 to 9 is implemented.