Text compression, decompression method, device, computer equipment and storage medium

By preprocessing text and predicting probability distributions, and using arithmetic coding to achieve efficient text compression, it solves the problem that existing lossless compression methods cannot achieve high compression rates and improves the storage efficiency of text data.

CN114048711BActive Publication Date: 2024-10-22SHENZHEN STORLEAD TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111355483.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-16
Publication Date
2024-10-22
Estimated Expiration
2041-11-16

AI Technical Summary

Technical Problem

Existing lossless text compression methods cannot achieve high compression rates and are difficult to effectively handle large amounts of text data storage requirements.

Method used

By performing text preprocessing on the text to be compressed, word encoding is generated, and the output probability distribution of the post-word segmentation is predicted based on the previous word segmentation, and arithmetic coding is used to convert the text into compression coding to achieve efficient text compression and decompression.

Benefits of technology

A higher text compression rate is achieved. Through context feature fitting and probability distribution prediction, the compressed encoding length is smaller than the original text length, thereby improving storage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114048711B_ABST
    Figure CN114048711B_ABST
Patent Text Reader

Abstract

The present application relates to a text compression and decompression method, device, computer equipment and storage medium. The method comprises: performing text preprocessing on a text to be compressed, obtaining word codes corresponding to each target word segment in the text to be compressed, that is, using the word code to represent each target word segment in the text to be compressed, predicting the output probability distribution of the subsequent word segment based on the word code of the preceding word segment in the text to be compressed, thereby fitting the contextual features of the text to be compressed, performing arithmetic coding on the text to be compressed using the predicted output probability distribution of the subsequent word segment, converting the target word segment in the text to be compressed into a compression code, wherein the length of the compression code is less than the length of multiple target word segments, thereby achieving a higher compression rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a text compression and decompression method, device, computer equipment and storage medium. Background Art

[0002] With the development of network technology and the advent of the era of data explosion, a large amount of data that needs to be stored is generated every day. For video and image data, lossy compression methods with a large compression ratio can be used for compression, but for text data, only lossless compression methods can be used. Existing lossless compression methods mainly include statistical coding, dictionary coding and context prediction compression methods, but based on existing lossless compression methods, it is impossible to achieve a high compression rate. Summary of the invention

[0003] In order to solve the above technical problems, the present application provides a text compression and decompression method, apparatus, computer device and storage medium.

[0004] In a first aspect, the present application provides a text compression method, comprising:

[0005] Performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed;

[0006] Based on the word encoding of the preceding participle in the text to be compressed, predict the output probability distribution of the succeeding participle; wherein the preceding participle and the succeeding participle are adjacent target participles in the text to be compressed;

[0007] The text to be compressed is arithmetically encoded based on the output probability distribution of the post-word segmentation to generate a compressed text represented by the compression code.

[0008] In a second aspect, the present application provides a text decompression method, comprising:

[0009] Based on the preceding participle in the text to be decompressed, predict the cumulative probability distribution corresponding to the succeeding participle;

[0010] In the cumulative probability distribution corresponding to the post-participle, determining the probability interval where the corresponding compression code of the text to be decompressed is located;

[0011] Based on the probability interval where the compression code is located and the coding dictionary, the decompressed text corresponding to the text to be decompressed is decoded.

[0012] In a third aspect, the present application provides a text compression device, comprising:

[0013] An encoding module, used for performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed;

[0014] A prediction module, configured to predict the output probability distribution of a subsequent participle based on the word encoding of the preceding participle in the text to be compressed; wherein the preceding participle and the subsequent participle are different target participles in the text to be compressed;

[0015] A compression module is used to perform arithmetic coding on the text to be compressed based on the output probability distribution of the post-word segmentation to generate a compressed text represented by the compression code; wherein the compressed text includes multiple compressed segments, each of which is represented by an integer code.

[0016] In a fourth aspect, the present application provides a text decompression device, comprising:

[0017] A second prediction module is used to predict the cumulative probability distribution corresponding to the subsequent participle based on the preceding participle in the text to be decompressed;

[0018] A determination module, used to determine the probability interval where the corresponding compression code of the text to be decompressed is located in the cumulative probability distribution corresponding to the subsequent participle;

[0019] A decoding module is used to decode and obtain a decompressed text corresponding to the text to be decompressed based on the probability interval of the compressed code and the coding dictionary.

[0020] In a fifth aspect, the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:

[0021] Performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed;

[0022] Based on the word encoding of the preceding participle in the text to be compressed, predict the output probability distribution of the succeeding participle; wherein the preceding participle and the succeeding participle are adjacent target participles in the text to be compressed;

[0023] The text to be compressed is arithmetically encoded based on the output probability distribution of the post-word segmentation to generate a compressed text represented by the compression code.

