Semantic verification method and device for encoding vector, electronic equipment and product
Patent Information
- Application Number
- CN202611178317.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-27
AI Technical Summary
然而,在采用文本编码模型处理个性化、口语化的输入文本时,极易产生隐蔽的语义偏差,导致编码模型输出的向量未能准确反映输入文本的真实语义
[0022]本申请实施例与现有技术相比存在的有益效果是:通过对原始文本进行特征提取,使得特征提取后的第一结构化文本中包括原始文本的描述对象、描述对象的属性及属性对应的属性值,从而第一结构化文本在去除原始文本中与描述对象无关的信息的同时,也可以准确、清楚地表达原始文本的语义。进而在原始文本的编码向量与第一结构化文本的编码向量之间的语义距离小于或等于第一阈值的情况下,确定原始文本的编码向量的语义与原始文本的语义相匹配;在语义距离大于第一阈值的情况下,确定原始文本的编码向量的语义与原始文本的语义不匹配。由此,基于第一结构化文本的语义与原始文本的语义相匹配,原始文本的编码向量与第一结构化文本的编码向量之间的语义距离应接近的原理,将原始文本的编码向量与第一结构化文本的编码向量之间的语义距离与第一阈值进行比较,可以准确地确定原始文本的编码向量的语义是否聚焦在与描述对象相关的信息上,及时发现原始文本的编码向量未能准确反映原始文本的语义的情况,避免因对原始文本编码错误导致后续应答或决策失误。
Smart Images

