WO2022095370A1 - 一种文本匹配方法、装置、终端设备和存储介质 - Google Patents
一种文本匹配方法、装置、终端设备和存储介质 Download PDFInfo
- Publication number
- WO2022095370A1 WO2022095370A1 PCT/CN2021/090952 CN2021090952W WO2022095370A1 WO 2022095370 A1 WO2022095370 A1 WO 2022095370A1 CN 2021090952 W CN2021090952 W CN 2021090952W WO 2022095370 A1 WO2022095370 A1 WO 2022095370A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- text
- sentence
- vector
- statement
- pinyin
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/30—Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
- G06F16/33—Querying
- G06F16/3331—Query processing
- G06F16/334—Query execution
- G06F16/3344—Query execution using natural language analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/30—Semantic analysis
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Definitions
- the present application belongs to the technical field of artificial intelligence, and in particular, relates to a text matching method, apparatus, terminal device and storage medium.
- Text matching is a core problem of natural language processing. Many natural language processing tasks can be abstracted into text matching problems, such as information retrieval systems, question answering systems, dialogue systems, and reading comprehension systems. With the continuous development of the voice system, more and more systems support voice input. The inventor realized that due to the differences in the conversion of voice into text and the error of manual input, there are certain errors in the input text. Traditional text matching models cannot perform text matching correctly, resulting in incorrect intent recognition and a bad experience for users.
- the present application proposes a text matching method, apparatus, terminal device and storage medium, which can improve the accuracy of text matching.
- an embodiment of the present application provides a text matching method, including:
- the matching degree between the first text sentence and the second text sentence is calculated according to the first sentence vector and the second sentence vector.
- an embodiment of the present application provides a text matching device, including:
- a text statement acquiring module used for acquiring the first text statement and the second text statement
- a pinyin conversion module for performing pinyin conversion on the first text statement and the second text statement to obtain the first pinyin of the first text statement and the second pinyin of the second text statement;
- a text splicing module for splicing the first text statement and the first pinyin to obtain a first text corpus, and splicing the second text statement and the second pinyin to obtain a second text corpus;
- a vector conversion module configured to respectively input the first text corpus and the second text corpus into a pre-built text conversion model to obtain the first sentence vector corresponding to the first text sentence and the corresponding second text sentence The second sentence vector of ;
- a matching degree calculation module configured to calculate the matching degree between the first text sentence and the second text sentence according to the first sentence vector and the second sentence vector.
- an embodiment of the present application provides a terminal device, 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 implementing the text matching method proposed in the first aspect of the embodiments of the present application.
- an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the implementation of the first aspect of the embodiment of the present application is implemented. The steps of the text matching method.
- pinyin is used as a new feature and is spliced with text sentences to form a new corpus and input into the text conversion model, so that the model can learn more semantic information including pinyin information. In this way, even when there is a text error in the speech conversion, the model can correct the input information according to the learned pinyin information and return correct matching information, thereby improving the accuracy of text matching.
- FIG. 1 is a flowchart of a first embodiment of a text matching method provided by an embodiment of the present application
- FIG. 2 is a flowchart of a second embodiment of a text matching method provided by an embodiment of the present application
- FIG. 3 is a flowchart of a third embodiment of a text matching method provided by an embodiment of the present application.
- FIG. 4 is a structural diagram of an embodiment of a text matching apparatus provided by an embodiment of the present application.
- FIG. 5 is a schematic diagram of a terminal device provided by an embodiment of the present application.
- Text matching is a core problem of natural language processing. Many natural language processing tasks can be abstracted into text matching problems, such as information retrieval systems, question answering systems, dialogue systems, and reading comprehension systems. Due to the huge difference of matching objects in text matching, the difficulty of obtaining a large number of high-quality training samples, and the hierarchical nature of text matching, selecting appropriate matching models for different tasks and improving the matching accuracy have become an important challenge for natural language processing tasks.
- the methods of text matching based on neural networks can be mainly divided into two categories: Sentence interaction (SI), which can better grasp the semantic focus and better model the importance of context, but ignore the
- SI Sentence interaction
- SE Sentence encoding
- SE category which can preprocess the text, build an index, and greatly reduce online
- the calculation is time-consuming, convenient and simple to use, and the effect is relatively good.
- the twin network is a typical SE structure, so many people will use the twin network for text matching.
- more and more systems support voice input. Due to the differences in the conversion of voice into text and the error of manual input, there are certain errors in the input text.
- Traditional text matching The model cannot correctly perform text matching, resulting in incorrect intent recognition and a bad experience for users.
- the present application proposes a text matching method, apparatus, terminal device and storage medium, which can improve the accuracy of text matching.
- the text matching method provided by the embodiments of the present application can be applied to mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR)/virtual reality (VR) devices, notebook computers, and super mobile personal computers (ultra-mobile personal computer, UMPC), netbook, personal digital assistant (personal digital assistant)
- AR augmented reality
- VR virtual reality
- UMPC ultra-mobile personal computer
- netbook personal digital assistant
- PDA digital assistant
- the embodiments of the present application do not impose any restrictions on the specific types of terminal devices and servers.
- the first embodiment of a text matching method in the embodiment of the present application includes:
- the first text sentence and the second text sentence are two Chinese character sentences that need to perform text matching, and each text sentence contains a plurality of Chinese characters.
- the number of Chinese characters contained in the first text sentence and the second text sentence may be the same or different.
- a pinyin converter can be used to convert the input Chinese characters into pinyin.
- the pinyin converter is a tool that can convert Chinese characters into pinyin.
- the xpinyin library in python can be used for conversion, and each Chinese character in a sentence can be directly converted. All are converted into pinyin, for example: "I love artificial intelligence" is converted into "wo ai ren gong zhi neng".
- each text sentence is spliced with the corresponding pinyin to obtain two new text corpora.
- the Chinese characters and pinyin can be spliced in sequence according to the specified character splicing sequence.
- the two text corpora are respectively input into a pre-built text conversion model.
- the text corpus can be converted into the corresponding sentence vector, that is, the first text corpus can be converted into the first sentence vector, and the second text corpus can be converted into the second sentence vector.
- the text conversion model is a pre-trained neural network model. It can include the Transformer encoding layer and the pooling layer.
- the Transformer encoding layer is used to encode the input text expectations, and a series of two-dimensional vectors represented by numbers are obtained, similar to the following structure:
- the features extracted by the pooling layer mainly include max-pooling (maximum pooling layer) and mean-pooling (mean pooling layer).
- max-pooling maximum pooling layer
- mean pooling layer mean pooling layer
- this application preferably uses the max-pooling layer for feature selection.
- the size of the pooling layer is 2*2, then the above vector is moved from left to right and top to bottom in a 2*2 window, and the window is extracted.
- the maximum value of the inner feature is finally converted into the following two-dimensional vector structure after maximum pooling:
- the matching degree between the first text sentence and the second text sentence can be calculated according to the two sentence vectors, Thereby completing the operation of text matching.
- calculating the matching degree between the first text sentence and the second text sentence according to the first sentence vector and the second sentence vector may include:
- Cosine similarity measures the similarity between two vectors by measuring the cosine value of the angle between them. Therefore, by calculating the cosine similarity between the first sentence vector and the second sentence vector, it can be used to determine two text sentences. match.
- pinyin is used as a new feature and is spliced with text sentences to form a new corpus and input into the text conversion model, so that the model can learn more semantic information including pinyin information. In this way, even when there is a text error in the speech conversion, the model can correct the input information according to the learned pinyin information and return correct matching information, thereby improving the accuracy of text matching.
- the second embodiment of a text matching method in the embodiment of the present application includes:
- Steps 201-204 are the same as steps 101-104, and for details, please refer to the relevant description of steps 101-104.
- the matching degree between the first text sentence and the second text sentence can be calculated according to the two sentence vectors, Specifically, the matching degree can be calculated by constructing a target feature vector, and the target feature vector is used to measure the matching relationship between the first sentence vector and the second sentence vector.
- constructing a target feature vector based on the first sentence vector and the second sentence vector may include:
- the first feature vector, the second feature vector, and the third feature vector are spliced in dimension reduction to obtain the target feature vector.
- the target feature vector can be used to measure the first sentence vector u and the second sentence vector v
- the matching relationship between the first text sentence and the second text sentence can be obtained by calculating the target feature vector.
- the target feature vector can be input into multiple fully connected layers for processing, so as to obtain the matching degree between the two text sentences.
- fully connected layer connected layers play the role of "classifier” in the entire neural network. If the operations such as convolutional layer, pooling layer and activation function layer are to map the original data to the hidden layer feature space, the fully connected layer plays the role of "classifier”. The role of mapping the learned "distributed feature representation" to the sample label space.
- each neuron in the fully connected layer is fully connected to all the neurons in the previous layer.
- Class-discriminative local information in convolutional or pooling layers can be integrated. That is, the text features of the target feature vector can be integrated into a numerical parameter for evaluating the similarity between two texts, that is, the matching degree.
- the matching degree between the first text sentence and the second text sentence it may further include:
- a softmax layer is used to process the matching degree to obtain a result of whether the first text sentence matches the second text sentence.
- a softmax layer can also be used to complete the classification, that is, a result of whether the first text sentence and the second text sentence match is obtained according to the matching degree of the input. For example, if the input matching degree is greater than a certain threshold, output the result that the first text sentence matches the second text sentence; otherwise, output the result that the first text sentence and the second text sentence do not match.
- pinyin is used as a new feature and is spliced with Chinese character corpus to form a new corpus and input into the text conversion model, so that the model can learn more semantic information including pinyin information. In this way, even when there is a text error in the speech conversion, the model can correct the input information according to the learned pinyin information and return correct matching information, thereby improving the accuracy of text matching.
- this embodiment proposes a specific method for calculating the matching degree between two text sentences according to the first sentence vector and the second sentence vector.
- a third embodiment of a text matching method in the embodiment of the present application includes:
- the lengths of the two text sentences are respectively detected, and specifically, the number of character strings in the text sentences can be detected.
- the text conversion model used in the subsequent steps has different processing effects for text sentences of different lengths. Therefore, before entering the text sentences into the model, the text sentences can be truncated or filled to a specified length to improve the subsequent model. processing effect.
- the length of the sentence can be set to 60 characters. When the length of a text sentence exceeds 60 characters, the text sentence is truncated according to the set method, so that the length of the text sentence is 60 characters. When the length of a text sentence is less than 60 characters, a specified character (such as the character "0") can be used to fill the text sentence, so that the length of the text sentence is 60 characters.
- a preferred text length range interval can also be set, such as [30, 60], where 30 is the lower limit of the length of the text sentence, and 60 is the upper limit of the length of the text sentence.
- the text sentence is truncated so that the length of the text sentence is 60; when the length of a text sentence is less than 30, the text sentence is filled with specified characters, Make the length of the text sentence 30.
- Steps 307-310 are the same as steps 102-105. For details, please refer to the relevant description of steps 102-105.
- pinyin is used as a new feature and is spliced with Chinese character corpus to form a new corpus and input into the text conversion model, so that the model can learn more semantic information including pinyin information. In this way, even if there is an error in the speech conversion text, the model can correct the input information according to the learned pinyin information, and return correct matching information, thereby improving the accuracy of text matching.
- the text sentence before inputting the text sentence into the model, the text sentence will be truncated or filled to a certain specified length, which can improve the processing effect of the subsequent model.
- FIG. 4 shows a structural block diagram of a text matching apparatus provided by an embodiment of the present application. For convenience of description, only parts related to the embodiments of the present application are shown.
- the device includes:
- a text sentence obtaining module 401 configured to obtain a first text sentence and a second text sentence
- Pinyin conversion module 402 configured to perform pinyin conversion on the first text statement and the second text statement to obtain the first pinyin of the first text statement and the second pinyin of the second text statement;
- Text splicing module 403 for splicing the first text statement and the first pinyin to obtain a first text corpus, and splicing the second text statement and the second pinyin to obtain a second text corpus;
- a vector conversion module 404 configured to respectively input the first text corpus and the second text corpus into a pre-built text vector conversion model to obtain the first sentence vector corresponding to the first text sentence and the second text The second sentence vector corresponding to the sentence;
- the matching degree calculation module 405 is configured to calculate the matching degree between the first text sentence and the second text sentence according to the first sentence vector and the second sentence vector.
- the matching degree calculation module may include:
- a cosine similarity calculation unit configured to calculate the cosine similarity between the first sentence vector and the second sentence vector
- a matching degree calculation unit configured to determine the matching degree between the first text sentence and the second text sentence according to the cosine similarity.
- the matching degree calculation module may include:
- a feature vector construction unit configured to construct a target feature vector based on the first sentence vector and the second sentence vector, where the target feature vector is used to measure the matching relationship between the first sentence vector and the second sentence vector ;
- a vector processing unit configured to use multiple fully connected layers to process the target feature vector to obtain the matching degree between the first text sentence and the second text sentence.
- the feature vector construction unit may include:
- the vector splicing subunit is used to connect the first sentence vector and the second sentence vector end to end to obtain the first feature vector;
- a vector multiplication subunit used for multiplying the element values of the corresponding positions of the first sentence vector and the second sentence vector to obtain a second feature vector
- the vector difference subunit is used to subtract the element values of the corresponding positions of the first sentence vector and the second sentence vector and take the absolute value to obtain the third feature vector;
- a vector dimension reduction subunit configured to splicing the first eigenvector, the second eigenvector and the third eigenvector in dimension reduction to obtain the target eigenvector.
- the matching degree calculation module may also include:
- a classification unit configured to use a softmax layer to classify the matching degree to obtain a result of whether the first text sentence matches the second text sentence.
- the text matching device may also include:
- a text length detection module for detecting the length of the first text sentence and the length of the second text sentence respectively
- a first text truncation module configured to truncate the first text statement if the length of the first text statement exceeds a preset length value, to obtain a first text statement whose length is the preset length value;
- a second text truncation module configured to truncate the second text statement if the length of the second text statement exceeds the preset length value to obtain a second text statement whose length is the preset length value .
- the text matching device may also include:
- the first text filling module is configured to fill the first text sentence with a specified character if the length of the first text sentence is less than the preset length value, to obtain the first text sentence whose length is the preset length value.
- a second text filling module configured to fill the second text sentence with the specified character if the length of the second text sentence is less than the preset length value, to obtain a length equal to the preset length value the second text sentence.
- Embodiments of the present application further provide a computer-readable storage medium, where computer-readable instructions are stored in the computer-readable storage medium, and when the computer-readable instructions are executed by a processor, any one of the instructions shown in FIG. 1 to FIG. 3 is implemented. steps of a text matching method.
- the computer-readable storage medium may be non-volatile or volatile.
- Embodiments of the present application also provide a computer program product, which, when the computer program product runs on the server, causes the server to execute the steps of implementing any one of the text matching methods shown in FIGS. 1 to 3 .
- FIG. 5 is a schematic diagram of a terminal device provided by an embodiment of the present application.
- the terminal device 5 in this embodiment includes: a processor 50 , a memory 51 , and computer-readable instructions 52 stored in the memory 51 and executable on the processor 50 .
- the processor 50 executes the computer-readable instructions 52
- the steps in each of the foregoing text matching method embodiments are implemented, for example, steps 101 to 105 shown in FIG. 1 .
- the processor 50 executes the computer-readable instructions 52
- the functions of the modules/units in the above-mentioned apparatus embodiments for example, the functions of the modules 401 to 405 shown in FIG. 4 are implemented.
- the computer-readable instructions 52 may be divided into one or more modules/units, and the one or more modules/units are stored in the memory 51 and executed by the processor 50, to complete this application.
- the one or more modules/units may be a series of computer-readable instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer-readable instructions 52 in the terminal device 5 .
- the terminal device 5 may be a computing device such as a smart phone, a notebook, a palmtop computer, and a cloud terminal device.
- the terminal device 5 may include, but is not limited to, a processor 50 and a memory 51 .
- FIG. 5 is only an example of the terminal device 5, and does not constitute a limitation on the terminal device 5, and may include more or less components than the one shown, or combine some components, or different components
- the terminal device 5 may further include an input and output device, a network access device, a bus, and the like.
- the processor 50 may be a central processing unit (Central Processing Unit, CPU), or other general-purpose processors, digital signal processors (Digital Signal Processors, DSP), application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf Programmable Gate Array (FieLd-Programmable Gate Array, 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 the processor may be any conventional processor or the like.
- the memory 51 may be an internal storage unit of the terminal device 5 , such as a hard disk or a memory of the terminal device 5 .
- the memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard disk equipped on the terminal device 5, a smart memory card (Smart Media Card, SMC), Secure Digital (SD) card, Flash Card (Flash Card), etc.
- the memory 51 may also include both an internal storage unit of the terminal device 5 and an external storage device.
- the memory 51 is used to store the computer-readable instructions and other programs and data required by the terminal device.
- the memory 51 can also be used to temporarily store data that has been output or will be output.
- the integrated unit if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium.
- the present application realizes all or part of the processes in the methods of the above embodiments, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium.
- the computer program includes computer program code
- the computer program code may be in the form of source code, object code, executable file or some intermediate form, and the like.
- the computer-readable medium may include at least: any entity or device capable of carrying computer program codes to the photographing device/terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunication signals, and software distribution media.
- ROM read-only memory
- RAM random access memory
- electrical carrier signals telecommunication signals
- software distribution media For example, U disk, mobile hard disk, disk or CD, etc.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Artificial Intelligence (AREA)
- Audiology, Speech & Language Pathology (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Machine Translation (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种文本匹配方法、装置、终端设备和存储介质,适用于人工智能技术领域。该方法包括:获取第一文本语句和第二文本语句(101);对第一文本语句和第二文本语句进行拼音转换,得到第一文本语句的第一拼音以及第二文本语句的第二拼音(102);将第一文本语句和第一拼音拼接,得到第一文本语料,以及将第二文本语句和第二拼音拼接,得到第二文本语料(103);将第一文本语料和第二文本语料分别输入预先构建的文本转换模型,得到第一文本语句对应的第一句向量以及第二文本语句对应的第二句向量(104);根据第一句向量和第二句向量计算得到第一文本语句与第二文本语句之间的匹配度(105)。采用该方法能够提高文本匹配的准确率。
Description
本申请要求于2020年11月06日提交中国专利局、申请号为202011228709.9,发明名称为“一种文本匹配方法、装置、终端设备和存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请属于人工智能技术领域,尤其涉及一种文本匹配方法、装置、终端设备和存储介质。
文本匹配是自然语言处理的一个核心问题,很多自然语言处理的任务都可以抽象成文本匹配问题,例如,信息检索系统、问答系统、对话系统、阅读理解系统等。随着语音系统的不断发展,越来越多的系统支持语音输入,发明人意识到,由于语音转换成文本存在一定的差异性及人工输入的误差性,使得输入的文本存在一定的差错,而传统的文本匹配模型没办法正确进行文本匹配,导致意图识别错误,给用户带来不好的体验。
有鉴于此,本申请提出一种文本匹配方法、装置、终端设备和存储介质,能够提高文本匹配的准确率。
第一方面,本申请实施例提供了一种文本匹配方法,包括:
获取第一文本语句和第二文本语句;
对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
第二方面,本申请实施例提供了一种文本匹配装置,包括:
文本语句获取模块,用于获取第一文本语句和第二文本语句;
拼音转换模块,用于对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
文本拼接模块,用于将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
向量转换模块,用于将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
匹配度计算模块,用于根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
第三方面,本申请实施例提供了一种终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如本申请实施例第一方面提出的文本匹配方法的步骤。
第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如本申请实施例第一方面提出的文本匹配方法的步骤。
本申请实施例将拼音作为一个新特征,与文本语句进行拼接,形成新的语料输入到文本转换模型中,使模型学习到包含拼音信息的更多语义信息。这样,即使出现语音转换文本错误时,模型也可以根据学习到的拼音信息,对输入信息进行纠正,返回正确的匹配信息,从而能够提高文本匹配的准确率。
图1是本申请实施例提供的一种文本匹配方法的第一个实施例的流程图;
图2是本申请实施例提供的一种文本匹配方法的第二个实施例的流程图;
图3是本申请实施例提供的一种文本匹配方法的第三个实施例的流程图;
图4是本申请实施例提供的一种文本匹配装置的一个实施例的结构图;
图5是本申请实施例提供的一种终端设备的示意图。
以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。另外,在本申请说明书和所附权利要求书的描述中,术语“第一”、“第二”、“第三”等仅用于区分描述,而不能理解为指示或暗示相对重要性。
文本匹配是自然语言处理的一个核心问题,很多自然语言处理的任务都可以抽象成文本匹配问题,例如,信息检索系统、问答系统、对话系统、阅读理解系统等。由于文本匹配存在匹配对象差异巨大、优质训练样本难以大量获取及文本匹配的层次性等问题,针对不同的任务选取合适的匹配模型,提高匹配的准确率成为自然语言处理任务的重要挑战。
目前,基于神经网络进行文本匹配的方式主要可以分为两大类:Sentence interaction(SI)类,该类模型可以更好的把握语义焦点,能对上下文重要性进行更好的建模,但忽视了句法、句间对照等全局性信息,无法由局部匹配信息刻画全局匹配信息;还有一类为Sentence encoding(Sentence representation)即SE类,它可以对文本进行预处理,构建索引,大幅度降低在线计算耗时、使用方便简单,且效果也比较好,孪生网络就是典型的SE结构,因此很多人都会采用孪生网络去进行文本匹配。然而,随着语音系统的不断发展,越来越多的系统支持语音输入,由于语音转换成文本存在一定的差异性及人工输入的误差性,使得输入的文本存在一定的差错,传统的文本匹配模型没办法正确进行文本匹配,导致意图识别错误,给用户带来不好的体验。
针对上述问题,本申请提出一种文本匹配方法、装置、终端设备和存储介质,能够提高文本匹配的准确率。
本申请实施例提供的文本匹配方法可以应用于手机、平板电脑、可穿戴设备、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personal
digital assistant,PDA)、大屏电视等终端设备或者服务器上,本申请实施例对终端设备和服务器的具体类型不作任何限制。
请参阅图1,本申请实施例中一种文本匹配方法的第一个实施例包括:
101、获取第一文本语句和第二文本语句;
首先,获取待匹配的第一文本语句和第二文本语句。第一文本语句和第二文本语句是需要执行文本匹配的两个汉字语句,每个文本语句都包含多个汉字。其中,第一文本语句和第二文本语句包含的汉字数量可以相同,也可以不同。
102、对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
在获取第一文本语句和第二文本语句后,对这两个文本语句分别进行拼音转换,得到第一文本语句的拼音以及第二文本语句的拼音。具体的,可以采用拼音转换器将输入的汉字转换成拼音,拼音转换器是可以将汉字转换成拼音的一种工具,比如可以采用python 中的xpinyin库进行转换,直接将句子中的每个汉字都转换成拼音,例如:“我爱人工智能”经过转换处理后得到“wo ai ren gong zhi neng”。
103、将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
在获得两个文本语句的拼音之后,分别将每个文本语句与对应的拼音进行拼接,得到两个新的文本语料。具体的,在拼接时,可以按照指定的字符拼接顺序,将汉字和拼音依次拼接。例如,在将我们是一家人”转换为“wo men shi yi jia ren”后,可以按照汉字在前,拼音在后的顺序,拼接成“我们是一家人 wo men shi yi jia ren”;可以按照拼音在前,汉字在后的顺序,拼接成“wo men shi yi jia ren我们是一家人”;也可以按照“汉字-拼音-汉字”的顺序,拼接成“我wo们men是shi一yi家jia人 ren”。
104、将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
在得到第一文本语料和第二文本语料之后,将这两个文本语料分别输入某个预先构建的文本转换模型中。通过该文本转换模型,可以将文本语料转换为对应的句向量,也即可以将第一文本语料转换为第一句向量,将第二文本语料转换为第二句向量。
具体的,该文本转换模型是预先训练完成的神经网络模型。可以包含Transformer编码层和pooling层,首先利用Transformer编码层对输入的文本预料进行编码,得到一系列数字表示的二维向量,类似于以下结构形式:
[ [0 2 1 0],
[3 1 2 1],
[4 0 5 1]]
然后,利用pooling层对编码后得到的二维向量执行文本特征提取操作。pooling层提取特征主要有max-pooling(最大池化层)和mean-pooling(均值池化层),max-pooling是对领域内特征点取最大值,而mean-pooling是对领域内特征点求平均,本申请优选采用的是max-pooling层进行特征选取,例如pooling层大小为2*2,则对上面向量从左到右,从上到下依次以2*2的窗口进行移动,抽取窗口内特征最大值,最后经过最大池化后变成以下二维向量结构:
[ [3 2 2],
[4 5 5]]
接着,对上述二维向量结构进行降维,得到一维向量(3 2 2 4 5 5),即为文本语句对应的句向量。
105、根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
在获得第一文本语句对应的第一句向量和第二文本语句对应的第二句向量之后,即可根据这两个句向量计算得到第一文本语句和第二文本语句之间的匹配度,从而完成文本匹配的操作。
进一步的,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,可以包括:
(1)计算所述第一句向量和所述第二句向量之间的余弦相似度;
(2)根据所述余弦相似度确定所述第一文本语句与所述第二文本语句之间的匹配度。
余弦相似度通过测量两个向量的夹角的余弦值来度量它们之间的相似性,故通过计算第一句向量和第二句向量之间的余弦相似度,可以用于确定两个文本语句的匹配度。
本申请实施例将拼音作为一个新特征,与文本语句进行拼接,形成新的语料输入到文本转换模型中,使模型学习到包含拼音信息的更多语义信息。这样,即使出现语音转换文本错误时,模型也可以根据学习到的拼音信息,对输入信息进行纠正,返回正确的匹配信息,从而能够提高文本匹配的准确率。
请参阅图2,本申请实施例中一种文本匹配方法的第二个实施例包括:
201、获取第一文本语句和第二文本语句;
202、对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
203、将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
204、将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
步骤201-204与步骤101-104相同,具体可参照步骤101-104的相关说明。
205、基于所述第一句向量和所述第二句向量构建目标特征向量,所述目标特征向量用于衡量所述第一句向量和所述第二句向量的匹配关系;
在获得第一文本语句对应的第一句向量和第二文本语句对应的第二句向量之后,即可根据这两个句向量计算得到第一文本语句和第二文本语句之间的匹配度,具体可以通过构建目标特征向量的方式计算匹配度,该目标特征向量用于衡量第一句向量和第二句向量之间的匹配关系。
具体的,基于所述第一句向量和所述第二句向量构建目标特征向量,可以包括:
(1)将所述第一句向量和所述第二句向量首尾相接,得到第一特征向量;
(2)将所述第一句向量和所述第二句向量对应位置的元素值相乘,得到第二特征向量;
(3)将所述第一句向量和所述第二句向量对应位置的元素值相减并取绝对值,得到第三特征向量;
(4)将所述第一特征向量、所述第二特征向量和所述第三特征向量降维度拼接,得到所述目标特征向量。
以举例的方式说明上述步骤(1)至(4),假设第一句向量为u=[1 2 3 1 1 0],第二句向量为v = [1 0 1 2 3 0],则可以对u和v进行首尾相接,得到第一特征向量(u,v)=[[1 2
3 1 1 0],[ 1 0 1 2 3 0]];将u和v对应位置的元素值分别相乘,得到第二特征向量u*v=[1 0 3 2 3 0];将u和v对应位置的元素值相减并取绝对值,得到第三特征向量|u-v|=[0 2 2 1 2 0]。然后,将这3个特征向量在-1维度进行拼接,得到以下目标特征向量:
[ [1 1 1 0]
[2 0 0 2]
[3 1 3 2]
[1 2 2 1]
[1 3 2 2]
[0 0 0 0]]
该目标特征向量可以用于衡量第一句向量u和第二句向量v
之间的匹配关系,可以通过该目标特征向量计算得到第一文本语句和第二文本语句之间的匹配度。
206、采用多个全连接层对所述目标特征向量进行处理,得到所述第一文本语句与所述第二文本语句之间的匹配度。
在获得目标特征向量之后,可以将该目标特征向量输入多个全连接层进行处理,从而得到两个文本语句之间的匹配度。全连接层(fully
connected layers)在整个神经网络中起到“分类器”的作用,如果说卷积层、池化层和激活函数层等操作是将原始数据映射到隐层特征空间的话,全连接层则起到将学到的“分布式特征表示”映射到样本标记空间的作用。
具体的,全连接层中的每个神经元与其前一层的所有神经元进行全连接.可以整合卷积层或者池化层中具有类别区分性的局部信息.也即可以将目标特征向量具有的文本特征整合成一个用于评价两个文本之间相似程度的数值参数,即匹配度。
进一步的,在得到所述第一文本语句与所述第二文本语句之间的匹配度之后,还可以包括:
采用softmax层对所述匹配度进行处理,得到所述第一文本语句与所述第二文本语句是否匹配的结果。
最后,还可以采用softmax层完成分类,也即根据输入的匹配度获得一个第一文本语句和第二文本语句是否匹配的结果。例如,若输入的匹配度大于某个阈值,则输出第一文本语句和第二文本语句匹配的结果;否则输出第一文本语句和第二文本语句不匹配的结果。
本申请实施例将拼音作为一个新特征,与汉字语料进行拼接,形成新的语料输入到文本转换模型中,使模型学习到包含拼音信息的更多语义信息。这样,即使出现语音转换文本错误时,模型也可以根据学习到的拼音信息,对输入信息进行纠正,返回正确的匹配信息,从而能够提高文本匹配的准确率。与本申请的第一个实施例相比,本实施例提出一种根据第一句向量和第二句向量计算得到两个文本语句之间的匹配度的具体方式。
请参阅图3,本申请实施例中一种文本匹配方法的第三个实施例包括:
301、获取第一文本语句和第二文本语句;
302、分别检测所述第一文本语句的长度和所述第二文本语句的长度;
本申请实施例在获取到两个文本语句之后,会分别检测这两个文本语句的长度,具体可以是检测文本语句具有的字符串的个数。
303、若所述第一文本语句的长度超过预设长度值,则对所述第一文本语句进行截断,得到长度为所述预设长度值的第一文本语句;
304、若所述第二文本语句的长度超过所述预设长度值,则对所述第二文本语句进行截断,得到长度为所述预设长度值的第二文本语句;
305、若所述第一文本语句的长度小于所述预设长度值,则采用指定字符对所述第一文本语句进行填充,得到长度为所述预设长度值的第一文本语句;
306、若所述第二文本语句的长度小于所述预设长度值,则采用所述指定字符对所述第二文本语句进行填充,得到长度为所述预设长度值的第二文本语句;
后续步骤中采用的文本转换模型,其针对不同长度文本语句的处理效果是有区别的,因此在将文本语句输入模型之前,可以先将文本语句截断或者填充至某个指定长度,以提高后续模型的处理效果。比如,可以设置语句长度值为60个字符,当某个文本语句的长度超过60个字符时,按照设定的方式对该文本语句进行截断,使得该文本语句的长度为60个字符。当某个文本语句的长度不足60个字符时,可以采用某个指定字符(比如字符“0”)对该文本语句进行填充,使得该文本语句的长度为60个字符。
另外,也可以设置一个优选的文本长度范围区间,比如[30,60],其中30是文本语句的长度下限,60是文本语句的长度上限。当检测到某个文本语句的长度超过60时,对该文本语句进行截断,使得该文本语句的长度为60;当某个文本语句的长度小于30时,采用指定字符对该文本语句进行填充,使得该文本语句的长度为30。
307、对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
308、将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
309、将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
310、根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
步骤307-310与步骤102-105相同,具体可参照步骤102-105的相关说明。
本申请实施例将拼音作为一个新特征,与汉字语料进行拼接,形成新的语料输入到文本转换模型中,使模型学习到包含拼音信息的更多语义信息。这样,即使出现语音转换文本错误时,模型也可以根据学习到的拼音信息,对输入信息进行纠正,返回正确的匹配信息,从而能够提高文本匹配的准确率。另外,本申请实施例在将文本语句输入模型之前,会先将文本语句截断或者填充至某个指定长度,能够提高后续模型的处理效果。
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
对应于上文实施例所述的文本匹配方法,图4示出了本申请实施例提供的一种文本匹配装置的结构框图,为了便于说明,仅示出了与本申请实施例相关的部分。
参照图4,该装置包括:
文本语句获取模块401,用于获取第一文本语句和第二文本语句;
拼音转换模块402,用于对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;
文本拼接模块403,用于将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;
向量转换模块404,用于将所述第一文本语料和所述第二文本语料分别输入预先构建的文本向量转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;
匹配度计算模块405,用于根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
进一步的,所述匹配度计算模块可以包括:
余弦相似度计算单元,用于计算所述第一句向量和所述第二句向量之间的余弦相似度;
匹配度计算单元,用于根据所述余弦相似度确定所述第一文本语句与所述第二文本语句之间的匹配度。
进一步的,所述匹配度计算模块可以包括:
特征向量构建单元,用于基于所述第一句向量和所述第二句向量构建目标特征向量,所述目标特征向量用于衡量所述第一句向量和所述第二句向量的匹配关系;
向量处理单元,用于采用多个全连接层对所述目标特征向量进行处理,得到所述第一文本语句与所述第二文本语句之间的匹配度。
更进一步的,所述特征向量构建单元可以包括:
向量拼接子单元,用于将所述第一句向量和所述第二句向量首尾相接,得到第一特征向量;
向量相乘子单元,用于将所述第一句向量和所述第二句向量对应位置的元素值相乘,得到第二特征向量;
向量作差子单元,用于将所述第一句向量和所述第二句向量对应位置的元素值相减并取绝对值,得到第三特征向量;
向量降维子单元,用于将所述第一特征向量、所述第二特征向量和所述第三特征向量降维度拼接,得到所述目标特征向量。
进一步的,所述匹配度计算模块还可以包括:
分类单元,用于采用softmax层对所述匹配度进行分类处理,得到所述第一文本语句与所述第二文本语句是否匹配的结果。
进一步的,所述文本匹配装置还可以包括:
文本长度检测模块,用于分别检测所述第一文本语句的长度和所述第二文本语句的长度;
第一文本截断模块,用于若所述第一文本语句的长度超过预设长度值,则对所述第一文本语句进行截断,得到长度为所述预设长度值的第一文本语句;
第二文本截断模块,用于若所述第二文本语句的长度超过所述预设长度值,则对所述第二文本语句进行截断,得到长度为所述预设长度值的第二文本语句。
进一步的,所述文本匹配装置还可以包括:
第一文本填充模块,用于若所述第一文本语句的长度小于所述预设长度值,则采用指定字符对所述第一文本语句进行填充,得到长度为所述预设长度值的第一文本语句;
第二文本填充模块,用于若所述第二文本语句的长度小于所述预设长度值,则采用所述指定字符对所述第二文本语句进行填充,得到长度为所述预设长度值的第二文本语句。
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可读指令,所述计算机可读指令被处理器执行时实现如图1至图3表示的任意一种文本匹配方法的步骤。其中,所述计算机可读存储介质可以是非易失性,也可以是易失性。
本申请实施例还提供一种计算机程序产品,当该计算机程序产品在服务器上运行时,使得服务器执行实现如图1至图3表示的任意一种文本匹配方法的步骤。
图5是本申请一实施例提供的终端设备的示意图。如图5所示,该实施例的终端设备5包括:处理器50、存储器51以及存储在所述存储器51中并可在所述处理器50上运行的计算机可读指令52。所述处理器50执行所述计算机可读指令52时实现上述各个文本匹配方法实施例中的步骤,例如图1所示的步骤101至105。或者,所述处理器50执行所述计算机可读指令52时实现上述各装置实施例中各模块/单元的功能,例如图4所示模块401至405的功能。
示例性的,所述计算机可读指令52可以被分割成一个或多个模块/单元,所述一个或者多个模块/单元被存储在所述存储器51中,并由所述处理器50执行,以完成本申请。所述一个或多个模块/单元可以是能够完成特定功能的一系列计算机可读指令段,该指令段用于描述所述计算机可读指令52在所述终端设备5中的执行过程。
所述终端设备5可以是智能手机、笔记本、掌上电脑及云端终端设备等计算设备。所述终端设备5可包括,但不仅限于,处理器50、存储器51。本领域技术人员可以理解,图5仅仅是终端设备5的示例,并不构成对终端设备5的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述终端设备5还可以包括输入输出设备、网络接入设备、总线等。
所述处理器50可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器 (Digital Signal Processor,DSP)、专用集成电路 (AppLication
Specific Integrated Circuit,ASIC)、现成可编程门阵列 (FieLd-Programmable Gate Array,FPGA) 或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
所述存储器51可以是所述终端设备5的内部存储单元,例如终端设备5的硬盘或内存。所述存储器51也可以是所述终端设备5的外部存储设备,例如所述终端设备5上配备的插接式硬盘,智能存储卡(Smart
Media Card, SMC),安全数字(Secure Digital, SD)卡,闪存卡(Flash Card)等。进一步地,所述存储器51还可以既包括所述终端设备5的内部存储单元也包括外部存储设备。所述存储器51用于存储所述计算机可读指令以及所述终端设备所需的其他程序和数据。所述存储器51还可以用于暂时地存储已经输出或者将要输出的数据。
需要说明的是,上述装置/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参见方法实施例部分,此处不再赘述。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质至少可以包括:能够将计算机程序代码携带到拍照装置/终端设备的任何实体或装置、记录介质、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质。例如U盘、移动硬盘、磁碟或者光盘等。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。
Claims (20)
- 一种文本匹配方法,其中,包括:获取第一文本语句和第二文本语句;对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求1所述的文本匹配方法,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:计算所述第一句向量和所述第二句向量之间的余弦相似度;根据所述余弦相似度确定所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求1文本匹配方法,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:基于所述第一句向量和所述第二句向量构建目标特征向量,所述目标特征向量用于衡量所述第一句向量和所述第二句向量的匹配关系;采用多个全连接层对所述目标特征向量进行处理,得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求3所述的文本匹配方法,其中,基于所述第一句向量和所述第二句向量构建目标特征向量,包括:将所述第一句向量和所述第二句向量首尾相接,得到第一特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相乘,得到第二特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相减并取绝对值,得到第三特征向量;将所述第一特征向量、所述第二特征向量和所述第三特征向量降维度拼接,得到所述目标特征向量。
- 如权利要求3所述的文本匹配方法,其中,在得到所述第一文本语句与所述第二文本语句之间的匹配度之后,还包括:采用softmax层对所述匹配度进行分类处理,得到所述第一文本语句与所述第二文本语句是否匹配的结果。
- 如权利要求1至5任一项所述的文本匹配方法,其中,在获取第一文本语句和第二文本语句之后,对所述第一文本语句和所述第二文本语句进行拼音转换之前,还包括:分别检测所述第一文本语句的长度和所述第二文本语句的长度;若所述第一文本语句的长度超过预设长度值,则对所述第一文本语句进行截断,得到长度为所述预设长度值的第一文本语句;若所述第二文本语句的长度超过所述预设长度值,则对所述第二文本语句进行截断,得到长度为所述预设长度值的第二文本语句。
- 如权利要求6所述的文本匹配方法,其中,在分别检测所述第一文本语句的长度和所述第二文本语句的长度之后,还包括:若所述第一文本语句的长度小于所述预设长度值,则采用指定字符对所述第一文本语句进行填充,得到长度为所述预设长度值的第一文本语句;若所述第二文本语句的长度小于所述预设长度值,则采用所述指定字符对所述第二文本语句进行填充,得到长度为所述预设长度值的第二文本语句。
- 一种文本匹配装置,其中,包括:文本语句获取模块,用于获取第一文本语句和第二文本语句;拼音转换模块,用于对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;文本拼接模块,用于将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;向量转换模块,用于将所述第一文本语料和所述第二文本语料分别输入预先构建的文本向量转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;匹配度计算模块,用于根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 一种终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,其中,所述处理器执行所述计算机程序时实现如下步骤:获取第一文本语句和第二文本语句;对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求9所述的终端设备,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:计算所述第一句向量和所述第二句向量之间的余弦相似度;根据所述余弦相似度确定所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求9所述的终端设备,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:基于所述第一句向量和所述第二句向量构建目标特征向量,所述目标特征向量用于衡量所述第一句向量和所述第二句向量的匹配关系;采用多个全连接层对所述目标特征向量进行处理,得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求11所述的终端设备,其中,基于所述第一句向量和所述第二句向量构建目标特征向量,包括:将所述第一句向量和所述第二句向量首尾相接,得到第一特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相乘,得到第二特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相减并取绝对值,得到第三特征向量;将所述第一特征向量、所述第二特征向量和所述第三特征向量降维度拼接,得到所述目标特征向量。
- 如权利要求11所述的终端设备,其中,在得到所述第一文本语句与所述第二文本语句之间的匹配度之后,还包括:采用softmax层对所述匹配度进行分类处理,得到所述第一文本语句与所述第二文本语句是否匹配的结果。
- 如权利要求9至13任一项所述的终端设备,其中,在获取第一文本语句和第二文本语句之后,对所述第一文本语句和所述第二文本语句进行拼音转换之前,还包括:分别检测所述第一文本语句的长度和所述第二文本语句的长度;若所述第一文本语句的长度超过预设长度值,则对所述第一文本语句进行截断,得到长度为所述预设长度值的第一文本语句;若所述第二文本语句的长度超过所述预设长度值,则对所述第二文本语句进行截断,得到长度为所述预设长度值的第二文本语句。
- 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其中,所述计算机程序被处理器执行时实现如下步骤:获取第一文本语句和第二文本语句;对所述第一文本语句和所述第二文本语句进行拼音转换,得到所述第一文本语句的第一拼音以及所述第二文本语句的第二拼音;将所述第一文本语句和所述第一拼音拼接,得到第一文本语料,以及将所述第二文本语句和所述第二拼音拼接,得到第二文本语料;将所述第一文本语料和所述第二文本语料分别输入预先构建的文本转换模型,得到所述第一文本语句对应的第一句向量以及所述第二文本语句对应的第二句向量;根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求15所述的计算机可读存储介质,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:计算所述第一句向量和所述第二句向量之间的余弦相似度;根据所述余弦相似度确定所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求15所述的计算机可读存储介质,其中,根据所述第一句向量和所述第二句向量计算得到所述第一文本语句与所述第二文本语句之间的匹配度,包括:基于所述第一句向量和所述第二句向量构建目标特征向量,所述目标特征向量用于衡量所述第一句向量和所述第二句向量的匹配关系;采用多个全连接层对所述目标特征向量进行处理,得到所述第一文本语句与所述第二文本语句之间的匹配度。
- 如权利要求17所述的计算机可读存储介质,其中,基于所述第一句向量和所述第二句向量构建目标特征向量,包括:将所述第一句向量和所述第二句向量首尾相接,得到第一特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相乘,得到第二特征向量;将所述第一句向量和所述第二句向量对应位置的元素值相减并取绝对值,得到第三特征向量;将所述第一特征向量、所述第二特征向量和所述第三特征向量降维度拼接,得到所述目标特征向量。
- 如权利要求17所述的计算机可读存储介质,其中,在得到所述第一文本语句与所述第二文本语句之间的匹配度之后,还包括:采用softmax层对所述匹配度进行分类处理,得到所述第一文本语句与所述第二文本语句是否匹配的结果。
- 如权利要求15至19任一项所述的终端设备,其中,在获取第一文本语句和第二文本语句之后,对所述第一文本语句和所述第二文本语句进行拼音转换之前,还包括:分别检测所述第一文本语句的长度和所述第二文本语句的长度;若所述第一文本语句的长度超过预设长度值,则对所述第一文本语句进行截断,得到长度为所述预设长度值的第一文本语句;若所述第二文本语句的长度超过所述预设长度值,则对所述第二文本语句进行截断,得到长度为所述预设长度值的第二文本语句。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011228709.9 | 2020-11-06 | ||
| CN202011228709.9A CN112182167B (zh) | 2020-11-06 | 2020-11-06 | 一种文本匹配方法、装置、终端设备和存储介质 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2022095370A1 true WO2022095370A1 (zh) | 2022-05-12 |
Family
ID=73916606
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2021/090952 Ceased WO2022095370A1 (zh) | 2020-11-06 | 2021-04-29 | 一种文本匹配方法、装置、终端设备和存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN112182167B (zh) |
| WO (1) | WO2022095370A1 (zh) |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112182167B (zh) * | 2020-11-06 | 2023-12-22 | 平安科技(深圳)有限公司 | 一种文本匹配方法、装置、终端设备和存储介质 |
| CN113297354B (zh) * | 2021-06-16 | 2025-03-07 | 深圳前海微众银行股份有限公司 | 文本匹配方法、装置、设备及存储介质 |
| CN113360623A (zh) * | 2021-06-25 | 2021-09-07 | 达闼机器人有限公司 | 一种文本匹配方法、电子设备及可读存储介质 |
| CN115098637A (zh) * | 2022-06-29 | 2022-09-23 | 中译语通科技股份有限公司 | 一种基于汉字形音义多元知识的文本语义匹配方法和系统 |
| CN116110392A (zh) * | 2023-02-08 | 2023-05-12 | 北京云迹科技股份有限公司 | 语音识别结果的修正方法及装置 |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20160217129A1 (en) * | 2014-11-28 | 2016-07-28 | Huawei Technologies Co., Ltd. | Method and Apparatus for Determining Semantic Matching Degree |
| CN106815197A (zh) * | 2015-11-27 | 2017-06-09 | 北京国双科技有限公司 | 文本相似度的确定方法和装置 |
| CN109460461A (zh) * | 2018-11-13 | 2019-03-12 | 苏州思必驰信息科技有限公司 | 基于文本相似度模型的文本匹配方法及系统 |
| CN109658938A (zh) * | 2018-12-07 | 2019-04-19 | 百度在线网络技术(北京)有限公司 | 语音与文本匹配的方法、装置、设备及计算机可读介质 |
| CN111159339A (zh) * | 2019-12-24 | 2020-05-15 | 北京亚信数据有限公司 | 一种文本匹配处理方法和装置 |
| CN111221960A (zh) * | 2019-10-28 | 2020-06-02 | 支付宝(杭州)信息技术有限公司 | 文本检测方法、相似度计算方法、模型训练方法及装置 |
| CN112182167A (zh) * | 2020-11-06 | 2021-01-05 | 平安科技(深圳)有限公司 | 一种文本匹配方法、装置、终端设备和存储介质 |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN106686404B (zh) * | 2016-12-16 | 2021-02-02 | 中兴通讯股份有限公司 | 一种视频分析平台、匹配方法、精准投放广告方法及系统 |
| CN111797204A (zh) * | 2020-07-01 | 2020-10-20 | 北京三快在线科技有限公司 | 文本匹配方法、装置、计算机设备及存储介质 |
-
2020
- 2020-11-06 CN CN202011228709.9A patent/CN112182167B/zh active Active
-
2021
- 2021-04-29 WO PCT/CN2021/090952 patent/WO2022095370A1/zh not_active Ceased
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20160217129A1 (en) * | 2014-11-28 | 2016-07-28 | Huawei Technologies Co., Ltd. | Method and Apparatus for Determining Semantic Matching Degree |
| CN106815197A (zh) * | 2015-11-27 | 2017-06-09 | 北京国双科技有限公司 | 文本相似度的确定方法和装置 |
| CN109460461A (zh) * | 2018-11-13 | 2019-03-12 | 苏州思必驰信息科技有限公司 | 基于文本相似度模型的文本匹配方法及系统 |
| CN109658938A (zh) * | 2018-12-07 | 2019-04-19 | 百度在线网络技术(北京)有限公司 | 语音与文本匹配的方法、装置、设备及计算机可读介质 |
| CN111221960A (zh) * | 2019-10-28 | 2020-06-02 | 支付宝(杭州)信息技术有限公司 | 文本检测方法、相似度计算方法、模型训练方法及装置 |
| CN111159339A (zh) * | 2019-12-24 | 2020-05-15 | 北京亚信数据有限公司 | 一种文本匹配处理方法和装置 |
| CN112182167A (zh) * | 2020-11-06 | 2021-01-05 | 平安科技(深圳)有限公司 | 一种文本匹配方法、装置、终端设备和存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN112182167B (zh) | 2023-12-22 |
| CN112182167A (zh) | 2021-01-05 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN112528672B (zh) | 一种基于图卷积神经网络的方面级情感分析方法及装置 | |
| WO2022095370A1 (zh) | 一种文本匹配方法、装置、终端设备和存储介质 | |
| CN112633419B (zh) | 小样本学习方法、装置、电子设备和存储介质 | |
| CN111695352A (zh) | 基于语义分析的评分方法、装置、终端设备及存储介质 | |
| CN111310441A (zh) | 基于bert的语音识别后文本修正方法、装置、终端及介质 | |
| CN111767375A (zh) | 语义召回方法、装置、计算机设备及存储介质 | |
| CN116258147B (zh) | 一种基于异构图卷积的多模态评论情感分析方法及系统 | |
| CN111368037A (zh) | 基于Bert模型的文本相似度计算方法和装置 | |
| CN111368066B (zh) | 获取对话摘要的方法、装置和计算机可读存储介质 | |
| CN115240712A (zh) | 一种基于多模态的情感分类方法、装置、设备及存储介质 | |
| CN114328894A (zh) | 文档处理方法、装置、电子设备及介质 | |
| CN115587583A (zh) | 噪声的检测方法、装置及电子设备 | |
| CN116483979A (zh) | 基于人工智能的对话模型训练方法、装置、设备及介质 | |
| CN116844573A (zh) | 基于人工智能的语音情感识别方法、装置、设备及介质 | |
| CN114925175A (zh) | 基于人工智能的摘要生成方法、装置、计算机设备及介质 | |
| CN115329176A (zh) | 搜索请求的处理方法、装置、计算机设备及存储介质 | |
| CN111079418A (zh) | 命名体识别方法、装置、电子设备和存储介质 | |
| CN114741468A (zh) | 文本去重方法、装置、设备及存储介质 | |
| CN113326383A (zh) | 一种短文本实体链接方法、装置、计算设备与存储介质 | |
| CN115394321A (zh) | 音频情感识别方法、装置、设备、存储介质及产品 | |
| CN114741487A (zh) | 基于图文语义嵌入的图文检索方法及系统 | |
| CN113255328A (zh) | 语言模型的训练方法及应用方法 | |
| CN117421641B (zh) | 一种文本分类的方法、装置、电子设备及可读存储介质 | |
| CN111401069A (zh) | 会话文本的意图识别方法、意图识别装置及终端 | |
| CN111898363B (zh) | 文本长难句的压缩方法、装置、计算机设备及存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 21888074 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 21888074 Country of ref document: EP Kind code of ref document: A1 |