[0024] In a sixth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:

[0025] Performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed;

[0026] Based on the word encoding of the preceding participle in the text to be compressed, predict the output probability distribution of the succeeding participle; wherein the preceding participle and the succeeding participle are adjacent target participles in the text to be compressed;

[0027] The text to be compressed is arithmetically encoded based on the output probability distribution of the post-word segmentation to generate a compressed text represented by the compression code.

[0028] Based on the above text compression method, the text to be compressed is preprocessed to obtain the word codes corresponding to each target word segment in the text to be compressed, that is, each target word segment in the text to be compressed is represented by the word code, and the output probability distribution of the subsequent word segment is predicted based on the word code of the previous word segment in the text to be compressed, so as to fit the contextual features of the text to be compressed, and the predicted output probability distribution of the subsequent word segment is used to perform arithmetic coding on the text to be compressed, and the target word segment in the text to be compressed is converted into a compression code, and the length of the compression code is less than the length of multiple target word segmentations, so as to achieve a higher compression rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0031] Figure 1 A flowchart of a text compression method in one embodiment;

[0032] Figure 2 A schematic diagram of a flow chart of outputting probability prediction in one embodiment;

[0033] Figure 3 A schematic diagram of the effect of probability interval limiting processing in one embodiment;

[0034] Figure 4 A schematic diagram of a flow chart of a text decompression method in an embodiment;

[0035] Figure 5 A schematic diagram of a program module of a text compression device in one embodiment;

[0036] Figure 6 A schematic diagram of a program module of a text decompression device in one embodiment;

[0037] Figure 7A structural diagram of a computer device in one embodiment. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0039] In one embodiment, Figure 1 A flowchart of a text compression method in an embodiment is shown in FIG. Figure 1 , provides a text compression method. This embodiment mainly uses the method applied to a server as an example to illustrate, and the text compression method specifically includes the following steps:

[0040] Step S210, performing text preprocessing on the text to be compressed to obtain the word code corresponding to each target word in the text to be compressed.

[0041] Specifically, the text to be compressed includes multiple target word segmentations to be compressed, the number of which is denoted as M. Text preprocessing is used to encode the text to be compressed into a numerical form that is convenient for subsequent processing and calculation, that is, text encoding is performed on each target word segmentation in the text to be compressed, and each target word segmentation is represented by a word code, which is a numerical value.

[0042] Step S220, predicting the output probability distribution of the subsequent word segmentation based on the word encoding of the preceding word segmentation in the text to be compressed.

[0043] The preceding participle and the following participle are adjacent target participles in the text to be compressed, that is, the preceding participle is the target participle that appears before the following participle in the text to be compressed. The preceding participle in the previous text of the text to be compressed is used to predict the output probability distribution of the following following participle, and the output probability distribution is used to indicate the probability of which participle the next participle is. In this way, multiple target participles in the text to be compressed are traversed and predicted to obtain multiple output probability distributions, each of which corresponds to a target participle.

[0044] Specifically, the first participle includes multiple target participles, and the second participle is a target participle. The length of the first participle is the predicted length, denoted by L, that is, the first participle includes L target participles. If the L consecutive target participles that appear from the 1st to the Lth in the text to be compressed are used as the first participle to predict the occurrence probability of the L+1th second participle, and then the L consecutive target participles from the 2nd to the L+2th are used as the first participle to predict the occurrence probability of the L+2th second participle, the output probability distribution of each target participle after the Lth in the text to be compressed is predicted according to the predicted length, thereby obtaining the output probability distribution corresponding to the (ML) target participles.

[0045] Step S230, performing arithmetic coding on the text to be compressed based on the output probability distribution of the post-word segmentation to generate a compressed text represented by a compression code.

[0046] Specifically, arithmetic coding is performed on the output probability distributions corresponding to the predicted multiple target participles in turn. The arithmetic coding is used to use the output probability distribution corresponding to the previous participle to narrow the output probability distribution corresponding to the subsequent participle, thereby realizing context iterative compression in the text to be compressed until the output probability distribution corresponding to the ending participle is compressed. The compression code is determined in the output probability distribution corresponding to the compressed ending participle, and the target participle in the text to be compressed is converted into a compression code. The length of the compression code is less than the length of the multiple target participles, thereby achieving a higher compression rate.

[0047] In one embodiment, the text to be compressed is subjected to text preprocessing to obtain word codes corresponding to each target word segment in the text to be compressed, including: constructing a coding dictionary based on the text to be compressed; wherein each text word segment in the coding dictionary corresponds to one word code; performing word segmentation processing on the text to be compressed to obtain multiple target word segments; and performing coding processing on each target word segment based on the coding dictionary to obtain the word code corresponding to each target word segment in the text to be compressed.

