Raw material price prediction and attribution method and device, electronic equipment and storage medium
By integrating textual and numerical data into a raw material price prediction and attribution model, the problems of low accuracy and insufficient interpretability in existing technologies are solved, achieving more accurate and reliable price prediction and attribution.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU SHIYUAN ELECTRONICS CO LTD
- Filing Date
- 2024-10-29
- Publication Date
- 2026-05-01
AI Technical Summary
Existing methods are not very accurate and lack interpretability in raw material price forecasting, leading to a lack of confidence in purchasing decisions.
By acquiring user questions and historical query data, a data generation network is used to retrieve relevant data from the knowledge base using retrieval strategies. Combined with a trained raw material price prediction and attribution model, textual and numerical data are integrated for prediction and attribution.
It improves the accuracy and interpretability of raw material price forecasts, thereby enhancing the credibility of procurement decisions.
Smart Images

Figure CN121961669A_ABST
Abstract
Description
Raw material price forecasting and attribution methods, devices, electronic equipment and storage media Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, electronic device, and storage medium for predicting and attributing raw material prices. Background Technology
[0002] Currently, traditional machine learning and deep learning algorithms are widely used in raw material price forecasting. However, existing methods have some shortcomings when forecasting raw material prices.
[0003] Specifically, existing methods are not very accurate in predicting raw material prices and cannot provide sufficient reasons for the predictions, resulting in a lack of interpretability and reasoning process in the predictions. Summary of the Invention
[0004] Based on this, the purpose of the present invention is to provide a method, apparatus, electronic device and storage medium for predicting and attributing raw material prices, which has the advantages of improving the accuracy of raw material price prediction, providing interpretable basis for raw material price prediction, and increasing the credibility of raw material procurement decisions.
[0005] According to a first aspect of the embodiments of this application, a method for predicting and attributing raw material prices is provided, comprising the following steps:
[0006] The system retrieves user questions, historical raw material query data before the specified time point, and real-time raw material query data at the specified time point. The user questions are used to inquire about the price data of raw materials for a preset period after the specified time point and the basis for that price data. The specified time point is either the time point included in the user questions or the time point at which the user questions are retrieved.
[0007] User questions, historical raw material query data, and real-time raw material query data are input into the retrieval strategy data generation network to obtain retrieval strategy data.
[0008] Based on the retrieval strategy data, retrieve relevant data related to the user's question from the knowledge base;
[0009] User questions and related data are input into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
[0010] According to a second aspect of the embodiments of this application, a raw material price prediction and attribution device is provided, comprising:
[0011] The user question acquisition module is used to acquire user questions, historical raw material query data before the indicated time point, and real-time raw material query data at the indicated time point. Among them, the user question is used to inquire about the price data of raw materials for a preset period after the indicated time point and the basis for the price data. The indicated time point is the time point contained in the user question or the time point when the user question is acquired.
[0012] The retrieval strategy data acquisition module is used to input user questions, historical raw material query data, and real-time raw material query data into the retrieval strategy data generation network to obtain retrieval strategy data.
[0013] The associated data acquisition module is used to retrieve associated data related to the user's question from the knowledge base based on the retrieval strategy data;
[0014] The price prediction result acquisition module is used to input user questions and related data into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
[0015] According to a third aspect of the embodiments of this application, an electronic device is provided, comprising: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed as a raw material price prediction and attribution method as described above.
[0016] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the raw material price prediction and attribution method as described above.
[0017] This application embodiment acquires user questions, historical raw material query data before the indicated time point, and real-time raw material query data at the indicated time point. The user question inquires about the price data of raw materials for a preset period after the indicated time point, along with the basis for that price data. The indicated time point is either a time point included in the user question or the time point at which the user question was acquired. The user question, historical raw material query data, and real-time raw material query data are input into a retrieval strategy data generation network to obtain retrieval strategy data. Based on the retrieval strategy data, related data concerning the user question is retrieved from a knowledge base. The user question and related data are then input into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results. This application utilizes a retrieval strategy data generation network to generate retrieval strategy data. Based on this data, related data concerning the user question is retrieved from a knowledge base. Since the related data includes textual data such as news and research reports, as well as numerical data such as historical prices, compared to traditional methods that can only process numerical data, the model integrates different types of input data, thereby improving the accuracy of raw material prediction results. Retrieving related data from the knowledge base based on the retrieval strategy data improves the retrieval efficiency and data quality of related data. Meanwhile, the raw material price prediction and attribution model trained in this application can output both raw material price prediction results and raw material price attribution results. Compared with traditional methods that can only output raw material price prediction results, the model provides interpretable evidence for raw material price prediction results, increasing the credibility of raw material procurement decisions.
[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application.
[0019] To better understand and implement this invention, the following detailed description is provided in conjunction with the accompanying drawings. Attached Figure Description
[0020] Figure 1 is a flowchart illustrating a raw material price prediction and attribution method provided in an embodiment of this application;
[0021] Figure 2 is a structural block diagram of a raw material price prediction and attribution device provided in an embodiment of this application;
[0022] Figure 3 is a schematic block diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0024] It should be understood that the described embodiments are merely some, not all, of the embodiments in this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0025] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the embodiments of this application. The singular forms “a,” “the,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0026] In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims. In the description of this application, it should be understood that the terms "first," "second," "third," etc., are used only to distinguish similar objects and are not necessarily used to describe a specific order or sequence, nor should they be construed as indicating or implying relative importance. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0027] Furthermore, in the description of this application, unless otherwise stated, "multiple" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0028] In the process of developing this invention, the inventors discovered that while related technologies based on machine learning or deep learning algorithms can provide predictions of raw material prices, they fail to offer sufficient justification for these predictions. This results in a lack of interpretability and reasoning process in the predictions, significantly impacting the confidence of business personnel in their raw material procurement decisions. Furthermore, the input data for these related technologies is numerical price data, which cannot handle heterogeneous data, such as textual data, leading to a relatively homogeneous data set and inaccurate prediction results.
[0029] To this end, this application utilizes a retrieval strategy data generation network to generate retrieval strategy data. Based on this data, it retrieves relevant data related to the user's question from a knowledge base. Since this relevant data includes textual data such as news and research reports, as well as numerical data such as historical prices, the model integrates different types of input data, unlike traditional methods that can only handle numerical data. This improves the accuracy of raw material prediction results. Furthermore, through a trained raw material price prediction and attribution model, this application can not only predict raw material prices but also provide corresponding price prediction basis, enhancing the credibility of business personnel's procurement decisions.
[0030] Please refer to Figure 1, which is a flowchart illustrating a raw material price forecasting and attribution method provided in one embodiment of this application. This embodiment of the application provides a raw material price forecasting and attribution method, including the following steps:
[0031] S10: Obtain user questions, historical raw material query data before the indicated time point, and real-time raw material query data at the indicated time point; wherein, the user questions are used to inquire about the price data of raw materials for a preset period after the indicated time point and the basis for the price data; the indicated time point is the time point contained in the user questions or the time point when the user questions are obtained.
[0032] If the user's question includes a time point, that time point will be used as the indication time point. For example, if the user's question is "The current time is May 11, 2024. What will be the price trend of crude oil in the next three weeks, and provide the basis for the price trend?", the indication time point is May 11, 2024. If the user's question does not include a time point, the time point when the user entered the question can be obtained through an online connection.
[0033] Price data includes, but is not limited to, prices and price trends, and the basis for price data includes price data and price trend data.
[0034] Historical raw material query data refers to the data queried by the user prior to the specified time point. This data includes, but is not limited to, historical characteristic data and historical price data for raw materials. Historical characteristic data includes, but is not limited to, raw material price fluctuation patterns, seasonality of raw material prices, and supply and demand relationships. Historical price data refers to the time-series price data of raw materials prior to the specified time point. For example, historical price data for crude oil includes '2024-03-01': 78.21, '2024-03-08': 87.25, '2024-05-10': 86.38, etc.
[0035] Real-time raw material query data refers to the data queried by the user at the specified time point, including but not limited to real-time characteristic data and real-time price data of raw materials. Real-time characteristic data includes, but is not limited to, real-time price fluctuation patterns, real-time seasonality of raw material prices, and real-time supply and demand relationships. Real-time price data refers to the time-series price data of raw materials at the specified time point. For example, the real-time price data for crude oil is '2024-05-11': 87.25.
[0036] In this embodiment, user questions can be obtained from the user interface, and historical raw material query data can be retrieved from the local disk or server. The user's historical query data is stored on the local disk or server. Real-time raw material query data can be obtained through the real-time raw material price query interface.
[0037] S20: Input user questions, historical raw material query data, and real-time raw material query data into the retrieval strategy data generation network to obtain retrieval strategy data.
[0038] The retrieval strategy data includes, but is not limited to, retrieval parameters such as retrieval depth, relevance threshold, and time window size. Retrieval depth refers to the number or levels of documents that the search engine traverses or accesses during the retrieval process. The relevance threshold defines the relevance between the information in the retrieval results and the user's query; by adjusting the relevance threshold, the accuracy and quantity of retrieval results can be controlled. A higher threshold reduces the number of results but may improve the accuracy; a lower threshold may increase the number of results but also introduce more irrelevant content. The time window size limits the time range of the retrieval results; by setting a time window, it can be specified that only information within a certain past time period is retrieved, thereby excluding outdated or irrelevant content.
[0039] In this embodiment of the application, the retrieval strategy data generation network can generate retrieval strategy data based on user questions, historical characteristic data of raw materials, historical price data of raw materials, real-time characteristic data of raw materials, and real-time price data of raw materials, so as to facilitate the retrieval of subsequent related data.
[0040] S30: Based on the retrieval strategy data, retrieve relevant data related to the user's question from the knowledge base.
[0041] The related data includes, but is not limited to, news data about raw materials, research reports on raw materials, and historical price data of raw materials related to user questions.
[0042] The knowledge base includes a relational knowledge base and a vector knowledge base. Specifically, knowledge documents in the raw materials domain are preprocessed using text preprocessing methods and stored in a relational database. Semantic representation models are then used to convert the preprocessed knowledge documents into semantic vectors, which are stored in a vector database. Semantic representation models include, but are not limited to, BERT and GPT models. The relational database stores the text data, while the vector database stores the vector representations of the text. Knowledge documents in the raw materials domain include, but are not limited to, raw materials news data, raw materials research report data, and raw materials price data.
[0043] Since news and research reports are updated in real time, when the knowledge base is not updated or the update frequency is slow, the news and research reports in the knowledge base can be continuously updated through online data feedback. For example, the update frequency of the knowledge base can be set to 1 hour.
[0044] In this embodiment of the application, Retrieval-augmented Generation (RAG) technology can be used to perform retrieval parameters such as retrieval depth, relevance threshold, and time window size to retrieve raw material news data, raw material research report data, and historical price data of raw materials related to the user's question from the knowledge base.
[0045] S40: Input the user's question and related data into the trained raw material price prediction and attribution model to obtain the raw material price prediction results and raw material price attribution results.
[0046] The trained raw material price prediction and attribution model is a trained large language model. This model can be trained based on sample text data, corresponding sample raw material price predictions, sample raw material price trend predictions, and the basis for these predictions. The sample text data includes sample user questions, sample news data, sample research report data, and historical raw material price data.
[0047] The raw material price forecast results include the predicted raw material prices and the predicted raw material price trends. The raw material price attribution results include the justification for the predicted raw material prices and the justification for the predicted raw material price trends.
[0048] In this embodiment, the trained raw material price prediction and attribution model can predict raw material prices and / or raw material price trends based on user questions and related data. It can also output the basis for raw material price prediction and / or the basis for raw material price trend prediction, so that business personnel can make accurate decisions based on raw material prices, raw material price trends, the basis for raw material price prediction, and the basis for raw material price trend prediction.
[0049] This application utilizes an embodiment to obtain user questions, historical raw material query data before a specified time point, and real-time raw material query data at the specified time point. The user question inquires about the price data of raw materials for a preset period after the specified time point, along with the basis for that price data. The specified time point is either a time point included in the user question or the time point at which the user question is obtained. The user question, historical raw material query data, and real-time raw material query data are input into a retrieval strategy data generation network to obtain retrieval strategy data. Based on the retrieval strategy data, related data concerning the user question is retrieved from a knowledge base. The user question and related data are then input into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results. This application utilizes a retrieval strategy data generation network to generate retrieval strategy data. Based on this data, related data concerning the user question is retrieved from a knowledge base. Since the related data includes textual data such as news and research reports, as well as numerical data such as historical prices, compared to traditional methods that can only process numerical data, the model integrates different types of input data, thereby improving the accuracy of raw material prediction results. Retrieving related data from the knowledge base based on the retrieval strategy data improves the retrieval efficiency and data quality of related data. Meanwhile, the raw material price prediction and attribution model trained in this application can output both raw material price prediction results and raw material price attribution results. Compared with traditional methods that can only output raw material price prediction results, the model provides interpretable evidence for raw material price prediction results, increasing the credibility of raw material procurement decisions.
[0050] In an optional embodiment, the historical raw material query data includes historical raw material characteristic data and historical raw material price data; the real-time raw material query data includes real-time raw material characteristic data and real-time raw material price data; the retrieval strategy data generation network includes a task encoder and a retrieval strategy data generator. Step S20 includes steps S21 to S24, as follows:
[0051] S21: Input the historical characteristic data and historical price data of raw materials into the task encoder to obtain the first task representation vector.
[0052] The task encoder is used to map the input sequence into a task representation vector.
[0053] In this embodiment of the application, historical feature data of raw materials and historical price data of raw materials are concatenated into a first input sequence, and the first input sequence is encoded into a first task representation vector by a task encoder.
[0054] S22: Input the real-time feature data and real-time price data of raw materials into the task encoder to obtain the second task representation vector.
[0055] In this embodiment of the application, real-time feature data of raw materials and real-time price data of raw materials are concatenated into a second input sequence, and the second input sequence is encoded into a second task representation vector by a task encoder.
[0056] S23: Input the user question into the task encoder to obtain the third task representation vector.
[0057] In this embodiment of the application, the user question is encoded into a third task representation vector by a task encoder.
[0058] S24: Input the first task representation vector, the second task representation vector, and the third task representation vector into the retrieval strategy data generator to obtain retrieval strategy data.
[0059] In this embodiment of the application, the first task representation vector, the second task representation vector, and the third task representation vector are concatenated to obtain a concatenated vector. The concatenated vector is then input into the retrieval strategy data generator to obtain retrieval strategy data.
[0060] By setting up a task encoder and a retrieval strategy data generator, and processing user questions, historical raw material query data, and real-time raw material query data, excellent retrieval strategy data can be generated, improving the efficiency of subsequent retrieval and the quality of retrieval data.
[0061] In an optional embodiment, step S30 includes steps S31 to S34, as follows:
[0062] S31: Based on the retrieval strategy data, retrieve several initial knowledge documents related to the user's question from the knowledge base.
[0063] In this embodiment, based on the retrieval depth, a first knowledge document level or number corresponding to the retrieval depth is retrieved from the knowledge base. Based on a relevance threshold, a second knowledge document level or number corresponding to the relevance threshold is retrieved from the knowledge base. Based on the time window size, a third knowledge document level or number corresponding to the time window size is retrieved from the knowledge base. The first knowledge document level or number, the second knowledge document level or number, and the third knowledge document level or number are used as several initial knowledge documents related to the user's question.
[0064] S32: Obtain user's historical Q&A data.
[0065] Among them, user historical question and answer data refers to the questions that users asked before the indicated time point and the corresponding answers to those questions.
[0066] In this embodiment of the application, user historical question and answer data can be obtained from the server where the user account is located.
[0067] S33: Input each initial knowledge document, user question, and user historical Q&A data into the relevance scoring model to obtain the relevance score between each initial knowledge document and user question.
[0068] Among them, the relevance scoring model is used to evaluate the degree of relevance between the initial knowledge document and the user's question and the user's historical question and answer data.
[0069] In this embodiment, a relevance score is output through a relevance scoring model to quantitatively describe the relevance between each initial knowledge document and the user's question. The higher the relevance score, the greater the relevance.
[0070] S34: Sort the relevance scores from high to low, and use the preset number of initial knowledge documents with the highest relevance scores as related data for the user's question.
[0071] In this embodiment of the application, knowledge documents that are highly relevant to the user's question are selected from multiple initial knowledge documents based on their relevance scores.
[0072] The correlation score output by the correlation scoring model can filter out relevant data related to user questions, improve the data quality of relevant data, and improve the accuracy of subsequent raw material price predictions.
[0073] In an optional embodiment, step S33 includes steps S331 to S334, as follows:
[0074] S331: Obtain the generation time of each initial knowledge document.
[0075] In this embodiment of the application, the generation time of each initial knowledge document is obtained by querying the file attribute data of each initial knowledge document.
[0076] S332: Determine the generation time of each initial knowledge document and the time difference between the indicated time points.
[0077] In this embodiment of the application, the time difference between the generation time and the indication time of each initial knowledge document is obtained by subtracting the generation time and the indication time of each initial knowledge document.
[0078] S333: Calculate the similarity between each initial knowledge document and user questions and user historical question-and-answer data.
[0079] In this embodiment, each initial knowledge document is vectorized to obtain several document vectors. User questions are vectorized to obtain question vectors. User historical question-and-answer data is vectorized to obtain question-and-answer vectors. Question vectors and question-and-answer vectors are concatenated to obtain a concatenated vector. The cosine similarity between each document vector and the concatenated vector is calculated, and this cosine similarity is used as the similarity between the initial knowledge document corresponding to that document vector and the user question and user historical question-and-answer data.
[0080] S334: Based on similarity, time difference, and a preset time decay factor, obtain a relevance score between each initial knowledge document and the user's question.
[0081] In this embodiment of the application, the formula for calculating the relevance score is as follows:
[0082] score(q,d)=S(q,d,c)*exp(-λΔt)
[0083] Where S(q,d,c) represents similarity, Δt represents time difference, λ represents preset time decay factor, q represents initial knowledge document, d represents user question, and c represents user historical question and answer data.
[0084] By introducing a time decay factor, the larger the time difference, the weaker the correlation, and the lower the corresponding correlation score, which can improve the accuracy of the correlation score.
[0085] In an optional embodiment, the associated data includes raw material news data, raw material research report data, and historical raw material price data. Step S40 includes steps S401 to S403, as follows:
[0086] S401: Retain the same number of decimal places for each price value in the historical price data of raw materials, and shift the decimal places of each retained price value to the right by a preset number of places to obtain each price value that is an integer.
[0087] In this embodiment, since the historical price data of raw materials is time-series data, it needs to be preprocessed to adapt the time-series data to the input of the large language model. Specifically, the time-series data is converted into numbers, which are then used as the input to the large language model.
[0088] Specifically, the decimal point position and number of digits for each price value are adjusted, and each price value is multiplied by a certain factor to make it an integer. For example, "78.21, 87.25, ..., 86.38" becomes "7821, 8725, ..., 8638". Data preprocessing ensures the standardization and consistency of price values, helping to reduce data variability and improve model stability.
[0089] S402: Use the space symbol to segment each number in each price value that is an integer to obtain a long string corresponding to the historical price data of raw materials.
[0090] In this embodiment, to adapt to the input requirements of a large language model, the price values are formatted. Specifically, spaces are added between each digit of the price value to prevent complete segmentation and obtain a long string corresponding to the historical price data of raw materials. For example, "7821,8725,......,8638" is segmented into 7 8 2 1, 8 7 25,......,8 6 3 8. Data formatting helps the large language model to correctly understand and process the input data.
[0091] S403: Integrate the long strings corresponding to user questions, raw material news data, raw material research report data, and raw material price data, and input them into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
[0092] In this embodiment, text data such as user questions, raw material news data, raw material research report data, and long strings corresponding to raw material price data are integrated through a preset prompt word template to obtain prompt words. The prompt words are then input into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
[0093] Specifically, the preset prompt word template includes several placeholders. The long strings corresponding to user questions, raw material news data, raw material research report data, and raw material price data are filled into the corresponding placeholders to obtain the prompt words.
[0094] By performing digital preprocessing and data formatting on the input data of large language models, the adaptability of the models can be improved and the predictive performance of the models can be enhanced.
[0095] In an optional embodiment, the trained raw material price prediction and attribution model includes a trained raw material price prediction model and a trained raw material price attribution model. The associated data includes raw material news data, raw material research report data, and historical raw material price data. Step S40 includes steps S41 to S45, as follows:
[0096] S41: Obtain a first prompt word template and a second prompt word template that match the user's question; wherein, the first prompt word template includes a task description for price prediction, and the second prompt word template includes a task description for the basis of price prediction.
[0097] In this embodiment, a first prompt word template and a second prompt word template can be obtained by matching from multiple preset prompt word templates based on the user question. Specifically, each prompt word template corresponds to a task description. By identifying the textual semantics of the user question, the task description that is closest in semantics to the text is matched, and the prompt word template corresponding to the task description is used as the prompt word template that matches the user question.
[0098] S42: Fill the first prompt word template with user questions, raw material news data, and raw material historical price data to obtain the first prompt word.
[0099] In this embodiment, the first prompt word template includes several placeholders. User questions, raw material news data, and historical raw material price data are filled into the corresponding placeholders in the first prompt word template to obtain the first prompt word. For example, the first prompt word template is: "Based on the news data and historical raw material price data provided below, predict the rise or fall of raw materials in the next three weeks. Please provide a clear answer, 'rise' or 'fall', <News Data><Historical Raw Material Price Data>, Input: <User Question>, Output:"
[0100] S43: Input the first prompt word into the trained raw material price prediction model to obtain the raw material price prediction result.
[0101] In this embodiment of the application, the trained raw material price prediction model outputs the predicted price of raw materials and / or the price trend of raw materials based on the first prompt word. For example, {'time':['2024-05-17','2024-05-24','2024-05-31'],'price':[88,76,92]}, the overall price trend is upward.
[0102] S44: Fill the second prompt word template with user questions and raw material research report data to obtain the second prompt word.
[0103] In this embodiment, the second prompt template includes several placeholders. User questions and raw material research report data are filled into the corresponding placeholders in the second prompt template to obtain the second prompt. For example, the second prompt template is: "Based on the research report data provided below, predict the basis for the rise and fall of raw material prices in the next three weeks. <Research Report Data>, Input: <User Question>, Output:".
[0104] S45: Input the second prompt word into the trained raw material price attribution model to obtain the raw material price attribution results.
[0105] In this embodiment, the trained raw material price attribution model outputs the basis for predicted raw material prices and / or the basis for raw material price trends based on the second prompt word. For example, "Considering that OPEC plans to cut crude oil production...therefore: the price trend of crude oil in the next three weeks is upward."
[0106] By using a pre-trained raw material price prediction model to predict raw material price data, and a pre-trained raw material price attribution model to generate the basis for the raw material price prediction data, the tasks of raw material price data prediction and raw material price data generation are completed by different models, which reduces the task difficulty of each model and improves the accuracy of each model.
[0107] In an optional embodiment, step S41 includes steps S411 to S412, as follows:
[0108] S411: Construct multiple prompt word templates.
[0109] In this embodiment, multiple different prompt word templates can be constructed to suit user questions. Specifically, prompt word templates can be manually written or automatically generated using a large language model. The prompt word templates include, but are not limited to, task descriptions, placeholders, inputs, and outputs.
[0110] S412: Identify the textual semantics of the user's question, calculate the similarity between the textual semantics and the task description of each prompt word template, and obtain the first prompt word template and the second prompt word template that match the user's question.
[0111] In this embodiment, a semantic extraction model can be used to extract the textual semantics of the user's question, and the textual semantics can be vectorized to obtain a text vector. The task description of each prompt word template is vectorized to obtain a task vector. The similarity between the text vector and the task vector is calculated, and the prompt word template corresponding to the task vector with high similarity is used as the prompt word template matching the user's question.
[0112] Since the user's question includes both raw material price data prediction and the basis for that data, a first prompt word template can be generated based on the raw material price data prediction. The task description of this first prompt word template includes price prediction. Conversely, a second prompt word template can be generated based on the raw material price data basis. The task description of this second prompt word template includes the basis for that price prediction.
[0113] Based on the textual semantics of the user's question and the similarity between the task description of the prompt word template, the first prompt word template and the second prompt word template can be accurately determined.
[0114] In an optional embodiment, before step S43, steps S431 to S432 are included, as follows:
[0115] S431: Obtain the raw material sample dataset and the first sample prompt word; wherein, the raw material sample dataset includes price data of raw materials in a first preset time period before the target time point, news data of raw materials in the target time point, and price data of raw materials in a second preset time period after the target time point; the first sample prompt word is used to query the price data of raw materials in the preset time period after the target time point.
[0116] The raw material sample dataset includes the raw material basic dataset, the raw material news dataset, the raw material dialogue dataset, and the raw material research report dataset.
[0117] The raw materials dataset primarily originates from sources such as chemical raw materials and materials online, containing rich information on the physical properties, chemical characteristics, and application scope of raw materials. The raw materials news dataset is collected through website interfaces and web crawling technologies, including news data from energy websites, international energy networks, business information platforms, and China Metals Network. Specifically, it includes both existing and incremental news data. At a given point in time, all historical news prior to that time is collected as existing data. After obtaining the existing data, incremental data updates are performed; for example, incremental data is collected hourly in real time. The raw materials news dataset includes the latest market dynamics, policy changes, and supply and demand relationships, providing real-time market background data for model predictions. The raw materials dialogue dataset consists of dialogue data related to raw materials collected from financial platforms and forums such as Tonghuashun. This dialogue data reflects the sentiment, expectations, and discussion hotspots of raw materials market participants, providing auxiliary information on market sentiment for price prediction. The raw materials research report dataset is a raw materials report dataset formed by manually processing and using CoT (Cooperative Thought Processing) technology to extract key information from reports by consulting firms such as Strategy&. This dataset includes in-depth market analysis, expert forecasts, and long-term trends, providing a comprehensive analytical perspective for price prediction.
[0118] S432: The large language model is trained by taking the first sample prompt word, the price data of raw materials in the first preset time period before the target time point, and the news data of raw materials at the target time point as input, and the price data of raw materials in the second preset time period after the target time point as output, to obtain a trained raw material price prediction model.
[0119] Among them, the large language model is the baseline model, including but not limited to the ChatGLM2-6B model, the LLaMA model, and the Qwen model.
[0120] The target time point can be a time point before the indicated time point. For example, if the indicated time point is "2024-05-11", the target time point can be "2024-05-01".
[0121] In this embodiment, the price prediction model for raw materials can be obtained by comparing the price data of raw materials predicted by the large language model based on the first sample prompt word, the price data of raw materials in a first preset time period before the target time point, and the price data of raw materials in the second preset time period after the target time point with the price data of raw materials in the second preset time period after the target time point. This comparison allows for fine-tuning of the large language model, resulting in a trained raw material price prediction model. Various fine-tuning strategies, such as full parameter fine-tuning, LoRA, QLoRA, and Adapter Tuning, can be employed to fine-tune the large language model.
[0122] By training a large language model based on news data and price data of raw materials, a well-trained raw material price prediction model can be automatically and quickly obtained, so that raw material price prediction data can be output based on the well-trained raw material price prediction model.
[0123] In an optional embodiment, before step S45, steps S451 to S452 are included, as follows:
[0124] S451: Obtain the raw material sample dataset and the second sample prompt; wherein, the raw material sample dataset includes research report data of raw materials at the target time point, price data of raw materials for a preset time period after the target time point, and the basis for the price data of raw materials for a preset time period after the target time point; the second sample prompt is used to inquire about the basis for the price data of raw materials for a preset time period after the target time point.
[0125] In this application embodiment, the basis for raw material price data can be obtained from the raw material research report dataset or from the raw material dialogue dataset.
[0126] S452: Using the second sample prompt words, research report data of raw materials at the target time point, and price data of raw materials in a preset time period after the target time point as input, and the basis of the price data of raw materials in the preset time period after the target time point as output, train the trained raw material price prediction model to obtain the trained raw material price attribution model.
[0127] In this embodiment, the trained raw material price prediction model can be fine-tuned by comparing the second sample prompts of the raw material price prediction model, the research report data of the raw material at the target time point, the price data of the raw material for a preset time period after the target time point, and the price data of the raw material for a preset time period after the target time point. This allows for the acquisition of a trained raw material price attribution model. Various fine-tuning strategies, such as full parameter fine-tuning, LoRA, QLoRA, and Adapter Tuning, can be employed to fine-tune the trained raw material price prediction model.
[0128] By training a pre-trained raw material price prediction model using research report data and price data, a pre-trained raw material price attribution model can be automatically and quickly obtained. This attribution model can then be used to output raw material price prediction data. Furthermore, training on a pre-trained raw material price prediction model can improve model convergence speed and training efficiency.
[0129] The following are embodiments of the apparatus described in this application, which can be used to execute the methods described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the methods described in the embodiments of this application.
[0130] Please refer to Figure 2, which shows a schematic diagram of the structure of the raw material price prediction and attribution device provided in an embodiment of this application. The raw material price prediction and attribution device 5 provided in this embodiment includes:
[0131] The user question acquisition module 51 is used to acquire user questions, historical raw material query data before the indicated time point, and real-time raw material query data at the indicated time point. The user question is used to inquire about the price data of raw materials for a preset period after the indicated time point and the basis for the price data. The indicated time point is the time point contained in the user question or the time point when the user question is acquired.
[0132] The retrieval strategy data acquisition module 52 is used to input user questions, historical raw material query data and real-time raw material query data into the retrieval strategy data generation network to obtain retrieval strategy data.
[0133] The associated data acquisition module 53 is used to retrieve associated data related to the user's question from the knowledge base based on the retrieval strategy data;
[0134] The price prediction result acquisition module 54 is used to input user questions and related data into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
[0135] This application utilizes an embodiment to acquire user questions, historical raw material query data before a specified time point, and real-time raw material query data at the specified time point. The user questions inquire about price data for raw materials within a preset time period after the specified time point, along with the basis for that price data. The specified time point is either a time point included in the user questions or the time point at which the user questions are acquired. The user questions, historical raw material query data, and real-time raw material query data are input into a retrieval strategy data generation network to obtain retrieval strategy data. Based on the retrieval strategy data, related data concerning the user questions is retrieved from a knowledge base. The user questions and related data are then input into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results. This application utilizes a retrieval strategy data generation network to generate retrieval strategy data. Based on this data, related data concerning the user questions is retrieved from a knowledge base. Since the related data includes textual data such as news and research reports, as well as numerical data such as historical prices, compared to traditional methods that can only process numerical data, the model integrates different types of input data, thereby improving the accuracy of raw material prediction results. Retrieving related data from the knowledge base based on the retrieval strategy data improves the retrieval efficiency and data quality of related data. Furthermore, the raw material price forecasting and attribution model trained in this application can output both raw material price forecast results and raw material price attribution results. Compared to traditional methods that can only output raw material price forecast results, the model provides interpretable evidence for the raw material price forecast results, increasing the credibility of raw material procurement decisions.
[0136] The following are embodiments of the device described in this application, which can be used to execute the methods described in the embodiments of this application. For details not disclosed in the embodiments of the device described in this application, please refer to the methods described in the embodiments of this application.
[0137] Please refer to Figure 3. This application also provides an electronic device 300. The electronic device may specifically be a computer, mobile phone, tablet computer, raw material price prediction and attribution device, etc. In an exemplary embodiment of this application, the electronic device 300 is a raw material prediction and attribution device. The raw material prediction and attribution device may include: at least one processor 301, at least one memory 302, at least one display, at least one network interface 303, user interface 304, and at least one communication bus 305.
[0138] The user interface 304 is primarily used to provide an input interface for the user and to acquire user input data. Optionally, the user interface may also include a standard wired interface or a wireless interface.
[0139] The network interface 303 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0140] The communication bus 305 is used to enable communication between these components.
[0141] The processor 301 may include one or more processing cores. The processor connects to various parts of the electronic device using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory, and by calling data stored in memory. Optionally, the processor may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor.
[0142] The memory 302 may include random access memory (RAM) or read-only memory. Optionally, the memory may include a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, code, code sets, or instruction sets. The memory may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor. As shown in Figure 3, the memory, as a computer storage medium, may include an operating system, a network communication module, a user interface module, and operating applications.
[0143] The processor can be used to call the application program of the raw material prediction and attribution method stored in the memory, and specifically execute the method steps of the above embodiment. For the specific execution process, please refer to the detailed description shown in the embodiment, which will not be repeated here.
[0144] This application also provides a computer-readable storage medium storing a computer program thereon, the instructions of which are adapted to be loaded by a processor and executed by the method steps of the embodiments shown above. For details of the execution process, please refer to the specific descriptions shown in the embodiments, which will not be repeated here. The device containing the storage medium can be an electronic device such as a personal computer, laptop computer, smartphone, or tablet computer.
[0145] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative, wherein the components described as separate parts may or may not be physically separate, and 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 modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0146] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0147] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of 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, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions selected in one or more flowchart illustrations and / or one or more block diagrams. These computer program instructions can also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions selected in one or more flowchart illustrations and / or one or more block diagrams.
[0148] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions selected in one or more flowcharts and / or one or more block diagrams.
[0149] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0150] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0151] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, 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 storage, disk storage, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0152] It should also be noted that 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 process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0153] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for predicting and attributing raw material prices, characterized in that, The method includes the following steps: acquiring a user question, historical raw material query data before an indicated time point, and real-time raw material query data at the indicated time point; wherein, the user question is used to inquire about the price data of raw materials for a preset period after the indicated time point and the basis for the price data; the indicated time point is a time point included in the user question or the time point when the user question is acquired; inputting the user question, the historical raw material query data, and the real-time raw material query data into a retrieval strategy data generation network to obtain retrieval strategy data; retrieving related data related to the user question from a knowledge base based on the retrieval strategy data; and inputting the user question and the related data into a trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
2. The raw material price forecasting and attribution method according to claim 1, characterized in that: The trained raw material price prediction and attribution model includes a trained raw material price prediction model and a trained raw material price attribution model; the associated data includes raw material news data, raw material research report data, and historical raw material price data; the step of inputting the user question and the associated data into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results includes: obtaining a first prompt word template and a second prompt word template matching the user question; wherein, the first prompt word template includes a task description for price prediction, and the second prompt word template includes a task description for the basis of price prediction; filling the user question, the raw material news data, and the historical raw material price data into the first prompt word template to obtain a first prompt word; inputting the first prompt word into the trained raw material price prediction model to obtain a raw material price prediction result; filling the user question and the raw material research report data into the second prompt word template to obtain a second prompt word; inputting the second prompt word into the trained raw material price attribution model to obtain a raw material price attribution result.
3. The raw material price forecasting and attribution method according to claim 2, characterized in that: The step of obtaining the first prompt word template and the second prompt word template that match the user question includes: constructing multiple prompt word templates; identifying the text semantics of the user question; calculating the similarity between the text semantics and the task description of each prompt word template; and obtaining the first prompt word template and the second prompt word template that match the user question.
4. The raw material price prediction and attribution method according to claim 2, characterized in that: Before the step of inputting the first prompt word into the trained raw material price prediction model to obtain the raw material price prediction result, the method includes: acquiring a raw material sample dataset and a first sample prompt word; wherein, the raw material sample dataset includes price data of raw materials for a first preset time period before the target time point, news data of raw materials at the target time point, and price data of raw materials for a second preset time period after the target time point; the first sample prompt word is used to query the price data of raw materials for the preset time period after the target time point; the large language model is trained with the first sample prompt word, the price data of raw materials for the first preset time period before the target time point, and the news data of raw materials at the target time point as input, and the price data of raw materials for the second preset time period after the target time point as output, to obtain a trained raw material price prediction model.
5. The raw material price forecasting and attribution method according to claim 2, characterized in that: Before the step of inputting the second prompt word into the trained raw material price attribution model to obtain the raw material price attribution result, the following steps are included: acquiring a raw material sample dataset and a second sample prompt word; wherein, the raw material sample dataset includes research report data of the raw material at the target time point, price data of the raw material for a preset time period after the target time point, and the basis for the price data of the raw material for the preset time period after the target time point; the second sample prompt word is used to inquire about the basis for the price data of the raw material for the preset time period after the target time point; the trained raw material price prediction model is trained using the second sample prompt word, the research report data of the raw material at the target time point, and the price data of the raw material for the preset time period after the target time point as input, and the basis for the price data of the raw material for the preset time period after the target time point as output, to obtain the trained raw material price attribution model.
6. The raw material price forecasting and attribution method according to any one of claims 1 to 5, characterized in that: The historical raw material query data includes historical raw material characteristic data and historical raw material price data; the real-time raw material query data includes real-time raw material characteristic data and real-time raw material price data; the retrieval strategy data generation network includes a task encoder and a retrieval strategy data generator. The step of inputting the user question, the historical query data of raw materials, and the real-time query data of raw materials into the retrieval strategy data generation network to obtain retrieval strategy data includes: inputting the historical feature data of raw materials and the historical price data of raw materials into the task encoder to obtain a first task representation vector; The real-time feature data and real-time price data of the raw materials are input into the task encoder to obtain a second task representation vector; the user question is input into the task encoder to obtain a third task representation vector; the first task representation vector, the second task representation vector, and the third task representation vector are input into the retrieval strategy data generator to obtain the retrieval strategy data.
7. The raw material price forecasting and attribution method according to any one of claims 1 to 5, characterized in that: The step of retrieving related data from the knowledge base based on the retrieval strategy data includes: retrieving a number of initial knowledge documents related to the user question from the knowledge base based on the retrieval strategy data; obtaining historical question-and-answer data of the user; inputting each initial knowledge document, the user question, and the historical question-and-answer data of the user into a relevance scoring model to obtain a relevance score between each initial knowledge document and the user question; arranging the relevance scores from high to low, and selecting a predetermined number of initial knowledge documents with the highest relevance scores as related data related to the user question.
8. The raw material price forecasting and attribution method according to claim 7, characterized in that: The step of inputting each initial knowledge document, the user question, and the user's historical question-and-answer data into a relevance scoring model to obtain a relevance score between each initial knowledge document and the user question includes: obtaining the generation time of each initial knowledge document; determining the time difference between the generation time of each initial knowledge document and the indicated time point; calculating the similarity between each initial knowledge document and the user question and the user's historical question-and-answer data; and obtaining a relevance score between each initial knowledge document and the user question based on the similarity, the time difference, and a preset time decay factor.
9. The raw material price forecasting and attribution method according to any one of claims 1 to 5, characterized in that: The associated data includes raw material news data, raw material research report data, and historical raw material price data. The step of inputting the user question and the associated data into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results includes: retaining the same number of decimal places for each price value in the historical raw material price data, and uniformly shifting the decimal places of each retained price value to the right by a preset number of places to obtain each price value that is an integer; using a space symbol to segment each number in each of the price values that is an integer to obtain a long string corresponding to the historical raw material price data; integrating the user question, the raw material news data, the raw material research report data, and the long string corresponding to the raw material price data, and inputting them into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
10. A raw material price prediction and attribution device, characterized in that, include: The user question acquisition module is used to acquire user questions, historical raw material query data before the indicated time point, and real-time raw material query data at the indicated time point; wherein, the user question is used to inquire about the price data of raw materials for a preset period after the indicated time point and the basis for the price data; the indicated time point is the time point included in the user question or the time point when the user question is acquired; The retrieval strategy data acquisition module is used to input the user question, the historical query data of the raw materials, and the real-time query data of the raw materials into the retrieval strategy data generation network to obtain retrieval strategy data; the association data acquisition module is used to retrieve association data related to the user question from the knowledge base based on the retrieval strategy data; the price prediction result acquisition module is used to input the user question and the association data into the trained raw material price prediction and attribution model to obtain raw material price prediction results and raw material price attribution results.
11. An electronic device, characterized in that, include: A processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed as described in any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the raw material price forecasting and attribution method as described in any one of claims 1 to 9.