Text encoding method, device, medium and equipment
By counting and filtering the solidification degree of continuous string words in the corpus, the quality of the dictionary and coding is improved, the problem of meaningless phrase occupation in the existing technology is solved, and the learning of the text processing model is promoted.
Patent Information
- Application Number
- CN202210996448.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-18
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2042-08-18
AI Technical Summary
In the existing technology, there are many phrases without practical meaning in dictionary encoding, resulting in low dictionary quality and low coding quality, which affects word vector learning in subsequent text processing.
By counting the number of continuous strings in the corpus to be encoded, calculating its word coagulation degree, selecting the continuous strings whose word coagulation degree meets the preset conditions as the target string, and encoding the corpus to be encoded until the encoding end condition is met, and then Improve the accuracy of the coding process.
It improves the quality of the dictionary and the accuracy of coding, reduces the impact of meaningless phrases, and promotes model learning of subsequent text processing models.
Smart Images

Figure CN115358189B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a text encoding method, device, computer-readable storage medium, and electronic device. Background Art
[0002] Among the related technologies for encoding text information, dictionary encoding technology belongs to lossless compression technology. It creates a phrase dictionary based on the input data. The phrases included in the phrase dictionary can be a combination of any characters. When encountering a phrase that has already appeared in the dictionary during the data encoding process, the index number of the phrase is output.
[0003] At present, how to improve the quality of text encoding by improving the quality of dictionaries is an urgent problem to be solved. Summary of the invention
[0004] To solve the above technical problems, embodiments of the present application provide a text encoding method, device, computer-readable storage medium and electronic device to improve the quality of text encoding by improving the quality of the dictionary.
[0005] According to one aspect of an embodiment of the present application, a text encoding method is provided, the method comprising: counting the number of each continuous character string in a corpus to be encoded to confirm an alternative continuous character string based on the number of the continuous character strings; calculating the word coagulation degree of the alternative continuous character string, the word coagulation degree being used to characterize the degree of association between each character in the alternative continuous character string; taking the alternative continuous characters whose word coagulation degree meets a preset condition as a target continuous character string; encoding the corpus to be encoded according to the target continuous character string until an encoding end condition corresponding to the corpus to be encoded is met.
[0006] In some embodiments, the calculating of the word coagulation degree of the alternative continuous character string includes: confirming the sub-characters constituting the alternative continuous character string; obtaining the number of occurrences of the alternative continuous character string and the number of occurrences of the sub-characters in the corpus to be encoded; and calculating the word coagulation degree of the alternative continuous character string based on the number of the alternative continuous character string and the number of the sub-characters.
[0007] In some embodiments, the word coagulation degree of the alternative continuous character string is calculated based on the number of the alternative continuous character strings and the number of the sub-characters, including: obtaining the number of vocabulary in the corpus to be encoded; calculating the probability values of the alternative continuous character strings based on the number of vocabulary and the number of the alternative continuous character strings, and calculating the probability values of the sub-characters based on the number of vocabulary and the number of the sub-characters; calculating the word coagulation degree of the alternative continuous character string based on the probability values of the alternative continuous character strings and the probability values of the sub-characters.
[0008] In some embodiments, counting the number of consecutive character strings in the corpus to be encoded includes: obtaining vocabulary in the corpus to be encoded; counting the number of each of the vocabulary corresponding to the corpus to be encoded, and marking a stop symbol corresponding to each of the vocabulary to obtain a word frequency representation of each of the vocabulary; wherein the stop symbol is used to represent the end position of the vocabulary; and calculating the number of consecutive character strings contained in the word frequency representation of each of the vocabulary.
[0009] In some embodiments, the calculating the number of continuous character strings contained in the word frequency representation of each of the words includes: respectively obtaining the continuous character strings contained in each of the word frequency representations; and counting the number of each of the continuous character strings in all the word frequency representations according to the number corresponding to each of the word frequency representations.
[0010] In some embodiments, respectively obtaining the continuous character string contained in each of the word frequency representations includes: generating a sliding window according to a preset length of the continuous character string; sampling each of the word frequency representations according to the sliding window of the preset length to obtain the continuous character string contained in each of the word frequency representations.
[0011] In some embodiments, encoding the corpus to be encoded according to the target continuous character string includes: confirming the encoded characters of the target continuous character string; associating the target continuous character string and the encoded characters of the target continuous character string and storing them in a dictionary, and replacing the target continuous characters in the corpus to be encoded with the encoded characters to obtain an updated corpus to be encoded.
[0012] According to one aspect of an embodiment of the present application, a text encoding device is provided, in which a registration management smart contract for defining registration management rules corresponding to software is deployed in a blockchain network, and the device includes: a registration processing module, configured to perform registration processing on the software corresponding to the registration management request according to a registration management request initiated by a software supply chain terminal for the registration management smart contract, and confirm the version management smart contract for defining the version information management rules corresponding to the software; a first contract deployment module, configured to deploy the version management smart contract, and add the address of the version management smart contract to the registration management smart contract; a version information management module, configured to perform version information management on the software according to a version information management request initiated by the software supply chain terminal for the version management smart contract, and confirm the transaction management smart contract for defining the transaction information management rules corresponding to the software; a second contract deployment module, configured to deploy the transaction management smart contract, and add the address of the transaction management smart contract to the version management smart contract; a supply chain management module, configured to manage the supply chain of the software according to the registration management smart contract, the version management smart contract and the transaction management smart contract corresponding to the software.
[0013] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above text encoding method is implemented.
[0014] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising one or more processors; a storage device for storing one or more programs, which, when the one or more programs are executed by the electronic device, enables the electronic device to implement the above text encoding method.
[0015] In the technical solution provided in the embodiments of the present application, the number of each continuous character string in the corpus to be encoded is counted to confirm the alternative continuous character string according to the number of continuous character strings, and then the word coagulation degree of the alternative continuous character string is calculated, so that the alternative continuous characters whose word coagulation degree meets the preset conditions are used as the target continuous character string, and then the corpus to be encoded is encoded according to the target continuous character string until the encoding end condition corresponding to the corpus to be encoded is met. The word coagulation degree of the alternative continuous character string is judged to evaluate whether the alternative continuous character string has a specific meaning, and then only the continuous character string whose word coagulation degree meets the preset conditions is encoded, so that the encoding process is more accurate, which facilitates the subsequent related text processing model to perform model learning.
[0016] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0018] Figure 1 is a schematic diagram of an exemplary application environment to which the technical solution of the embodiments of the present application can be applied;
[0019] Figure 2 is a flowchart of a text encoding method shown in an exemplary embodiment of the present application;
[0020] Figure 3 is a coding schematic diagram shown in an exemplary embodiment of the present application;
[0021] Figure 4 is a schematic diagram of obtaining a continuous character string shown in an exemplary embodiment of the present application;
[0022] Figure 5 is a flowchart of a text encoding method shown in another exemplary embodiment of the present application;
[0023] Figure 6 is a flowchart of a text encoding method in a specific application scenario shown in an exemplary embodiment of the present application;
[0024] Figure 7 is a block diagram of a text encoding device shown in an exemplary embodiment of the present application;
[0025] Figure 8 It is a structural diagram of a computer system suitable for implementing an electronic device of an embodiment of the present application. DETAILED DESCRIPTION
[0026] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments that are the same as the present application. Instead, they are merely examples of apparatus and methods that are the same as some aspects of the present application as detailed in the appended claims.
[0027] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in the form of an application program, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0028] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0029] It should be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0030] Encoding is the process of converting information from one form or format to another. Encoding is also called the code of a computer programming language. Specifically, it can use preset rules to encode text, numbers or other objects into a specified representation. Decoding is the reverse process of encoding.
[0031] In the related art, dictionary encoding is generally used to encode text, but the applicant has found that there are many phrases in the dictionary that have no practical meaning. These phrases not only take up space in the dictionary, but also affect the learning of word vectors in subsequent text processing.
[0032] Based on this, in order to improve the quality of the dictionary and the quality of encoding, the embodiments of the present application propose a text encoding method, device, computer-readable storage medium, electronic device and computer program product.
[0033] Optionally, in this embodiment, the above text encoding method can be applied to Figure 1 In the environment shown. Figure 1 As shown, the implementation environment includes a terminal 110 and a server 120. The terminal 110 and the server 120 may be directly or indirectly connected via wired or wireless communication, which is not limited in the present application.
[0034] Terminal 110 may be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, vehicle-mounted terminal, etc., but is not limited thereto. Terminal 110 may generally refer to one of a plurality of terminals, and this embodiment is only illustrated by terminal 110. Those skilled in the art may know that the number of the above-mentioned terminals may be more or less. For example, the above-mentioned terminal may be only one, or the above-mentioned terminal may be dozens or hundreds, or a greater number, in which case the implementation environment of the above-mentioned text encoding method also includes other terminals. The embodiment of the present application does not limit the number of terminals and device types.
[0035] The server 120 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 server 120 is used to provide background services for the applications running on the terminal 110.
[0036] Optionally, the wireless network or wired network described above uses standard communication technology and / or protocol. The network is typically the Internet, but may also be any network, including but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a dedicated network or any combination of a virtual private network). In some embodiments, technologies and / or formats including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. are used to represent data exchanged over the network. In addition, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec), etc. may be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies may also be used to replace or supplement the above data communication technologies.
[0037] Optionally, the server 120 undertakes the primary text encoding task, and the terminal 110 undertakes the secondary text encoding task; or, the server 120 undertakes the secondary text encoding task, and the terminal 110 undertakes the primary text encoding task; or, the server 120 or the terminal 110 can each undertake the text encoding task independently.
[0038] Exemplarily, the terminal 110 sends a text encoding instruction to the server 120, and the server 120 receives the text encoding instruction sent by the terminal 110 and obtains the corpus to be encoded; the server 120 confirms the alternative continuous character strings in the corpus to be encoded, and calculates the word coagulation degree of the alternative continuous character strings; the alternative continuous characters whose word coagulation degree meets the preset conditions are taken as the target continuous character strings, so as to encode the corpus to be encoded according to the target continuous character strings until the encoding end conditions corresponding to the corpus to be encoded are met.
[0039] See also Figure 2 , Figure 2 is a flowchart of a text encoding method according to an embodiment of the present application, and the text encoding method can be applied to Figure 1 The implementation environment shown is specifically executed by the server 120 in the implementation environment. It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.
[0040] The text encoding method proposed in the embodiment of the present application is introduced in detail below using the server as the specific execution entity.
[0041] like Figure 2 As shown, in an exemplary embodiment, the text encoding method at least includes steps S210 to S240, which are described in detail as follows:
[0042] Step S210 , counting the number of each continuous character string in the corpus to be encoded, so as to determine candidate continuous character strings according to the number of continuous character strings.
[0043] The above-mentioned corpus to be encoded includes but is not limited to computer text, audio text, recording text, article text, paragraph text, sentence text, etc. The above-mentioned computer text includes but is not limited to HyperText Transfer Protocol (HTTP) text corresponding to the World Wide Web (WEB), HyperText Transfer Protocol over SecureSocketLayer (HTTPS) text, uniform resource locator (URL) text, etc.
[0044] A continuous string consists of at least two characters, and the characters in the continuous string are located continuously in the corpus to be encoded.
[0045] Optionally, the corpus to be encoded may be first segmented to obtain the vocabulary in the corpus to be encoded. The input corpus to be encoded is divided into words by the word segmentation method to obtain vocabulary. Then, the continuous character string corresponding to each vocabulary is obtained according to the preset character string length. It can be understood that a vocabulary may correspond to multiple continuous character strings or zero continuous character strings.
[0046] For example, when the preset string length is 2, a continuous string is obtained for the word "abcd", and the obtained continuous string includes "ab, bc, cd"; a continuous string is obtained for the word "a", and it is found that the word "a" does not meet the length requirement of the continuous string, so the word "a" has no corresponding continuous string.
[0047] After obtaining the continuous character strings contained in the corpus to be encoded, the number of each continuous character string in the corpus to be encoded is counted to confirm the candidate continuous character string according to the number of continuous character strings. For example, the continuous character string with the highest number can be used as the candidate continuous character string. The higher the number of continuous character strings, the more the continuous character string appears in the corpus to be encoded, and the better the text compression effect achieved by encoding the continuous character string.
[0048] Step S220 , calculating the word coagulation degree of the candidate continuous character string, where the word coagulation degree is used to characterize the degree of association between each character in the candidate continuous character string.
[0049] It can be understood that the greater the word coagulation degree of the alternative continuous string, the higher the degree of association between each character in the alternative continuous string, that is, the greater the probability that the alternative continuous string has specific meaning; conversely, the smaller the word coagulation degree of the alternative continuous string, the lower the degree of association between each character in the alternative continuous string, that is, the smaller the probability that the alternative continuous string has substantial meaning.
[0050] Exemplarily, the word coagulation degree can be calculated based on the number of each character constituting the alternative continuous string in the corpus text. For example, if the number of each character of the alternative continuous string in the corpus text is much greater than the number of occurrences of the alternative continuous string, it indicates that because the number of characters in the alternative continuous string is large, the number of occurrences of the alternative continuous string in the corpus to be encoded is high, so the probability that the alternative continuous string has substantive meaning is low. On the contrary, if the number of each character of the alternative continuous string in the corpus text is close to the number of occurrences of the alternative continuous string, it indicates that the number of these characters is mainly determined by the number of occurrences of the alternative continuous string in the corpus to be encoded, so the probability that the alternative continuous string has substantive meaning is high.
[0051] Exemplarily, the word coagulation degree can also be obtained by a word coagulation degree calculation model obtained through pre-training. For example, a word coagulation degree calculation model is obtained by training a neural network according to a training sample, and the training sample includes a character string with substantial meaning and a character string without substantial meaning, such as a character string with substantial meaning may include "BOOK, CAT, THE", etc., and a character string without substantial meaning may include "CXC, CBT, MXKL", etc. The training sample is input into the neural network to obtain the prediction result output by the neural network, and the loss is calculated according to the prediction result and the label corresponding to the training sample, and the parameters of the neural network are adjusted according to the loss until the condition for training completion is met to obtain the word coagulation degree calculation model. Among them, the condition for training completion may be that the neural network training reaches a preset number of iterations, or it may be that the loss converges. The word coagulation degree calculation model can calculate the probability that the input candidate continuous character string belongs to the category with substantial meaning and the category without substantial meaning, so as to obtain the word coagulation degree of the candidate continuous character string.
[0052] It is understandable that other calculation methods may be used to calculate the word coagulation degree of the candidate continuous character string, and the present application does not limit this.
[0053] The present application calculates the word coagulation degree of each candidate continuous character string during the encoding process to evaluate whether the candidate continuous character string has specific meaning, so as to make the subsequently generated dictionary more accurate and refined, thereby facilitating the subsequent related text processing model to perform model learning according to the dictionary.
[0054] Step S230: taking candidate continuous characters whose word coagulation degree meets preset conditions as target continuous character strings.
[0055] Among them, the preset conditions can be flexibly set according to the actual application scenarios. For example, the preset condition can be greater than or equal to the word coagulation threshold. The word coagulation threshold can be a value preset by the user, or a value dynamically calculated by a computer device, such as a value dynamically calculated based on information such as the length of the corpus to be encoded, the type of the corpus to be encoded, the length of alternative consecutive characters, etc. This application does not impose any restrictions on this.
[0056] The candidate continuous characters whose word coagulation degree meets the preset conditions are taken as the target continuous character string, and the target continuous character string refers to a character string judged to have substantial meaning, so as to perform subsequent processing on the target continuous character string.
[0057] Step S240 , encoding the corpus to be encoded according to the target continuous character string until an encoding end condition corresponding to the corpus to be encoded is met.
[0058] Optionally, the encoding end condition may be that the number of characters in the encoded text reaches a preset number, or that the maximum number of consecutive character strings is 1, and this application does not impose any restrictions on this.
[0059] It can be understood that if after encoding the corpus to be encoded once according to the target continuous character string, it is determined that the encoding end condition is not met, steps S210 to S240 are repeatedly executed to iteratively encode the corpus to be encoded until the encoding end condition is met to obtain the final encoding result.
[0060] Exemplarily, encoding processing is performed on the corpus to be encoded according to the target continuous string, including: confirming the encoding characters of the target continuous string; associating the target continuous string and the encoding characters of the target continuous string into a dictionary, and replacing the target continuous characters in the corpus to be encoded with the encoding characters to obtain an updated corpus to be encoded.
[0061] For example, Figure 3 As shown, the corpus to be encoded is "abbcabdbcab", the target continuous string is "ab", and the encoding character of the target continuous string is confirmed to be "A", then the target continuous string and the encoding character of the target continuous string are stored in the dictionary in association. Then, the corpus to be encoded is encoded according to the encoding character of the target continuous string, and the target continuous characters in the corpus to be encoded "abbcabdbcab" are replaced with the encoding characters to obtain the updated corpus to be encoded "AbcAdbcA". Then, if it is judged that the encoding end condition is not met at present, the encoding program is executed again for the updated corpus to be encoded "AbcAdbcA", and the target continuous string is obtained as "bc", and the encoding character of the target continuous string is confirmed to be "B", then the target continuous string and the encoding character of the target continuous string are stored in the dictionary in association, and the target continuous characters in the corpus to be encoded "AbcAdbcA" are replaced with the encoding characters to obtain the updated corpus to be encoded "ABAdBA". Then it is determined that the encoding end condition is not met at present, and the encoding program is executed again on the updated corpus to be encoded "ABAdBA", and the target continuous character string is obtained as "BA". It is confirmed that the encoded character of the target continuous character string is "C", and the target continuous character string and the encoded character of the target continuous character string are associated and stored in the dictionary, and the target continuous characters in the corpus to be encoded "ABAdBA" are replaced with the encoded characters to obtain the updated corpus to be encoded "ACdC". This is to determine that the updated corpus to be encoded "ACdC" meets the encoding end condition, and the final encoding result obtained is "ACdC", and the mapping relationship between the target continuous character string and the encoded character of the target continuous character string in the dictionary includes "ab=A, bc=B, BA=C".
[0062] The text encoding method provided in the present application determines the word coagulation degree of the candidate continuous character strings to evaluate whether the candidate continuous character strings have specific meanings, and then only performs encoding processing on the continuous character strings whose word coagulation degrees meet preset conditions, thereby making the encoding process more accurate and facilitating the subsequent related text processing model execution model learning.
[0063] In some embodiments, counting the number of each continuous character string in the corpus to be encoded may include: obtaining vocabulary in the corpus to be encoded; counting the number of each vocabulary corresponding to the corpus to be encoded, and marking the stop symbol corresponding to each vocabulary to obtain a word frequency representation of each vocabulary; wherein the stop symbol is used to represent the end position of the vocabulary; and calculating the number of continuous character strings contained in the word frequency representation of each vocabulary to confirm the candidate continuous character strings according to the number of continuous character strings.
[0064] The corpus to be encoded consists of multiple words, and the server can perform word segmentation on the corpus to be encoded to obtain the words in the corpus to be encoded. For example, the corpus to be encoded " / url / jump / yytc?code=aa" is segmented, and the obtained words include " / ,url, / ,jump, / ,yytc,?,code,=,aa". Among them, when performing word segmentation on the corpus to be encoded, a word segmentation tool can be used, such as SnowNLP word segmentation, Thulac word segmentation, HanLP word segmentation, jieba word segmentation, etc. The word segmentation tool obtains multiple words based on the semantic relationship between each character in the corpus to be encoded.
[0065] Then, count the number of each word corresponding to the corpus to be encoded, and mark the stop sign corresponding to each word to obtain the word frequency representation of each word. For example, the stop sign can be "". It is understandable that other symbols can also be selected as stop signs. Add a stop sign at the end of each word, and count the frequency of each word. For example, the frequency of the word "code" is 10, then the word frequency corresponding to "code" is represented as "code: 10". Among them, the end position of each word is indicated by a stop sign to ensure the accuracy of the encoding. For example, st can appear at the beginning of a word without a stop sign, such as star; and st with a stop sign indicates that the string is at the end of the word, such as west, and its meaning is completely different.
[0066] In some implementations, calculating the number of continuous character strings included in the frequency representation of each vocabulary word includes: obtaining the continuous character strings included in each frequency representation respectively; and counting the number of each continuous character string in all frequency representations according to the number corresponding to each frequency representation.
[0067] For example, the word frequency representation corresponding to the corpus to be encoded includes:
[0068] "abcd: 10"; "abs: 2"; "dce: 5";
[0069] Get the continuous string contained in each word frequency representation and get:
[0070] "abcd:10": ab, bc, cd;
[0071] "abs:2": ab, bs;
[0072] "dce:5": bc, ce;
[0073] Then, according to the number corresponding to each word frequency representation, the number of each continuous string in all word frequency representations is counted. For example, the number of continuous strings "ab" is 12, and the number of continuous strings "bc" is 15.
[0074] In some implementations, obtaining the continuous character string contained in each word frequency representation includes: generating a sliding window according to a preset length of the continuous character string; sampling each word frequency representation according to the sliding window of the preset length to obtain the continuous character string contained in each word frequency representation.
[0075] The preset length of the continuous character string can be preset according to the encoding requirements corresponding to the corpus to be encoded.
[0076] For example, see Figure 4 , Figure 4 This is a schematic diagram for obtaining a continuous string. Figure 4 As shown in the figure, the preset length of the continuous string is 2, and the character information corresponding to the word frequency is "a,b,c,d," and a sliding window of length 2 is generated to traverse the character information. The character string in the sliding window of each traversal is regarded as a continuous string until the traversal is completed. For example, the continuous string obtained in the first traversal is "a,b", and the continuous string obtained in the last traversal is "d,".
[0077] See also Figure 5 , Figure 5 FIG. 1 is a flowchart of a text encoding method according to another exemplary embodiment. Figure 5 As shown, in an exemplary embodiment, the process of calculating the word coagulation degree of the candidate continuous character string in step S220 may include the following steps:
[0078] Step S221, confirming the sub-characters constituting the candidate continuous character string.
[0079] The alternative continuous string is composed of multiple sub-characters, and the sub-characters that constitute the alternative continuous string are obtained.
[0080] For example, when the candidate continuous character string is "a,b", the sub-characters constituting the candidate continuous character string include "a" and "b".
[0081] Step S222, obtaining the number of occurrences of candidate continuous character strings and the number of occurrences of sub-characters in the corpus to be encoded.
[0082] The number of candidate continuous character strings contained in the corpus to be encoded is counted, and the number of sub-characters contained in the corpus to be encoded is counted.
[0083] For example, the corpus to be encoded is traversed to count the number of occurrences of candidate continuous character strings and the number of occurrences of sub-characters respectively.
[0084] Step S223: Calculate the word coagulation degree of the candidate continuous character string according to the number of the candidate continuous character string and the number of sub-characters.
[0085] Some character strings in the corpus to be encoded may be located adjacently due to the corpus environment, so that a large number of corresponding candidate continuous character strings are identified in the encoding stage, while the candidate continuous character strings themselves have no substantial meaning.
[0086] Therefore, the word coagulation degree of the alternative continuous string is calculated according to the number of alternative continuous string and the number of sub-characters. If the number of alternative continuous string is closer to the number of sub-characters, it means that the degree of association between each character in the alternative continuous string is higher, that is, the probability that the alternative continuous string has a specific meaning is greater, and the obtained word coagulation degree is greater; conversely, if the difference between the number of alternative continuous string and the number of sub-characters is greater, it means that the degree of association between each character in the alternative continuous string is lower, that is, the probability that the alternative continuous string has a specific meaning is smaller, and the obtained word coagulation degree is smaller.
[0087] Exemplarily, the word coagulation degree of the alternative continuous character strings is calculated based on the number of alternative continuous character strings and the number of sub-characters, including: obtaining the number of words in the corpus to be encoded; calculating the probability values of the alternative continuous character strings based on the number of words and the number of alternative continuous character strings, and calculating the probability values of the sub-characters based on the number of words and the number of sub-characters; calculating the word coagulation degree of the alternative continuous character strings based on the probability values of the alternative continuous character strings and the probability values of the sub-characters.
[0088] For example, when the length of the continuous string is 2, the word coagulation degree of the candidate continuous string can be calculated using the following formula:
[0089] Among them, N(S1,S2) represents the word solidification corresponding to the alternative continuous string "S1,S2", the alternative continuous string includes sub-characters "S1" and "S2", p(S1S2) represents the probability value of the alternative continuous string, p(S1) represents the probability value of the sub-character "S1", and p(S2) represents the probability value of the sub-character "S2".
[0090] In some embodiments, the word coagulation degree can also be obtained by a word coagulation degree calculation model obtained by pre-training. Exemplarily, before counting the number of each continuous character string in the corpus to be encoded, it also includes: obtaining a training sample set, the training sample set includes training samples with sample labels; inputting the training samples in the training sample set into a preset neural network; the preset neural network extracts text features from the input training samples to obtain a text feature vector, and the text feature extraction includes but is not limited to extracting the semantic features of the text, the positional features of the text, etc.; the preset neural network classifies the input training samples according to the text feature vector to obtain a classification result; calculates the loss value between the classification result and the sample label according to a preset loss function; adjusts the network parameters of the preset neural network according to the loss value, so as to obtain a word coagulation degree calculation model after multiple iterations of training.
[0091] Then, the candidate continuous character string is input into the word coagulation calculation model to obtain the probability that the candidate continuous character string output by the word coagulation calculation model belongs to a meaningful word and the probability that the candidate continuous character string belongs to a meaningless word, and then a weighted calculation is performed according to the probability of a meaningful word and the probability of a meaningless word to obtain the word coagulation degree of the candidate continuous character string.
[0092] Among them, the sample label of the training sample is used to mark whether the training sample belongs to a meaningful word or a meaningless word. Since the number of training samples of meaningful words is large in practical applications, while the number of training samples of meaningless words is small, in order to ensure the training effect of the model, the meaningless word samples can be obtained by reordering the character sequence of meaningful words; the meaningless word samples can also be obtained by inserting characters into meaningful words; and the meaningless word samples can also be obtained by deleting characters from meaningful words, thereby balancing the number of meaningless word samples and meaningful word samples.
[0093] The following is a detailed description of a specific application scenario of the embodiment of the present application:
[0094] See also Figure 6, step 1, input the training corpus corresponding to the web request to obtain the corpus to be encoded. Step 2, segment the corpus to be encoded according to the characteristic symbols, such as segmenting " / url / jump / key" in the corpus to be encoded to obtain the vocabulary including " / ,url, / ,jump, / ,key". Step 3, split the vocabulary after the segmentation process, such as segmenting the vocabulary " / ,url, / ,jump, / ,key" to obtain " / ,u,r,l, / ,j,u,m,p, / ,k,e,y". Step 4, count the number of occurrences of all continuous character strings in the corpus to be encoded, such as the number of occurrences of the continuous character string "ur" is 13. Step 5, confirm the candidate continuous character strings according to the statistical results. If it is detected that the continuous character string "ur" has the largest number of occurrences, the continuous character string "ur" is used as the candidate continuous character string. Step 6, calculate the word coagulation degree of the candidate continuous string, such as calculating the word coagulation degree of the candidate continuous string based on the number of times the candidate continuous string appears in the corpus to be encoded and the number of times each sub-character in the candidate continuous string appears in the corpus to be encoded. Step 7, determine whether the word coagulation degree of the candidate continuous string is greater than the word coagulation degree threshold. If the word coagulation degree is greater than the preset word coagulation degree, the candidate continuous string is used as the target continuous string and step 8 is executed; if the word coagulation degree is less than the preset word coagulation degree, the candidate continuous string is discarded and the process returns to step 4 to select the candidate continuous string again. Step 8, perform encoding processing and dictionary addition processing on the corpus to be encoded according to the target continuous string. Step 9, determine whether the encoding end condition is met. If the encoding end condition is met, the encoding program is terminated. If the encoding end condition is not met, the process returns to step 4 to select the candidate continuous string again.
[0095] In some embodiments, the present application also provides a text decoding method. Exemplarily, a text to be decrypted and a dictionary corresponding to the text to be decoded are obtained, and the text to be decoded is decoded according to a phrase mapping relationship in the dictionary until a decoding condition is met, wherein the phrase mapping relationship is used to represent a mapping relationship between a target continuous string and a coded character of the target continuous string.
[0096] The dictionary includes two data items, one of which is a target continuous string and the other is a coded character corresponding to the target continuous string. Decoding the text to be decrypted according to the phrase mapping relationship in the dictionary includes: detecting the coded characters contained in the text to be decoded, converting these coded characters into the target continuous string corresponding to the coded characters, so as to update the text to be decoded; then detecting whether the updated text to be decoded still contains coded characters, if it contains coded characters, it indicates that the decoding condition is not met at present, then returning to the above steps to convert these coded characters into the target continuous string corresponding to the coded characters again; if it does not contain coded characters, it indicates that the decoding condition is met at present, and outputting the updated text to be decoded as the final decoding result.
[0097] For example, the text to be decoded is "ACdC", and the target continuous string and the coded character relationship of the target continuous string in the dictionary include "ab=A, bc=B, BA=C", wherein the data item before the equation is the target continuous string, and the data item after the equation is the coded character. Then, the coded characters contained in the text to be decoded "ACdC" are detected as "A, C, C", and these coded characters are converted into the target continuous string corresponding to the coded characters according to the coded character relationship of the target continuous string and the target continuous string in the dictionary "ab=A, BA=C", and the updated text to be decoded is obtained as "abBAdBA". Further, it is detected that the updated text to be decoded "abBAdBA" also contains the coded characters "B, A", which indicates that the current text to be decoded does not meet the decoding conditions. Therefore, according to the coded character relationship of the target continuous string and the target continuous string in the dictionary "ab=A, bc=B", these coded characters are converted into the target continuous string corresponding to the coded characters, and the updated text to be decoded is obtained as "abbcabdbcab". Then, it is detected that there is no encoded character in the updated text to be decoded "abbcabdbcab", which indicates that the current text to be decoded meets the decoding condition, and the updated text to be decoded is output as the final decoding result.
[0098] The present application counts the number of each continuous character string in the corpus to be encoded to confirm the alternative continuous character string according to the number of continuous character strings, and then calculates the word coagulation degree of the alternative continuous character string, so as to take the alternative continuous characters whose word coagulation degree meets the preset conditions as the target continuous character string, and then encodes the corpus to be encoded according to the target continuous character string until the encoding end condition corresponding to the corpus to be encoded is met, and judges the word coagulation degree of the alternative continuous character string to evaluate whether the alternative continuous character string has a specific meaning, and then only performs encoding processing on the continuous character string whose word coagulation degree meets the preset conditions, so that the encoding process is more accurate, and then it is convenient for the subsequent related text processing model to execute model learning.
[0099] Figure 7 is a block diagram of a text encoding device shown in an embodiment of the present application, such as Figure 7 As shown, the device comprises:
[0100] The candidate continuous character string confirmation module 710 is configured to count the number of each continuous character string in the corpus to be encoded, so as to confirm the candidate continuous character string according to the number of the continuous character strings;
[0101] A word coagulation degree calculation module 720, configured to calculate the word coagulation degree of the candidate continuous character string, wherein the word coagulation degree is used to characterize the degree of association between each character in the candidate continuous character string;
[0102] A target continuous character string confirmation module 730 is configured to take candidate continuous characters whose word coagulation degree meets a preset condition as a target continuous character string;
[0103] The encoding module 740 is configured to perform encoding processing on the corpus to be encoded according to the target continuous character string until an encoding end condition corresponding to the corpus to be encoded is met.
[0104] In one embodiment of the present application, the word coagulation degree calculation module 720 includes a sub-character confirmation unit, a first quantity acquisition unit and a word coagulation degree calculation unit, specifically:
[0105] a sub-character confirmation unit configured to confirm the sub-characters constituting the candidate continuous character string;
[0106] A quantity acquisition unit, configured to acquire the number of occurrences of the candidate continuous character string and the number of occurrences of the sub-character in the corpus to be encoded;
[0107] The word coagulation degree calculation unit is configured to calculate the word coagulation degree of the candidate continuous character string according to the number of the candidate continuous character string and the number of the sub-characters.
[0108] In one embodiment of the present application, the word solidification degree calculation unit may include a vocabulary quantity acquisition unit, a probability value calculation unit and a calculation unit, specifically:
[0109] A vocabulary number acquisition unit, configured to acquire the number of vocabulary in the corpus to be encoded;
[0110] a probability value calculation unit configured to calculate the probability value of the candidate continuous character string according to the number of the vocabulary and the number of the candidate continuous character string, and to calculate the probability value of the sub-character according to the number of the vocabulary and the number of the sub-character;
[0111] The calculation unit is configured to calculate the word coagulation degree of the candidate continuous character string according to the probability value of the candidate continuous character string and the probability value of the sub-character.
[0112] In one embodiment of the present application, the candidate continuous string confirmation module 710 may include:
[0113] A vocabulary acquisition unit, configured to acquire vocabulary from the corpus to be encoded;
[0114] A counting and marking unit, configured to count the number of each of the words corresponding to the corpus to be encoded, and mark the stop symbol corresponding to each of the words, so as to obtain a word frequency representation of each of the words; wherein the stop symbol is used to represent the end position of the word;
[0115] The continuous character string quantity obtaining unit is configured to calculate the quantity of the continuous character strings contained in the word frequency representation of each of the words.
[0116] In one embodiment of the present application, the continuous character string quantity acquisition unit may include a character string acquisition unit and a quantity counting unit, specifically:
[0117] A character string acquisition unit, configured to respectively acquire the continuous character strings contained in each of the word frequency representations;
[0118] The quantity counting unit is configured to count the quantity of each of the continuous character strings in all the word frequency representations according to the quantity corresponding to each of the word frequency representations.
[0119] In one embodiment of the present application, the character string acquisition unit may include a sliding window generation unit and a sampling unit, specifically:
[0120] a sliding window generating unit, configured to generate a sliding window according to a preset length of the continuous character string;
[0121] The sampling unit is configured to perform sampling processing on each of the word frequency representations according to the sliding window of the preset length to obtain a continuous character string contained in each of the word frequency representations.
[0122] In one embodiment of the present application, the encoding module 740 may include a coded character confirmation unit and a processing unit, specifically:
[0123] A coded character confirmation unit, configured to confirm the coded characters of the target continuous character string;
[0124] The processing unit is configured to store the target continuous character string and the encoding characters of the target continuous character string in a dictionary in association, and replace the target continuous characters in the corpus to be encoded with the encoding characters to obtain an updated corpus to be encoded.
[0125] It should be noted that the text encoding device provided in the above embodiment and the text encoding method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment, and will not be repeated here. In practical applications, the text encoding device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0126] Figure 8 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0127] It should be noted that Figure 8 The computer system 800 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0128] like Figure 8 As shown, the electronic device 800 is in the form of a general computing device. The components of the electronic device 800 may include, but are not limited to: the at least one processing unit 810, the at least one storage unit 820, a bus 830 connecting different system components (including the storage unit 820 and the processing unit 810), and a display unit 840.
[0129] The storage unit stores program codes, which can be executed by the processing unit 810, so that the processing unit 810 executes the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification.
[0130] The storage unit 820 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 821 and / or a cache memory unit 822 , and may further include a read-only memory unit (ROM) 823 .
[0131] The storage unit 820 may also include a program / utility 824 having a set (at least one) of program modules 825, such program modules 825 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.
[0132] Bus 830 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0133] The electronic device 800 may also communicate with one or more external devices 870 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 850. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 860. As shown, the network adapter 860 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or application modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0134] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer application. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. When the computer program is executed by the processing unit 810, various functions defined in the system of the present application are executed.
[0135] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may initiate, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0136] The units involved in the embodiments described in this application may be implemented by application programs or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0137] Another aspect of the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the text encoding method as described above is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0138] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the text encoding method provided in each of the above embodiments.
[0139] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. Ordinary technicians in this field can make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A text encoding method, characterized in that: The method comprises: Count the number of each continuous string in the corpus to be encoded, and take the continuous string with the highest number as the candidate continuous string; Calculating the word coagulation degree of the candidate continuous character string, wherein the word coagulation degree is used to characterize the degree of association between each character in the candidate continuous character string; The candidate continuous characters whose word coagulation degree meets the preset conditions are taken as the target continuous character string; Encoding the corpus to be encoded according to the target continuous character string until an encoding end condition corresponding to the corpus to be encoded is met; The encoding process of the corpus to be encoded according to the target continuous character string includes: confirming the encoding characters of the target continuous character string; associating the target continuous character string and the encoding characters of the target continuous character string and storing them in a dictionary, and replacing the target continuous characters in the corpus to be encoded with the encoding characters to obtain an updated corpus to be encoded.
2. The method according to claim 1, characterized in that The calculating the word coagulation degree of the candidate continuous character string includes: confirming the sub-characters constituting the candidate continuous character string; Obtaining the number of occurrences of the candidate continuous character string and the number of occurrences of the sub-character in the corpus to be encoded; The word coagulation degree of the candidate continuous character string is calculated according to the number of the candidate continuous character string and the number of the sub-characters.
3. The method according to claim 2, characterized in that The calculating the word coagulation degree of the candidate continuous character string according to the number of the candidate continuous character string and the number of the sub-characters includes: Obtaining the number of words in the corpus to be encoded; Calculating the probability value of the candidate continuous character string according to the number of the vocabulary and the number of the candidate continuous character string, and calculating the probability value of the sub-character according to the number of the vocabulary and the number of the sub-character; The word coagulation degree of the candidate continuous character string is calculated according to the probability value of the candidate continuous character string and the probability value of the sub-character.
4. The method according to claim 1, characterized in that The counting of the number of each continuous character string in the corpus to be encoded includes: Obtaining vocabulary in the corpus to be encoded; Counting the number of each of the words corresponding to the corpus to be encoded, and marking a stop sign corresponding to each of the words, so as to obtain a word frequency representation of each of the words; wherein the stop sign is used to represent the end position of the word; The number of consecutive character strings contained in the word frequency representation of each of the words is calculated.
5. The method according to claim 4, characterized in that The step of calculating the number of consecutive character strings contained in the word frequency representation of each of the words comprises: Respectively obtain the continuous character strings contained in each of the word frequency representations; According to the number corresponding to each of the word frequency representations, the number of each of the continuous character strings in all the word frequency representations is counted.
6. The method according to claim 5, characterized in that The step of respectively obtaining the continuous character strings contained in each of the word frequency representations comprises: generating a sliding window according to a preset length of the continuous character string; Each of the word frequency representations is sampled according to the sliding window of the preset length to obtain a continuous character string contained in each of the word frequency representations.
7. A text encoding device, characterized in that: The device comprises: A candidate continuous string confirmation module is configured to count the number of each continuous string in the corpus to be encoded, so as to select the continuous string with the highest number as the candidate continuous string; a word coagulation degree calculation module, configured to calculate the word coagulation degree of the candidate continuous character string, wherein the word coagulation degree is used to characterize the degree of association between each character in the candidate continuous character string; a target continuous character string confirmation module configured to take candidate continuous characters whose word coagulation degree meets preset conditions as the target continuous character string; An encoding module configured to perform encoding processing on the corpus to be encoded according to the target continuous character string until an encoding end condition corresponding to the corpus to be encoded is met; the encoding module includes an encoding character confirmation unit and a processing unit; The coded character confirmation unit is configured to confirm the coded characters of the target continuous character string; The processing unit is configured to associate and store the target continuous character string and the encoding characters of the target continuous character string in a dictionary, and replace the target continuous characters in the corpus to be encoded with the encoding characters to obtain an updated corpus to be encoded.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the text encoding method according to any one of claims 1 to 6 is implemented.
9. An electronic device, characterized in that: include: processor; as well as A memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the text encoding method as described in any one of claims 1 to 6.