[0048] Specifically, an encoding dictionary is constructed based on the text to be compressed or a large corpus in a field related to the text to be compressed. The encoding dictionary includes multiple text segmentations, and the encoding dictionary includes all target segmentations in the text to be compressed. The text segmentations in the encoding dictionary are encoded in sequence, for example, {text: 1, compression: 2, based on: 3, Chinese: 4, we: 5, a: 6, system: 7, word: 8, embedding: 9, compression: 10, recurrent neural network: 11, of: 12, algorithm: 13, ..., xxx: N}, that is, each segmentation corresponds to a numerical value, which is the word encoding corresponding to the segmentation.

[0049] Based on the encoding dictionary, an open source word segmenter can be used to perform word segmentation on the compressed text. The word segmenter can be specifically a word segmenter such as Hanlp or jieba. For example, the text to be compressed is "a Chinese text compression algorithm based on word embedding". The word segmentation is performed to obtain "a Chinese text compression algorithm based on word embedding". In this way, multiple target word segments are obtained, that is, any two target word segments are separated by a separator. Based on the encoding dictionary, the word encoding corresponding to each target word segment can be found. For example, based on the encoding dictionary, it can be found that the word encoding corresponding to "a kind" is 6, and the word encoding corresponding to "based on" is 3. The target word segment in the compressed text is encoded by using multiple text word segments in the encoding dictionary and the word encoding corresponding to each text word segment, so that the multiple target word segments in the compressed text are encoded into a numerical vector.

[0050] For example, the encoding of “a Chinese text compression algorithm based on word embedding” is [6, 3, 8, 9, 12, 4, 1, 2, 13], from which the encoding numerical vector corresponding to the full text to be compressed can be obtained, denoted as ,in, and Corresponding to different target word segmentations, based on the text to be compressed in the above example, It is used to indicate the appearance sequence number of the target word "one" in the first position in the compressed text. The value corresponding to the appearance sequence number is the word code of the target word, that is, , It refers to the matrix number of the target word segmentation "algorithm" at the end of the text to be compressed. The text to be compressed includes M target word segmentations.

[0051] In one embodiment, the predicting the output probability distribution of the subsequent participle based on the word encoding of the preceding participle in the text to be compressed includes: determining a plurality of reference participles corresponding to the subsequent participle according to a preset number; and iteratively learning the plurality of reference participles in turn to determine the output probability of each of the text participles as the subsequent participle.

[0052] Among them, the preceding participle is a participle that appears before the following participle in the text to be compressed and is adjacent to the following participle. The preset number is used to indicate the length of the preceding participle, that is, the preceding participle includes L consecutive reference participles, the first L target participles in the text to be compressed are used as seed participles, each reference participle is a target participle that appears before the following participle, the following participle is a target participle, and the multiple reference participles are iteratively learned in turn to obtain the output probability of each text participle in the encoding dictionary as the following participle, and the output probability distribution includes the output probability of each text participle in the encoding dictionary as the following participle.

[0053] That is, the preceding reference participle and the following reference participle are two adjacent reference participles among the L reference participles, and the preceding reference participle is located before the following reference participle, that is, the appearance sequence number corresponding to the preceding reference participle is smaller than the appearance sequence number corresponding to the following reference participle. Figure 2 In the above formula, X_(t-1) is used to indicate the word encoding of the previous reference participle relative to X_t, and X_t is used to indicate the word encoding of the subsequent reference participle relative to X_(t-1). After learning the previous reference participle, the learning result of the previous reference participle will be obtained. When learning the subsequent reference participle, iterative learning will be combined with the learning result of the previous reference participle to generate the learning result of the subsequent reference participle. In this way, iterative learning is performed until the learning of the last reference participle among the L reference participles is completed, and the output probability distribution of the L+1th subsequent participle is obtained. The output probability distribution is , It is used to indicate the probability that the last segmentation is the first segmentation in the encoding dictionary. The encoding dictionary includes N text segmentations, that is, the output probability distribution includes the probability of each text segmentation in the encoding dictionary as the last segmentation. After the Lth target segmentation in the compressed text, each target segmentation has a corresponding output probability distribution. The compressed text corresponds to (ML) last segmentations. The output probability distribution corresponding to (ML) last segmentations is as follows:

[0054]

[0055]

[0056] …

[0057]

[0058] …

[0059]

[0060] in, It is used to indicate the output probability distribution of the L+1th subsequent word after the L reference words, each subsequent word corresponds to an output probability distribution, and each output probability distribution includes N text words as the output probability of the subsequent word. The above iterative learning process can be specifically implemented by an LSTM network model or a GRU model.

[0061] In one embodiment, performing arithmetic coding on the text to be compressed based on the output probability distribution of the post-segmentation to generate compressed text represented by the compression code includes:

