Text data sparse coding method and system for HTM model
By using Unicode encoding values to calculate the encoding conversion value and activate the start bit in the HTM model, sparse encoding is built, and the problem of insufficient encoding accuracy in text processing of the HTM model is solved, efficient and accurate text data encoding is achieved, and the model is improved Application capability in text processing tasks.
Patent Information
- Application Number
- CN202410274024.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-11
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-03-11
AI Technical Summary
The existing HTM model lacks effective text encoder in the field of text processing, resulting in insufficient accuracy of encoding results, limiting its application in text data processing.
Provide a sparse encoding method for text data for HTM model. By obtaining the Unicode encoding value of text data, calculating the encoding conversion value and activation start bit, constructing sparse encoding, and identifying the starting area using preset continuous activation point value marks. , realize efficient and accurate text data encoding.
It improves the sparse encoding efficiency and accuracy of text data, making the HTM model more applicable in text processing tasks, especially in entity recognition and text anomaly detection.
Smart Images

Figure CN118278360B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a text data sparse coding method and system for an HTM model. Background Art
[0002] The Hierarchical Temporal Memory (HTM) model consists of three main parts: encoder, cortical layer and classifier. At present, encoders for HTM models mainly include four categories: numerical encoder, category encoder, geospatial encoder and natural language encoder. However, the current HTM model has not been effectively promoted in the field of text processing. The main reason is the lack of corresponding text encoders and the insufficient accuracy of the encoding results obtained by the relevant text encoders.
[0003] Therefore, there is an urgent need for a text data sparse coding method and system for the HTM model to solve the above problems. Summary of the invention
[0004] In view of the problems existing in the prior art, the present invention provides a text data sparse coding method and system for an HTM model.
[0005] The present invention provides a text data sparse coding method for an HTM model, comprising:
[0006] Obtain text data to be input into the HTM model;
[0007] According to the preset continuous activation point value and the preset code value corresponding to each character in the text data, the code conversion value of each character in the text data is obtained, wherein the preset continuous activation point value is used to mark the recognition start area in the sparse code corresponding to the character;
[0008] Determining the encoding length of the characters in the text data according to the encoding conversion value;
[0009] According to the encoding conversion value and the preset encoding value, an activation start bit corresponding to each of the characters in the text data is obtained, wherein the activation start bit represents the starting position of the preset continuous activation point bit value in the sparse code;
[0010] The sparse code corresponding to each of the characters in the text data is constructed based on the preset code value, the code length, the preset continuous activation point value and the activation start bit.
[0011] According to a text data sparse coding method for an HTM model provided by the present invention, before obtaining the text data to be input into the HTM model, the method further includes:
[0012] The text data is encoded based on the Unicode encoding method to obtain the preset encoding value corresponding to each character in the text data.
[0013] According to a text data sparse coding method for an HTM model provided by the present invention, the encoding conversion value of each character in the text data is obtained according to the preset continuous activation point value and the preset encoding value corresponding to each character in the text data, including:
[0014] Sorting the preset code values corresponding to the characters in the text data from small to large to obtain a code value sorting result;
[0015] Determine the character position value corresponding to each of the characters in the text data according to the encoding value sorting result;
[0016] Obtaining a code value difference according to two adjacent preset code values in the code value sorting result;
[0017] Based on the comparison result between the encoding value difference and the preset continuous activation point value, the encoding conversion value of each character in the text data is calculated according to the preset encoding value and the character position value.
[0018] According to a text data sparse coding method for an HTM model provided by the present invention, the method further includes:
[0019] Based on the comparison result between the code value difference and the preset continuous activation point value, according to the preset code value and the character position value, the code conversion value of each character in the text data is calculated by a code conversion value calculation formula, and the code conversion value calculation formula is:
[0020]
[0021] Wherein, i=1,2,3,...,n, and i is a positive integer; Indicates the encoding conversion value corresponding to the i-th character in the encoding value sorting result; represents the character position value corresponding to the i-th character in the coding value sorting result; w represents the preset continuous activation point value, U i Indicates the preset code value corresponding to the ith character in the code value sorting result.
[0022] According to a text data sparse coding method for an HTM model provided by the present invention, determining the coding length of the characters in the text data according to the coding conversion value comprises:
[0023] Based on the encoding conversion values of all the characters in the text data, obtaining a maximum encoding conversion value and a minimum encoding conversion value;
[0024] Obtaining a code conversion value range according to a difference between the maximum code conversion value and the minimum code conversion value;
[0025] Determining the encoding length of the character in the text data according to the encoding conversion value range and the preset continuous activation point value;
[0026] The step of obtaining the activation start bit corresponding to each character in the text data according to the encoding conversion value and the preset encoding value includes:
[0027] According to the minimum code conversion value and the preset code value corresponding to each character, the activation start bit corresponding to each character is calculated by the activation start bit calculation formula, and the activation start bit calculation formula is:
[0028] l = floor[m-minValue+1];
[0029] Among them, l represents the activation start bit, m represents the preset encoding value corresponding to the character, and minValue represents the minimum encoding conversion value.
[0030] According to a text data sparse coding method for an HTM model provided by the present invention, the sparse coding corresponding to each character in the text data is constructed according to the preset coding value, the coding length, the preset continuous activation point value and the activation start bit, including:
[0031] According to the activation start bit, determining the start bit of the preset continuous activation point bit value;
[0032] Based on the starting bit of the preset continuous activation point bit value and according to the code length, the preset continuous activation point bit value and the preset code value are combined to construct the sparse code corresponding to each character in the text data.
[0033] The present invention also provides a text data sparse coding system for an HTM model, comprising:
[0034] A text data acquisition module, used to acquire text data to be input into the HTM model;
[0035] A code conversion value calculation module, used for obtaining the code conversion value of each character in the text data according to a preset continuous activation point value and a preset code value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the recognition start area in the sparse code corresponding to the character;
[0036] A first processing module, used for determining the encoding length of the character in the text data according to the encoding conversion value;
[0037] A second processing module is used to obtain an activation start bit corresponding to each of the characters in the text data according to the encoding conversion value and the preset encoding value, wherein the activation start bit represents the starting position of the preset continuous activation point bit value in the sparse code;
[0038] A sparse coding construction module is used to construct the sparse code corresponding to each character in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit.
[0039] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the text data sparse coding method for the HTM model as described in any one of the above is implemented.
[0040] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the text data sparse encoding method for the HTM model as described in any one of the above is implemented.
[0041] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method for sparse coding of text data for an HTM model as described above is implemented.
[0042] The text data sparse coding method and system for the HTM model provided by the present invention preset continuous activation point value and preset coding value corresponding to each character in the text data, and the coding conversion value of each character, and then determine the coding length of the character and the activation start position corresponding to the character according to the coding conversion value, and finally construct the sparse coding corresponding to each character in the text data according to the preset coding value, coding length, preset continuous activation point value and activation start position, so that the sparse coding of the text data is more efficient and accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A schematic diagram of a flow chart of a text data sparse coding method for an HTM model provided by the present invention;
[0045] Figure 2 A schematic diagram of sparse coding of text data provided by the present invention;
[0046] Figure 3 A schematic diagram of the application of sparse coding of text data provided by the present invention;
[0047] Figure 4 A schematic diagram of the structure of a text data sparse coding system for an HTM model provided by the present invention;
[0048] Figure 5 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] In the existing HTM model, the cortical layer includes two processes: spatial pooling and temporal memory, which are used for feature extraction and temporal learning; the classifier classifies the output of the cortical layer, which is equivalent to the decoder; and the encoder encodes the input object into a binary vector that can be processed by the cortical layer.
[0051] In the encoder of the existing HTM model, the numerical encoder can convert continuous digital data (such as date, temperature, speed, etc.) into binary codes that can be processed by HTM by specifying the minimum value, maximum value, number of continuous activation sites, total coding length, and mapping function (linear, exponential or hash). In addition, the numerical encoder pays attention to the difference between adjacent data values and encodes continuously increasing and decreasing values into the same binary vector to reduce redundancy.
[0052] The category encoder is used to convert discrete categorical data (such as days of the week, hours, and colors) into binary codes that can be processed by the HTM model. For completely independent categories, one-hot encoding is used; for related categories, encodings containing overlapping sites are required; for categories with head-to-tail connections such as days of the week and hours, circular encoding is required.
[0053] The geospatial encoder takes the input GPS coordinates and projects them into a two-dimensional one-hot matrix, which represents the activation site area around the location, covering all possible movement ranges of the tracked target.
[0054] Natural language encoders mainly include text encoding methods such as semantic folding. "Semantic folding" is an encoding method based on dictionary entries, which uses the semantic space obtained by pre-training as the encoding space. In this space, each site represents a group of words used to represent specific semantic features, and the relationship between sites follows the principle of "semantically similar sites are close to each other". When a piece of natural language is input, each site in the space is traversed. If the natural language contains the same word as a site, it means that the semantic feature corresponding to the site is activated. However, semantic folding has not been widely used, partly because it has not yet been open sourced and its encoding accuracy needs to be improved.
[0055] In order to make the HTM model better applied in the field of text processing, the design of its HTM encoder is crucial. The HTM encoder is required to effectively convert multiple objects into binary vectors so that the HTM cortical layer can achieve sparse distributed representation (SDR) and recognize the input pattern.
[0056] Figure 1 The flowchart of the text data sparse coding method for the HTM model provided by the present invention is as follows: Figure 1 As shown, the present invention provides a text data sparse coding method for an HTM model, comprising:
[0057] Step 101, obtaining text data to be input into the HTM model;
[0058] In the present invention, text data to be processed are collected from various sources (eg, text files, databases, networks, etc.) Optionally, pre-processing operations such as cleaning, standardization, and word segmentation are performed on the acquired text data to facilitate subsequent analysis and modeling.
[0059] Furthermore, the preprocessed text data is organized into a format suitable for HTM model input. Specifically, before obtaining the text data to be input into the HTM model, the method further includes:
[0060] The text data is encoded based on the Unicode encoding method to obtain the preset encoding value corresponding to each character in the text data.
[0061] In the present invention, a corresponding sparse code is further constructed for each character through the preset code value, namely, Unicode code. Unicode code is a standard character set that assigns a unique digital code to almost all characters, including text, symbols, and punctuation marks in various languages. In traditional text processing, ASCII code or other encoding methods are often used to represent characters, but these encoding methods have limitations for multi-language text processing. In the existing Unicode code of characters, the Unicode codes of similar characters are arranged in nearby positions. Based on this, the present invention combines the Unicode code of characters and the encoding ideas of numerical encoders to propose a text encoding method based on Unicode code conversion values. Taking into account the problem of excessive code length in the original numerical encoding method, the present invention maps and converts the Unicode code to obtain the Unicode code conversion value, thereby achieving the effect of reducing the overall code length.
[0062] Step 102, according to the preset continuous activation point value and the preset code value corresponding to each character in the text data, obtain the code conversion value of each character in the text data, wherein the preset continuous activation point value is used to mark the recognition starting area in the sparse code corresponding to the character.
[0063] In the present invention, the preset continuous activation point bit values are used to mark the recognition start area corresponding to the character in the sparse code. In the HTM model, sparse coding is used to represent input data, wherein each feature or character corresponds to a code, and by setting the preset continuous activation point bit values, it is possible to specify which bits in the code are used to represent the recognition start area of the character.
[0064] Furthermore, each character has a preset code value in the sparse coding, namely the Unicode code, which is used to represent the position or feature of the character in the coding space. In the present invention, the code conversion value of each character can be calculated according to the preset continuous activation point value and the preset code value corresponding to the character, so that the code conversion value reflects the specific representation of the character in the sparse coding, helps the model to accurately understand and process text data, and realize various natural language processing tasks.
[0065] Step 103: Determine the encoding length of the characters in the text data according to the encoding conversion value.
[0066] In the present invention, by analyzing the encoding conversion values, such as the maximum encoding conversion value and the minimum encoding conversion value corresponding to all characters in the current input text data, the length of each character in the text data in the encoding representation can be determined.
[0067] Step 104, obtaining the activation start bit corresponding to each of the characters in the text data according to the encoding conversion value and the preset encoding value, wherein the activation start bit represents the starting position of the preset continuous activation point bit value in the sparse code.
[0068] In the present invention, by combining the code conversion value and the preset code value, the activation start bit corresponding to each character in the text data can be calculated. This activation start bit indicates the starting position of the preset continuous activation point bit value in the sparse coding, thereby determining the position of the character in the coding.
[0069] Step 105, constructing the sparse code corresponding to each of the characters in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit.
[0070] In the present invention, based on the characteristics of the text Unicode encoding arrangement, and combined with the encoding ideas of the numerical encoder, the basic principle of similar encoding of similar objects is met, so that the generated encoding has semantic information, and the HTM model is widely used in tasks such as entity recognition and text anomaly detection. Specifically, the Unicode encoding corresponding to each character in the text data is obtained; then, the Unicode encoding conversion value is obtained by combining the Unicode encoding, the corresponding position sorting value of the Unicode encoding, and the preset continuous activation point value, so as to map the Unicode encoding to the corresponding Unicode encoding conversion value; then, the maximum value maxValue and the minimum value minValue of the Unicode encoding conversion value are calculated, and the range between the maximum value and the minimum value (i.e., the encoding conversion value range) is divided into corresponding data buckets; further, these data buckets are mapped to a group of active cells to further realize sparse encoding conversion. In the present invention, the encoding length of the characters in the currently input text data can be calculated through the encoding conversion value range and the preset continuous activation point value, and the corresponding data bucket (i.e., the activation start position) is obtained according to the Unicode encoding of the character, and the preset continuous activation point value and the preset encoding value are combined to construct the sparse encoding of the character. Figure 2The sparse coding diagram of the text data provided by the present invention is as follows: the character with a Unicode code value of m (such as the number 1) has an activation start bit of l in a code length of n, and the preset continuous activation point bit value is w. The sparse coding can be referred to as Figure 2 shown.
[0071] The text data sparse coding method for the HTM model provided by the present invention presets continuous activation point value and preset coding value corresponding to each character in the text data, and the coding conversion value of each character, and then determines the coding length of the character and the activation start position corresponding to the character according to the coding conversion value, and finally constructs the sparse coding corresponding to each character in the text data according to the preset coding value, coding length, preset continuous activation point value and activation start position, so that the sparse coding of the text data is more efficient and accurate.
[0072] On the basis of the above embodiment, the step of obtaining the encoding conversion value of each character in the text data according to the preset continuous activation point value and the preset encoding value corresponding to each character in the text data includes:
[0073] Sorting the preset code values corresponding to the characters in the text data from small to large to obtain a code value sorting result;
[0074] Determine the character position value corresponding to each of the characters in the text data according to the encoding value sorting result;
[0075] Obtaining a code value difference according to two adjacent preset code values in the code value sorting result;
[0076] Based on the comparison result between the encoding value difference and the preset continuous activation point value, the encoding conversion value of each character in the text data is calculated according to the preset encoding value and the character position value.
[0077] In the present invention, the preset code values corresponding to each character in the text data are first sorted from small to large to obtain the code value sorting result. In one embodiment, the Unicode code corresponding to the currently commonly used 3500 characters (including Chinese characters, characters, symbols and numbers, etc.) is used for illustration. Assume that the Unicode code values corresponding to the commonly used characters are:
[0078] U1,U2,U3,...,U i-1 ,U i ,...,U n (i=1,2,3,...,n);
[0079] Then sort these Unicode code values from small to large to get the code value sorting result:
[0080] U1<U2<U3<...<U i-1 <U i <...<U n (i=1,2,3,...,n);
[0081] In the present invention, the character position value refers to the position of the character in the sorted sequence. After sorting the characters, each character corresponds to a position value, indicating its position in the sorted sequence. For example, suppose there is a string "hello", and the characters therein are sorted to obtain "ehllo". In this sorted sequence, the position value of each character can be represented by their index in the sorted sequence, that is, the position value of "e" in the sorted sequence is 1, the position value of "h" is 2, the position value of "l" is 3, and the position value of "o" is 4.
[0082] Then, in the coding value sorting result, the difference between two adjacent preset coding values (i.e., U i -U i-1 ), these differences can provide distance information between adjacent positions of characters in the coding space. Further, based on the comparison result between the coding value difference and the preset continuous activation point value, combined with the preset coding value and the character position value, the coding conversion value of each character can be calculated.
[0083] Based on the above embodiment, the method further includes:
[0084] Based on the comparison result between the code value difference and the preset continuous activation point value, according to the preset code value and the character position value, the code conversion value of each character in the text data is calculated by a code conversion value calculation formula, and the code conversion value calculation formula is:
[0085]
[0086] Wherein, i=1,2,3,...,n, and i is a positive integer; Indicates the encoding conversion value corresponding to the i-th character in the encoding value sorting result; represents the character position value corresponding to the i-th character in the coding value sorting result; w represents the preset continuous activation point value, w is a positive integer; U i Indicates the preset code value corresponding to the ith character in the code value sorting result.
[0087] In the present invention, according to the comparison result between the code value difference and the preset continuous activation point value, the corresponding formula is selected to calculate the code conversion value, wherein, among the 3500 commonly used characters, the minimum code conversion value (that is, the code conversion value corresponding to the first sort in the code value sorting result) is 1; when the code value difference (the absolute value of the difference) is greater than the preset continuous activation point value, the code conversion value corresponding to the current character is calculated according to the previous character position value and the preset continuous activation point value; when the code value difference (the absolute value of the difference) is less than or equal to the preset continuous activation point value, and greater than 0, the code conversion value corresponding to the current character is calculated according to the previous character position value and the code value difference (the difference between the preset code value of the current character and the preset code value of the previous character); when the code value difference is equal to 0, the code conversion value corresponding to the current character is equal to the code conversion value of the previous character.
[0088] Based on the above embodiment, determining the encoding length of the character in the text data according to the encoding conversion value includes:
[0089] Based on the encoding conversion values of all the characters in the text data, obtaining a maximum encoding conversion value and a minimum encoding conversion value;
[0090] Obtaining a code conversion value range according to a difference between the maximum code conversion value and the minimum code conversion value;
[0091] Determining the encoding length of the character in the text data according to the encoding conversion value range and the preset continuous activation point value;
[0092] The step of obtaining the activation start bit corresponding to each character in the text data according to the encoding conversion value and the preset encoding value includes:
[0093] According to the minimum code conversion value and the preset code value corresponding to each character, the activation start bit corresponding to each character is calculated by the activation start bit calculation formula, and the activation start bit calculation formula is:
[0094] l = floor[m-minValue+1];
[0095] Among them, l represents the activation start bit, m represents the preset encoding value corresponding to the character, and minValue represents the minimum encoding conversion value.
[0096] In the present invention, based on the above embodiment, the encoding conversion value of each character in the text data is calculated, the maximum encoding conversion value maxValue and the minimum encoding conversion value minValue are obtained, and then the Unicode encoding conversion value range is calculated to be max Value-min Value, and the value of the data bucket divided according to the encoding conversion value range is bucket=maxValue-minValue.
[0097] Furthermore, the number of encoding bits n of a single character is calculated, that is, the encoding length of the character in the unified text data:
[0098] n=bucket+w=maxValue-minValue+w;
[0099] For a character in the text data, for example, a character with a Unicode encoding value of m, the corresponding data bucket l (i.e., the activation start position) is:
[0100] l = floor[m-minValue+1];
[0101] Thus, it is determined that the character with Unicode encoding value m has a corresponding activation start position of l in the encoding length of n, and its preset continuous activation point position value is w.
[0102] On the basis of the above embodiment, the sparse code corresponding to each character in the text data is constructed according to the preset code value, the code length, the preset continuous activation point value and the activation start bit, including:
[0103] According to the activation start bit, determining the start bit of the preset continuous activation point bit value;
[0104] Based on the starting bit of the preset continuous activation point bit value and according to the code length, the preset continuous activation point bit value and the preset code value are combined to construct the sparse code corresponding to each character in the text data.
[0105] In the present invention, the activation start bit obtained according to the above embodiment can determine the start bit of the preset continuous activation point bit value. The activation start bit provides the starting position of the preset continuous activation point bit value in sparse coding, thereby determining the position information of the activation point bit value.
[0106] Furthermore, based on the activation start bit and the coding length of the preset continuous activation point bit value, combined with the coding length (filled with 0 to meet the coding length), the preset continuous activation point bit value and the preset coding value can be combined to construct a sparse code corresponding to each character in the text data.
[0107] In the present invention, the input characters are encoded according to the above encoding steps, and the encoding method adopted has the following characteristics: as the value increases, the code gradually increases forward. There is an intersection in the activation site positions between adjacent values, which is consistent with the characteristic that the Unicode encoding values between similar characters are similar. This characteristic satisfies the condition that similar objects obtain similar encodings, which is beneficial for the subsequent text information extraction. In one embodiment, it is assumed that the Unicode encoding value corresponding to the input text data after mapping ranges from 1 to 1000 (i.e., the encoding conversion value), and the preset continuous activation point bit value is 31 (i.e., composed of 31 1s), so that the total encoding length of a single character is 1030. The position of each encoding activation is different, and there is the same activation site between adjacent values. For details, please refer to Figure 2 shown.
[0108] In one embodiment, Figure 3 The application diagram of the sparse coding of text data provided by the present invention can be referred to Figure 3 As shown, taking the name of the earth science dataset as an example, the dataset name is first segmented using the word segmentation tool NLPIR, and the Unicode code value corresponding to a single character is obtained; then, the numerical mapping method provided in the above embodiment is used to obtain the Unicode code conversion value of the corresponding code, and the sparse code of a single character is obtained according to the text sparse coding idea. In this embodiment, in order to ensure the consistency of the HTM model input data, the code combination is performed according to the maximum length of the dataset name after word segmentation, and it is padded with 0 to achieve a fixed length, and finally a text sparse code suitable for the HTM model is obtained.
[0109] In another embodiment, the encoding result of the sparse encoding of the text data provided by the present invention is evaluated. First, 66 pairs of representative terms in the geographic term similarity dataset (Geo-Terminology Relatedness Dataset, referred to as GTRD) are used as the benchmark dataset, and the semantic folding method website interface is called to calculate the overlap corresponding to each pair of terms; secondly, the 66 terms of GTRD are encoded using the encoding method provided by the present invention (hereinafter referred to as sparse coding), and the Jaccard coefficient and cosine similarity of each pair of terms are calculated; finally, the cosine similarity and Jaccard coefficient obtained by sparse coding are respectively calculated with the GTRD similarity by Pearson correlation coefficient and Spearman correlation coefficient. At the same time, the overlap obtained by the semantic folding method is respectively calculated with the GTRD similarity by Pearson correlation coefficient and Spearman correlation coefficient to evaluate the advantages and disadvantages of the encoding effects of sparse coding and semantic folding methods. Table 1 is the geographic term similarity dataset and similarity, which can be referred to as shown in Table 1:
[0110] Table 1 Geographic term similarity dataset and similarity
[0111]
[0112]
[0113] In this embodiment, in order to compare the encoding effects of sparse coding and semantic folding methods, 66 pairs of typical geographic terms are selected as the test set in the geographic term similarity dataset. Let the encoding vector corresponding to the first column of terms be C i (i=1,2,3,...,66), the encoding value corresponding to the first column vector is m ik (k=1,2,3,...,n); let the encoding vector corresponding to the term in the second column be C j (i=1,2,3,...,66), the encoding value corresponding to the second column vector is n jk (k=1,2,3,...,n), the corresponding cosine similarity calculation formula is:
[0114]
[0115] Assume T 00 is m ik and n jk At the same time, the number of matches that are 0 is taken, T 01 is m ik Take 0 and n jk Take the number of 1s, T 10 is m ikTake 1 and n jk Take the number of 0, T 11 is m ik and n jk The number of matches that are taken as 1 at the same time. The corresponding Jaccard coefficient calculation formula is:
[0116]
[0117] Let x il is the cosine similarity or Jaccard coefficient value obtained by the proposed encoding method, x jl is the similarity value corresponding to the geographic term similarity dataset, P ij is the calculated Pearson correlation coefficient. ij is the difference between the sparse coding method, semantic folding method and the corresponding similarity value in GTRD, S ij is the calculated Spearman correlation coefficient, l is the 66 pairs of terms in the geographic term similarity dataset, and the specific formula is as follows:
[0118]
[0119]
[0120] Let n be the number of corresponding test samples, T p is the test statistic corresponding to the Pearson correlation coefficient, P1 is the P value corresponding to the two-sided test of the Pearson correlation coefficient, t(T p ) is the cumulative probability value of the t distribution. The corresponding Pearson correlation coefficient test statistic and P value calculation formula are as follows:
[0121]
[0122] P1=2*(1-t(T p ));
[0123] Let n be the number of corresponding test samples, N p is the test statistic corresponding to the Spearman correlation coefficient, P2 is the P value corresponding to the two-sided test of the Spearman correlation coefficient, N(N p ) is the cumulative probability value of the standard normal distribution. In the case of large samples (n>30), the Spearman correlation coefficient test statistic approximately follows the standard normal distribution. The corresponding Spearman correlation coefficient test statistic and P value calculation formula are as follows:
[0124]
[0125] P2=2*(1-N(N p ));
[0126] This example uses 66 pairs of terms in the Geographical Term Similarity Dataset (GTRD) as test samples, and calculates the Pearson correlation coefficient and Spearman correlation coefficient between the similarity obtained by the sparse coding and semantic folding methods and the GTRD similarity. At the same time, a statistical test is performed on the correlation coefficient, and the significance of the correlation coefficient is judged based on whether the P value is greater than 0.05. Table 2 is a test table of the correlation coefficient and P value between the sparse coding, semantic folding method and GTRD. For details, please refer to Table 2:
[0127] Table 2
[0128]
[0129] Among them, "***" in Table 2 means significant at the 0.05 level (two-sided test).
[0130] This embodiment selects 66 pairs of terms in the geographic terminology data set as a benchmark, and compares the proposed text sparse coding method with the existing semantic folding method. According to the above correlation coefficient and P value test results, it is found that the Pearson correlation coefficient corresponding to the semantic folding method on GTRD is 0.622, while the Pearson correlation coefficient corresponding to the sparse coding method is 0.703. In addition, the test results of the correlation coefficients have passed the statistical significance test. Based on the basic principle that similar texts correspond to similar encodings, the sparse coding method provided by the present invention is superior to the existing semantic folding method.
[0131] The present invention combines the maximum and minimum values of the input text data and the number of continuous activation sites, and remaps the Unicode code value corresponding to the text data, thereby greatly reducing the code length. Compared with the existing numerical coding method, this method avoids the influence of the numerical value size on the code length and improves the coding efficiency.
[0132] Secondly, by statistically analyzing the arrangement characteristics of commonly used characters, it is found that similar characters are often arranged in similar positions and have intersections with adjacent numerical activation sites. This is consistent with the characteristic that adjacent numerical activation sites have intersections, making the sparse coding provided by the present invention superior to the existing semantic folding method on the principle of "similar objects are encoded similarly". The advantages of the text data sparse coding method for the HTM model provided by the present invention are reflected in the reduction of coding length and the adaptability of the coding method, making text sparse coding more efficient and accurate.
[0133] The text data sparse coding system for the HTM model provided by the present invention is described below. The text data sparse coding system for the HTM model described below and the text data sparse coding method for the HTM model described above can be referred to each other.
[0134] Figure 4 The structural diagram of the text data sparse coding system for the HTM model provided by the present invention is as follows: Figure 4 As shown, the present invention provides a text data sparse coding system for an HTM model, comprising a text data acquisition module 401, a coding conversion value calculation module 402, a first processing module 403, a second processing module 404 and a sparse coding construction module 405, wherein the text data acquisition module 401 is used to acquire text data to be input into the HTM model; the coding conversion value calculation module 402 is used to acquire the coding conversion value of each character in the text data according to a preset continuous activation point value and a preset coding value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the sparse The identification starting area in the code; the first processing module 403 is used to determine the code length of the characters in the text data according to the code conversion value; the second processing module 404 is used to obtain the activation start bit corresponding to each of the characters in the text data according to the code conversion value and the preset code value, wherein the activation start bit represents the starting position of the preset continuous activation point value in the sparse code; the sparse code construction module 405 is used to construct the sparse code corresponding to each of the characters in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit.
[0135] The text data sparse coding system for the HTM model provided by the present invention presets continuous activation point value and preset coding value corresponding to each character in the text data, and the coding conversion value of each character, and then determines the coding length of the character and the activation start position corresponding to the character according to the coding conversion value, and finally constructs the sparse coding corresponding to each character in the text data according to the preset coding value, coding length, preset continuous activation point value and activation start position, so that the sparse coding of the text data is more efficient and accurate.
[0136] The system provided by the present invention is used to execute the above-mentioned method embodiments. Please refer to the above-mentioned embodiments for the specific processes and detailed contents, which will not be repeated here.
[0137] Figure 5 A schematic diagram of the structure of an electronic device provided by the present invention, such as Figure 5As shown, the electronic device may include: a processor (Processor) 501, a communication interface (Communications Interface) 502, a memory (Memory) 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504. The processor 501 can call the logic instructions in the memory 503 to execute the sparse coding method of text data for the HTM model, which method includes: obtaining text data to be input into the HTM model; obtaining the code conversion value of each character in the text data according to the preset continuous activation point value and the preset code value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the recognition starting area in the sparse code corresponding to the character; determining the code length of the character in the text data according to the code conversion value; obtaining the activation start bit corresponding to each character in the text data according to the code conversion value and the preset code value, wherein the activation start bit represents the starting position of the preset continuous activation point value in the sparse code; constructing the sparse code corresponding to each character in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit.
[0138] In addition, the logic instructions in the above-mentioned memory 503 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0139] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the text data sparse coding method for the HTM model provided by the above methods, and the method includes: obtaining text data to be input into the HTM model; obtaining a coding conversion value of each character in the text data according to a preset continuous activation point value and a preset coding value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the recognition starting area in the sparse coding corresponding to the character; determining the coding length of the character in the text data according to the coding conversion value; obtaining the activation start bit corresponding to each character in the text data according to the coding conversion value and the preset coding value, wherein the activation start bit represents the starting position of the preset continuous activation point value in the sparse coding; constructing the sparse coding corresponding to each character in the text data according to the preset coding value, the coding length, the preset continuous activation point value and the activation start bit.
[0140] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the text data sparse coding method for the HTM model provided in the above-mentioned embodiments, the method comprising: obtaining text data to be input into the HTM model; obtaining a coding conversion value of each character in the text data according to a preset continuous activation point value and a preset coding value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the recognition starting area in the sparse coding corresponding to the character; determining the coding length of the character in the text data according to the coding conversion value; obtaining the activation starting position corresponding to each character in the text data according to the coding conversion value and the preset coding value, wherein the activation starting position represents the starting position of the preset continuous activation point value in the sparse coding; constructing the sparse coding corresponding to each character in the text data according to the preset coding value, the coding length, the preset continuous activation point value and the activation starting position.
[0141] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0142] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0143] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A text data sparse coding method for an HTM model, characterized in that: include: Obtain text data to be input into the HTM model; According to the preset continuous activation point value and the preset code value corresponding to each character in the text data, the code conversion value of each character in the text data is obtained, wherein the preset continuous activation point value is used to mark the recognition start area in the sparse code corresponding to the character; Determining the encoding length of the characters in the text data according to the encoding conversion value; According to the encoding conversion value and the preset encoding value, an activation start bit corresponding to each of the characters in the text data is obtained, wherein the activation start bit represents the starting position of the preset continuous activation point bit value in the sparse code; Constructing the sparse code corresponding to each character in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit; Before obtaining the text data to be input into the HTM model, the method further includes: Encode the text data based on the Unicode encoding method to obtain the preset encoding value corresponding to each character in the text data; The step of obtaining the encoding conversion value of each character in the text data according to the preset continuous activation point value and the preset encoding value corresponding to each character in the text data includes: Sorting the preset code values corresponding to the characters in the text data from small to large to obtain a code value sorting result; Determine the character position value corresponding to each of the characters in the text data according to the encoding value sorting result; Obtaining a code value difference according to two adjacent preset code values in the code value sorting result; Based on the comparison result between the encoding value difference and the preset continuous activation point value, the encoding conversion value of each character in the text data is calculated according to the preset encoding value and the character position value.
2. The text data sparse coding method for the HTM model according to claim 1, characterized in that: The method further comprises: Based on the comparison result between the code value difference and the preset continuous activation point value, according to the preset code value and the character position value, the code conversion value of each character in the text data is calculated by a code conversion value calculation formula, and the code conversion value calculation formula is: Wherein, i=1,2,3,...,n, and i is a positive integer; represents the encoding conversion value corresponding to the i-th character in the encoding value sorting result; P [Ui] represents the character position value corresponding to the i-th character in the coding value sorting result; w represents the preset continuous activation point value, U i Indicates the preset code value corresponding to the ith character in the code value sorting result.
3. The text data sparse coding method for the HTM model according to claim 1 or 2, characterized in that: Determining the encoding length of the character in the text data according to the encoding conversion value includes: Based on the encoding conversion values of all the characters in the text data, obtaining a maximum encoding conversion value and a minimum encoding conversion value; Obtaining a code conversion value range according to a difference between the maximum code conversion value and the minimum code conversion value; Determining the encoding length of the character in the text data according to the encoding conversion value range and the preset continuous activation point value; The step of obtaining the activation start bit corresponding to each character in the text data according to the encoding conversion value and the preset encoding value includes: According to the minimum code conversion value and the preset code value corresponding to each character, the activation start bit corresponding to each character is calculated by the activation start bit calculation formula, and the activation start bit calculation formula is: l = floor[m-minValue+1]; Among them, l represents the activation start bit, m represents the preset encoding value corresponding to the character, and minValue represents the minimum encoding conversion value.
4. The text data sparse coding method for the HTM model according to claim 1, characterized in that: The step of constructing the sparse code corresponding to each character in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit includes: According to the activation start bit, determining the start bit of the preset continuous activation point bit value; Based on the starting bit of the preset continuous activation point bit value and according to the code length, the preset continuous activation point bit value and the preset code value are combined to construct the sparse code corresponding to each character in the text data.
5. A text data sparse coding system for an HTM model, characterized in that: include: A text data acquisition module, used to acquire text data to be input into the HTM model; A code conversion value calculation module, used for obtaining the code conversion value of each character in the text data according to a preset continuous activation point value and a preset code value corresponding to each character in the text data, wherein the preset continuous activation point value is used to mark the recognition start area in the sparse code corresponding to the character; A first processing module, used for determining the encoding length of the character in the text data according to the encoding conversion value; A second processing module is used to obtain an activation start bit corresponding to each of the characters in the text data according to the encoding conversion value and the preset encoding value, wherein the activation start bit represents the starting position of the preset continuous activation point bit value in the sparse code; A sparse coding construction module, used to construct the sparse code corresponding to each of the characters in the text data according to the preset code value, the code length, the preset continuous activation point value and the activation start bit; The system is also used to: Encode the text data based on the Unicode encoding method to obtain the preset encoding value corresponding to each character in the text data; The encoding conversion value calculation module is specifically used for: Sorting the preset code values corresponding to the characters in the text data from small to large to obtain a code value sorting result; Determine the character position value corresponding to each of the characters in the text data according to the encoding value sorting result; Obtaining a code value difference according to two adjacent preset code values in the code value sorting result; Based on the comparison result between the encoding value difference and the preset continuous activation point value, the encoding conversion value of each character in the text data is calculated according to the preset encoding value and the character position value.
6. An electronic 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 text data sparse encoding method for the HTM model according to any one of claims 1 to 4 is implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the text data sparse encoding method for the HTM model as claimed in any one of claims 1 to 4 is implemented.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the text data sparse encoding method for the HTM model as claimed in any one of claims 1 to 4 is implemented.
