Time extraction method, device and equipment and computer readable storage medium
By combining a large language model with prompt word templates, the problem of low generalization caused by the diversity of time expressions in natural language is solved, and a method for extracting explicit time information from natural language is realized, which is suitable for applications such as event time series analysis, information retrieval and intelligent question answering.
Patent Information
- Application Number
- CN202511297740.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2025-12-05
AI Technical Summary
Existing rule-based matching methods cannot fully cover the diverse time expressions in natural language, resulting in low generalization of time extraction and difficulty in identifying time units, figurative times, and the same expression referring to different times in specific domains.
By combining a large language model with prompt word templates, and by designing first and second prompt messages based on the input time and the filling position of the natural language input, the large language model is guided to extract and adjust the time description information, ensuring the accuracy and generalization of the output time.
It enables the extraction of explicit time information from natural language, improves the generalization of time extraction, and is applicable to application scenarios such as event time series analysis, information retrieval, and intelligent question answering.
Smart Images

Figure CN121071121A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of artificial intelligence, and particularly relates to a time extraction method and device, equipment and a computer readable storage medium. BACKGROUND
[0002] As an important semantic element in text content, time information is of great significance for event timing analysis, information retrieval, intelligent question answering and many other application scenarios. In actual situations, due to differences in fields, language diversity and other reasons, the description of time information is often varied.
[0003] At present, time information is usually extracted from text based on rule matching. However, the position and manner of time-related expressions in natural language are not fixed, and the rule-based matching method cannot cover it. That is, the rule-based matching method can only extract the time information involved in the rules, but cannot extract the time information not involved in the rules, thereby reducing the generalization of time extraction. SUMMARY
[0004] The embodiments of the application provide a time extraction method, device, equipment, computer readable storage medium and computer program product, which can ensure that the explicit time information is extracted from the natural language input, thereby improving the generalization of time extraction.
[0005] In a first aspect, the embodiments of the application provide a time extraction method, which comprises:
[0006] obtaining a natural language input of a user, an input time of the natural language input, and a prompt word template, wherein the prompt word template comprises first prompt information for instructing a large language model to extract time information from the natural language input, a first filling position of the input time, a second filling position of the natural language input, and second prompt information for adjusting an output time according to the input time, wherein the input time is used to provide a real reference time for the large language model;
[0007] adding the input time to the first filling position and adding the natural language input to the second filling position to obtain a target prompt word;
[0008] extracting time description information from the natural language input based on the first prompt information in the target prompt word through the large language model;
[0009] adjusting the time description information by using the input time based on the second prompt information in the target prompt word through the large language model to obtain a first output time.
[0010] In a possible implementation, the adjusting, by the large language model, the time description information based on the second prompt information in the target prompt word, and using the input time to obtain a first output time, comprises:
[0011] In a case where the time description information is not extracted from the natural language input, the input time is determined as the first output time by the large language model.
[0012] In a possible implementation, after the first output time is obtained, the method further comprises:
[0013] performing multi-line pattern matching on the first output time to obtain a structured string;
[0014] converting the structured string into a time object to obtain a program-readable time.
[0015] In a possible implementation, the first output time is in a form of a first time interval, and the prompt word template further comprises a time type corresponding to the first time interval, the time type comprising a time point and a time range.
[0016] The converting the structured string into a time object to obtain a program-readable time comprises:
[0017] In a case where the time requirement of the program-readable time is a time point, determining a first target time point in the structured string based on the time type corresponding to the first time interval.
[0018] converting the first target time point into a time object to obtain a program-readable time.
[0019] In a possible implementation, the structured string comprises a first time point and a second time point, the first time point being a lower limit of the first time interval, and the second time point being an upper limit of the first time interval.
[0020] The determining, in a case where the time requirement of the program-readable time is a time point, a first target time point in the structured string based on the time type corresponding to the first time interval, comprises:
[0021] In a case where the time requirement of the program-readable time is a time point and the time type corresponding to the first time interval is a time point, determining any one of the first time point and the second time point as the first target time point.
[0022] When the program's readable time requirement is a specific point in time, and the time type corresponding to the first time interval is a time range, the second point in time is determined as the first target point in time.
[0023] In one possible implementation, before performing multi-line pattern matching on the first output time to obtain a structured string, the method further includes:
[0024] The authenticity of the first output time is verified, and the verification result is obtained;
[0025] If the verification result indicates that the first output time is not real, the first output time is converted into a real second output time according to a preset rule.
[0026] The process of performing multi-line pattern matching on the first output time to obtain a structured string includes:
[0027] Perform multi-line pattern matching on the second output time to obtain a structured string.
[0028] Secondly, embodiments of this application provide a time extraction device, the device comprising:
[0029] The acquisition module is used to acquire the user's natural language input, the input time of the natural language input, and the prompt word template. The prompt word template includes a first prompt message for instructing the large language model to extract time information from the natural language input, a first filling position for the input time, a second filling position for the natural language input, and a second prompt message for adjusting the output time according to the input time. The input time is used to provide the large language model with a realistic reference time.
[0030] An addition module is used to add the input time to the first fill position and the natural language input to the second fill position to obtain the target prompt word;
[0031] The extraction module is used to extract time description information from the natural language input based on the first prompt information in the target prompt word using the large language model;
[0032] The adjustment module is used to adjust the time description information based on the second prompt information in the target prompt word using the large language model, and to obtain a first output time.
[0033] Thirdly, embodiments of this application provide an electronic device, which includes: a processor and a memory storing computer program instructions;
[0034] When the processor executes the computer program instructions, it implements any of the possible implementations of the first aspect described above.
[0035] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the method in any of the possible implementations of the first aspect described above.
[0036] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform a method as described in any of the possible implementations of the first aspect above.
[0037] This application provides a prompt word template for a large language model, including a first prompt message to instruct the large language model to extract time information from natural language input, a first filling position for the input time, a second filling position for the natural language input, and a second prompt message to adjust the output time according to the input time. In the prompt word template, the input time is used to provide a realistic reference time for the large language model. Based on this, by adding the user's natural language input time to the first filling position and adding the natural language input to the second filling position, a target prompt word is obtained. Then, through the large language model, based on the first prompt message in the target prompt word, time description information is extracted from the natural language input. This enables the large language model's natural language understanding capability, extracting time description information described in various ways from the natural language input. Furthermore, through the large language model, based on the second prompt message in the target prompt word, the time description information is adjusted using the input time to obtain a clear first output time. Thus, through this application embodiment, clear time information can be extracted from the natural language input, thereby improving the generalization of time extraction. Attached Figure Description
[0038] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 This is a flowchart illustrating the first time extraction method provided in the embodiments of this application;
[0040] Figure 2 This is a flowchart illustrating the second time extraction method provided in the embodiments of this application;
[0041] Figure 3 This is a flowchart illustrating the third time extraction method provided in the embodiments of this application;
[0042] Figure 4 This is a flowchart illustrating the fourth time extraction method provided in the embodiments of this application;
[0043] Figure 5 This is a schematic diagram of the structure of a time extraction device provided in an embodiment of this application;
[0044] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0045] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0046] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0047] Furthermore, the acquisition, storage, use, and processing of data in this application's technical solution all comply with relevant national laws and regulations.
[0048] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.
[0049] As described in the background section, current methods typically extract time information from text based on rule matching. However, the location and manner of time-related expressions in natural language are not fixed, and rule matching cannot cover them all. In other words, rule matching can only extract time information covered by the rules, but not time information not covered by the rules, resulting in low generalization of time extraction.
[0050] In addition to the above, extracting time information from natural language presents several challenges: 1) Certain domains have uncommon time units, such as the ten-day period (the 10th and 20th of each month are called the ten-day period points, dividing each month into early, middle, and late ten days). Without corresponding rules, it is difficult to identify these uncommon time units; 2) Time in natural language may be vague, such as "a while ago," and rule-based matching methods struggle to determine the specific time corresponding to "a while ago"; 3) In natural language, the same expression may refer to different times, such as yesterday, last year, and the year before last. Rule-based matching methods struggle to determine the different specific times corresponding to the same expression. These challenges have prevented a satisfactory solution to the problem of extracting time information from natural language, thus affecting the subsequent application of time information.
[0051] Therefore, there is an urgent need for a method to extract explicit time information from natural language, so as to provide data support for many application scenarios such as event timeline analysis, information retrieval, and intelligent question answering that require explicit time information.
[0052] Building upon this, the inventors of this application noted that temporal extraction can be performed using the natural language understanding capabilities of Large Language Models (LLMs). Specifically, LLMs can learn the token distribution in text based on a decoder-only model architecture. Given the model architecture, its weight parameters can be considered as unbiased estimates of the training text data. However, due to limitations in the number and accuracy of model parameters, LLMs cannot achieve an accurate reconstruction of the original text; therefore, their generated results merely follow the maximum probability distribution at execution time, lacking logical correctness—this is the origin of the hallucination of large models.
[0053] To minimize the illusions created by large language models, in-context learning can be used to influence the probability distribution of the model's output. In other words, the model's output is primarily influenced by two factors: the overall distribution of symbols learned during training and the relevance to the input prompt.
[0054] Therefore, while it's impossible to directly and reliably generate API request parameters using a large language model, we can first define the output format, allowing the model to fill in the content according to the format, and then extract precise information from it. In other words, a standardized, scenario-specific descriptive language can serve as a bridge between human thought, model weights, and program code. This approach is convenient for human expression, facilitates the generation of large models, and is easy for programs to parse and use.
[0055] Therefore, to address the problems of the prior art, embodiments of this application provide a time extraction method, apparatus, device, computer-readable storage medium, and computer program product. The time extraction method can be applied to scenarios involving extracting readable program time from natural language input.
[0056] The time extraction method provided in the embodiments of this application will be introduced first below.
[0057] Figure 1 A flowchart illustrating a time extraction method provided in an embodiment of this application is shown. This time extraction method can be executed by an electronic device equipped with a large language model. Figure 1 As shown, the time extraction method provided in this application includes the following steps:
[0058] S110. Obtain the user's natural language input, the input time of the natural language input, and a prompt word template. The prompt word template includes a first prompt message for instructing the large language model to extract time information from the natural language input, a first padding position for the input time, a second padding position for the natural language input, and a second prompt message for adjusting the output time according to the input time. The input time is used to provide a realistic reference time for the large language model.
[0059] S120. Add the input time to the first fill position and add the natural language input to the second fill position to obtain the target prompt word;
[0060] S130. Using a large language model, extract time description information from natural language input based on the first prompt information in the target prompt word;
[0061] S140. Using a large language model, based on the second prompt information in the target prompt word, adjust the time description information using the input time to obtain the first output time.
[0062] This application provides a prompt word template for a large language model, including a first prompt message to instruct the large language model to extract time information from natural language input, a first filling position for the input time, a second filling position for the natural language input, and a second prompt message to adjust the output time according to the input time. In the prompt word template, the input time is used to provide a realistic reference time for the large language model. Based on this, by adding the user's natural language input time to the first filling position and adding the natural language input to the second filling position, a target prompt word is obtained. Then, through the large language model, based on the first prompt message in the target prompt word, time description information is extracted from the natural language input. This enables the large language model's natural language understanding capability, extracting time description information described in various ways from the natural language input. Furthermore, through the large language model, based on the second prompt message in the target prompt word, the time description information is adjusted using the input time to obtain a clear first output time. Thus, through this application embodiment, clear time information can be extracted from the natural language input, thereby improving the generalization of time extraction.
[0063] The specific implementation methods for each of the above steps are described below.
[0064] In some embodiments, in S110, the user's natural language input can be any natural language input by the user into the large language model. This natural language may or may not include time information; this is a specific limitation. The time information can be time in a broad sense. That is, the time information can include year, date, time, etc. Furthermore, if the natural language includes time information, the time information can be in any form and at any position within the natural language. For example, in natural language, the time information can be represented as "March 1st," "yesterday," or "a while ago," etc.
[0065] In addition, the input time of natural language can be the input time when a user inputs natural language into an electronic device equipped with a large language model.
[0066] As an example, an electronic device equipped with a large language model can also include a clock module. After the electronic device receives the user's natural language input, the clock module can obtain the time when the natural language input was received and determine that time as the input time.
[0067] In addition, before performing time extraction using a large language model, a dedicated prompt word template for time extraction can be designed. This prompt word template can include a first prompt message instructing the large language model to extract time information from the natural language input. For example, the first prompt message could be "Extract time information from the user's natural language input." Furthermore, the prompt word template can also include a first padding position for the user's natural language input time, a second padding position for the natural language input, and a second prompt message adjusting the output time based on the input time. These padding positions can also be called placeholders. Additionally, the input time can be a time base point, used to provide a realistic reference time for the large language model. Furthermore, to ensure the large language model outputs according to a predetermined format, the prompt word template can also include the output format for the time information. Building upon this, to facilitate the large language model's understanding of the above and increase the probability of the large language model following the prompt words, the prompt word template can also include a specific example.
[0068] Taking the extraction of date from natural language input as an example, a prompt word template provided in this application embodiment can be as follows: "Extract date from natural language input.\nFormat as follows:\nDate: [date:[yyyy-MM-dd,yyyy-MM-dd],type:time point / time range]\nRequirement: The date is adjusted according to the input time {base_time}.\n\nFor example, if the natural language input is 'loan balance', the output should be\nDate: {date:[2024-08-30,2024-08-30],type:time point}\n\nNatural language input: {query}".
[0069] In the above prompt template, \n can represent a newline without a blank line, and \n\n can represent a newline with a blank line. "Extract date from natural language input" can be the first prompt; "Format as follows: \nDate: [date:[yyyy-MM-dd,yyyy-MM-dd],type:time point / time range]" can be the output format; "Requirement: Adjust date according to input time {base_time}" can be the second prompt, and "{base_time}" can represent the first padding position; "For example, if the natural language input is 'loan balance', the output should be \nDate: {date:[2024-08-30,2024-08-30],type:time point}" can be a specific example; "{query}" in "Natural language input: {query}" can represent the second padding position.
[0070] As can be seen from the above prompt template, the prompt input into the large language model in the embodiments of this application is relatively short. Therefore, the large language model consumes less computing resources and takes less time when splitting this prompt into Tokens. Thus, the latency of time extraction based on the above prompt meets the requirements of real-time tasks.
[0071] In addition, considering that the proportion of language in program-related texts in the training corpus of the large language model is relatively high, in the prompt template, English attribute names (such as date, type) are selected instead of Chinese attribute names (such as date, type) to imply the actual meaning of the attribute name to the large language model. In addition, based on the occurrence frequency of formatted texts generated by programs in Internet texts, yyyy-MM-dd is selected as the target format, and square brackets are used as marginal markers. The above design method of the prompt template is not only convenient for human expression, but also convenient for the large model to generate, and is easy to be parsed and used by programs.
[0072] In some embodiments, in S120, after obtaining the above natural language input, input time, and prompt template, the complete input of the model, that is, the target prompt, can be obtained by adding the input time to the first filling position and adding the natural language input to the second filling position. For example, in the prompt template of the above example, by replacing base_time with the input time and replacing query with the natural language input, the target prompt can be obtained.
[0073] In some embodiments, in S130, the time description information can be any time-related description information. The time description information can include "March 1st", "yesterday", "some time ago", etc.
[0074] After obtaining the target prompt, the target prompt can be input into the large language model. Then, the large language model can first extract the time description information from the natural language input based on the first prompt information in the target prompt and its powerful natural language understanding ability.
[0075] In some embodiments, in S140, since the input time in the target prompt can provide a real reference time for the large language model to achieve time awareness. Therefore, after extracting the time description information, the large language model can also adjust the time description information based on the second prompt information in the target prompt and its powerful natural language understanding ability to obtain the first output time. For example, if the time description information is "yesterday" and the input time is "March 2, 2024 10:00", the first output time can be "March 1, 2024 10:00".
[0076] Furthermore, as mentioned above, natural language input may not include time information. If natural language input does not include time information, large language models will be unable to extract time description information from it.
[0077] Based on this, in order to ensure that explicit time information is extracted from natural language input, thereby improving the generalization of time extraction, in some embodiments, the above-mentioned S140 may specifically include:
[0078] By using a large language model, the input time is determined as the first output time when no time description information is extracted from the natural language input.
[0079] Since large language models provide a time extraction result for all natural language inputs based on probability, they cannot guarantee the absolute accuracy of all output times. Therefore, by determining the input time as the first output time when there is no time-related text in the natural language input, and thus reducing the output time to the natural language input time, we can ensure that explicit time information is extracted from the natural language input, thereby improving the generalization of time extraction.
[0080] Based on this, in order to ensure that the time information extracted by the large language model can be used normally in the future, and to provide data support for many application scenarios that require explicit time information, such as event time series analysis, information retrieval, and intelligent question answering, in some embodiments, such as Figure 2 As shown, after S140 above, the time extraction method may further include the following steps:
[0081] S210. Perform multi-line pattern matching on the first output time to obtain a structured string;
[0082] S220. Convert the structured string into a time object to obtain the program-readable time.
[0083] Here, the large language model can output the first output time according to the output format in the target prompt word. As mentioned above, the output format can be "date: [date:[yyyy-MM-dd,yyyy-MM-dd],type:time point / time range]". Assuming the first output time is a point in time, and that point in time is August 30, 2024, then the first output time output by the large language model can be as follows: "date: [date:[2024-08-30,2024-08-30],type:time point]".
[0084] Additionally, the regular expression "(?<=date:)\[date:\s?\[([^\]\n]+)],\s?type:\s?((.*))\]" can be used to perform multi-line pattern matching on the first output time to obtain a structured string. In the regular expression, "(?<=date:)" matches the content after "date:", but not including "date:" itself. "\[date:\s?\[" matches the fixed format "[date:[". "([^\]\n]+)" is the first capturing group, used to capture the value of "date". "],\s?type:\s?" matches the fixed part before "type". "((.*))" is the second capturing group, used to capture the value of "type".
[0085] Assuming the first output time is "date: [date:[2024-08-30,2024-08-30],type:time point]", then by performing multi-line pattern matching on the first output time using regular expressions, we can obtain the structured string: "date:2024-08-30,2024-08-30;type:time point".
[0086] Then, using a time object parsing tool (such as strptime), the above structured string can be converted into a time object, thus obtaining the program's readable time.
[0087] This application embodiment, after outputting the first output time according to the output format in the target prompt words, first performs multi-line pattern matching on the first output time to obtain a structured string, and then converts the structured string into a time object to obtain a program-readable time. This enables end-to-end mapping of natural language to program-parsable text, thereby ensuring that the time information extracted by the large language model can be used normally in the future, providing data support for many application scenarios such as event time series analysis, information retrieval, and intelligent question answering that require explicit time information.
[0088] Furthermore, to improve the generalizability of program readability, in some embodiments, the output format of the first output time can be a first time interval. Therefore, the prompt word template can also include the time type corresponding to the first time interval. The time type can include a specific time point or a time range. Additionally, the first time interval can have a first time point as the lower limit and a second time point as the upper limit. That is, the first time interval can be denoted as [first time point, second time point]. The first time point and the second time point can be the same or different. Based on this, the structured string can include both the first and second time points.
[0089] Based on this, such as Figure 3 As shown, the above S220 may specifically include the following steps:
[0090] S221. When the time requirement for program readability is a time point, determine the first target time point in the structured string based on the time type corresponding to the first time interval.
[0091] S222. Convert the first target time point into a time object to obtain the program-readable time.
[0092] Here, the time requirement for program readability can be the type of query parameters needed by subsequent interfaces.
[0093] The time requirement for program readability can be a time range or a specific point in time. If the time requirement for program readability is a time range, then the upper limit of the first time range (i.e., the first point in time) and the lower limit of the range (i.e., the second point in time) can be converted into time objects to obtain the program readability time.
[0094] If the program's readable time requirement is a point in time, then based on the time type corresponding to the first time interval, a point in time can be selected as the first target time from the structured string of the first time interval, and the first target time can be converted into a time object to obtain the program's readable time.
[0095] This application embodiment sets the output format of the first output time to a time interval, so that regardless of whether the time requirement for program readability is a time range or a time point, the program readability time can be determined based on the first output time, thereby improving the generalization of program readability time.
[0096] Building upon this, to improve the accuracy of program readability time and make it closer to user intent, in some embodiments, when the program readability time requirement is a specific time point, a first target time point is determined in a structured string based on the time type corresponding to the first time interval. Specifically, this may include:
[0097] If the program's readable time requirement is a time point, and the time type corresponding to the first time interval is a time point, then either the first time point or the second time point will be determined as the first target time point.
[0098] Given that the program's readable time requirement is a specific point in time, and the time type corresponding to the first time interval is a time range, the second point in time is determined as the first target point in time.
[0099] Here, if the time type corresponding to the first time interval is a point in time, it means that the first point in time is the same as the second point in time. Therefore, either the first point in time or the second point in time can be determined as the first target point in time. If the time type corresponding to the first time interval is a time range, it means that the second point in time is later than the first point in time. Since in practical application scenarios, the most recent deadline or the latest data is usually more meaningful, the second point in time can be determined as the first target point in time.
[0100] In this way, by converting the more practically meaningful first target time point into a time object to obtain the program's readable time, the accuracy of the program's readable time can be improved, making the program's readable time closer to the user's intent.
[0101] Furthermore, as mentioned above, large language models cannot accurately reproduce the original text; therefore, their generated results merely follow the maximum probability distribution at execution time and lack logical correctness. For example, if a large language model extracts the time description information "last month" from the natural language input, and the input time is "May 31st," then the first output time of the large language model could be "April 31st." However, "April 31st" is not a real date. Therefore, to improve the accuracy of the program's readable time, in some embodiments, such as... Figure 4 As shown, prior to S210 above, the time extraction method may further include the following steps:
[0102] S410. Verify the authenticity of the first output time and obtain the verification result.
[0103] S420. If the verification result indicates that the first output time is not real, convert the first output time into a real second output time according to the preset rules.
[0104] Based on this, the above-mentioned S210 may specifically include:
[0105] S211. Perform multi-line pattern matching on the second output time to obtain a structured string.
[0106] Here, if the first output time is a date, a calendar library can be used to verify its authenticity. If the first output time exists on the calendar, the verification result indicates that the first output time is real. If the first output time does not exist on the calendar, the verification result indicates that the first output time is not real, and it can then be converted into a real second output time according to a preset rule. This preset rule could be to convert the first output time to the nearest real date with the same month as the first output time. For example, if the first output time is "April 31st," and April does not have a 31st but has a 30th, then the second output time can be determined to be "April 30th." Alternatively, if the first output time includes a specific hour, a clock library can be used to verify the authenticity of that hour.
[0107] This application embodiment obtains a structured string by performing multi-line pattern matching on the second output time, and then converts the structured string into a time object to obtain a program-readable time, which can improve the accuracy of the program-readable time.
[0108] Therefore, this application embodiment, by defining a set of prompt word templates that enable large language models to stably extract time information, and a set of format parsing code that can connect the model output with the Application Programming Interface (API) class interface, can achieve a function that is extremely lightweight in deployment but still powerful in functionality for extracting time information from natural language, and for using this time information for other functions that require time input. Furthermore, this implementation can interface with the access interface of any large language model, requires no independent deployment, and has low resource requirements.
[0109] Furthermore, the prompt word template in this application embodiment can be flexibly expanded to extract not only time information but also indicator information, amount information, and other information in a single request, achieving high accuracy without requiring modification of subsequent processing programs.
[0110] Based on the time extraction method provided in the above embodiments, this application also provides specific implementations of a time extraction device. Please refer to the following embodiments.
[0111] like Figure 5 As shown, the time extraction device 500 provided in this embodiment includes the following modules:
[0112] The acquisition module 510 is used to acquire the user's natural language input, the input time of the natural language input, and the prompt word template. The prompt word template includes a first prompt message for instructing the large language model to extract time information from the natural language input, a first filling position for the input time, a second filling position for the natural language input, and a second prompt message for adjusting the output time according to the input time. The input time is used to provide a realistic reference time for the large language model.
[0113] Add module 520 to add the input time to the first fill position and add the natural language input to the second fill position to obtain the target prompt word;
[0114] The extraction module 530 is used to extract time description information from natural language input based on the first prompt information in the target prompt word through a large language model;
[0115] The adjustment module 540 is used to adjust the time description information based on the second prompt information in the target prompt word using the large language model, and obtain the first output time.
[0116] The time extraction device 500 described above will be explained in detail below:
[0117] In some embodiments, the adjustment module 540 may specifically include:
[0118] The first determination submodule is used to determine the input time as the first output time by using a large language model when no time description information is extracted from the natural language input.
[0119] In some embodiments, the time extraction device 500 may further include:
[0120] The matching module is used to perform multi-line pattern matching on the first output time after obtaining the first output time to obtain a structured string;
[0121] The first conversion module is used to convert structured strings into time objects to obtain program-readable timestamps.
[0122] In some embodiments, the output of the first output time is in the form of a first time interval, and the prompt word template also includes the time type corresponding to the first time interval, which includes time point and time range.
[0123] Based on this, the first conversion module may specifically include:
[0124] The second determination submodule is used to determine the first target time point in the structured string based on the time type corresponding to the first time interval, when the time requirement for program readability is a time point.
[0125] The conversion submodule is used to convert the first target time point into a time object to obtain a time that the program can read.
[0126] In some embodiments, the structured string includes a first time point and a second time point, where the first time point is the lower limit of a first time interval and the second time point is the upper limit of the first time interval.
[0127] Based on this, the second determining submodule may specifically include:
[0128] The first determining unit is used to determine either the first time point or the second time point as the first target time point when the time requirement for program readability is a time point and the time type corresponding to the first time interval is a time point.
[0129] The second determining unit is used to determine the second time point as the first target time point when the time requirement for program readability is a time point and the time type corresponding to the first time interval is a time range.
[0130] In some embodiments, the time extraction device 500 may further include:
[0131] The verification module is used to verify the authenticity of the first output time before performing multi-line pattern matching on the first output time to obtain a structured string, and to obtain the verification result.
[0132] The second conversion module is used to convert the first output time into a real second output time according to preset rules when the verification result indicates that the first output time does not actually exist.
[0133] Based on this, the matching module may specifically include:
[0134] The matching submodule is used to perform multi-line pattern matching on the second output time to obtain a structured string.
[0135] This application provides a prompt word template for a large language model, including a first prompt message to instruct the large language model to extract time information from natural language input, a first filling position for the input time, a second filling position for the natural language input, and a second prompt message to adjust the output time according to the input time. In the prompt word template, the input time is used to provide a realistic reference time for the large language model. Based on this, by adding the user's natural language input time to the first filling position and adding the natural language input to the second filling position, a target prompt word is obtained. Then, through the large language model, based on the first prompt message in the target prompt word, time description information is extracted from the natural language input. This enables the large language model's natural language understanding capability, extracting time description information described in various ways from the natural language input. Furthermore, through the large language model, based on the second prompt message in the target prompt word, the time description information is adjusted using the input time to obtain a clear first output time. Thus, through this application embodiment, clear time information can be extracted from the natural language input, thereby improving the generalization of time extraction.
[0136] Based on the time extraction method provided in the above embodiments, this application also provides specific implementation methods for electronic devices. Figure 6 A schematic diagram of an electronic device 600 provided in an embodiment of this application is shown.
[0137] Electronic device 600 may include processor 610 and memory 620 storing computer program instructions.
[0138] Specifically, the processor 610 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0139] Memory 620 may include mass storage for data or instructions. For example, and not limitingly, memory 620 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where suitable, memory 620 may include removable or non-removable (or fixed) media. Where suitable, memory 620 may be internal or external to electronic device 600. In a particular embodiment, memory 620 is a non-volatile solid-state memory.
[0140] In a specific embodiment, the memory 620 can be implemented as ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 620 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 620 and executed by the processor 610. The processor 610 implements any of the time extraction methods in the above embodiments by reading and executing the computer program instructions stored in the memory 620.
[0141] The processor 610 implements any of the time extraction methods described in the above embodiments by reading and executing computer program instructions stored in the memory 620.
[0142] In one example, electronic device 600 may further include communication interface 630 and bus 640. For example, Figure 6 As shown, the processor 610, memory 620, and communication interface 630 are connected via bus 640 and communicate with each other.
[0143] The communication interface 630 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0144] Bus 640 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 640 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.
[0145] For example, the electronic device 600 can be a mobile phone, tablet computer, laptop computer, handheld computer, in-vehicle electronic device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc.
[0146] The electronic device can execute the time extraction method in the embodiments of this application, thereby achieving the combination Figures 1 to 5 The time extraction method described, and the beneficial effects of the corresponding method embodiments, will not be elaborated further here.
[0147] Furthermore, in conjunction with the time extraction methods in the above embodiments, this application embodiment can provide a computer-readable storage medium for implementation. This computer-readable storage medium stores computer program instructions; when executed by a processor, these computer program instructions implement any of the time extraction methods in the above embodiments.
[0148] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0149] The computer program instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the time extraction method as shown in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0150] Based on the time extraction methods described in the above embodiments, this application provides a computer program product for implementation. When the instructions in this computer program product are executed by the processor of an electronic device, they implement any of the time extraction methods described in the above embodiments.
[0151] The computer program products of the above embodiments are used to implement the time extraction method shown in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0152] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0153] The functional blocks shown in the above-described structural diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0154] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0155] The aspects of this application have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by dedicated hardware performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0156] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A time extraction method, characterized by, The method comprises: obtaining natural language input of a user, input time of the natural language input, and a prompt word template, wherein the prompt word template comprises first prompt information for instructing a large language model to extract time information from the natural language input, a first filling position of the input time, a second filling position of the natural language input, and second prompt information for adjusting output time according to the input time, wherein the input time is used to provide a real reference time for the large language model; adding the input time to the first filling position and adding the natural language input to the second filling position to obtain a target prompt word; extracting time description information from the natural language input based on the first prompt information in the target prompt word by using the large language model; adjusting the time description information by using the input time based on the second prompt information in the target prompt word by using the large language model to obtain first output time.
2. The method of claim 1, wherein, The method further comprises: performing multi-line pattern matching on the first output time to obtain a structured string; 3. The method of claim 1, wherein, converting the structured string into a time object to obtain a program-readable time. The first output time is in the form of a first time interval, and the prompt word template further comprises a time type corresponding to the first time interval, wherein the time type comprises a time point and a time range. The method further comprises:
4. The method of claim 3, wherein, in a case where a time requirement of the program-readable time is a time point, determining a first target time point in the structured string based on the time type corresponding to the first time interval; converting the first target time point into a time object to obtain a program-readable time. The structured string comprises a first time point and a second time point, wherein the first time point is a lower limit of the first time interval, and the second time point is an upper limit of the first time interval. The method further comprises:
5. The method of claim 4, wherein, in a case where the time requirement of the program-readable time is a time point and the time type corresponding to the first time interval is a time point, determining any one of the first time point and the second time point as the first target time point; in a case where the time requirement of the program-readable time is a time point and the time type corresponding to the first time interval is a time range, determining the second time point as the first target time point. 6. The method according to any one of claims 3-5, characterized in that, Before the multi-line pattern matching on the first output time to obtain the structured string, the method further comprises: performing authenticity verification on the first output time to obtain a verification result; in a case where the verification result represents that the first output time does not exist in reality, converting the first output time into a second output time that exists in reality according to a preset rule; the multi-line pattern matching on the first output time to obtain the structured string comprises: performing multi-line pattern matching on the second output time to obtain a structured string.
7. A time extraction device, characterized by The device comprises: an acquisition module configured to acquire a natural language input of a user, an input time of the natural language input, and a prompt word template, the prompt word template comprising first prompt information for instructing a large language model to extract time information from the natural language input, a first filling position of the input time, a second filling position of the natural language input, and second prompt information for adjusting an output time according to the input time, wherein the input time is used to provide a real reference time for the large language model; an adding module configured to add the input time to the first filling position and add the natural language input to the second filling position to obtain a target prompt word; an extraction module configured to extract time description information from the natural language input based on the first prompt information in the target prompt word by using the large language model; an adjusting module configured to adjust the time description information by using the input time based on the second prompt information in the target prompt word by using the large language model to obtain a first output time.
8. An electronic device, comprising: The electronic device comprises a processor and a memory storing computer program instructions; the processor executes the computer program instructions to implement the time extraction method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer program instructions, and the computer program instructions are executed by the processor to implement the time extraction method according to any one of claims 1-6.
10. A computer program product, characterised in that, The instructions in the computer program product are executed by the processor of the electronic device, so that the electronic device performs the time extraction method according to any one of claims 1-6.