[0062] Determine the cumulative probability distribution corresponding to the subsequent participle based on the output probability distribution of each of the text participles as the subsequent participle;

[0063] Determine the probability interval corresponding to the subsequent participle within the cumulative probability distribution; wherein the probability interval is used to indicate the probability corresponding to the actual target participle in the to-be-compressed text as the subsequent participle;

[0064] Based on the probability interval corresponding to the following participle, iteratively limit the cumulative probability distribution corresponding to the remaining participles in the text to be compressed to obtain the probability interval corresponding to the ending participle in the text to be compressed; wherein the remaining participles are target participles whose appearance order in the text to be compressed is after the following participle, and the ending participle is the target participle that appears at the end of the text to be compressed;

[0065] Based on the probability interval corresponding to the terminal participle, the compression code corresponding to the text to be compressed is determined; wherein the compression code is used to indicate the compressed text.

[0066] The cumulative probability distribution is used to indicate the cumulative set of the output probability distributions corresponding to each of the text segmentations in the coding dictionary, and the cumulative probability distribution is denoted by C. ,in, , , , taking this as a rule, , that is, the probability interval corresponding to the i-th text segmentation in the encoding dictionary as the subsequent segmentation is , each output probability distribution corresponds to a cumulative probability distribution, thus we can get (ML) cumulative probability distributions, corresponding to (ML) output probability distributions of the post-segmentation as follows:

[0067]

[0068] …

[0069]

[0070] …

[0071]

[0072] in, It refers to the cumulative probability distribution corresponding to the i-th target word after the seed word in the text to be compressed.

[0073] In order to quickly find the probability interval corresponding to the post-segmentation, the (ML) target segmentations in the compressed text except the seed segmentation are segmented, and each X words are divided into a segment, which can be divided into D segments, D = (ML) / X, thereby obtaining the numerical vector corresponding to each segment, that is, , , …, ,in, represents the numerical vector corresponding to the first word segment, represents the word code corresponding to the first target word in the first segment, that is, the numerical vector corresponding to each segment is composed of the word codes corresponding to each target word in the segment. The numerical vector for the i-th segment is , the corresponding cumulative probability distribution is , that is, for The jth target word in , that is Used to indicate that the target word is any one of the N text words in the encoding dictionary. , where t is the word code corresponding to the jth target word in the i-th word segment.

[0074] The cumulative probability distribution corresponding to the target word segmentation refers to the probability distribution obtained by predicting the previous word segmentation, combined with the word encoding corresponding to the real target word segmentation in the text to be compressed, to determine the probability interval corresponding to the target word segmentation, denoted as For example, the encoding dictionary includes 5 text segmentation words, that is, the word codes corresponding to the 5 text segmentation words are (1, 2, 3, 4, 5). After probability prediction, the output probability distribution of the first target segmentation word in the first word segment of the text to be compressed is P = (0.1, 0.3, 0.2, 0.15, 0.25), and the corresponding cumulative probability distribution is C = (0.1, 0.4, 0.6, 0.75, 1). The actual word code corresponding to the target segmentation word in the text to be compressed is 3. Therefore, the probability interval corresponding to the target segmentation word can be determined as (0.4,0.6).

[0075] The probability interval corresponding to the first target word in the first paragraph determined above is taken as the first interval, and the cumulative probability distribution corresponding to the second target word in the first paragraph is limited based on the determined first interval, that is, the first interval is taken as the upper and lower limits of the interval corresponding to the second target word in the first paragraph, referring to Figure 3 , determine the probability interval corresponding to the second target word in (0.4, 0.6), and get the second interval, recorded as , and so on, the probability interval determined by each target word will limit the probability interval of the target word after it, so as to determine the probability interval corresponding to each target word after the seed word, that is, the probability interval of the Xth target word in the first paragraph is , since the number of digits after the decimal point of the value corresponding to the probability interval will increase with continuous compression, an integer B will be selected to multiply the probability interval to enlarge the probability interval. For example, set B= .

[0076] In the probability interval corresponding to the Xth target word segment in the first segment, the value used to represent the shortest length can be selected as the compression code corresponding to the first segment. Each segment is arithmetically encoded in the above manner to obtain compression codes corresponding to multiple segments, that is, the compressed text generated by compressing the text to be compressed is represented by D compression codes. Based on the probability interval corresponding to the Xth target word segment in the first segment, the X target words in the second segment can be further limited until the probability interval corresponding to the Xth target word in the Dth segment is obtained. The minimum value in the probability interval is selected as the compression code corresponding to the entire text to be compressed, that is, the compressed text is represented by one compression code. Specifically, it can be determined according to the size of the text to be compressed. For a large text to be compressed, the compression codes corresponding to multiple segments are selected to represent the compressed text; for a small text to be compressed, one compression code is selected to represent the compressed text, and the compression code and the seed word segment are saved to complete the text compression.

