Method, device and related equipment for processing sentence probability based on artificial intelligence
Through word segmentation processing and similarity calculation, replacement sentences are generated and their prior probabilities are calculated, which solves the problem of low accuracy in predicting the sentence probability of ngram language model when no sentences appear, and achieves higher recognition accuracy and recognition speed. The generalization ability of the model is enhanced.
Patent Information
- Application Number
- CN202111152560.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-29
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-09-29
AI Technical Summary
The existing ngram language model has low prediction accuracy when calculating the sentence probability of sentences that have not appeared before, and cannot effectively handle the inaccurate calculation of sentence probability caused by the lack of text corpus in the corpus.
Through word segmentation processing and similarity calculation, replacement words are found to generate replacement sentences, and the sentence probability of the sentence to be recognized is calculated based on the prior probability of the replacement sentence. Artificial intelligence technology is used to improve the accuracy of the sentence probability prediction of sentences that do not appear.
While maintaining the advantages of fast training and fast decoding of the ngram language model, it improves the accuracy of sentence probability calculation and recognition speed of unoccurred sentences, enhances the generalization ability of the model, and improves the performance of downstream tasks.
Smart Images

Figure CN113887222B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device, computer equipment and storage medium for processing sentence probability based on artificial intelligence. Background Art
[0002] The ngram language model is widely used in fields such as speech recognition and natural language processing. It is used to calculate the conditional probability of each word combination. Specifically, the product of the conditional probability of each word and the previous words is used as the sentence probability of the whole sentence.
[0003] When the existing ngram language model calculates the sentence probability of a sentence, for example, P(T) represents the sentence probability of any text sentence T, w1, w2, w3, …, wn represent each word in the text sentence, and P(w3|w1w2) represents the conditional probability that word w3 appears after word w1w2, then P(T) = P(w1)*P(w2|w1)*P(w3|w1w2)*…*P(wn|w1w2w3…wn-1).
[0004] It can be seen that the disadvantage of the existing ngram language model in calculating the probability of a sentence is that it completely relies on the sentences already stored in the original corpus. For example, if the original corpus contains the sentence "I have a cat at home", but the sentence "I have a dog at home" has never appeared, the conditional probability of the context combination in the sentence "I have a dog at home" is very low. Then the sentence probability given by the language model for the sentence "I have a dog at home" will be much lower than that for "I have a cat at home", which is obviously inconsistent with the actual sentence probability of a sentence. Summary of the invention
[0005] The embodiments of the present invention provide a method, apparatus, computer device and storage medium for processing sentence probability based on artificial intelligence to solve the technical problem of low prediction accuracy of sentence probability of sentences that have not appeared in the original corpus.
[0006] A method for processing sentence probability based on artificial intelligence, the method comprising:
[0007] Get the sentence to be recognized;
[0008] Determine whether there is a sentence identical to the sentence to be recognized in the corpus, and if not, perform word segmentation processing on the sentence to be recognized to obtain multiple original words;
[0009] According to all the sentences stored in the corpus, counting the initial context prior probability of each of the original words;
[0010] Obtaining the original word whose initial context prior probability is zero from each of the original words to obtain a first word;
[0011] Calculating the similarity between the first word and each word in the corpus, determining a replacement word from each word in the corpus according to the calculated similarity, and selecting the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized;
[0012] The context prior probability of each word in the replacement sentence is counted, and the sentence probability of the sentence to be recognized is obtained according to the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence.
[0013] A sentence probability processing device based on artificial intelligence, the device comprising:
[0014] A sentence acquisition module, used for acquiring sentences to be recognized;
[0015] A judgment module is used to judge whether there is a sentence identical to the sentence to be recognized in the corpus, and if not, perform word segmentation processing on the sentence to be recognized to obtain multiple original words;
[0016] A probability statistics module, used for counting the initial context prior probability of each of the original words according to all the sentences stored in the corpus;
[0017] A word acquisition module, used for acquiring the original word with the initial context prior probability of zero from each of the original words to obtain a first word;
[0018] a replacement module, configured to calculate the similarity between the first word and each word in the corpus, determine a replacement word from each word in the corpus according to the calculated similarity, and select the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized;
[0019] The sentence formation probability obtaining module is used to count the context prior probabilities of each word in the replacement sentence, and obtain the sentence formation probability of the sentence to be identified according to the similarity between the replacement word and the first word and the context prior probabilities of each word in the replacement sentence.
[0020] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned artificial intelligence-based sentence probability processing method when executing the computer program.
[0021] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above-mentioned artificial intelligence-based sentence probability processing method.
[0022] The method, device, computer equipment and storage medium for processing sentence probability based on artificial intelligence proposed in the present application are based on the characteristics of the ngram language model itself. When the corresponding sentence to be recognized does not exist in its corpus, a replacement word for the disconnected word is found according to the similarity, and then the replacement word is replaced with the disconnected first word to obtain a replacement sentence, and at the same time, the replacement sentence is made to exist in the corpus. The sentence probability of the sentence to be recognized is finally obtained by calculating the context prior probability of the replacement sentence and combining the context prior probability of the replacement sentence and the similarity between the first word and the replacement word. On the one hand, the advantages of the ngram language model itself, such as fast training and fast decoding, are retained. On the other hand, the technical defect that the calculation result of the sentence probability of the sentence to be recognized is inaccurate due to its complete reliance on the sentences already stored in the original corpus and the text corpus in the corpus is insufficient, is overcome. This makes the recognition speed fast and the recognition accuracy high when determining the sentence probability of the sentence to be recognized, so that the results predicted by the ngram model have better generalization and perform better in downstream tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0024] Figure 1 It is a schematic diagram of an application environment of a method for processing sentence probability based on artificial intelligence in one embodiment of the present invention;
[0025] Figure 2 is a flow chart of a method for processing sentence probability based on artificial intelligence in one embodiment of the present invention;
[0026] Figure 3 is a flow chart of a method for processing sentence probability based on artificial intelligence in another embodiment of the present invention;
[0027] Figure 4 It is a structural schematic diagram of a sentence probability processing device based on artificial intelligence in one embodiment of the present invention;
[0028] Figure 5 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments 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.
[0030] The sentence probability processing method based on artificial intelligence provided in this application can be applied in Figure 1 In an application environment, the computer device can communicate with the server through a network. The computer device can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0031] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0032] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0033] When predicting the sentence probability of the to-be-recognized sentence by using the ngram language model, in order to improve the prediction accuracy of the sentence probability of the sentence that has not appeared in the original corpus, in one embodiment, Figure 2 As shown, a method for processing sentence probability based on artificial intelligence is provided, and the method is applied in Figure 1 The computer device in the example is used as an example to illustrate, including the following steps:
[0034] S101: Obtain a sentence to be recognized.
[0035] In one embodiment, the sentence to be recognized is, for example, "I have a cat at home."
[0036] S102: Determine whether there is a sentence identical to the sentence to be recognized in the corpus; if not, perform word segmentation processing on the sentence to be recognized to obtain a plurality of original words.
[0037] In one of the embodiments, the sentence to be recognized can be segmented by a segmentation tool, which includes but is not limited to Jieba segmentation, HanLP (Han Language Processing, natural language processing) segmentation, Tencent Wenzhi, etc.
[0038] S103: According to all the sentences stored in the corpus, the initial context prior probability of each of the original words is counted.
[0039] In one embodiment, counting the initial context prior probabilities of each of the original words can be achieved in the following manner: counting the probability that the first word of the original word appears at the beginning of a sentence in the corpus, then counting the probability that the second word in the original word appears after the first word, then counting the probability that the third word in the original word appears after the second word and the second word in the original word appears after the first word, and so on, until the context prior probabilities of all words in the original word are counted.
[0040] S104: Obtain the original word whose initial context prior probability is zero from each of the original words to obtain a first word.
[0041] It can be understood that an original word with an initial context prior probability of zero indicates that the sentence to be recognized is disconnected at the first word. For example, the sentence to be recognized is "I have a cat at home." By comparing the corpus, it is found that there is no sentence "I have a cat at home" in the corpus, only "I have a dog at home." When counting the initial context prior probabilities of each of the original words, the initial context prior probability of "cat" is 0, which means that the sentence is disconnected at the original word "cat."
[0042] S105, calculating the similarity between the first word and each word in the corpus, determining a replacement word from each word in the corpus according to the calculated similarity, and selecting the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized.
[0043] In one embodiment, the step of calculating the similarity between the first word and each word in the corpus, and determining a replacement word from each word in the corpus according to the calculated similarity further comprises:
[0044] Calculating the similarity between the first word and words in each sentence of the corpus;
[0045] Selecting words with similarity within a preset range from the words in each sentence of the corpus as candidate words;
[0046] Selecting corresponding candidate words in descending order of similarity to replace the first word, to obtain corresponding candidate sentences;
[0047] The candidate word having the highest similarity to the candidate words and the candidate sentence after replacement is included in the corpus is determined as the replacement word, and the corresponding candidate sentence is determined as the replacement sentence.
[0048] In one of the embodiments, when all replacement sentences obtained by replacing the candidate words with similarities within a preset range are not in the corpus, the sentence to be identified is determined to be an erroneous sentence.
[0049] In one embodiment, the step of calculating the similarity between the first word and the words in each sentence of the corpus further comprises:
[0050] Convert the first word into a first word vector using a pre-trained word vector model;
[0051] The words in each sentence of the corpus are converted into corresponding word vectors by using the trained word vector model;
[0052] The cosine similarity between the first word vector and each of the word vectors is calculated, and the cosine similarity is used as the similarity between the first word and the word corresponding to each sentence in the corpus.
[0053] In one embodiment, the preset range of the similarity is, for example, the calculated cosine similarity value is between 0 and 1. Preferably, the cosine similarity value is greater than 0.8.
[0054] According to an application scenario of this embodiment, for example, the sentence to be recognized is "I have a cat at home". By comparing the corpus, it is found that there is no sentence "I have a cat at home" in the corpus. The initial context prior probabilities of the original words are counted, and it is found that the initial context prior probability of the sentence to be recognized in the word "cat" is zero. Further query the word closest to the word vector of the word "cat", and the value of cos(Vector(cat), Vector(dog)) is closest to 1, so "dog" is selected to replace "cat", and the replacement sentence obtained is "I have a dog at home", where Vector(cat) represents the word vector of the word "cat", and Vector(dog) represents the word vector of the word "dog", so the following is obtained:
[0055] P(cat|I have one at home)=P(dog|I have one at home)*cos(Vector(cat),Vector(dog));
[0056] By comparing the corpus, if we find that the sentence "I have a dog" does not exist in the corpus, that is, the initial context prior probability P(dog|I have a dog) is still 0, we fall back to find the word vector with the second highest cosine similarity to "cat", such as "rabbit", and we get:
[0057] P(cat|I have one at home)=P(rabbit|I have one at home)*cos(Vector(cat),Vector(rabbit));
[0058] This process is repeated in this way until a candidate sentence after replacement is included in the corpus and has the highest cosine similarity, and the corresponding candidate sentence is determined as the replacement sentence.
[0059] In layman's terms, in the artificial intelligence-based sentence probability processing method proposed in this embodiment, when the word group W1W2...Wn of the sentence to be recognized by the ngram language model does not exist, by finding a replacement word Vn, W1W2...Wn-1Vn exists. At this time, let:
[0060] P(Wn|W1W2..Wn-1)=P(Vn|W1W2..Wn-1)*cos(Vec(Vn),Vec(Wn));
[0061] It is required that cos(Vec(Vn), Vec(Wn)) is greater than a specific threshold c, and the threshold c is between 0 and 1, and preferably can be 0.8.
[0062] In one embodiment, the step of training the word vector model includes:
[0063] Extracting sample texts with fluent text sample labels;
[0064] Inputting the sample text into the word vector model to be trained to obtain the vector of each sample word in the sample text;
[0065] Calculate the difference between the sum of the vectors of the adjacent sample words on both sides and the vector of the middle sample word;
[0066] When the difference is greater than a preset value, the parameters of the word vector model are adjusted, and the steps of extracting the sample text carrying the fluent text sample label to calculating the difference between the sum of the vectors of the adjacent two side sample words and the vector of the middle sample word are repeated until the difference is less than or equal to the preset value, thereby obtaining a trained word vector model.
[0067] The pre-trained word vector model can directly convert each word contained in the sentence to be recognized into a corresponding word vector.
[0068] S106: Count the contextual prior probabilities of each word in the replacement sentence, and obtain the sentence probability of the sentence to be recognized according to the similarity between the replacement word and the first word and the contextual prior probabilities of each word in the replacement sentence.
[0069] In one embodiment, the step of obtaining the sentence probability of the sentence to be recognized according to the similarity between the replacement word and the first word and the above prior probability further includes:
[0070] Calculating the sentence probability of the replacement sentence according to the contextual prior probability of each word in the replacement sentence;
[0071] The product of the sentence probability of the replacement sentence and the similarity is used as the sentence probability of the sentence to be recognized.
[0072] In one embodiment, the similarity is cosine similarity, and the step of calculating the sentence probability of the replacement sentence according to the context prior probability of each word in the replacement sentence further includes:
[0073] The sentence probability of the replacement sentence is calculated by the following formula:
[0074] P(W)=P(w1)*P(w2)*P(w3)*…*P(wn)=P(w1)*P(w2|w1)*P(w3|w1w2)*…*P(wn|w1w2w3…wn-1);
[0075] Wherein, P(W) represents the sentence formation probability of the replacement sentence, P(w1) represents the probability that word w1 appears at the beginning of each sentence in the corpus, P(w2|w1) represents the probability that word w2 appears after word w1, P(w3|w1w2) represents the probability that word w2 appears after word w1 and word w3 appears after word w2, P(wn|w1w2w3…wn-1) represents the probability that word wn appears after word wn-1 and… and word w3 appears after word w2 and the probability that word w2 appears after word w1, and n represents the total number of words contained in the replacement sentence;
[0076] The step of obtaining the sentence probability of the sentence to be recognized according to the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence further includes:
[0077] The product of the sentence probability of the replacement sentence and the cosine similarity is used as the sentence probability of the sentence to be recognized.
[0078] The ngram language model has the characteristics of fast training and decoding, and is widely used in scenarios with abundant corpus. The sentence probability processing method based on artificial intelligence proposed in this embodiment is based on the characteristics of the ngram language model itself. When there is no corresponding sentence to be recognized in its corpus, a replacement word for the disconnected word is found according to the similarity, and then the replacement word is replaced with the first disconnected word to obtain a replacement sentence, and at the same time, the replacement sentence is made to exist in the corpus. By calculating the context prior probability of the replacement sentence, and combining the context prior probability of the replacement sentence and the probability of the first word and the replacement word, the replacement sentence is obtained. The similarity between the two sentences is calculated, and finally the sentence probability of the sentence to be recognized is obtained. The sentence probability processing method based on artificial intelligence proposed in this embodiment retains the advantages of the ngram language model itself, such as fast training and fast decoding, and on the other hand, overcomes the technical defect that it completely relies on the sentences already stored in the original corpus, resulting in inaccurate calculation results of the sentence probability of the sentence to be recognized when the text corpus in the corpus is insufficient. This makes the recognition speed fast and the recognition accuracy high when determining the sentence probability of the sentence to be recognized, so that the results predicted by the ngram model have better generalization and perform better in downstream tasks.
[0079] In one embodiment, the corpus includes corpora in different fields, and the artificial intelligence-based sentence probability processing method further includes:
[0080] Select corpora from different fields, and repeat the steps from determining whether there is a sentence identical to the sentence to be identified in the corpus to obtaining the sentence probability of the sentence to be identified based on the similarity between the replacement word and the first word and the above prior probability, to obtain the sentence probability of the sentence to be identified corresponding to each corpus;
[0081] Obtaining the target domain corresponding to the corpus with the highest sentence probability of the sentence to be recognized;
[0082] The category to which the sentence to be recognized belongs is determined as the target domain.
[0083] Optionally, the corpora in different fields include but are not limited to finance, technology, sports, etc.
[0084] This embodiment selects corpora from different fields, calculates the sentence probability of the sentence to be recognized in the corresponding corpus for each corpus, and classifies the category to which the sentence to be recognized belongs into the category corresponding to the corpus with the highest sentence probability, so as to classify the sentence to be recognized.
[0085] In other embodiments, the sentence probability processing method based on artificial intelligence can also be used to perform text error correction, speech semantic recognition, input method word selection and other related scenario applications on the recognized sentences.
[0086] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0087] In one embodiment, a processing device for sentence formation probability based on artificial intelligence is provided, and the processing device for sentence formation probability based on artificial intelligence corresponds to the processing method for sentence formation probability based on artificial intelligence in the above embodiment. Figure 4 As shown, the artificial intelligence-based sentence probability processing device 100 includes a sentence acquisition module 11, a judgment module 12, a probability statistics module 13, a word acquisition module 14, a replacement module 15 and a sentence probability acquisition module 16. The functional modules are described in detail as follows:
[0088] A sentence acquisition module 11, used to acquire a sentence to be recognized;
[0089] A judgment module 12 is used to judge whether there is a sentence identical to the sentence to be recognized in the corpus, and if not, perform word segmentation processing on the sentence to be recognized to obtain a plurality of original words;
[0090] A probability statistics module 13, used for counting the initial context prior probability of each of the original words according to all the sentences stored in the corpus;
[0091] A word acquisition module 14 is used to acquire the original word with the initial context prior probability of zero from each of the original words to obtain a first word;
[0092] A replacement module 15, configured to calculate the similarity between the first word and each word in the corpus, determine a replacement word from each word in the corpus according to the calculated similarity, and select the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized;
[0093] The sentence formation probability obtaining module 16 is used to count the context prior probabilities of each word in the replacement sentence, and obtain the sentence formation probability of the sentence to be identified according to the similarity between the replacement word and the first word and the context prior probabilities of each word in the replacement sentence.
[0094] In one embodiment, the replacement module 15 specifically includes:
[0095] A first calculation unit, configured to calculate the similarity between the first word and words in each sentence of the corpus;
[0096] A word selection unit, used to select words with similarity within a preset range from the words in each sentence of the corpus as candidate words;
[0097] A replacement unit, configured to select corresponding candidate words in descending order of similarity to replace the first word, so as to obtain a corresponding candidate sentence;
[0098] The replacement word determination unit is used to determine the candidate word that has the highest similarity to the candidate words and whose replaced candidate sentence is included in the corpus as the replacement word.
[0099] In one embodiment, the artificial intelligence-based sentence probability processing device 100 further includes:
[0100] The wrong sentence judging unit is used to judge that the sentence to be identified is an wrong sentence when the replacement sentences obtained by replacing all the candidate words with similarities within a preset range are not in the corpus.
[0101] In one embodiment, the first computing unit further comprises:
[0102] A first conversion subunit, configured to convert the first word into a first word vector using a pre-trained word vector model;
[0103] A second conversion subunit, configured to convert each word in each sentence of the corpus into a corresponding word vector by using the trained word vector model;
[0104] The similarity calculation subunit is used to calculate the cosine similarity between the first word vector and each of the word vectors, and use the cosine similarity as the similarity between the first word and the words corresponding to each sentence in the corpus.
[0105] In one embodiment, the sentence probability obtaining module 16 specifically includes:
[0106] A probability calculation unit, used to calculate the sentence probability of the replacement sentence according to the context prior probability of each word in the replacement sentence;
[0107] The product operation unit is used to take the product of the sentence probability of the replacement sentence and the similarity as the sentence probability of the sentence to be identified.
[0108] In one embodiment, the similarity is cosine similarity, and the probability calculation unit is specifically used to calculate the sentence probability of the replacement sentence by the following formula:
[0109] P(W)=P(w1)*P(w2)*P(w3)*…*P(wn)=P(w1)*P(w2|w1)*P(w3|w1w2)*…*P(wn|w1w2w3…wn-1);
[0110] Wherein, P(W) represents the sentence formation probability of the replacement sentence, P(w1) represents the probability that word w1 appears at the beginning of each sentence in the corpus, P(w2|w1) represents the probability that word w2 appears after word w1, P(w3|w1w2) represents the probability that word w2 appears after word w1 and word w3 appears after word w2, P(wn|w1w2w3…wn-1) represents the probability that word wn appears after word wn-1 and… and word w3 appears after word w2 and the probability that word w2 appears after word w1, and n represents the total number of words contained in the replacement sentence;
[0111] The product operation unit is specifically used to take the product of the sentence probability of the replacement sentence and the cosine similarity as the sentence probability of the sentence to be identified.
[0112] In one embodiment, the artificial intelligence-based sentence probability processing device 100 further includes:
[0113] A loop module, for selecting corpora of different fields, looping the steps from determining whether there is a sentence identical to the sentence to be identified in the corpus to obtaining the sentence probability of the sentence to be identified based on the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence, to obtain the sentence probability of the sentence to be identified corresponding to each corpus;
[0114] A target domain acquisition module, used to acquire the target domain corresponding to the corpus with the highest sentence probability of the sentence to be recognized;
[0115] The category determination module is used to determine the category to which the sentence to be identified belongs as the target domain.
[0116] The meaning of "first" and "second" in the above embodiments is only to distinguish different objects, and is not used to define which object has a higher priority or other limiting meanings. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of modules in this application is only a logical division, and there may be other division methods when implemented in actual applications.
[0117] For the specific definition of the processing device of sentence probability based on artificial intelligence, please refer to the definition of the processing method of sentence probability based on artificial intelligence in the above text, which will not be repeated here. Each module in the above-mentioned processing device of sentence probability based on artificial intelligence can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0118] In one embodiment, a computer device is provided, which may be a server. The computer device includes a processor, a memory, a network interface, and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a storage medium and an internal memory. The storage medium includes a non-volatile storage medium and / or a volatile storage medium, and the storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the storage medium. The database of the computer device is used to store data involved in a method for processing sentence probability based on artificial intelligence. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for processing sentence probability based on artificial intelligence is implemented.
[0119] In another embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a storage medium and an internal memory. The storage medium includes a non-volatile storage medium and / or a volatile storage medium, and the storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, a method for processing sentence probability based on artificial intelligence is implemented.
[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. When the processor executes the computer program, the steps of the method for processing sentence probability based on artificial intelligence in the above embodiment are implemented, for example: Figure 2Alternatively, when the processor executes the computer program, the functions of each module / unit of the processing device for sentence probability based on artificial intelligence in the above embodiment are realized, for example Figure 4 The functions of modules 11 to 16 are shown in Figure 1. To avoid repetition, they will not be described here.
[0121] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer device, and various interfaces and lines are used to connect various parts of the entire computer device.
[0122] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer device by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc.
[0123] The memory may be integrated into the processor or may be arranged separately from the processor.
[0124] 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 steps of the method for processing sentence probability based on artificial intelligence in the above embodiment are implemented, such as Figure 2 Alternatively, when the computer program is executed by a processor, the functions of each module / unit of the processing device for sentence probability based on artificial intelligence in the above-mentioned embodiment are realized, for example Figure 4 The functions of modules 11 to 16 are shown in Figure 1. To avoid repetition, they will not be described here.
[0125] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile and / or volatile computer-readable storage medium. When the computer 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. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data 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), etc.
[0126] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
Claims
1. A method for processing sentence probability based on artificial intelligence, characterized in that: The method comprises: Get the sentence to be recognized; Determine whether there is a sentence identical to the sentence to be recognized in the corpus, and if not, perform word segmentation processing on the sentence to be recognized to obtain multiple original words; According to all the sentences stored in the corpus, counting the initial context prior probability of each of the original words; Obtaining the original word whose initial context prior probability is zero from each of the original words to obtain a first word; Calculating the similarity between the first word and each word in the corpus, determining a replacement word from each word in the corpus according to the calculated similarity, and selecting the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized; Counting the context prior probabilities of each word in the replacement sentence, and obtaining the sentence probability of the sentence to be identified according to the similarity between the replacement word and the first word and the context prior probabilities of each word in the replacement sentence; the step of obtaining the sentence probability of the sentence to be identified according to the similarity between the replacement word and the first word and the context prior probabilities of each word in the replacement sentence further includes calculating the sentence probability of the replacement sentence according to the context prior probabilities of each word in the replacement sentence; taking the product of the sentence probability of the replacement sentence and the similarity as the sentence probability of the sentence to be identified; The similarity is cosine similarity, and the step of calculating the sentence probability of the replacement sentence according to the context prior probability of each word in the replacement sentence further includes: The sentence probability of the replacement sentence is calculated by the following formula: P(W)=P(w1)*P(w2)*P(w3)*…*P(wn)=P(w1)*P(w2|w1)*P(w3|w1w2)*…*P(wn|w1w2w3…wn-1); Wherein, P(W) represents the sentence formation probability of the replacement sentence, P(w1) represents the probability that word w1 appears at the beginning of each sentence in the corpus, P(w2|w1) represents the probability that word w2 appears after word w1, P(w3|w1w2) represents the probability that word w2 appears after word w1 and word w3 appears after word w2, P(wn|w1w2w3…wn-1) represents the probability that word wn appears after word wn-1 and word w3 appears after word w2 and the probability that word w2 appears after word w1, and n represents the total number of words contained in the replacement sentence; The step of obtaining the sentence probability of the sentence to be recognized according to the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence further includes: The product of the sentence probability of the replacement sentence and the cosine similarity is used as the sentence probability of the sentence to be recognized.
2. The method for processing sentence probability based on artificial intelligence according to claim 1, characterized in that: The step of calculating the similarity between the first word and each word in the corpus, and determining a replacement word from each word in the corpus according to the calculated similarity further comprises: Calculating the similarity between the first word and words in each sentence of the corpus; Selecting words with similarity within a preset range from the words in each sentence of the corpus as candidate words; Selecting corresponding candidate words in descending order of similarity to replace the first word, to obtain corresponding candidate sentences; The candidate word having the highest similarity to the candidate words and the candidate sentence after replacement is included in the corpus is determined as the replacement word.
3. The method for processing sentence probability based on artificial intelligence according to claim 2, characterized in that: After the step of selecting the words with similarity within a preset range from the words in each sentence of the corpus as candidate words, the method further includes: When all the replacement sentences obtained by replacing the candidate words with similarities within a preset range are not in the corpus, the sentence to be recognized is determined to be an erroneous sentence.
4. The method for processing sentence probability based on artificial intelligence according to claim 2, characterized in that: The step of calculating the similarity between the first word and the words in each sentence of the corpus further comprises: Convert the first word into a first word vector using a pre-trained word vector model; The words in each sentence of the corpus are converted into corresponding word vectors by using the trained word vector model; The cosine similarity between the first word vector and each of the word vectors is calculated, and the cosine similarity is used as the similarity between the first word and the word corresponding to each sentence in the corpus.
5. The method for processing sentence probability based on artificial intelligence according to any one of claims 1 to 4, characterized in that: The corpus includes corpora in different fields, and the method further includes: Select corpora from different fields, and repeat the steps from determining whether there is a sentence identical to the sentence to be identified in the corpus to obtaining the sentence probability of the sentence to be identified based on the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence, to obtain the sentence probability of the sentence to be identified corresponding to each corpus; Obtaining the target domain corresponding to the corpus with the highest sentence probability of the sentence to be recognized; The category to which the sentence to be recognized belongs is determined as the target domain.
6. A sentence probability processing device based on artificial intelligence, characterized in that: The device comprises: A sentence acquisition module, used for acquiring sentences to be recognized; A judgment module is used to judge whether there is a sentence identical to the sentence to be recognized in the corpus, and if not, perform word segmentation processing on the sentence to be recognized to obtain multiple original words; A probability statistics module, used for counting the initial context prior probability of each of the original words according to all the sentences stored in the corpus; A word acquisition module, used for acquiring the original word with the initial context prior probability of zero from each of the original words to obtain a first word; a replacement module, configured to calculate the similarity between the first word and each word in the corpus, determine a replacement word from each word in the corpus according to the calculated similarity, and select the replacement word to replace the first word to obtain a replacement sentence corresponding to the sentence to be recognized; A sentence formation probability obtaining module is used to count the context prior probabilities of each word in the replacement sentence, and obtain the sentence formation probability of the sentence to be identified according to the similarity between the replacement word and the first word and the context prior probabilities of each word in the replacement sentence; the sentence formation probability obtaining module specifically includes a probability calculation unit, which is used to calculate the sentence formation probability of the replacement sentence according to the context prior probabilities of each word in the replacement sentence; a product calculation unit, which is used to take the product of the sentence formation probability of the replacement sentence and the similarity as the sentence formation probability of the sentence to be identified; the similarity is cosine similarity, and the step of calculating the sentence formation probability of the replacement sentence according to the context prior probabilities of each word in the replacement sentence further includes: The sentence probability of the replacement sentence is calculated by the following formula: P(W)=P(w1)*P(w2)*P(w3)*…*P(wn)=P(w1)*P(w2|w1)*P(w3|w1w2)*…*P(wn|w1w2w3…wn-1); Wherein, P(W) represents the sentence formation probability of the replacement sentence, P(w1) represents the probability that word w1 appears at the beginning of each sentence in the corpus, P(w2|w1) represents the probability that word w2 appears after word w1, P(w3|w1w2) represents the probability that word w2 appears after word w1 and word w3 appears after word w2, P(wn|w1w2w3…wn-1) represents the probability that word wn appears after word wn-1 and word w3 appears after word w2 and the probability that word w2 appears after word w1, and n represents the total number of words contained in the replacement sentence; The step of obtaining the sentence probability of the sentence to be recognized according to the similarity between the replacement word and the first word and the context prior probability of each word in the replacement sentence further includes: The product of the sentence probability of the replacement sentence and the cosine similarity is used as the sentence probability of the sentence to be recognized.
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 for processing sentence probability based on artificial intelligence as described in any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for processing sentence probability based on artificial intelligence as claimed in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Anaphora recovery method and device, dialogue robot and storage medium
CN112231451A
Data sentiment analysis method and device, electronic device and medium
CN112364170A