Figure CN122987940A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of natural language processing technology, and in particular relates to a semantic verification method, device, electronic device and product for encoded vectors. Background Technology
[0002] Smart terminal devices (such as home service robots, intelligent voice assistants, and in-vehicle intelligent systems) record daily conversations with users in text form during interactions, using this information as a basis for subsequent decisions regarding user inquiries and the execution of related tasks. For example, the terminal can record users' health records (such as food allergens), care information for special groups (such as contraindications for chronic diseases), and daily safety parameters (such as medication guidelines).
[0003] In related technologies, terminal devices employ text encoding models to convert the text corresponding to users' daily conversations into vector representations to support subsequent semantic retrieval and matching. However, when using text encoding models to process personalized, conversational input text, hidden semantic biases are easily generated, causing the vectors output by the encoding model to fail to accurately reflect the true semantics of the input text. This semantic bias, amplified in subsequent retrieval or matching stages, may lead the terminal to make incorrect decisions based on distorted semantics. Summary of the Invention
[0004] This application provides a semantic verification method, apparatus, electronic device, and product for encoded vectors, which can accurately determine whether the semantics of the encoded vector of the original text matches the semantics of the original text.
[0005] In a first aspect, embodiments of this application provide a semantic verification method for encoded vectors, including: Get the raw text input by the user; Feature extraction is performed on the original text to obtain a first structured text, which includes the description object of the original text, the attributes of the description object, and the attribute values corresponding to the attributes. If the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text. If the semantic distance is greater than the first threshold, it is determined that the semantics of the encoding vector of the original text does not match the semantics of the original text.
[0006] In one possible implementation of the first aspect, after performing feature extraction on the original text to obtain the first structured text, the method further includes: If the semantic distance is less than the second threshold and the first structured text includes other text besides the described object, the attribute, and the attribute value corresponding to the attribute, the other text in the first structured text is removed to obtain a new first structured text, and the second threshold is less than the first threshold. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than the second threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text.
[0007] In one possible implementation of the first aspect, the method further includes: Obtain multiple sample texts and the encoding vector of each sample text, wherein the semantics of the sample texts are matched with the semantics of the encoding vectors of the sample texts; Feature extraction is performed on each of the sample texts to obtain a second structured text, which includes a sample description object of the sample text, sample attributes of the sample description object, and sample attribute values corresponding to the sample attributes. Based on the semantic distance between the encoding vector of the sample text and the encoding vector of the second structured text, the first threshold and the second threshold are determined, wherein the first threshold is greater than the first mean of the semantic distances of the plurality of sample texts and less than the maximum value among the semantic distances of the plurality of sample texts, and the second threshold is greater than the minimum value among the semantic distances of the plurality of sample texts and less than the first mean.
[0008] In one possible implementation of the first aspect, after determining that the semantics of the encoding vector of the original text matches the semantics of the original text, the method further includes: Based on the semantic distances corresponding to multiple texts, a new first threshold and a new second threshold are determined. The multiple texts include multiple sample texts and the original text. The new first threshold is greater than the second mean of the semantic distances of the multiple texts and less than the maximum value of the semantic distances of the multiple texts. The second threshold is greater than the minimum value of the semantic distances of the multiple texts and less than the second mean.
[0009] In one possible implementation of the first aspect, the encoded vector of the original text is a vector output after encoding the original text using a first encoding model, and the encoded vector of the first structured text is a vector output after encoding the first structured text using a second encoding model. The method further includes: The first structured text of the first original text from multiple original texts is input into the second encoding model to obtain a predicted encoding vector. The semantic distance between the encoding vector of the first original text and the encoding vector of the corresponding first structured text is greater than the first threshold, and the semantics of the first original text and the encoding vector of the first original text have been verified by the user to match. Determine a first similarity between the predicted encoding vector and the encoding vector of the first original text, and a second similarity between the predicted encoding vector and the encoding vector of the second original text among the plurality of original texts; The first similarity and the second similarity are input into the contrastive learning loss function to determine the loss value; Based on the loss value, the second encoding model is modified.
[0010] In one possible implementation of the first aspect, the feature extraction of the original text to obtain the first structured text includes any one of the following: Receive a user's query statement. If the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than a similarity threshold, perform feature extraction on the original text to obtain a first structured text. In response to receiving a target instruction sent by a user, feature extraction is performed on the original text to obtain a first structured text, wherein the target instruction is used to instruct the semantics of the encoding vector of the original text to be verified; In response to a task instruction, if the similarity between the encoding vector of the retrieval condition corresponding to the task instruction and the encoding vector of the original text is greater than a similarity threshold, feature extraction is performed on the original text to obtain a first structured text.
[0011] In one possible implementation of the first aspect, after determining that the semantics of the encoding vector of the original text does not match the semantics of the original text, it further includes at least one of the following: Generate a verification request, which requests the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text; If the similarity between the encoding vector of the user's query statement and the encoding vector of the original text is greater than a similarity threshold, a response statement is generated based on text other than the original text. Reduce the search priority of the encoding vector of the original text.
[0012] Secondly, embodiments of this application provide a semantic verification apparatus for encoded vectors, comprising: The acquisition module is used to acquire the raw text input by the user; An extraction module is used to extract features from the original text to obtain a first structured text, wherein the first structured text includes a description object of the original text, attributes of the description object, and attribute values corresponding to the attributes. The determining module is configured to determine that the semantics of the encoding vector of the original text matches the semantics of the original text when the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold. The determining module is further configured to determine, when the semantic distance is greater than the first threshold, that the semantics of the encoding vector of the original text does not match the semantics of the original text.
[0013] In one possible implementation, a first processing module is also included, for: If the semantic distance is less than the second threshold and the first structured text includes other text besides the described object, the attribute, and the attribute value corresponding to the attribute, the other text in the first structured text is removed to obtain a new first structured text, and the second threshold is less than the first threshold. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than the second threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text.
[0014] In one possible implementation, a second processing module is also included, for: Obtain multiple sample texts and the encoding vector of each sample text, wherein the semantics of the sample texts are matched with the semantics of the encoding vectors of the sample texts; Feature extraction is performed on each of the sample texts to obtain a second structured text, which includes a sample description object of the sample text, sample attributes of the sample description object, and sample attribute values corresponding to the sample attributes. Based on the semantic distance between the encoding vector of the sample text and the encoding vector of the second structured text, the first threshold and the second threshold are determined, wherein the first threshold is greater than the first mean of the semantic distances of the plurality of sample texts and less than the maximum value among the semantic distances of the plurality of sample texts, and the second threshold is greater than the minimum value among the semantic distances of the plurality of sample texts and less than the first mean.
[0015] In one possible implementation, the second processing module is further used for: Based on the semantic distances corresponding to multiple texts, a new first threshold and a new second threshold are determined. The multiple texts include multiple sample texts and the original text. The new first threshold is greater than the second mean of the semantic distances of the multiple texts and less than the maximum value of the semantic distances of the multiple texts. The second threshold is greater than the minimum value of the semantic distances of the multiple texts and less than the second mean.
[0016] In one possible implementation, the encoded vector of the original text is a vector output after encoding the original text using a first encoding model, and the encoded vector of the first structured text is a vector output after encoding the first structured text using a second encoding model. The device further includes a correction module for: The first structured text of the first original text from multiple original texts is input into the second encoding model to obtain a predicted encoding vector. The semantic distance between the encoding vector of the first original text and the encoding vector of the corresponding first structured text is greater than the first threshold, and the semantics of the first original text and the encoding vector of the first original text have been verified by the user to match. Determine a first similarity between the predicted encoding vector and the encoding vector of the first original text, and a second similarity between the predicted encoding vector and the encoding vector of the second original text among the plurality of original texts; The first similarity and the second similarity are input into the contrastive learning loss function to determine the loss value; Based on the loss value, the second encoding model is modified.
[0017] In one possible implementation, the extraction module 502 is used for: Receive a user's query statement. If the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than a similarity threshold, perform feature extraction on the original text to obtain a first structured text. In response to receiving a target instruction sent by a user, feature extraction is performed on the original text to obtain a first structured text, wherein the target instruction is used to instruct the semantics of the encoding vector of the original text to be verified; In response to a task instruction, if the similarity between the encoding vector of the retrieval condition corresponding to the task instruction and the encoding vector of the original text is greater than a similarity threshold, feature extraction is performed on the original text to obtain a first structured text.
[0018] In one possible implementation, a third processing module is also included, for: Generate a verification request, which requests the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text; If the similarity between the encoding vector of the user's query statement and the encoding vector of the original text is greater than a similarity threshold, a response statement is generated based on text other than the original text. Reduce the search priority of the encoding vector of the original text.
[0019] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the electronic device performs the steps of the method as described in any of the first aspects above.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a computer, implements the method steps as described in any one of the first aspects above.
[0021] Fifthly, embodiments of this application provide a computer program product, including a computer program, which, when run, implements the method steps as described in any one of the first aspects above.
[0022] The beneficial effects of this application embodiment compared with the prior art are as follows: By extracting features from the original text, the first structured text after feature extraction includes the description object of the original text, the attributes of the description object, and the attribute values corresponding to the attributes. Thus, while removing information irrelevant to the description object from the original text, the first structured text can accurately and clearly express the semantics of the original text. Furthermore, if the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text; if the semantic distance is greater than the first threshold, it is determined that the semantics of the encoding vector of the original text does not match the semantics of the original text. Therefore, based on the principle that the semantics of the first structured text should match the semantics of the original text, and that the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text should be close, by comparing the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text with a first threshold, it is possible to accurately determine whether the semantics of the encoding vector of the original text is focused on information related to the described object, and to promptly detect situations where the encoding vector of the original text fails to accurately reflect the semantics of the original text, thus avoiding subsequent response or decision-making errors due to encoding errors in the original text. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application; Figure 2 This is a flowchart illustrating a semantic verification method for encoded vectors provided in an embodiment of this application; Figure 3 This is another flowchart illustrating a semantic verification method for encoded vectors provided in an embodiment of this application; Figure 4 A flowchart illustrating a method for correcting a second encoding model provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a semantic verification device for encoded vectors provided in an embodiment of this application. Detailed Implementation
[0025] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0026] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0027] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0028] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0029] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized.
[0030] The semantic verification method for encoded vectors provided in this application can be applied to application scenarios that require encoding text into vectors and performing responses or decisions based on those vectors, such as intelligent customer service systems, voice assistants, and personal assistant robots.
[0031] The semantic verification method for encoded vectors provided in this application can be applied to electronic devices such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, desktop computers, servers, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application does not impose any restrictions on the specific type of electronic device.
[0032] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1 As shown, the electronic device 10 of this embodiment includes: at least one processor 100 ( Figure 1 (Only one is shown in the diagram), memory 101, and computer program 102 stored in memory 101 and executable on at least one processor 100, wherein processor 100 executes computer program 102 to implement the steps in any of the above method embodiments.
[0033] The electronic device may include, but is not limited to, a processor 100 and a memory 101. Those skilled in the art will understand that... Figure 1 This is merely an example of electronic device 10 and does not constitute a limitation on electronic device 10. It may include more or fewer components than shown, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0034] The processor 100 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), 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.
[0035] In some embodiments, memory 101 may be an internal storage unit of electronic device 10, such as a hard disk or memory of electronic device 10. In other embodiments, memory 101 may be an external storage device of electronic device 10, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on electronic device 100. Furthermore, memory 101 may include both internal and external storage units of electronic device 10. Memory 101 is used to store operating system, application programs, bootloader, data, and other programs, such as program code of computer programs. Memory 101 may also be used to temporarily store data that has been output or will be output.
[0036] Please see Figure 2 , Figure 2 The flowchart illustrating the semantic verification method for encoded vectors provided in this application is shown as an example and not a limitation. The method includes the following steps: S201, Obtain the original text input by the user.
[0037] The original text input by the user refers to the natural language expression provided by the user through various input methods (such as voice, keyboard input, etc.). For example, in the scenario of a home service robot, when the user has a voice conversation with the robot, the robot collects the user's voice through a speech recognition module and converts it into text, thus obtaining the original text input by the user. For example, the original text could be "Baby is allergic to peanuts" or "Grandpa has a history of high blood pressure," etc.
[0038] S202, perform feature extraction on the original text to obtain the first structured text, which includes the description object of the original text, the attributes of the description object, and the attribute values corresponding to the attributes.
[0039] The described object can be a specific thing or task described in the original text. A specific thing refers to an objectively identifiable and referential entity, such as "baby" or "dog." A specific task refers to an action that needs to be performed or has been completed, such as "watering flowers," "changing the filter," or "feeding medicine." In the memory scenario of a home service robot, the described object can be a family member, such as a baby, grandfather, or pet. For example, if the original text is "Yesterday Dr. Wang came to our house and said my baby is allergic to chicken," then the corresponding described object is "baby."
[0040] The attributes of the described object can be some observable or recordable characteristic, state, or relationship category possessed by the described object. For example, if the described object is a baby, the corresponding attributes could be "allergen," "medication contraindications," "vaccination history," "age," etc. For instance, if the original text is "Yesterday Dr. Wang came to our house and said my baby is allergic to chicken," then the corresponding described object is "baby," and the attribute of the described object is "allergen."
[0041] In this context, the attribute value refers to the specific value or state of the attribute that describes the object. For example, if the attribute is "allergen," the corresponding attribute value could be "peanut," "pollen," or "penicillin." For instance, if the original text is "Yesterday Dr. Wang came to my house and said my baby is allergic to chicken," then the corresponding object is "baby," the attribute is "allergen," and the attribute value is "chicken."
[0042] It should be noted that the semantic verification method terminates if the first structured text does not contain at least one of the following: the description object, the description object's attributes, and the attribute values corresponding to the attributes. In one possible implementation, if the first structured text does not contain at least one of the following: the description object, the description object's attributes, and the attribute values corresponding to the attributes, then the original text cannot provide a basis for response or execution decisions, and the original text can be deleted.
[0043] In one possible implementation, features can be extracted from the original text based on a pre-trained language model to obtain the first structured text. Specifically, a set of unstructured texts and their corresponding structured texts are used to fine-tune the pre-trained language model, enabling the fine-tuned model to extract features from the original text and obtain the corresponding first structured text.
[0044] In another possible implementation, a large language model can be used to extract features from the original text to obtain the first structured text. Specifically, cue words for feature extraction can be pre-constructed, and the cue words and the original text can be input into the large language model to obtain the first structured text corresponding to the original text.
[0045] In one possible implementation, the user's query statement is received, and if the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than a similarity threshold, features are extracted from the original text to obtain the first structured text.
[0046] A query can be a natural language expression used by a user to retrieve information from a device during interaction. For example, in the context of a home service robot, a query could be "What can my baby eat?"
[0047] Here, the encoded vector of the original text is its vector representation in the semantic space. In one possible implementation, the original text is input into a first encoding model to obtain the encoded vector of the original text output by the first encoding model. In another possible implementation, the first encoding model can be a pre-trained language model based on the Transformer architecture. In yet another possible implementation, each received piece of original text is input into the first encoding model to obtain its encoded vector, which is then stored in a vector library for later direct use.
[0048] Here, the encoding vector of the query statement is the vector representation of the query statement in the semantic space. In one possible implementation, the query statement is input into a first encoding model to obtain the encoding vector of the query statement output by the first encoding model.
[0049] The similarity between the encoded vector of the query statement and the encoded vector of the original text is a numerical measure of how close their semantic spaces are. A higher similarity value indicates a closer semantic relationship between the query and original text. One possible implementation is to calculate the cosine distance between the two vectors; a smaller cosine distance indicates greater semantic similarity. Another possible implementation is to calculate the Euclidean distance between the two vectors; a smaller Euclidean distance indicates greater similarity.
[0050] The similarity threshold is a preset fixed boundary value used to determine whether the encoding vector of the query statement matches the semantics of the encoding vector of the original text. If the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than the similarity threshold, it is determined that the encoding vector of the query statement matches the semantics of the encoding vector of the original text, that is, the query statement matches the original text semantically, meaning the query statement matches the original text.
[0051] It should be noted that if the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than the similarity threshold, a response statement needs to be generated based on the original text. In order to ensure that the original text on which the response statement is based is accurate and reliable, the feature extraction and subsequent verification process of the original text is triggered to verify whether the semantics of the encoding vector of the original text matches the true semantics of the original text, thereby avoiding the generation of incorrect response statements due to errors in the encoding vector of the original text.
[0052] In another possible implementation, in response to receiving a target instruction sent by the user, features are extracted from the original text to obtain a first structured text, and the target instruction is used to instruct the semantics of the encoded vector of the original text to be verified.
[0053] For example, in the scenario of home service robots, the target instruction could be "verify whether the encoding vector corresponding to the previous text is correct" or "confirm the baby's allergy information".
[0054] It should be noted that after receiving the target instruction sent by the user, feature extraction is performed on the original text to obtain the first structured text. Then, the semantics of the encoding vectors of the original text and the corresponding first structured text are verified to see if they match. This can promptly detect situations where the semantics of the original text and the encoding vectors of the first structured text do not match, thereby avoiding erroneous responses caused by encoding errors when the original text is actually used to generate response statements.
[0055] In another possible implementation, in response to a task instruction, if the similarity between the encoding vector of the retrieval condition corresponding to the task instruction and the encoding vector of the original text is greater than a similarity threshold, feature extraction is performed on the original text to obtain the first structured text.
[0056] Task instructions can be natural language expressions issued by the user to the device, instructing it to perform a certain operation or complete a certain task. For example, in the scenario of a home service robot, the task instruction could be "prepare breakfast" or "remind grandpa to take his medicine." Alternatively, task instructions can also be tasks that the device autonomously generates based on preset strategies, scheduled tasks, environmental perception, or internal state judgment. For example, the device might autonomously trigger a "medication reminder" task at a fixed time each day based on a preset scheduled task, or it might autonomously trigger a "turn on the air conditioner" task when it detects that the current ambient temperature exceeds a preset temperature.
[0057] The search criteria are used to retrieve the text needed to perform the task from the stored text. In one possible implementation, the task instruction includes the search criteria. In another possible implementation, if the task instruction does not include search criteria, a preset mapping table can be consulted based on the task instruction to obtain the search criteria corresponding to the task instruction. The mapping table contains the search criteria for each task. For example, if the task instruction is "make lunch for the baby," the corresponding search criteria could be "find the baby's allergens" or "find the baby's favorite and least favorite foods," etc.
[0058] It should be noted that if the similarity between the encoding vector of the search criteria and the encoding vector of the original text is greater than a similarity threshold, it indicates that the original text must be used as a reference during the execution of the task instructions. To ensure that the original text on which the task instructions are based is accurate and reliable, a feature extraction and subsequent verification process for the original text is triggered to verify whether the semantics of the encoding vector of the original text matches the true semantics of the original text, thereby avoiding task execution errors due to incorrect encoding vectors of the original text.
[0059] S203, if the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold, determine that the semantics of the encoding vector of the original text matches the semantics of the original text.
[0060] In this embodiment, the encoded vector of the first structured text is its vector representation in the semantic space. In one possible implementation, the first structured text is input into a second encoding model, resulting in the encoded vector of the first structured text output by the second encoding model. It should be noted that the second encoding model and the first encoding model can be the same or different encoding models. If the first and second encoding models are different, their architectures can be the same or different. If their architectures are the same, the parameters of the first and second encoding models can be the same or different. This application does not impose any limitations on this.
[0061] It should be noted that the encoding vector of the original text has the same dimension as the encoding vector of the first structured text. For example, the dimension can be 256 dimensions or 384 dimensions.
[0062] Semantic distance is a numerical measure of the difference between the encoded vectors of the original text and the encoded vectors of the first structured text in the semantic space. A smaller semantic distance indicates that the semantics of the first structured text and the original text are closer; a larger semantic distance indicates a greater semantic difference between the two texts. In one possible implementation, the cosine distance between the encoded vectors of the original text and the first structured text can be calculated, indicating their semantic distance. A smaller cosine distance indicates that the two vectors are semantically similar in direction, and their similarity is higher. In another possible implementation, the Euclidean distance between the encoded vectors of the original text and the first structured text can also be calculated, indicating their semantic distance. A smaller Euclidean distance indicates that the two vectors are closer, and their similarity is higher.
[0063] Specifically, the semantic distance and a first threshold are used to determine whether the semantics of the encoded vector of the original text match the semantics of the original text. In one possible implementation, the first threshold can be a value preset based on experience.
[0064] It should be noted that the semantics of the encoded vector of the original text match the semantics of the original text. This can be understood as the encoded vector of the original text obtained after the first encoding process correctly reflecting the semantics of the original text, without any substantial semantic deviation. This original text can then be used for subsequent semantic retrieval and response tasks.
[0065] S204, if the semantic distance is greater than the first threshold, determine that the semantics of the encoding vector of the original text does not match the semantics of the original text.
[0066] In this case, the semantics of the encoded vector of the original text do not match the semantics of the original text. This can be understood as the encoded vector of the original text, obtained after the first encoding process, failing to accurately reflect the semantics of the original text, resulting in a substantial semantic bias. Therefore, this original text cannot be used for subsequent semantic retrieval and response tasks to avoid incorrect responses or inappropriate decisions due to encoding bias.
[0067] It should be noted that the original text may contain information unrelated to the described object, but users will focus more on information related to the described object during subsequent use. Feature extraction from the original text can refine the information related to the described object into a first structured text. This first structured text, while removing irrelevant information from the original text, can accurately and clearly express the semantics related to the described object. Therefore, if the encoding vector of the original text accurately reflects the semantics of the content related to the described object, the semantics of the encoding vector of the first structured text matches the semantics of the encoding vector of the original text. However, due to textual differences between the first structured text and the original text, there is a certain semantic distance between their encoding vectors. If the encoding vector of the original text accurately reflects the true semantics of the original text, the semantic distance should be within a reasonable range, i.e., less than or equal to a first threshold; if the semantics of the encoding vector of the original text deviates from the semantics of the original text, the semantic distance will exceed a reasonable range, i.e., greater than the first threshold. Therefore, by comparing the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text with the first threshold, it can be determined whether the semantics of the encoding vector of the original text matches the semantics of the original text.
[0068] In this embodiment, feature extraction is performed on the original text, resulting in a first structured text that includes the object being described, the attributes of the object, and the corresponding attribute values. This allows the first structured text to accurately and clearly express the semantics of the original text while removing information irrelevant to the object being described. Furthermore, if the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold, the semantics of the encoding vector of the original text is determined to match the semantics of the original text; if the semantic distance is greater than the first threshold, the semantics of the encoding vector of the original text is determined to not match the semantics of the original text. Therefore, based on the principle that the semantics of the first structured text should match the semantics of the original text, and that the semantic distance between the encoding vectors of the original text and the first structured text should be close, comparing the semantic distance between the encoding vectors of the original text and the first structured text with the first threshold accurately determines whether the semantics of the encoding vector of the original text focuses on information related to the object being described. This allows for timely detection of situations where the encoding vector of the original text fails to accurately reflect the semantics of the original text, avoiding subsequent response or decision-making errors due to incorrect encoding of the original text.
[0069] In the process of interacting with users, the raw text accumulated by home service robots typically comes from daily conversations with family members. These conversations often contain rich descriptions of scenes, time adverbs, and emotional expressions—information irrelevant to the described object. However, users, in actual use, focus on information closely related to the described object. Therefore, this application extracts features from the raw text, refining the information related to the described object into a first structured text. This first structured text, while removing irrelevant information from the raw text, accurately and clearly expresses the semantics of the raw text. Furthermore, comparing the semantic distance between the encoding vector of the raw text and the encoding vector of the first structured text with a first threshold determines whether the encoding vector of the raw text focuses on the semantics of information related to the described object. This effectively ensures that the encoding vector of the raw text used by the home service robot in subsequent semantic retrieval accurately reflects the semantics related to the described object, avoiding incorrect decisions by the home service robot due to encoding errors in the raw text, and ensuring the safety and reliability of the services provided by the home service robot to users.
[0070] Please see Figure 3 , Figure 3 This is a flowchart illustrating a semantic verification method for encoded vectors provided in an embodiment of this application. The method further includes: S301, if the semantic distance is less than the second threshold and the first structured text also includes other text besides the description object, attributes and the attribute values corresponding to the attributes, remove the other text in the first structured text to obtain a new first structured text, and the second threshold is less than the first threshold.
[0071] Specifically, the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text are determined by comparing the relationship between the semantic distance and the second threshold.
[0072] The "other text" refers to text in the first structured text that is unrelated to the described object, excluding the object description field, attribute field, and attribute value field. For example, the other text could be contextual descriptions such as time adverbs like "afternoon" or place adverbs like "at the hospital" contained in the original text.
[0073] It should be noted that when the first structured text contains other text, it means that the feature extraction process has failed to sufficiently remove information unrelated to the described object from the original text, resulting in a small difference in content between the first structured text and the original text. Consequently, the encoding vectors of the original text and the first structured text are too similar. This application verifies the semantics of the encoding vector of the original text based on the semantic difference between the first structured text and the original text. If the first structured text contains other text and has a small difference in content from the original text, it may lead to inaccurate verification results regarding the described object in the semantics of the encoding vector of the original text. Therefore, this application removes other text from the first structured text when the semantic distance is less than the second threshold and the first structured text includes text other than the described object, attributes, and their corresponding attribute values, to obtain a new first structured text. This ensures that there is a moderate and measurable difference between the first structured text and the original text, guaranteeing the accuracy and reliability of semantic verification.
[0074] S302, if the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than a second threshold, determine that the semantics of the encoding vector of the original text matches the semantics of the original text.
[0075] In one possible implementation, if the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than a first threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is greater than or equal to the first threshold, it is determined that the semantics of the encoding vector of the original text does not match the semantics of the original text.
[0076] In one example, if the semantic distance is less than a second threshold and the first structured text does not include any text other than the described object, attribute, and the attribute value corresponding to the attribute, the semantics of the encoded vector of the original text is determined to match the semantics of the original text.
[0077] It should be noted that after removing other text from the first structured text, the resulting new first structured text retains only three core fields: the object being described, the attribute, and the attribute value. If, at this point, the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is still less than the second threshold, it indicates that even though the first structured text no longer contains any redundant information, its encoding difference from the original text is still relatively small. This situation may be due to the original text itself not containing much information unrelated to the object being described. Therefore, it is necessary to ensure that the semantics of the encoding vector of the original text match the semantics of the original text.
[0078] In one possible implementation, the first threshold and the second threshold can be determined through the following steps: Step 1: Obtain multiple sample texts and the encoding vector of each sample text. The semantics of the sample texts are matched with the semantics of the encoding vectors of the sample texts.
[0079] The encoding vector of the sample text can be a vector representation of the sample text in the semantic space. In one possible implementation, the sample text is input into the first encoding model, and the encoding vector of the sample text output by the first encoding model is obtained.
[0080] The matching of the semantics of the sample text with the semantics of its encoding vector can be confirmed by the user. In one possible implementation, the sample text can be input into a first encoding model to obtain the encoding vector of the sample text. Then, if the user's sample query statement matches the sample text, a sample response statement corresponding to the sample query statement is generated based on the sample text. If the user confirms that the sample response statement is correct, then the semantics of the sample text is determined to match the semantics of the corresponding encoding vector of the sample text.
[0081] Step 2: Extract features from the sample text to obtain the second structured text. The second structured text includes the sample description object of the sample text, the sample attributes of the sample description object, and the sample attribute values corresponding to the sample attributes.
[0082] It should be noted that the specific implementation method of step 2 can be found in the detailed description in S202, and will not be elaborated here.
[0083] Step 3: Based on the semantic distance between the encoding vector of the sample text and the encoding vector of the second structured text, determine the first threshold and the second threshold, wherein the first threshold is greater than the first mean of the semantic distances of the multiple sample texts and less than the maximum value of the semantic distances of the multiple sample texts, and the second threshold is greater than the minimum value of the semantic distances of the multiple sample texts and less than the first mean.
[0084] Here, the encoding vector of the second structured text is the vector representation of the second structured text of the sample text in the semantic space. In one possible implementation, the second structured text of the sample text is input into the second encoding model to obtain the encoding vector of the second structured text of the sample text output by the second encoding model.
[0085] It should be noted that when the semantics of multiple sample texts match the semantics of their corresponding encoded vectors, the semantic distances of most samples are concentrated within a certain range around the mean, with only a minority of samples falling outside this range. Therefore, determining a first threshold and a second threshold based on the semantic distance of the sample texts ensures that the range between the first and second thresholds covers the main distribution interval near the first mean, and that sample texts outside this range constitute only a minority. This allows for effective differentiation of whether the semantics of the encoded vector of the original text matches the semantics of the original text, reducing the probability of misjudgment and thus improving the accuracy of semantic verification.
[0086] In one possible implementation, a Gaussian distribution model can also be used to model the semantic distance of the sample text, using the first mean. The central location reflecting normal semantic distance, expressed as the first standard deviation. Reflecting its degree of dispersion, and through the first confidence coefficient Control the width of the normal focusing range of semantic distance; the upper limit of the normal focusing range is the first threshold. The lower limit is the second threshold. For example, when the semantic distance of 95% of the sample texts lies between the first threshold and the second threshold, The value is 2.0; when the semantic distance of 87% of the sample texts is between the first threshold and the second threshold, The value is set to 1.5. Therefore, by determining the first and second thresholds through statistical modeling, the semantic distance characteristics of different application scenarios can be adapted to avoid the problem of high false alarm rate caused by using a fixed threshold, thus improving the accuracy and robustness of the semantic verification method.
[0087] The first mean is the arithmetic mean of the semantic distances of multiple sample texts. This first mean reflects the typical semantic distance when the semantics of the sample text matches the semantics of the second structured text.
[0088] The first standard deviation measures the dispersion of semantic distance when the semantics of the sample text matches the semantics of the corresponding second structured text. The smaller the first standard deviation, the more concentrated and stable the semantic distance of the sample text is; the larger the first standard deviation, the more dispersed and uncertain the semantic distance of the sample text is.
[0089] The first confidence coefficient controls the range between the second threshold and the first threshold. A larger first confidence coefficient results in a wider range between the first and second thresholds, and a higher tolerance for semantic verification errors. Conversely, a smaller first confidence coefficient results in a narrower range between the first and second thresholds, and a lower tolerance for semantic verification errors.
[0090] It should be noted that as the semantic verification method for encoded vectors continues to run, more and more encoded vectors of the original text are verified and confirmed to be semantically matched with the corresponding encoded vectors of the original text. These semantically matched original texts provide a richer and more representative data foundation for updating the first and second thresholds. Therefore, after determining that the semantics of the encoded vectors of the original text match the semantics of the original text, a new first threshold and a new second threshold are determined based on the semantic distances of multiple texts, including multiple sample texts and the original text. The new first threshold is greater than the second mean of the semantic distances of the multiple texts and less than the maximum value among the semantic distances of the multiple texts. The second threshold is greater than the minimum value among the semantic distances of the multiple texts and less than the second mean. Thus, recalculating the new first and second thresholds based on the original texts containing sample texts and newly accumulated semantic matches can more accurately reflect the distribution characteristics of semantic distances in the current application scenario, thereby reducing statistical bias caused by insufficient sample size and further improving the accuracy and robustness of semantic verification.
[0091] In one possible implementation, when the number of original texts whose semantics match the encoding vector of the original text reaches a preset number (e.g., 20, 40, etc.), a new first threshold and a new second threshold can be determined based on the semantic distance between the multiple texts. The multiple texts include multiple sample texts and the preset number of texts whose semantics match the encoding vector of the original text.
[0092] In one possible implementation, a Gaussian distribution model can be used to model the semantic distance of the text, using the second mean. The central location reflecting normal semantic distance, expressed as the second standard deviation. Reflecting its degree of dispersion, and through the second confidence coefficient Control the width of the normal focusing range of semantic distance; the upper limit of the normal focusing range is the first threshold. The lower limit is the second threshold. .
[0093] In one possible implementation, the second confidence coefficient can be the difference between the first confidence coefficient and a preset value, where the preset value is a positive number. The preset value controls the reduction in the confidence coefficient used each time the first and second thresholds are redefined, compared to the previous confidence coefficient used to determine the first and second thresholds. For example, the preset value could be 0.02, meaning the confidence coefficient used each time the first and second thresholds are redefined is 0.02 less than the previous confidence coefficient used to determine the first and second thresholds. Thus, by controlling the confidence coefficient to gradually decrease through a preset value, a smooth transition is achieved where the normal focusing range gradually narrows as the method matures. This allows for greater tolerance of uncertainty in the early stages of method operation and higher sensitivity for accurate verification in the later stages, balancing initial stability with later accuracy.
[0094] The specific implementation methods for determining the new first threshold and the new second threshold can be found in the detailed description of determining the first threshold and the second threshold, which will not be repeated here.
[0095] In this embodiment, when the semantic distance is less than a second threshold and the first structured text includes text other than the described object, attributes, and their corresponding attribute values, the other text in the first structured text is removed to obtain a new first structured text. If the second threshold is less than the first threshold, a second encoding process is performed on the new first structured text to obtain its encoding vector. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than the second threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text. Therefore, by removing other text from the first structured text and performing encoding vector verification again based on the new first structured text, the error of the encoding vector of the original text being misjudged as a match due to insufficient feature extraction is avoided, further improving the accuracy of encoding vector verification.
[0096] In one possible implementation, the encoding vector of the original text is the vector output after encoding the original text through a first encoding model, and the encoding vector of the first structured text is the vector output after encoding the first structured text through a second encoding model.
[0097] In this model, the architecture of the first encoding model is identical to that of the second encoding model, and the parameters of the first encoding model are the same as those of the second encoding model at the initial time. The identical structure of the first and second encoding models means that they employ the same neural network architecture, including the same number of layers, the same number of attention heads, the same hidden layer dimension, and the same activation function type. This identical architecture ensures that the first and second encoding models have the same representational power and the same output vector dimension, facilitating semantic distance calculation.
[0098] The statement that the parameters of the first and second coding models are identical at the initial moment means that when the first and second coding models are first deployed on the electronic device, the parameters of the second coding model are copied from the first coding model, and both have exactly the same weight values. This means that they have completely consistent semantic mapping capabilities at the initial moment. This ensures that in the initial stage of system operation, the encoding results of the first and second coding models for the same or similar text are consistent, and the statistical distribution baseline of semantic distance can be established on a stable and comparable basis.
[0099] However, after the aforementioned semantic verification method for encoded vectors has been running on electronic devices for a period of time, the second encoding model may be affected by factors such as accumulated errors, changes in environmental data distribution, or parameter drift during operation. This may lead to situations where the encoded vector of the original text, which actually matches semantically, is judged as mismatched with the original text. In such cases, the second encoding model can be modified to reduce such erroneous judgments and improve the accuracy of vector semantic verification.
[0100] It should be noted that during operation, the encoding model may be affected by factors such as accumulated errors, changes in environmental data distribution, or parameter drift. This may lead to situations where the encoded vector of the semantically matching original text is judged as a mismatch. In such cases, the encoding model needs to be corrected to improve the accuracy of vector semantic verification. However, the first encoding model is used to encode the original text, and its output encoded vector is the basis for subsequent semantic retrieval and task decision-making. If the first encoding model is corrected, its encoding space will shift, requiring all stored encoded vectors of the original text to be recalculated. Without recalculation, the original text may not be correctly retrieved and recalled, affecting the continuity and stability of the service. Therefore, this application only corrects the second encoding model, keeping the parameters of the first encoding model frozen throughout the process. This improves the accuracy of semantic verification while ensuring that stored encoded vectors do not need to be recalculated, thus ensuring the stable operation of the system.
[0101] Figure 4This is a flowchart illustrating a method for correcting a second encoding model provided in an embodiment of this application. Figure 4 As shown, the method also includes: S401, input the first structured text of the first original text from multiple original texts into the second encoding model to obtain the predicted encoding vector. The semantic distance between the encoding vector of the first original text and the encoding vector of the corresponding first structured text is greater than a first threshold, and the semantics of the first original text has been verified by the user to match the semantics of the encoding vector of the first original text.
[0102] In one possible implementation, if the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is greater than a first threshold, the user is requested to verify the semantics of the original text against the semantics of its encoding vector. Specifically, if the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is greater than the first threshold, a verification request is generated. This request asks the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text. If the user determines that the semantics of the encoding vector of the original text matches the semantics of the original text, the first original text is obtained.
[0103] The predicted encoding vector is the encoding vector output by the current second encoding model after encoding the first structured text of the first original text.
[0104] S402, determine the first similarity between the predicted encoding vector and the encoding vector of the first original text, and the second similarity between the predicted encoding vector and the encoding vector of the second original text among the multiple original texts.
[0105] Here, the first similarity is the similarity value between the predicted encoding vector and the encoding vector of the first original text. The first similarity measures the closeness between the encoding result of the second encoding model on the first structured text and the encoding result of the first encoding model on the first original text. The higher the first similarity, the closer the predicted encoding vector is to the encoding vector of the first original text. In one possible implementation, the cosine similarity between the predicted encoding vector and the encoding vector of the first original text can be calculated, and the first similarity is indicated by the cosine distance between them. The smaller the cosine distance, the closer the semantics of the two vectors are, and the higher the first similarity. Alternatively, the Euclidean distance between the predicted encoding vector and the encoding vector of the first original text can also be calculated, and the first similarity is indicated by the Euclidean distance. The smaller the Euclidean distance, the closer the two vectors are, and the higher the first similarity.
[0106] The second similarity is the similarity value between the predicted encoding vector and the encoding vector of the second original text. The second similarity measures the closeness between the encoding result of the second encoding model on the first structured text and the encoding result of the first encoding model on the second original text. The higher the second similarity, the closer the predicted encoding vector is to the encoding vector of the second original text. In one possible implementation, the cosine similarity between the predicted encoding vector and the encoding vector of the second original text can be calculated, and the second similarity can be indicated by the cosine distance between them. Alternatively, the Euclidean distance between the predicted encoding vector and the encoding vector of the second original text can also be calculated, and the second similarity can be indicated by the Euclidean distance.
[0107] S403, Input the first similarity and the second similarity into the contrastive learning loss function to determine the loss value.
[0108] In this context, the encoding vector of the first original text and the corresponding first structured text are positive sample pairs, the first similarity is the similarity between the positive sample pairs, the encoding vectors of the first structured text corresponding to the first original text and the original text corresponding to the second original text are negative sample pairs, and the second similarity is the similarity between the negative sample pairs.
[0109] The contrastive learning loss function is used to train the second encoding model to distinguish between positive and negative sample pairs. Its purpose is to narrow the representational distance between positive sample pairs and widen the representational distance between negative sample pairs. In one possible implementation, the contrastive learning loss function can be the Information Noise-Contrastive Estimation (InfoNCE) loss function. In another possible implementation, the contrastive learning loss function can also be the triplet loss function.
[0110] The loss value is a scalar value calculated using the contrastive learning loss function, used to quantify the quality of the current second encoding model parameters. The smaller the loss value, the better the second encoding model parameters are, and the more closely the second encoding model's encoding result for the first structured text matches the requirement that the encoded vector of the original text corresponding to the positive sample is close to the encoded vector of the original text corresponding to the negative sample, and far away from the encoded vector of the original text corresponding to the negative sample.
[0111] S404, based on the loss value, modifies the second encoding model.
[0112] The modification of the second coding model involves calculating the gradient using the loss value through backpropagation, and updating the parameters of the second coding model based on the gradient to reduce the loss value. The goal of the modification is to make the predicted coding vector output by the second coding model closer to the coding vector of the original text in positive sample pairs, while moving away from the coding vector of the original text in negative sample pairs, thereby continuously optimizing the coding capability of the second coding model.
[0113] In one possible implementation, only the parameters of the last N layers of the second encoding model can be updated, while the parameters of other layers remain frozen. For example, if the second encoding model is a Transformer architecture, only the parameters of the last 3 self-attention layers can be updated, while the parameters of layers 1 to N-1 remain frozen. This partial fine-tuning strategy can reduce the number of parameters and computational overhead, while avoiding the risk of catastrophic forgetting.
[0114] In one possible implementation, if the device is a home service robot, the second coding model can be corrected during the robot's idle time (e.g., from 2 a.m. to 4 a.m.).
[0115] In this embodiment, after the semantic verification method has been running for a period of time, the original text and its encoding vector that the semantic verification method judges as mismatched but the user verifies as matched can be used as training samples to correct the second encoding model. This can reduce the number of cases where the encoding vector of the original text that actually matches semantically is judged as mismatched with the original text, thereby improving the accuracy of semantic verification of encoding vectors.
[0116] In one possible implementation, after determining that the semantics of the encoding vector of the original text does not match the semantics of the original text, a verification request can be generated to ask the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text.
[0117] In the specific implementation, after generating the verification request, the user can be prompted via voice broadcast or message push to verify whether the semantics of the encoded vector of the original text matches the semantics of the original text. For example, based on the original text, the user inputs a verification query statement corresponding to the original text, where the similarity between the verification query statement and the original text is greater than a similarity threshold. The user then determines whether the verification response statement corresponding to the output verification query statement is correct. If the user determines the verification response statement is correct, it is determined that the semantics of the original text matches the semantics of the corresponding encoded vector of the original text. If the user determines the verification response statement is incorrect, it is determined that the semantics of the original text does not match the semantics of the corresponding encoded vector of the original text. It should be noted that since the similarity between the verification query statement and the original text is greater than the similarity threshold, the verification response statement is generated based on the original text. Therefore, by having the user determine whether the verification response statement is correct, it is possible to verify whether the semantics of the encoded vector of the original text matches the semantics of the original text.
[0118] As an example, after determining that the semantics of the encoding vector of the original text does not match the semantics of the original text, the original text can be marked as pending user verification, and a verification request can be generated to ask the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text.
[0119] Marking the original text as pending user verification means setting its status field in the database to "pending verification". Original text marked as pending verification will have a lower probability of being hit in subsequent semantic searches until the user completes the verification and updates its status.
[0120] In one possible implementation, the original text to be verified by the user can be added to a separate verification queue. Verification requests are sent at a preset rhythm to remind the user to verify whether the semantics of the encoded vector of the original text matches the semantics of the original text. This can avoid frequently disturbing the user while ensuring that the memory to be verified can be processed in a timely manner.
[0121] Therefore, by generating a verification request after determining that the semantics of the original text does not match the semantics of the encoding vector of the original text, the user can confirm whether the semantics of the encoding vector of the original text matches the semantics of the original text. This can accurately determine whether the semantics of the original text matches the semantics of the encoding vector of the original text, avoiding the situation where the encoding vector of the original text, which matches the semantics, is judged as mismatched with the original text, thus preventing the generation of an accurate response statement based on the encoding vector of the correctly encoded original text.
[0122] In one possible implementation, after determining that the semantics of the encoding vector of the original text do not match the semantics of the original text, a response statement to the query statement can be generated based on other texts besides the original text if the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than a similarity threshold.
[0123] The encoding vector of the query statement is the encoding vector corresponding to the user's query statement.
[0124] Among them, the similarity between the encoding vectors of other texts and the encoding vectors of the query statement is greater than the similarity threshold.
[0125] It's important to note that if the similarity between the encoded vector of the query statement and the encoded vector of the original text exceeds a similarity threshold, it indicates that the query statement semantically matches the original text, meaning a response statement is prepared to be generated based on that original text. However, at this point, the semantics of the encoded vector of the original text has been determined to be a semantic mismatch, meaning the encoded vector of the original text fails to accurately reflect its true meaning. Generating a response statement based solely on the original text could lead to incorrect information being transmitted to the user. Therefore, responses to queries should not be generated based on the original text. Instead, responses should be generated based on text other than the original text. This avoids inappropriate responses due to encoding errors in the original text and ensures the security and reliability of subsequent interactions.
[0126] In one possible implementation, after determining that the semantics of the encoding vector of the original text do not match the semantics of the original text, the search priority of the encoding vector of the original text can be reduced.
[0127] Lowering the search priority of the original text's encoding vector can be understood as follows: the search priority is used to indicate the ranking position of the original text's encoding vector in the semantic retrieval results. Lowering the search priority of the original text's encoding vector means lowering the ranking position of the original text's encoding vector in the semantic retrieval results, thereby reducing the risk that incorrect original text encoding vectors will be hit and used by user queries.
[0128] It should be understood that the sequence number of each step in the above embodiments does not imply 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 embodiments of this application.
[0129] The semantic verification method corresponding to the encoded vector in the above embodiment, Figure 5 A schematic diagram of the structure of the semantic verification device for encoded vectors provided in the embodiments of this application is shown. For ease of explanation, only the parts related to the embodiments of this application are shown.
[0130] Reference Figure 5 The device includes: The acquisition module 501 is used to acquire the raw text input by the user; The extraction module 502 is used to extract features from the original text to obtain the first structured text. The first structured text includes the description object of the original text, the attributes of the description object, and the attribute values corresponding to the attributes. The determination module 503 is used to determine that the semantics of the encoding vector of the original text matches the semantics of the original text when the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold. The determination module 503 is also used to determine that the semantics of the encoding vector of the original text does not match the semantics of the original text when the semantic distance is greater than a first threshold.
[0131] In one possible implementation, a first processing module is also included, for: If the semantic distance is less than the second threshold and the first structured text also includes other text besides the description object, attributes and the attribute values corresponding to the attributes, remove the other text in the first structured text to obtain a new first structured text, and the second threshold is less than the first threshold. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than a second threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text.
[0132] In one possible implementation, a second processing module is also included, for: Obtain multiple sample texts and the encoding vector of each sample text, and match the semantics of the sample texts with the semantics of their encoding vectors; Feature extraction is performed on each sample text to obtain the second structured text. The second structured text includes the sample description object of the sample text, the sample attributes of the sample description object, and the sample attribute values corresponding to the sample attributes. Based on the semantic distance between the encoding vector of the sample text and the encoding vector of the second structured text, a first threshold and a second threshold are determined. The first threshold is greater than the first mean of the semantic distances of the multiple sample texts and less than the maximum value of the semantic distances of the multiple sample texts. The second threshold is greater than the minimum value of the semantic distances of the multiple sample texts and less than the first mean.
[0133] In one possible implementation, the second processing module is further used for: Based on the semantic distances of multiple texts, a new first threshold and a new second threshold are determined. The multiple texts include multiple sample texts and the original text. The new first threshold is greater than the second mean of the semantic distances of the multiple texts and less than the maximum value of the semantic distances of the multiple texts. The second threshold is greater than the minimum value of the semantic distances of the multiple texts and less than the second mean.
[0134] In one possible implementation, the encoded vector of the original text is the vector output after encoding the original text using a first encoding model, and the encoded vector of the first structured text is the vector output after encoding the first structured text using a second encoding model. The device further includes a correction module for: The first structured text of the first original text from multiple original texts is input into the second encoding model to obtain the predicted encoding vector. The semantic distance between the encoding vector of the first original text and the encoding vector of the corresponding first structured text is greater than the first threshold, and the semantics of the first original text has been verified by the user to match the semantics of the encoding vector of the first original text. Determine a first similarity between the predicted encoding vector and the encoding vector of the first original text, and a second similarity between the predicted encoding vector and the encoding vector of the second original text among a plurality of original texts; The first and second similarity scores are input into the contrastive learning loss function to determine the loss value; The second encoding model is modified based on the loss value.
[0135] In one possible implementation, the extraction module 502 is used for: Receive the user's query statement. If the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than the similarity threshold, extract features from the original text to obtain the first structured text. In response to receiving a target instruction sent by the user, feature extraction is performed on the original text to obtain the first structured text. The target instruction is used to instruct the semantics of the encoded vector of the original text to be verified. In response to the task instruction, if the similarity between the encoding vector of the retrieval condition corresponding to the task instruction and the encoding vector of the original text is greater than the similarity threshold, feature extraction is performed on the original text to obtain the first structured text.
[0136] In one possible implementation, a third processing module is also included, for: Generate a verification request, which is used to request the user to verify whether the semantics of the encoded vector of the original text matches the semantics of the original text. If the similarity between the encoding vector of the user's query statement and the encoding vector of the original text is greater than the similarity threshold, a response statement is generated based on text other than the original text. Reduce the search priority of the encoding vector of the original text.
[0137] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0138] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to 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. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0139] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.
[0140] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps described in the above-described method embodiments.
[0141] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0142] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0143] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0144] In the embodiments provided in this application, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings or direct couplings or communication connections may be through some interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0145] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0146] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A semantic verification method for encoded vectors, characterized in that, The method includes: Get the raw text input by the user; Feature extraction is performed on the original text to obtain a first structured text, which includes the description object of the original text, the attributes of the description object, and the attribute values corresponding to the attributes. If the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text. If the semantic distance is greater than the first threshold, it is determined that the semantics of the encoding vector of the original text does not match the semantics of the original text.
2. The method according to claim 1, characterized in that, After performing feature extraction on the original text to obtain the first structured text, the method further includes: If the semantic distance is less than the second threshold and the first structured text includes other text besides the described object, the attribute, and the attribute value corresponding to the attribute, the other text in the first structured text is removed to obtain a new first structured text, and the second threshold is less than the first threshold. If the semantic distance between the encoding vector of the original text and the encoding vector of the new first structured text is less than the second threshold, it is determined that the semantics of the encoding vector of the original text matches the semantics of the original text.
3. The method according to claim 2, characterized in that, The method further includes: Obtain multiple sample texts and the encoding vector of each sample text, wherein the semantics of the sample texts are matched with the semantics of the encoding vectors of the sample texts; Feature extraction is performed on each of the sample texts to obtain a second structured text, which includes a sample description object of the sample text, sample attributes of the sample description object, and sample attribute values corresponding to the sample attributes. Based on the semantic distance between the encoding vector of the sample text and the encoding vector of the second structured text, the first threshold and the second threshold are determined, wherein the first threshold is greater than the first mean of the semantic distances of the plurality of sample texts and less than the maximum value among the semantic distances of the plurality of sample texts, and the second threshold is greater than the minimum value among the semantic distances of the plurality of sample texts and less than the first mean.
4. The method according to claim 3, characterized in that, After determining that the semantics of the encoded vector of the original text matches the semantics of the original text, the method further includes: Based on the semantic distances corresponding to multiple texts, a new first threshold and a new second threshold are determined. The multiple texts include multiple sample texts and the original text. The new first threshold is greater than the second mean of the semantic distances of the multiple texts and less than the maximum value of the semantic distances of the multiple texts. The second threshold is greater than the minimum value of the semantic distances of the multiple texts and less than the second mean.
5. The method according to claim 1, characterized in that, The encoded vector of the original text is a vector output after encoding the original text using a first encoding model, and the encoded vector of the first structured text is a vector output after encoding the first structured text using a second encoding model. The method further includes: The first structured text of the first original text from multiple original texts is input into the second encoding model to obtain a predicted encoding vector. The semantic distance between the encoding vector of the first original text and the encoding vector of the corresponding first structured text is greater than the first threshold, and the semantics of the first original text and the encoding vector of the first original text have been verified by the user to match. Determine a first similarity between the predicted encoding vector and the encoding vector of the first original text, and a second similarity between the predicted encoding vector and the encoding vector of the second original text among the plurality of original texts; The first similarity and the second similarity are input into the contrastive learning loss function to determine the loss value; Based on the loss value, the second encoding model is modified.
6. The method according to claim 1, characterized in that, The feature extraction of the original text to obtain the first structured text includes any one of the following: Receive a user's query statement. If the similarity between the encoding vector of the query statement and the encoding vector of the original text is greater than a similarity threshold, perform feature extraction on the original text to obtain a first structured text. In response to receiving a target instruction sent by a user, feature extraction is performed on the original text to obtain a first structured text, wherein the target instruction is used to instruct the semantics of the encoding vector of the original text to be verified; In response to a task instruction, if the similarity between the encoding vector of the retrieval condition corresponding to the task instruction and the encoding vector of the original text is greater than a similarity threshold, feature extraction is performed on the original text to obtain a first structured text.
7. The method according to any one of claims 1-6, characterized in that, After determining that the semantics of the encoded vector of the original text does not match the semantics of the original text, the method further includes at least one of the following: Generate a verification request, which requests the user to verify whether the semantics of the encoding vector of the original text matches the semantics of the original text; If the similarity between the encoding vector of the user's query statement and the encoding vector of the original text is greater than a similarity threshold, a response statement is generated based on text other than the original text. Reduce the search priority of the encoding vector of the original text.
8. A semantic verification device for encoded vectors, characterized in that, include: The acquisition module is used to acquire the raw text input by the user; An extraction module is used to extract features from the original text to obtain a first structured text, wherein the first structured text includes a description object of the original text, attributes of the description object, and attribute values corresponding to the attributes. The determining module is configured to determine that the semantics of the encoding vector of the original text matches the semantics of the original text when the semantic distance between the encoding vector of the original text and the encoding vector of the first structured text is less than or equal to a first threshold. The determining module is further configured to determine, when the semantic distance is greater than the first threshold, that the semantics of the encoding vector of the original text does not match the semantics of the original text.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it causes the electronic device to perform the steps of the method as described in any one of claims 1 to 7.
10. A computer program product, characterized in that, Includes a computer program, which, when executed, implements the steps of the method as described in any one of claims 1 to 7.