[0077] In one embodiment, a text decompression method is provided. The following decoding method is applied to the case where the text to be decoded corresponds to one compression code. When the text to be decoded is represented by multiple compression codes, the multiple compression codes can be decoded in sequence according to the same steps. The method includes:

[0078] Step S310, predicting the cumulative probability distribution corresponding to the subsequent participle based on the preceding participle in the text to be decompressed.

[0079] Specifically, the text to be decompressed includes several seed participles that appear in the first order and are adjacent to the first order, and also includes a compression code for representing the text. The text to be decompressed is a compressed text represented in numerical form. First, several seed participles in the text to be decompressed are used to predict the output probability of the subsequent participle located after the seed participle. The output probability is used to indicate the probability of each text participle in the encoding dictionary as the subsequent participle, that is, the subsequent participle corresponds to multiple output probabilities, each output probability corresponds to a text participle, and an output probability distribution is formed according to the multiple output probabilities corresponding to the subsequent participle. The output probability distribution is recorded as , which includes the output probabilities corresponding to N text segmentations, and generates a cumulative probability distribution based on the output probability distribution, which is recorded as C. ,in, , , , taking this as a rule, , each output probability distribution corresponds to a cumulative probability distribution. The text to be decompressed includes L seed words, and L is used as the prediction length. Each time, the output probability distribution of the next unknown word is predicted based on the L known words, thus (ML) cumulative probability distributions can be obtained.

[0080] Step S320, determining the probability interval of the compressed code corresponding to the text to be decompressed in the cumulative probability distribution corresponding to the subsequent word segmentation.

[0081] Specifically, the corresponding probability interval can be determined based on the cumulative probability distribution, that is, the probability interval corresponding to C is However, since the probability value has more digits after the decimal point, in order to facilitate encoding and decoding, the probability interval is multiplied by a larger integer B to enlarge the probability value. B can be set to , so the probability interval is , based on this probability interval, select the interval containing the compression code, if , where Y is used to indicate the compression code, then the probability interval of the corresponding compression code of the text to be decompressed is obtained .

[0082] Step S330, based on the probability interval of the compressed code and the coding dictionary, decoding is performed to obtain the decompressed text corresponding to the text to be decompressed.

[0083] Specifically, the word code corresponding to the post-participle is determined within the probability interval of the compressed code, and the word code is queried in the coding dictionary to decode the corresponding target participle. In this way, each post-participle is decoded in turn to obtain the decompressed text represented by the target participle.

[0084] In one embodiment, decoding to obtain the decompressed text corresponding to the text to be decompressed based on the probability interval of the compression code and the coding dictionary includes:

[0085] Based on the coding dictionary, the upper limit value of the probability interval where the compressed code is located is decoded to obtain the real participle corresponding to the subsequent participle; wherein the decompressed text includes a plurality of the real participles;

[0086] Taking the real participle as the preceding participle, executing the step of predicting the cumulative probability distribution corresponding to the succeeding participle based on the preceding participle in the to-be-decompressed text;

[0087] Based on the probability interval where the compression code is located, the predicted cumulative probability distribution is subjected to clipping processing to obtain a cumulative probability distribution after clipping;

[0088] Based on the cumulative probability distribution after limiting, the step of determining the probability interval of the corresponding compression code of the text to be decompressed in the cumulative probability distribution corresponding to the post-word segmentation is performed.

[0089] Specifically, the probability interval of the corresponding compression code of the text to be decompressed The upper limit value in , then the word encoding corresponding to the subsequent participle is K, and the participle corresponding to K is searched in the encoding dictionary to decode a participle. On the basis of contacting a participle, the participle is taken as the known previous participle, and the above steps are repeated to execute the steps of predicting the cumulative probability distribution of the subsequent participle based on the previous participle, that is, each time a participle is solved, the newly decoded participle will be used to predict the cumulative probability distribution of the next participle to be decoded, but the cumulative probability distribution obtained by the latest prediction will be limited in the probability interval of the previous participle, that is, the upper and lower limits of the cumulative probability distribution obtained by the new prediction will not exceed the probability interval corresponding to the previous participle, and the cumulative probability distribution after limiting is obtained, refer to Figure 3 , that is , based on the cumulative probability distribution after clipping, determine the probability interval containing the compression code in the cumulative probability distribution after clipping. , then the probability interval corresponding to the post-participle is , and then according to the upper limit value , the word encoding corresponding to the post-participle is V, and the participle corresponding to V is searched in the encoding dictionary to decode a participle after K.

[0090] Exemplarily, the text to be decompressed will follow the above process, using the first L seed word segmentations to predict the cumulative probability distribution of the L+1th subsequent word segmentation. Assume that L=10, that is, use the first ten word segmentations to predict the output probability distribution corresponding to the eleventh word segmentation. The output probability distribution includes the probability of each text word segmentation in the encoding dictionary as the eleventh word segmentation. The corresponding cumulative probability distribution can be obtained by cumulatively superimposing the output probability distribution. Based on the cumulative probability distribution, the interval containing the compression code is determined, that is, the probability interval is obtained, and the word code corresponding to the maximum value in the probability interval is decoded, that is, the word segmentation corresponding to the word code is found in the encoding dictionary. , thereby decompressing the eleventh participle, and then using the ten participles from the second to the eleventh as the preceding participle, predicting the cumulative probability distribution corresponding to the twelfth subsequent participle, but using the probability interval corresponding to the eleventh word to narrow the cumulative probability distribution corresponding to the twelfth word, that is, according to the probability interval of the eleventh word, the upper and lower limits of the corresponding cumulative probability distribution of the twelfth word are limited, and the probability interval containing the compressed code is determined within the cumulative probability distribution after limiting, and the twelfth word is obtained by continuing to decode according to the upper limit value of the probability interval, that is, the entire text to be compressed will be decoded according to this process, so as to decode and obtain the decompressed text represented by the participle.

[0091] Figure 1 and Figure 4 FIG. 1 is a flowchart of a text compression and decompression method in an embodiment. It should be understood that although Figure 1 and Figure 4The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 and Figure 4 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0092] In one embodiment, Figure 5 As shown, a text compression device is provided, comprising:

[0093] The encoding module 410 is used to perform text preprocessing on the text to be compressed to obtain the word code corresponding to each target word in the text to be compressed;

[0094] A first prediction module 420 is configured to predict an output probability distribution of a subsequent participle based on a word code of a preceding participle in the text to be compressed; wherein the preceding participle and the subsequent participle are adjacent target participles in the text to be compressed;

[0095] The compression module 430 is used to perform arithmetic coding on the text to be compressed based on the output probability distribution of the post-word segmentation to generate a compressed text represented by a compression code.

[0096] In one embodiment, the encoding module 410 is further configured to:

[0097] Constructing a coding dictionary based on the text to be compressed; wherein each text segment in the coding dictionary corresponds to one of the word codes;

[0098] Performing word segmentation processing on the text to be compressed to obtain a plurality of target word segments;

[0099] Each of the target word segments is encoded based on the encoding dictionary to obtain the word encoding corresponding to each of the target word segments in the text to be compressed.

[0100] In one embodiment, the first prediction module 420 is further configured to:

[0101] Determine a plurality of reference participles corresponding to the latter participle according to a preset number; wherein the former participle is a participle that appears before the latter participle in the to-be-compressed text and is adjacent to the latter participle, and the former participle includes a plurality of the reference participles;

[0102] Iterative learning is performed on the plurality of reference segmentations in sequence to determine the output probability of each of the text segmentations as the subsequent segmentation; wherein the output probability distribution includes the output probability of each of the text segmentations in the encoding dictionary as the subsequent segmentation.

[0103] In one embodiment, the compression module 430 is further configured to:

[0104] Based on the output probability distribution of each of the text segmentations as the subsequent segmentation, determining the cumulative probability distribution corresponding to the subsequent segmentation; wherein the cumulative probability distribution is used to indicate the cumulative set of the output probability distributions corresponding to each of the text segmentations in the encoding dictionary;

[0105] Determine the probability interval corresponding to the subsequent participle within the cumulative probability distribution; wherein the probability interval is used to indicate the probability corresponding to the actual target participle in the to-be-compressed text as the subsequent participle;

[0106] Based on the probability interval corresponding to the following participle, iteratively limit the cumulative probability distribution corresponding to the remaining participles in the text to be compressed to obtain the probability interval corresponding to the ending participle in the text to be compressed; wherein the remaining participles are target participles whose appearance order in the text to be compressed is after the following participle, and the ending participle is the target participle that appears at the end of the text to be compressed;

[0107] Based on the probability interval corresponding to the terminal participle, the compression code corresponding to the text to be compressed is determined; wherein the compression code is used to indicate the compressed text.

[0108] In one embodiment, referring to Figure 6 This embodiment provides a text decompression device, the device comprising:

[0109] A second prediction module 510, configured to predict the cumulative probability distribution corresponding to the subsequent participle based on the preceding participle in the text to be decompressed;

[0110] A determination module 520, configured to determine the probability interval where the compression code corresponding to the to-be-decompressed text is located in the cumulative probability distribution corresponding to the subsequent participle;

[0111] The decoding module 530 is used to decode and obtain the decompressed text corresponding to the text to be decompressed based on the probability interval of the compressed code and the coding dictionary.

[0112] In one embodiment, the decoding module 530 is further configured to:

[0113] Based on the coding dictionary, the upper limit value of the probability interval where the compressed code is located is decoded to obtain the real participle corresponding to the subsequent participle; wherein the decompressed text includes a plurality of the real participles;

[0114] The second prediction module 510 is further used to: take the real participle as the preceding participle, and perform the step of predicting the cumulative probability distribution corresponding to the succeeding participle based on the preceding participle in the to-be-decompressed text;

[0115] Based on the probability interval where the compression code is located, the predicted cumulative probability distribution is subjected to clipping processing to obtain a cumulative probability distribution after clipping;

[0116] The second prediction module 510 is further used to: based on the cumulative probability distribution after limiting, execute the step of determining the probability interval of the corresponding compression code of the to-be-decompressed text in the cumulative probability distribution corresponding to the post-word segmentation.

[0117] Figure 7 FIG. 1 shows an internal structure diagram of a computer device in an embodiment. The computer device may specifically be a server. Figure 7 As shown, the computer device includes a processor, a memory, a network interface, an input device and a display screen connected via a system bus. Among them, the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement a text compression and decompression method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can implement a text compression and decompression method. Those skilled in the art can understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0118] In one embodiment, the text compression device provided by the present application can be implemented in the form of a computer program. The computer program can be Figure 7 The computer device shown in the figure is run. The memory of the computer device can store various program modules constituting the text compression device, such as: Figure 5 The coding module 410, the first prediction module 420 and the compression module 430 are shown. The computer program composed of various program modules enables the processor to execute the steps of the text compression and decompression method of each embodiment of the present application described in this specification.

[0119] Figure 7The computer device shown can be Figure 5 The encoding module 410 in the text compression device shown performs text preprocessing on the text to be compressed to obtain the word encoding corresponding to each target word in the text to be compressed. The computer device can predict the output probability distribution of the subsequent word based on the word encoding of the previous word in the text to be compressed through the first prediction module 420; wherein the previous word and the subsequent word are adjacent target words in the text to be compressed. The computer device can perform arithmetic encoding on the text to be compressed based on the output probability distribution of the subsequent word through the compression module 430 to generate a compressed text represented by the compression code.

[0120] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the method described in any one of the above embodiments is implemented when the processor executes the computer program.

[0121] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method described in any one of the above embodiments is implemented.

[0122] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0123] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0124] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A text compression method, characterized in that: The method comprises: Performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed; Based on the word encoding of the preceding participle in the text to be compressed, predict the output probability distribution of the succeeding participle; wherein the preceding participle and the succeeding participle are adjacent target participles in the text to be compressed; Performing arithmetic coding on the text to be compressed based on the output probability distribution of the post-segmentation to generate a compressed text represented by a compression code; The step of performing arithmetic coding on the text to be compressed based on the output probability distribution of the post-segmentation to generate a compressed text represented by a compression code includes: Based on each text segmentation as the output probability distribution of the subsequent segmentation, determine the cumulative probability distribution corresponding to the subsequent segmentation; wherein the cumulative probability distribution is used to indicate the cumulative set of the output probability distributions corresponding to each of the text segmentations in the encoding dictionary; Determine the probability interval corresponding to the subsequent participle within the cumulative probability distribution; wherein the probability interval is used to indicate the probability corresponding to the actual target participle in the to-be-compressed text as the subsequent participle; Based on the probability interval corresponding to the following participle, iteratively limit the cumulative probability distribution corresponding to the remaining participles in the text to be compressed to obtain the probability interval corresponding to the ending participle in the text to be compressed; wherein the remaining participles are target participles whose appearance order in the text to be compressed is after the following participle, and the ending participle is the target participle that appears at the end of the text to be compressed; Based on the probability interval corresponding to the terminal participle, the compression code corresponding to the text to be compressed is determined; wherein the compression code is used to indicate the compressed text.

2. The method according to claim 1, characterized in that The text preprocessing to be compressed is performed to obtain the word code corresponding to each target word in the text to be compressed, including: Constructing a coding dictionary based on the text to be compressed; wherein each text segment in the coding dictionary corresponds to one of the word codes; Performing word segmentation processing on the text to be compressed to obtain a plurality of target word segments; Each of the target word segments is encoded based on the encoding dictionary to obtain the word encoding corresponding to each of the target word segments in the text to be compressed.

3. The method according to claim 2, characterized in that The step of predicting the output probability distribution of the subsequent word segmentation based on the word encoding of the preceding word segmentation in the to-be-compressed text comprises: Determine a plurality of reference participles corresponding to the latter participle according to a preset number; wherein the preset number is used to indicate the length of the preceding participle, the preceding participle is a participle that appears before the latter participle and is adjacent to the latter participle in the to-be-compressed text, and the preceding participle includes a plurality of the reference participles; Iterative learning is performed on the plurality of reference segmentations in sequence to determine the output probability of each of the text segmentations as the subsequent segmentation; wherein the output probability distribution includes the output probability of each of the text segmentations in the encoding dictionary as the subsequent segmentation.

4. A text decompression method, characterized in that: The method comprises: Based on the preceding participle in the text to be decompressed, predict the cumulative probability distribution corresponding to the succeeding participle; In the cumulative probability distribution corresponding to the post-participle, determining the probability interval where the corresponding compression code of the text to be decompressed is located; Based on the probability interval of the compression code and the coding dictionary, decoding is performed to obtain the decompressed text corresponding to the text to be decompressed; The decoding to obtain the decompressed text corresponding to the text to be decompressed based on the probability interval of the compression code and the coding dictionary includes: Based on the coding dictionary, the upper limit value of the probability interval where the compressed code is located is decoded to obtain the real participle corresponding to the subsequent participle; wherein the decompressed text includes a plurality of the real participles; Taking the real participle as the preceding participle, executing the step of predicting the cumulative probability distribution corresponding to the succeeding participle based on the preceding participle in the to-be-decompressed text; Based on the probability interval where the compression code is located, the predicted cumulative probability distribution is subjected to clipping processing to obtain a cumulative probability distribution after clipping; Based on the cumulative probability distribution after limiting, the step of determining the probability interval of the corresponding compression code of the text to be decompressed in the cumulative probability distribution corresponding to the post-word segmentation is performed.

5. A text compression device, characterized in that: The device comprises: An encoding module, used for performing text preprocessing on the text to be compressed to obtain word codes corresponding to each target word in the text to be compressed; A first prediction module is used to predict the output probability distribution of the subsequent participle based on the word encoding of the preceding participle in the text to be compressed; wherein the preceding participle and the subsequent participle are adjacent target participles in the text to be compressed; A compression module, used for performing arithmetic coding on the text to be compressed based on the output probability distribution of the post-segmentation to generate a compressed text represented by a compression code; Wherein, the compression module is specifically used for: Based on each text segmentation as the output probability distribution of the subsequent segmentation, determine the cumulative probability distribution corresponding to the subsequent segmentation; wherein the cumulative probability distribution is used to indicate the cumulative set of the output probability distributions corresponding to each of the text segmentations in the encoding dictionary; Determine the probability interval corresponding to the subsequent participle within the cumulative probability distribution; wherein the probability interval is used to indicate the probability corresponding to the actual target participle in the to-be-compressed text as the subsequent participle; Based on the probability interval corresponding to the following participle, iteratively limit the cumulative probability distribution corresponding to the remaining participles in the text to be compressed to obtain the probability interval corresponding to the ending participle in the text to be compressed; wherein the remaining participles are target participles whose appearance order in the text to be compressed is after the following participle, and the ending participle is the target participle that appears at the end of the text to be compressed; Based on the probability interval corresponding to the terminal participle, the compression code corresponding to the text to be compressed is determined; wherein the compression code is used to indicate the compressed text.

6. A text decompression device, characterized in that: The device comprises: A second prediction module is used to predict the cumulative probability distribution corresponding to the subsequent participle based on the preceding participle in the text to be decompressed; A determination module, used to determine the probability interval where the corresponding compression code of the text to be decompressed is located in the cumulative probability distribution corresponding to the subsequent participle; A decoding module, used for decoding to obtain a decompressed text corresponding to the text to be decompressed based on the probability interval of the compressed code and the coding dictionary; Wherein, the decoding module is specifically used for: Based on the coding dictionary, the upper limit value of the probability interval where the compressed code is located is decoded to obtain the real participle corresponding to the subsequent participle; wherein the decompressed text includes a plurality of the real participles; Taking the real participle as the preceding participle, executing the step of predicting the cumulative probability distribution corresponding to the succeeding participle based on the preceding participle in the to-be-decompressed text; Based on the probability interval where the compression code is located, the predicted cumulative probability distribution is subjected to clipping processing to obtain a cumulative probability distribution after clipping; Based on the cumulative probability distribution after limiting, the step of determining the probability interval of the corresponding compression code of the text to be decompressed in the cumulative probability distribution corresponding to the post-word segmentation is performed.

7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.

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

Citation Information

Patent Citations

  • Remote channel message compression method and system for electricity consumption collection system

    CN105553625A

  • Text simplification method based on word vector query model

    CN107844469A

  • Method, apparatus and electronic device for determining word representation vector

    WO2021112647A1