Model training and multi-item order quantity prediction method, computer equipment and medium
By constructing a multi-product order quantity prediction model with a self-attention mechanism and combining multi-dimensional features, the accuracy problem of fresh commodity demand prediction is solved, and accurate order quantity prediction of fresh commodities is achieved, which is suitable for production with different sales models. Fresh store.
Patent Information
- Application Number
- CN202410659523.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-05-27
AI Technical Summary
Existing product demand forecasting solutions are difficult to accurately predict the demand for fresh products, especially due to the strong seasonality, short shelf life, and non-standardized characteristics of fresh products, which result in items being inconsistent, large price fluctuations, unsalable and unsalable. Due to the problem of frequent shortages, traditional time series and single product forecasting models are difficult to effectively cope with these characteristics.
A multi-product order quantity prediction model based on the self-attention mechanism is used to build multi-dimensional features, including fresh store features, sales day and date features, weather features, static and dynamic features of ordered goods, and static and dynamic features of unordered goods. Features, sequence-to-sequence model training, capturing the correlation of different fresh products during sales and the synergistic influence of external factors, and generating accurate order quantity forecasts.
It achieves accurate order quantity prediction for a variety of fresh products, can handle the unique characteristics of fresh products, such as the problem that sales volume is not equal to demand, and is suitable for fresh food stores under Nissin and non-Nissin models.
Smart Images

Figure CN118246970B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a model training and multi-item order quantity prediction method, computer equipment and medium. Background Art
[0002] Fresh food stores refer to retail stores that specialize in selling unprocessed or simply processed fresh foods, which usually include fresh vegetables, fruits, meat, seafood, dairy products and cooked food. The characteristics of fresh food stores are that the products have a short shelf life and need to be circulated quickly to ensure the freshness and quality of the food. Since fresh products are perishable, such stores face special challenges in terms of product procurement, inventory management, ordering strategies and sales strategies. In order to allow consumers to buy fresher products, some fresh food stores also adopt a daily clearance model. The daily clearance model means that the products that enter the store on the same day must be sold out on the same day. Under the daily clearance model, the sales period of all products is 1 day. In order to achieve daily clearance, fresh food stores will sell at a discount in the evening, and the products that have not been sold out by closing time will be directly reported as losses.
[0003] Fresh food stores mainly rely on the manual experience of store managers or store clerks to place orders, including determining the fresh products that need to be ordered and the demand for various fresh products (the demand is usually the order quantity). However, human experience varies greatly, and human computing power is limited, so it is difficult to place accurate orders. In recent years, with the development of artificial intelligence technology, many companies have used data analysis technologies based on machine learning and deep learning to predict market demand for specific products, and then place orders based on predicted demand information such as product sales. However, compared with other categories of goods, fresh products have three major characteristics: strong seasonality, short shelf life, and non-standardization. In terms of sales data, it will show characteristics such as occasional items, large price fluctuations, frequent slow sales and shortages. Moreover, there is a strong correlation between fresh products, including complementarity and substitutability. The current commodity demand forecasting scheme does not fully take into account the above characteristics of fresh products, and therefore cannot accurately predict the demand for fresh products. For example, the time series prediction model is a commonly used model for predicting commodity demand. However, many fresh products are sometimes available in fresh food stores, and their order and sales data are also intermittent on the time axis, so it is difficult to directly use the time series prediction model to predict the demand for fresh products. For another example, there is a correlation between fresh products, so the single-product prediction model commonly used in the field of commodity demand prediction cannot be used to predict the demand for fresh products. At this time, a multi-product prediction model needs to be introduced. However, the input features of traditional machine learning and deep learning are fixed, which is difficult to deal with fresh products that are sometimes available. If one or more corresponding features are constructed for all fresh products in history, the number of features will be very large and the data will be very sparse, which will make it difficult to train the multi-product prediction model. In addition, commodity demand forecasting usually predicts the future sales volume of the commodity, that is, the sales volume of the commodity is used as the demand for the commodity. However, fresh commodities are often unsalable and out of stock, which leads to the sales volume of fresh commodities often not being equal to the demand. Therefore, if only the sales volume of fresh commodities is predicted, the real demand will not be obtained. If the demand for multiple fresh commodities is to be predicted, the current commodity demand forecasting scheme is difficult to implement. Summary of the invention
[0004] In view of the above-mentioned deficiencies or shortcomings, the present application provides a model training and multi-item order quantity prediction method, computer equipment and medium, which can accurately predict the order quantity of multiple fresh commodities.
[0005] The present application provides a model training method according to a first aspect. In some embodiments, the method includes:
[0006] Construct multiple training samples based on multiple sample data collected in advance from multiple fresh food stores;
[0007] Build a multi-product order quantity forecasting model;
[0008] Using the multiple training samples to train the multi-product order quantity prediction model;
[0009] The multi-product order quantity prediction model is used to generate multi-dimensional features based on the input training samples, construct multiple sequence units based on the multi-dimensional features, and construct an input sequence based on the multiple sequence units; convert the received input sequence into a first transition sequence based on the self-attention mechanism; convert the first transition sequence into a second transition sequence through linear transformation, extract and output multi-product order quantity prediction information from the second transition sequence; the multi-dimensional features include store characteristics of the fresh food stores related to the training samples, date characteristics and weather characteristics of multiple store sales days, static product characteristics of each ordered product and dynamic operating characteristics including actual sales progress characteristics, and static product characteristics and dynamic operating characteristics of each non-ordered product.
[0010] In some embodiments, using the plurality of training samples to train the multi-item order quantity prediction model includes:
[0011] The multiple training samples are divided into multiple batches according to date binning and sequence length binning;
[0012] Determine the date of each batch, and determine the training order of each batch according to the date of each batch;
[0013] The multi-product order quantity prediction model is trained using each batch in turn according to the training order of each batch.
[0014] In some embodiments, the training process for each training of the multi-product order quantity prediction model includes:
[0015] Input a batch of training samples into the multi-product order quantity prediction model respectively;
[0016] Obtaining multi-product order quantity prediction information corresponding to each training sample output by the multi-product order quantity prediction model;
[0017] Calculate the prediction loss based on the multi-item order quantity prediction information and the multi-item order quantity actual information corresponding to each training sample;
[0018] The model parameters of the multi-product order quantity prediction model are updated according to the predicted loss.
[0019] In some embodiments, constructing a plurality of sequence units according to the multi-dimensional features, and constructing an input sequence according to the plurality of sequence units includes:
[0020] The store feature is taken as a sequence unit and recorded as the first sequence unit;
[0021] The date feature and weather feature of each store sales day are combined into a sequence unit, which is recorded as the second sequence unit; the number of the second sequence units is the same as the number of store sales days;
[0022] The static commodity characteristics of each ordered commodity and the dynamic operating characteristics including the actual sales progress characteristics are combined into a sequence unit, which is recorded as the third sequence unit; the number of the third sequence units is the same as the number of types of ordered commodities;
[0023] The static commodity characteristics and dynamic operation characteristics of each non-ordered commodity are combined into a sequence unit, which is recorded as the fourth sequence unit; the number of the fourth sequence units is the same as the number of types of non-ordered commodities;
[0024] The first sequence unit, each second sequence unit, each fourth sequence unit and any third sequence unit are feature aligned so that the dimensions of all sequence units are the same, and then the input sequence is constructed according to all sequence units.
[0025] In some embodiments, feature-aligning the first sequence unit, each second sequence unit, each fourth sequence unit, and any third sequence unit comprises:
[0026] Processing the first sequence unit by using the first feature space alignment transformation matrix so that the dimension of the processed first sequence unit is the same as the dimension of the third sequence unit;
[0027] Processing each second sequence unit by a second feature space alignment transformation matrix so that the dimension of each processed second sequence unit is the same as the dimension of the third sequence unit;
[0028] Each fourth sequence unit is processed by the third feature space alignment transformation matrix, so that the dimension of each processed fourth sequence unit is the same as the dimension of the third sequence unit.
[0029] In some embodiments, the input sequence is obtained according to all sequence unit constructions, including:
[0030] After feature alignment, all sequence units are stacked to obtain the initial input sequence;
[0031] Get the maximum sequence length of the batch used in this training;
[0032] Determine whether the sequence length of the initial input sequence is less than the maximum sequence length;
[0033] If so, padding units are added to the initial input sequence to obtain an input sequence with a sequence length equal to the maximum sequence length; the sequence length of the padding unit is equal to the maximum sequence length minus the sequence length of the initial input sequence.
[0034] In some embodiments, when the received input sequence is converted into a first transition sequence based on the self-attention mechanism, each padding unit in the input sequence is masked by a pre-built padding unit masking mechanism so that the attention weight of each padding unit is approximately 0.
[0035] In some embodiments, the date features of each store sales day include a holiday category feature and a holiday location feature, and the holiday category feature of each store sales day is used to indicate the holiday category corresponding to the store sales day; the holiday category includes non-holidays and multiple holidays; for any store sales day, when the holiday category feature of the store sales day indicates that the holiday category corresponding to the store sales day is any holiday, the holiday location feature of the store sales day is used to indicate on which day of the holiday the store sales day is located.
[0036] In some embodiments, when the received input sequence is converted into a first transition sequence based on the self-attention mechanism, the attention weights of each fresh product in the input sequence for dates and weather characteristics whose corresponding dates are after the sales period of the fresh product are masked through a pre-built date masking mechanism, so that the attention weights of each fresh product for dates and weather characteristics whose corresponding dates are after the sales period of the fresh product are 0.
[0037] According to a second aspect, the present application provides a method for predicting multi-item order quantities. In some embodiments, the method includes:
[0038] Obtain the optimal sales progress characteristics of multiple fresh products with predicted order quantities;
[0039] Inputting the optimal sales progress features of the multiple fresh commodities into a multi-product order quantity prediction model that has been trained in advance using the model training method provided in any of the above embodiments;
[0040] Obtaining multi-item order quantity forecast information output by the multi-item order quantity forecast model;
[0041] The order quantity forecast value of each fresh product is obtained from the multi-product order quantity forecast information.
[0042] According to a third aspect, the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the model training method or multi-product order quantity prediction method provided in any of the above embodiments is implemented.
[0043] According to a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the model training method or multi-product order quantity prediction method provided in any of the above embodiments is implemented.
[0044] Based on the discovery that the characteristics of sentences in a machine translation scenario and the characteristics of fresh food in a fresh food ordering scenario are basically the same, this application cleverly converts the fresh food ordering problem into a sequence-to-sequence problem, and then can handle the fresh food ordering problem based on the machine translation processing method, and achieve accurate prediction of the demand for various fresh foods.
[0045] In the above embodiment, multiple sample data are collected from multiple fresh food stores in advance, and multiple training samples are constructed based on the multiple sample data, and then the multiple training samples are used to train the multi-product order quantity prediction model based on the self-attention mechanism. The multi-product order quantity prediction model can generate multi-dimensional features according to the input training samples, construct multiple sequence units according to the multi-dimensional features, and construct an input sequence according to the multiple sequence units; convert the received input sequence into a first transition sequence based on the self-attention mechanism; convert the first transition sequence into a second transition sequence through a linear transformation, extract the multi-product order quantity prediction information from the second transition sequence and output it; wherein the input sequence is constructed by multi-dimensional features, and the multi-dimensional features include the relevant features of each fresh food product itself, the features of the fresh food store, the date features of the sales date, and the weather features, and then in the training process of the sequence-to-sequence model, it can capture the correlation of different fresh food products during sales through the self-attention mechanism, and at the same time take into account the synergistic effects of external factors such as stores, dates, and weather on the sales of fresh food products.
[0046] In some embodiments, by merging the static product characteristics and dynamic operating characteristics of the ordered product into a sequence unit, the model can identify which fresh product each dynamic operating characteristic belongs to, without arranging the dynamic operating characteristics of all fresh products in a fixed order, thereby reducing the complexity of the system.
[0047] In some embodiments, sales progress features are embedded in the relevant features of the ordered goods, and the output sequence of the sequence-to-sequence model is used to determine the order quantity of each fresh product. In addition, the actual sales progress features are used in the model training phase, and the optimal sales progress features are used in the model reasoning phase. The above feature setting method solves the problem that sales volume is not equal to demand volume. Subsequently, reasonable order quantities of fresh products can be obtained by setting reasonable sales progress features for fresh products. It is also worth pointing out that this embodiment can predict the order quantities of fresh products with different sales periods. Therefore, regardless of whether the fresh food store adopts a daily clearance mode or a non-daily clearance mode, this embodiment can be used to accurately predict the order quantities of a variety of fresh products.
[0048] In some embodiments, a small batch training method is used to train a multi-product order quantity prediction model, wherein, when batching multiple training samples, batching is implemented in accordance with date binning and sequence length binning methods, that is, first batching is performed by date binning method, and then further batching is performed by sequence length binning method, so that sample input sequences with similar dates are put in the same batch for training, and sequence input sequences with similar lengths are put in the same batch for training, and during training, batch data with earlier corresponding dates are first used for training, and then batch data with closer corresponding dates are used for training, so as to further improve the efficiency and effect of model training.
[0049] In some embodiments, to facilitate batch training, after the batching operation is completed, padding units are added to the initial input sequence whose sequence length in each batch is less than the maximum sequence length of the batch, so that the sequence length of each initial input sequence in each batch is equal to the maximum sequence length of the batch.
[0050] At the same time, in some embodiments, a mask mechanism is used to set a corresponding attention mask (which may be referred to as a filling unit mask) for the filling unit, so that the attention weight of each filling unit is approximately 0, thereby solving the problem that the stores in the same batch of data have different ordered goods and different quantities of ordered goods. Furthermore, a date mask mechanism is constructed to make each fresh product have a corresponding date that is 1 to 24 hours after the sales period of the fresh product. The attention weight of the date and weather features within the day is 0, which solves the problem that different fresh products are affected by holidays and weather on different dates due to their different sales periods. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 A flowchart of a model training method provided by the present application according to one or more embodiments;
[0052] Figure 2 A schematic diagram of a model architecture of a multi-product order quantity prediction model provided by the present application according to one or more embodiments;
[0053] Figure 3 A schematic diagram of a process for constructing an input sequence according to one or more embodiments of the present application;
[0054] Figure 4 A parameter statistical diagram of a multi-product order quantity prediction model provided by the present application according to one or more embodiments;
[0055] Figure 5 A flowchart of a method for predicting multi-product order quantities provided by the present application according to one or more embodiments;
[0056] Figure 6This is a diagram of the internal structure of a computer device provided by the present application according to one or more embodiments. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings. It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0058] When the following description refers to the 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 the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0059] In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0060] The inventor of the present application discovered that the task of machine translation is to translate sentence A into sentence B. Sentence A consists of a series of tokens. These tokens are correlated with each other, and the tokens of each sentence may be different, and the length of the sentences is also different. This feature is exactly consistent with the characteristics of fresh goods in the fresh goods ordering scenario, that is, there is a correlation between fresh goods, and the types of fresh goods ordered each time may be different, and the quantity of fresh goods ordered may also be different. Based on the discovery that the characteristics of sentences in machine translation scenarios and the characteristics of fresh goods in fresh goods ordering scenarios are basically the same, the fresh goods ordering problem can be cleverly converted into a sequence-to-sequence problem, and then the fresh goods ordering problem can be processed based on the processing method of machine translation, and accurate prediction of the demand for multiple fresh goods can be achieved. Among them, a model can be constructed to "translate" the information related to the sales of each fresh product into the order quantity of each fresh product.
[0061] Based on the above inventive concept, the present application provides a model training method. In some embodiments, the method includes: Figure 1 The steps shown are:
[0062] S110: constructing a plurality of training samples based on a plurality of sample data collected in advance from a plurality of fresh food stores.
[0063] S120: Build a multi-product order quantity prediction model.
[0064] S130: Use the multiple training samples to train the multi-product order quantity prediction model.
[0065] The multi-product order quantity prediction model is used to generate multi-dimensional features based on the input training samples, construct multiple sequence units based on the multi-dimensional features, and construct an input sequence based on the multiple sequence units; convert the received input sequence into a first transition sequence based on the self-attention mechanism; convert the first transition sequence into a second transition sequence through linear transformation, extract and output multi-product order quantity prediction information from the second transition sequence; the multi-dimensional features include store characteristics of the fresh food stores related to the training samples, date characteristics and weather characteristics of multiple store sales days, static product characteristics of each ordered product and dynamic operating characteristics including actual sales progress characteristics, and static product characteristics and dynamic operating characteristics of each non-ordered product.
[0066] See also Figure 2 , Figure 2 Shown is a schematic diagram of the architecture of a multi-product order quantity prediction model in some typical embodiments. The multi-product order quantity prediction model consists of three parts, namely, an input sequence generator, a Transformer encoder, and an output sequence generator.
[0067] The input sequence generator is used to generate multi-dimensional features based on the training data and to structure the multi-dimensional features to generate a sequence that can be input into the Transformer encoder.
[0068] The Transformer encoder is used to realize the conversion of the input sequence into the first transition sequence. Transformer is an encoder-decoder structure. Machine translation is predicted one word at a time, and the word predicted in the front will become the input information for predicting the following word. Therefore, when using the Transformer model to implement machine translation, it is necessary to use the encoder and decoder of the Transformer model at the same time. However, in the fresh product ordering scenario, there is no such situation. There is no order problem between fresh products. Therefore, only the encoder part of the Transformer is needed, and the decoder part of the Transformer is not needed. The encoder structure is basically the same as the original encoder of the Transformer. It should be noted that the Transformer encoder can have many layers, but in this embodiment, the number of layers of the encoder is only 2 or 3 layers.
[0069] The output sequence generator is used to generate multi-item order quantity forecast information according to the first transition sequence output by the encoder, wherein the multi-item order quantity forecast information includes the order quantity forecast value of each ordered commodity. The multi-item order quantity forecast information will be used to participate in the calculation of the loss function.
[0070] The following is a detailed description of each part.
[0071] An input sequence generator is used to generate multi-dimensional features according to the input training samples, construct multiple sequence units according to the multi-dimensional features, and construct an input sequence according to the multiple sequence units, and output the input sequence to the encoder.
[0072] The training samples are various feature data constructed based on the sample data. The input sequence generator maps the various feature data in the training samples into embedded representations, and splices the embedded representations into sequence data that meets the encoder input requirements according to preset rules, that is, a sequence including multiple sequence units. The above sample data can be collected from the historical data of multiple fresh food stores. For example, assuming that there are historical data of 300 fresh food stores in the past three years, these stores have a total of 357 sales days each year (that is, excluding the 8 days of the Spring Festival holiday). Assuming that each fresh food store places an order on each sales day, and each order is sampled once, then 357×3×300 =321,300 sample data can be obtained.
[0073] The sample data of each store every day includes various information that may affect the order quantity of fresh products, such as the store itself, the day of the week corresponding to the sales day, whether it is a holiday, the weather on the sales day, the recent sales volume and price of each fresh product, etc., and also includes the actual order quantity of each fresh product. Multi-dimensional features can be extracted from the sample data, which include store features of related fresh stores, date features and weather features of multiple store sales days, static product features of each ordered product and dynamic operating features including actual sales progress features, static product features and dynamic operating features of each unordered product.
[0074] In some embodiments, if an order is placed once a day, a store will generate one sample point a day. However, holidays account for a small proportion of a year. Even if the days before and after holidays are counted, it is still less than one-third of the whole year. The small proportion of holiday samples in the total samples will affect the training effect of holidays. In order to improve the training effect of holidays, the holidays can be sampled twice. This is equivalent to doubling the holiday data.
[0075] In some embodiments, the multi-dimensional features may include store features, The date characteristics and weather characteristics of each sales day within the sales day (including the arrival day), and the characteristics related to fresh products. The following is a detailed description of each feature.
[0076] Store features, which represent the demand characteristics of the customer base of fresh food stores. Understandably, the demand characteristics of customer bases in different stores are different. Store features can be embedded and represented by the embedding vector , the dimension is recorded as The value of its dimension is related to the number of stores, so its dimension can be set according to the number of stores in the actual scenario. For example, if the number of stores is 500, the embedding dimension of the store feature is It can be much smaller than 500, considering that the complexity of the demand characteristics of different customer groups in reality is not too high, so 10 dimensions are usually sufficient to describe them.
[0077] After arrival The date characteristics of each sales day within the sales days (including the arrival day). Different dates after arrival are marked with superscripts. To distinguish, Represents the arrival date, Represents the first sales day after the arrival date, and so on until . The value of is related to the sales period and the effective days of the weather forecast, and this embodiment does not impose any special restrictions on its value. The date characteristics of each sales day include the arrival day characteristics, the day of the week characteristics, and the holiday characteristics.
[0078] Regarding the arrival day feature, this feature is mainly used to indicate the corresponding arrival day of the relevant sales day. In the fresh product sales scenario, the sales situation is different when the first day of arrival (referring to the arrival day) is a holiday and the second day of arrival is a holiday, so it is necessary to distinguish the arrival day. Among them, the arrival day feature can be represented by a unique hot encoding, recorded as , the dimension is .
[0079] The day of the week feature is used to indicate the day of the week on which the relevant sales day falls. The day of the week feature represents the different consumption habits of customers on seven days of the week, such as the increase in demand on weekends. This feature is a relatively simple category feature and can be directly embedded. The embedding vector is recorded as , the embedding dimension is recorded as There are 7 days in a week, so the dimension The value of can be less than 7, and the complexity of this habit feature will not be too high, so the dimension Can be set to 2 or 3.
[0080] Regarding holiday characteristics, considering that holiday situations are relatively complicated, this embodiment divides holiday characteristics into two characteristics, namely holiday category characteristics and holiday location characteristics, for separate characterization. This can more carefully characterize the impact of holidays on the sales of fresh products.
[0081] Regarding the holiday category feature, it is used to indicate which holiday category the relevant sales day corresponds to. Holiday categories include non-holidays and multiple holidays. The following takes Chinese holidays as an example. Chinese holidays include New Year's Day, Spring Festival, Qingming Festival, Labor Day, Dragon Boat Festival, Mid-Autumn Festival, and National Day, a total of 7 categories. Adding non-holidays, the holiday category can be divided into 8 categories. Therefore, the holiday category feature can be embedded in a 2- or 3-dimensional space, and the embedding vector is recorded as .
[0082] The holiday category feature of each sales day is used to indicate the holiday category corresponding to the store sales day. For any sales day, when the holiday category feature of the sales day indicates that the holiday category corresponding to the sales day is any holiday, the holiday position feature of the sales day is used to indicate which day of the holiday the sales day is located on. To mark the middle day of a holiday (odd-numbered holidays, such as Labor Day, which lasts 5 days) or two days (even-numbered holidays, such as Spring Festival, which lasts 8 days), the day before the middle day is recorded as , 2 days ago is recorded as , and so on; the day after the middle day is recorded as , and the next 2 days are recorded as , and so on. In addition, if the holiday category feature of the relevant sales day indicates whether the holiday category corresponding to the sales day is a non-holiday, the holiday position feature is also recorded as . Preferably, considering the particularity of fresh product sales, its sales will be affected not only during holidays, but also before and after holidays, especially around the Spring Festival. Therefore, the impact of holidays can be expanded. For example, for the Spring Festival, the 20 days before the festival and the 30 days after the festival (the specific number of days is only for example) can be taken into account. That is, any day within 20 days before the festival or any day within 30 days after the festival, the corresponding holiday category is the Spring Festival. At this time, the holiday position characteristics of these dates are also determined according to the previous rules.
[0083] Regarding the weather characteristics of each sales day, in some embodiments, the characteristics are used to represent the weather category corresponding to the relevant sales day. In other embodiments, considering that the weather will have an impact on the sales or demand of fresh goods, however, there is a difficulty in considering weather factors, namely the accuracy of the weather forecast. At present, the weather forecast two days later is difficult to be accurate to the hourly level, especially whether it will rain, how heavy the rain will be, etc. It is difficult to predict accurately, therefore, this embodiment does not consider raining. At the same time, considering that the temperature also has a certain impact on the sales of fresh goods, especially the sudden temperature rise and sudden temperature drop will have a significant impact, and the forecast of the temperature will be relatively more accurate, therefore, this embodiment divides the weather characteristics into 4 characteristics to characterize, namely: the lowest temperature , maximum temperature , the change of the minimum temperature relative to the previous day and the change in maximum temperature relative to the previous day . These features are all scalars.
[0084] Fresh product related features, which represent the relevant information unique to the fresh product itself.
[0085] In some embodiments, the feature refers to a feature related to the fresh product that was ordered at the time of sampling.
[0086] In other embodiments, considering that in the sales scenario of fresh goods, the sales of unordered fresh goods will also affect the order quantity of ordered goods. For example, a store has just finished a promotion of black pork and will no longer sell black pork. At this time, the sales of white pork will also be affected. Therefore, the fresh product-related features of this embodiment are specifically divided into ordered product-related features and unordered product-related features.
[0087] The characteristics related to ordered goods refer to the characteristics related to fresh goods that are ordered at the time of sampling, which can be specifically divided into static goods characteristics and dynamic business characteristics. The characteristics related to unordered goods refer to the characteristics related to fresh goods that are not ordered at the time of sampling, which can also be specifically divided into static goods characteristics and dynamic business characteristics.
[0088] Among them, the static product features in the ordered product related features and the unordered product related features refer to the product SKU embedding, which is recorded as , which represents the demand characteristics of fresh products (subscripts are used to distinguish different fresh products) themselves, and its dimensions are recorded as , The value of is related to the number of products. For example, if there are 2,000 products (or 2,000 SKUs) in the training data, then the dimension of the product SKU embedding is You can choose between 6 and 12.
[0089] There are some differences between the dynamic operating features in the features related to ordered goods and those in the features related to non-ordered goods. Among them, the dynamic operating features in the features related to ordered goods include the recent sales volume vector, the in-transit order volume vector, the inventory volume at the time of ordering, the inventory volume at the time of ordering, whether it is a promotional product, the product price, the price change rate, and the sales progress feature. The dynamic operating features in the features related to non-ordered goods only include the recent sales volume vector, the in-transit order volume vector, and the inventory volume at the time of ordering.
[0090] Recent sales volume vector, which represents fresh products exist to Days (inclusive and The actual sales volume of each day is recorded as , whose dimension is . Indicates the order date, represents M days before the order date. Since the shelf life of fresh products is relatively short, the demand on the day will not be affected by the sales in the past. Just take 3 or 4.
[0091] The vector of in-transit orders represents fresh goods. exist to Days (inclusive and The actual order quantity for each day is recorded as , its dimension . Indicates the store arrival date. The value of N can be determined based on the actual order-to-arrival time. For example, chain stores usually have the goods arrive the day after the order date. Usually it is 2.
[0092] The inventory quantity at the time of ordering, which refers to fresh goods The inventory quantity at the time of ordering is recorded as , which is a scalar and thus has dimension 1.
[0093] Whether it is a promotional product, which means fresh products Whether it is sold as a promotional item, recorded as , which is a scalar. The value is 0 or 1, 1 means yes, 0 means no.
[0094] Product price, which refers to fresh products The price on the arrival date is , which is a scalar.
[0095] Price change rate, which refers to fresh products The rate of change of the price on the arrival day relative to the price on the previous day is recorded as , which is a scalar.
[0096] This implementation method specifically divides the sales progress characteristics into two characteristics: the commodity sales time and the unsalable inventory amount for characterization, so as to more carefully characterize the impact of the sales progress characteristics on the sales of fresh commodities.
[0097] The length of time the product is sold, which refers to fresh products The sales time after arriving at the store is recorded as It should be noted that the value of this feature is different during model training and inference. It is fresh product For example, for daily clearance products (i.e., sales period ), assuming that the store opens at 6:00 and closes at 21:00 (i.e. 15 hours of sales per day), if the fresh goods Sold out at 12:00, then If it is still not sold out at 21 o'clock, then For non-Nissin products, such as , still assuming that the store opens at 6:00 and closes at 21:00, if the fresh goods If it is sold out at 12:00 on the second day after arrival, If fresh goods If it is still not sold out at 21:00 on the third day after arrival, then In order to reduce the difficulty of training, this implementation does not take into account the nighttime non-business hours. In the inference and prediction stage, in order to obtain the "real" demand or the "optimal" order quantity, Fresh goods For daily clearance items, we usually choose the time when the discounted price is equal to the cost, for example, 20 o'clock. For non-daily clearance items, the optimal sales time can be selected to be 1 to 2 hours shorter than the maximum sales time, that is or .
[0098] Unsalable inventory, which refers to fresh goods The remaining inventory after the maximum sales period is recorded as The value of this feature is different during model training and inference. Pick up fresh goods The actual remaining inventory after the maximum sales time. For example, for a daily clearance product, if 2 kg is left at 21:00, then The same applies to non-daily clearance items. For items sold out in advance, In order to obtain the real demand during inference and prediction, we usually set Of course, in some cases, Configured as a certain safety stock.
[0099] In some implementations, the features of each dimension (such as store, date, weather, fresh products, etc.) can be respectively used as a sequence unit, and then all the sequence units are feature aligned and then stacked to obtain a two-dimensional tensor (or matrix) as an input sequence.
[0100] In some other embodiments, a plurality of sequence units are constructed according to the multi-dimensional features, and an operation of obtaining an input sequence is constructed according to the plurality of sequence units, such as Figure 3 As shown, including:
[0101] S210: Take the store feature as a sequence unit, recorded as the first sequence unit.
[0102] S220: Combining the date feature and weather feature of each store sales day into a sequence unit, recorded as a second sequence unit; the number of the second sequence units is the same as the number of store sales days.
[0103] The following formula can be used to combine the date characteristics and weather characteristics of each sales day. That is: ;
[0104] The vector dimensions are: ;
[0105] Assumptions ,but .
[0106] S230: Combine the static commodity characteristics of each ordered commodity and the dynamic business characteristics including the actual sales progress characteristics into one sequence unit, recorded as the third sequence unit; the number of the third sequence units is the same as the number of types of ordered commodities.
[0107] Among them, the following formula can be used to combine the static product characteristics and dynamic business characteristics of each order product: ;
[0108] The vector dimensions are: ;
[0109] Assumptions , , ,but .
[0110] S240: Combine the static product characteristics and dynamic business characteristics of each unordered product into one sequence unit, recorded as the fourth sequence unit; the number of the fourth sequence units is the same as the number of types of the unordered products.
[0111] Among them, the following formula can be used to combine the static product characteristics and dynamic business characteristics of each unordered product: ;
[0112] The vector dimensions are: ;
[0113] Assumptions , , ,but .
[0114] S250: aligning the features of the first sequence unit, each second sequence unit, each fourth sequence unit and any third sequence unit so that the dimensions of all sequence units are the same, and then constructing an input sequence according to all sequence units.
[0115] In this embodiment, the multi-dimensional features are specifically divided into four independent feature spaces, namely: store features (denoted as ), date and weather characteristics (denoted as ), order product related features (denoted as ), and the characteristics of non-ordered goods (denoted as ). This makes the store feature a sequence unit, each sales day and its corresponding date feature and weather feature a sequence unit, and each fresh product's related feature also corresponds to a sequence unit.
[0116] From the above description, we can see that the store characteristics (i.e. first sequence unit), date and weather characteristics (i.e., the second sequence unit), order product related features (i.e., the third sequence unit), and features related to unordered goods The dimensions of (i.e., the fourth sequence unit) can be different, i.e. , and the meanings of the features are also different, so feature alignment is required to make all features in the same feature space.
[0117] This embodiment realizes feature alignment through linear transformation. In some embodiments, feature alignment of the first sequence unit, each second sequence unit, each fourth sequence unit and any third sequence unit includes:
[0118] Processing the first sequence unit by using the first feature space alignment transformation matrix so that the dimension of the processed first sequence unit is the same as the dimension of the third sequence unit;
[0119] Processing each second sequence unit by a second feature space alignment transformation matrix so that the dimension of each processed second sequence unit is the same as the dimension of the third sequence unit;
[0120] Each fourth sequence unit is processed by the third feature space alignment transformation matrix, so that the dimension of each processed fourth sequence unit is the same as the dimension of the third sequence unit.
[0121] Specifically, due to The value of is the largest, so when the features are aligned, the linear transformation is used to transform Transform to Dimensional space:
[0122] ;
[0123] ;
[0124] ;
[0125] Among them, the first feature space alignment transformation matrix, the second feature space alignment transformation matrix, and the third feature space alignment transformation matrix are respectively , the dimensions of each transformation matrix are , ,as well as .
[0126] After completing the above feature alignment operation, all sequence units are stacked together to form a two-dimensional tensor (or matrix), which can be used as the input sequence of the sequence-to-sequence model.
[0127] Among them, stacking can be achieved by the following formula:
[0128]
[0129] This embodiment combines the static commodity features and dynamic business features of the ordered commodity into a sequence unit, so that the model can identify which fresh commodity each dynamic business feature is the business feature of, without arranging the dynamic business features of all fresh commodities in a fixed order, thereby reducing the complexity of the system. At the same time, this embodiment also embeds the sales progress feature in the relevant features of the ordered commodity, and uses the output sequence of the sequence-to-sequence model to determine the order quantity of each fresh commodity. In addition, the actual sales progress feature is used in the model training stage, and the optimal sales progress feature is used in the model reasoning stage. The above feature setting method solves the problem that sales volume is not equal to demand. Subsequently, a reasonable order quantity of fresh commodities can be obtained by setting a reasonable sales progress feature for fresh commodities. It is also worth pointing out that this embodiment can predict the order quantity of fresh commodities with different sales periods. Regardless of whether the fresh food store adopts a daily clearance mode or a non-daily clearance mode, this embodiment can be used to accurately predict the order quantity of a variety of fresh commodities.
[0130] Regarding the encoder, it is used to convert the received input sequence into a first transition sequence based on the self-attention mechanism.
[0131] The encoder of this embodiment has 2 or 3 layers, and each layer of the encoder consists of three modules: multi-head self-attention mechanism, normalization, and feedforward network.
[0132] About the multi-head self-attention mechanism:
[0133] First, the input sequence Perform linear transformation to obtain the query matrix (Query matrix, denoted as ), key matrix (Key matrix, denoted as ) and the value matrix (Value matrix, denoted as ):
[0134] ;
[0135] ;
[0136] ;
[0137] The above Both The self-attention weight can be written as:
[0138] ;
[0139] ;
[0140] in Indicates transpose.
[0141] The multi-head attention mechanism can capture more information. , , Divide into multiple parts, perform attention calculations separately, and then splice them together. , , Divide part, that is head, each part can be written as , they are The matrix of Therefore, to do multi-head attention, when constructing features, we must quilt Divisible.
[0142] ;
[0143] .
[0144] in yes The matrix obtained is a In code implementation, the multi-head attention mechanism can be quickly implemented by using tensor deformation operations.
[0145] About standardization:
[0146] right Each row vector of is Z-score standardized and then scaled.
[0147]
[0148] represents the attention weight of the i-th element in the input sequence; and All are of length Vector.
[0149] About feedforward networks:
[0150]
[0151] represents the output of the feedforward network. yes , yes The matrix of Is the length The vector of Is the length That is, a ReLU activation function is added between the two fully connected layers.
[0152] The final output sequence of the encoder (i.e. the first transition sequence) is of dimension A two-dimensional tensor of .
[0153] Regarding the output sequence generator, the first transition sequence is converted into a second transition sequence through linear transformation, and the multi-item order quantity forecast information is extracted from the second transition sequence and outputted. The multi-item order quantity forecast information is the output sequence generated by the output sequence generator.
[0154] The output sequence generator converts the first transition sequence into the second transition sequence by the following formula:
[0155] ;
[0156] is the first transition sequence output by the encoder, with dimension , is a dimensional column vector, is the second transition sequence obtained by linearly transforming the first transition sequence, which has a dimension of The column vector of , written in vector form is:
[0157] .
[0158] in Ordered goods The order quantity forecast values are called multi-item order quantity forecast information. The forecast loss will be calculated based on the multi-item order quantity forecast information corresponding to all sample input sequences of the same batch, and the model parameters will be updated based on the forecast loss. None of them participate in the calculation of the loss function. means and The loss function of this embodiment is preferably a loss function that is not very sensitive to outliers, such as the MAE (Mean Absolute Error) loss function. The formula of the MAE loss function is as follows: ; Among them, is the order quantity forecast value, is the true value (i.e. the actual order quantity). The Mean operation is performed on all samples and all ordered items in the batch.
[0159] Regarding the training of the multi-item order quantity prediction model, in some embodiments, the training process for each training of the multi-item order quantity prediction model includes: inputting a batch of training samples into the multi-item order quantity prediction model respectively; obtaining the multi-item order quantity prediction information corresponding to each training sample output by the multi-item order quantity prediction model; calculating the prediction loss based on the multi-item order quantity prediction information corresponding to each training sample and the multi-item order quantity actual information; and updating the model parameters of the multi-item order quantity prediction model according to the prediction loss.
[0160] In order to improve the training efficiency and stability during training and obtain higher model performance, this embodiment adopts batch training to train the multi-item order quantity prediction model. That is, during each training, a batch of training samples are input into the multi-item order quantity prediction model, and the model processes each input training sample and outputs a corresponding output sequence, i.e., multi-item order quantity prediction information. For each training sample corresponding to the multi-item order quantity prediction information, it is necessary to calculate the loss corresponding to the training sample according to the multi-item order quantity prediction information, and then average the losses corresponding to all training samples in the batch to obtain the prediction loss, and finally update the model parameters according to the prediction loss, and one training can be completed.
[0161] Accordingly, in some embodiments, an input sequence is constructed based on all sequence units, including: after feature alignment, stacking all sequence units to obtain an initial input sequence; obtaining the maximum sequence length of the batch used for this training; determining whether the sequence length of the initial input sequence is less than the maximum sequence length; if so, adding padding units to the initial input sequence to obtain an input sequence with a sequence length equal to the maximum sequence length; the sequence length of the padding unit is equal to the maximum sequence length minus the sequence length of the initial input sequence.
[0162] In this embodiment, generally, each sample data can be used to construct an initial input sequence. The construction method of the initial input sequence can refer to the description of constructing the corresponding input sequence according to the training sample in the above embodiment, which will not be repeated here. In order to facilitate batch training, this embodiment will determine the maximum sequence length of each batch (the sequence length can be recorded as , ), when constructing the input sequence, the input sequence generator can add padding units to the initial input sequence whose sequence length is less than the maximum sequence length. This operation can make the sequence length of each input sequence obtained in each batch the same.
[0163] Furthermore, in some embodiments, the process of training a multi-product order quantity prediction model using multiple training samples includes: dividing the multiple training samples into multiple batches in sequence according to date binning and sequence length binning; determining the date of each batch, and determining the training order of each batch according to the date of each batch; and, using each batch in sequence according to the training order of each batch to train the multi-product order quantity prediction model.
[0164] When determining the training order of each batch according to the date of the training samples of each batch, for each batch, the farther the date of the batch is from the current date, the earlier the training order is set for the batch. The date of each batch can be a range, and each training sample in each batch has a corresponding sampling time, and then the range is determined by the sampling time of the earliest training sample and the sampling time of the latest training sample in each batch.
[0165] Taking into account the obvious seasonality of fresh product sales, the closer the data is to the current time, the greater the reference value. At the same time, considering that in order to improve the convenience of batch training in the above embodiment, it is necessary to add filling units in specific sequences in each batch, and when there are more filling units in each batch, the memory overhead will increase, affecting the calculation efficiency. Therefore, when batching the training samples, this embodiment first batches them according to the date binning method, and then further batches them according to the sequence length binning method, so that the training samples with similar dates are put together for training, and when training, early batch data are used for training first, and recent batch data are used for training later, so as to make fuller use of the reference value of the sample data, thereby making the training effect of the model better; at the same time, the above batching method will also put sequences with similar lengths in one batch, which can reduce the number of filling units in each batch, thereby reducing memory overhead and improving calculation efficiency.
[0166] In some embodiments, when the encoder converts the received input sequence into a first transition sequence based on the self-attention mechanism, each padding unit in the input sequence is masked through a pre-built padding unit masking mechanism so that the attention weight of each padding unit is approximately 0.
[0167] Taking into account the presence of padding units in some input sequences of the input encoder, this embodiment pre-sets padding unit masks (referring to attention masks set for padding units) through a mask mechanism. These padding unit masks can make the attention weight of each padding unit approximately 0, so that these padding units will basically have no effect on the prediction results of the demand for fresh goods.
[0168] In some embodiments, when the received input sequence is converted into a first transition sequence based on the self-attention mechanism, the date features in the input sequence are masked through a pre-built date masking mechanism, so that the attention weight of each fresh product to the date features and weather features within 1 to k days after its sales period is 0.
[0169] In this embodiment, fresh products with different sales periods are affected by the date characteristics and weather characteristics of different sales days. For example, fresh products with a sales period of 1 day are only affected by the day of the week characteristics, holiday characteristics and weather characteristics of the first day, and are not affected by the relevant date characteristics and / or weather characteristics of the second day and subsequent dates. For this reason, this embodiment performs corresponding masking on "fresh product-date" to reduce the impact of the above factors. Specifically, when converting the received input sequence into the first transition sequence based on the self-attention mechanism, the attention weight of each fresh product in the input sequence for the date and weather characteristics whose corresponding date is after the sales period of the fresh product is masked through the pre-constructed date masking mechanism, so that the attention weight of each fresh product for the date and weather characteristics whose corresponding date is after the sales period of the fresh product is 0.
[0170] Among them, the following mask processing can be used:
[0171] .
[0172] i is used to represent the i-th fresh product, and j is used to represent the j-th date and weather characteristics (the characteristics obtained by combining date characteristics and weather characteristics). The above formula can be used to represent the i-th fresh product in the input sequence with the corresponding date between 1 and 2 after the sales period. The attention scores of the date and weather features within the day are set to negative infinity, so that the corresponding attention weights after softmax are set to 0. K represents the number of sales days after the arrival of fresh goods whose date features and weather features may affect the sales of fresh goods.
[0173] In some embodiments, if the number of SKUs of fresh products increases, the embedding parameters of the static product features of the fresh products will increase, but the number of samples will not increase.
[0174] For example, the following assumptions can be made about the parameters of the multi-item order quantity forecasting model: Assumptions , , ,but Assumptions , , but , Assumptions , , ; Assuming that the encoder has 2 layers; then the parameter statistics of the multi-product order quantity prediction model are as follows Figure 4 shown.
[0175] It can be seen that the number of model parameters is independent of the sequence length and the number of padding units. All padding units only add one product SKU embedding, that is, parameters. Because there are many types of fresh products, the parameters for embedding the product SKU account for the largest proportion of all parameters. A large number of model parameters require a large amount of training data to train. Assuming that each fresh food store has historical data for the past three years, and the Spring Festival holiday is 8 days, that is, there are 357 sales days each year, and each store orders once a day, the amount of sample data that can be sampled is: 357×3×300=321300. This amount of data is sufficient to train the above parameters.
[0176] However, if the number of SKUs of fresh goods increases, the parameters for embedding the product SKUs will also increase accordingly, but the number of samples will not increase as a result. Therefore, when the number of SKUs of fresh goods reaches a certain level, the number of samples will not be sufficient to train the model parameters. In response to this problem, the present embodiment applies pre-training technology to first determine all or part of the embedding parameters of the static product features of fresh goods. For example, a BERT model can be constructed to pre-train the static product features of fresh goods. In order to make the obtained static product features of fresh goods (i.e., product SKU embedding) more suitable for the ordering scenario of fresh goods, the embedding parameters of the static product features also need to be fine-tuned. Exemplarily, the relevant pre-training and fine-tuning schemes are as follows:
[0177] Entity recognition: First, segment the text data. Before segmentation, you can edit some fresh product dictionaries in advance. After segmentation, you need to replace synonyms for fresh products. For example, replace all tomatoes with tomatoes.
[0178] Pre-training: Build a BERT model and use fresh product text data to pre-train the BERT model, so that the BERT model can obtain the product SKU embedding of fresh products. The dimension of the static product features of fresh products used to construct the input sequence is During pre-training, the embedding dimension of the static product features of fresh products output by the BERT model must be less than .
[0179] Fine-tuning: The product SKU embeddings given by the pre-trained BERT (Bidirectional Encoder Representations from Transformers) model cannot fully capture the product characteristics in the fresh product sales scenario, so we need to fine-tune the product SKU embeddings. The fine-tuning method can be to add one or more layers on the basis of the pre-trained BERT model to expand the dimension of the product SKU embedding output by the BERT model to For example, the dimension of the product SKU embedding output by the BERT model is , then we can add two more dimensions on the basis of the newly added layer structure, so that the dimension of product SKU embedding becomes The features of the first 8 dimensions are fixed during training, while the features of the two newly added dimensions are learnable parameters.
[0180] In some embodiments, in order to further reduce the difficulty of training, some of the above features can be standardized. Indicates which day falls on a holiday, and has nothing to do with the product, so all data can be standardized. Weather characteristics , , and It can also be standardized. Indicates the sales time of fresh products. Although this feature is related to the product, the magnitude and dimension of this feature are the same for all products, so all products can be standardized. , , , , and All of them are related to fresh products, and their magnitude or dimension may be different for different products, so each product needs to be standardized separately. Other embedded features, Boolean features and ratio features do not need to be standardized. Optionally, for all features that need to be standardized, a standardization method that is insensitive to outliers, such as Z-score, is used for processing.
[0181] It should be noted that, with respect to the various steps included in the method for predicting the multi-item order quantity provided in any of the above embodiments, unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of these steps can include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0182] Based on the same inventive concept, the present application also provides a method for predicting multi-item order quantities. In some embodiments, Figure 5 As shown, the multi-item order quantity forecasting method includes:
[0183] S310: Obtaining optimal sales progress characteristics of multiple fresh products with order quantities to be predicted;
[0184] S320: Inputting the optimal sales progress features of the multiple fresh commodities into a trained multi-product order quantity prediction model; wherein the multi-product order quantity prediction model is pre-trained using the model training method provided in any of the above embodiments;
[0185] S330: Obtaining multi-item order quantity forecast information output by the multi-item order quantity forecast model;
[0186] S340: Obtain the order quantity forecast value of each fresh product from the multi-product order quantity forecast information.
[0187] In this embodiment, the order quantity of multiple fresh products is predicted by using a pre-trained multi-product order quantity prediction model, wherein a fresh product may refer to a fresh food SKU (Stock Keeping Unit).
[0188] In some embodiments, for a variety of fresh products (which may be referred to as ordered products) in a fresh food store whose order quantities need to be predicted, for example, all or part of the fresh products in a fresh food store, the person in charge of ordering in the store (such as a store manager) only needs to set the optimal sales progress characteristics of each ordered product through a store terminal (such as a laptop computer, a mobile smart device such as a smart phone, a PC, etc.) and trigger a prediction instruction. The prediction system (referring to a system used to predict the order quantity of ordered products for each fresh food store, specifically a computer device deployed with a multi-product order quantity prediction model, such as a server) will automatically obtain the latest feature data of the store (including the optimal sales progress characteristics of each ordered product in the store) and input it into the multi-product order quantity prediction model. The method for determining the optimal sales progress characteristics of the ordered products can refer to the description of the above embodiment. The input sequence generator of the multi-product order quantity prediction model will process the received feature data into multiple sequence units, and perform operations such as feature space alignment and stacking on these sequence units to construct an input sequence that meets the input requirements of the encoder. The input sequence is then input into the encoder, and the encoder performs a series of processing on the input sequence, converts it into another sequence and outputs it to the output sequence generator. The sequence output by the encoder implies the core content and meaning captured by the encoder from the input sequence. The subsequent output sequence generator can determine the order quantity of various order items based on the sequence output by the encoder. For example, the sequence output by the encoder can be converted into a column vector (i.e., the second transition sequence mentioned above) through linear transformation, and then the multi-product order quantity prediction information is extracted from the column vector and output, and the multi-product order quantity prediction information includes the order quantity prediction values of various order items.
[0189] After receiving the prediction instruction, the prediction system will obtain the latest feature data of the relevant fresh food stores, including store characteristics, The date characteristics and weather characteristics of each sales day within the sales days (including the arrival day), the relevant characteristics of each ordered product (including the optimal sales progress characteristics of each ordered product), and the relevant characteristics of each unordered product.
[0190] The various characteristics of the above stores can be automatically maintained by the data warehouse system. Take the date characteristics and weather characteristics of each sales day after the arrival date of a store as an example. Assuming that today is the ordering day and the arrival date is the day after tomorrow, the calendar can be used to determine the date characteristics of each day during the K days from the day after tomorrow (such as the day of the week, holiday category, holiday location, etc.), and the real-time weather forecast information can be used to determine the weather characteristics of each day during the K days from the day after tomorrow (such as the weather category; or the lowest temperature, the highest temperature, the change in the lowest temperature relative to the previous day, and the change in the highest temperature relative to the previous day).
[0191] Furthermore, the optimal sales progress feature of each ordered commodity of each fresh food store can be set by the store staff or pre-configured, and the configuration information of the optimal sales progress feature of each ordered commodity of each fresh food store can be flexibly adjusted according to demand. Then, when predicting the order quantity of various ordered commodities of the fresh food store each time, the optimal sales progress feature of each ordered commodity can be obtained according to the relevant configuration information, thereby reducing the workload of each fresh food store in setting the optimal sales progress feature of each ordered commodity each time an order is placed.
[0192] Furthermore, a scheduled task for predicting the order quantity of ordered goods can be set for each fresh food store. The scheduled task will automatically trigger the prediction instruction. In response to the prediction instruction, the prediction system will obtain the latest feature data of the relevant fresh food stores and process the latest feature data through a multi-product order quantity prediction model to predict the order quantity of each ordered commodity.
[0193] For the specific limitations of the multi-product order quantity prediction method, please refer to the limitations of the model training method above, which will not be repeated here.
[0194] In some embodiments, the present application provides a computer device, whose internal structure diagram can be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as the optimal sales progress characteristics of a variety of fresh commodities whose order quantities are to be predicted. The specific stored data can also be found in the definitions in the above method embodiments. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a model training method or a multi-product order quantity prediction method is implemented.
[0195] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0196] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the model training method or multi-product order quantity prediction method provided in any of the above embodiments can be implemented.
[0197] In some embodiments, the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the model training method or multi-product order quantity prediction method provided in any of the above embodiments is implemented.
[0198] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0199] Those of ordinary skill in the art can understand that all or part of the processes in the above method embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink), DRAM (SLDRAM), memory bus (Rambus), direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0200] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0201] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A model training method, characterized in that: The method comprises: Construct multiple training samples based on multiple sample data collected in advance from multiple fresh food stores; Build a multi-product order quantity forecasting model; The multi-product order quantity prediction model is trained using the multiple training samples; the multi-product order quantity prediction model is used to generate multi-dimensional features according to the input training samples, construct multiple sequence units according to the multi-dimensional features, and construct an input sequence according to the multiple sequence units; based on the self-attention mechanism, the received input sequence is converted into a first transition sequence; the first transition sequence is converted into a second transition sequence by linear transformation, and multi-product order quantity prediction information is extracted from the second transition sequence and output; the multi-dimensional features include store characteristics of the fresh food stores related to the training samples, date characteristics and weather characteristics of multiple store sales days, static product characteristics and dynamic operating characteristics of each ordered product, and static product characteristics and dynamic operating characteristics of each non-ordered product; the dynamic operating characteristics of each ordered product include recent sales volume vector, in-transit order volume vector, inventory at the time of ordering, whether it is a promotional product, product price, price change rate and sales progress characteristics; the dynamic operating characteristics of each non-ordered product only include recent sales volume vector, in-transit order volume vector and inventory at the time of ordering; Constructing a plurality of sequence units according to the multi-dimensional features, and constructing an input sequence according to the plurality of sequence units, including: taking the store features as a sequence unit, recorded as a first sequence unit; merging the date features and weather features of each store sales day into a sequence unit, recorded as a second sequence unit; the number of the second sequence units is the same as the number of store sales days; merging the static product features of each ordered product and the dynamic business features including the actual sales progress features into a sequence unit, recorded as a third sequence unit; the number of the third sequence units is the same as the number of types of ordered products; merging the static product features and the dynamic business features of each unordered product into a sequence unit, recorded as a fourth sequence unit; the number of the fourth sequence units is the same as the number of types of unordered products; aligning the features of the first sequence unit, each of the second sequence units, each of the fourth sequence units, and any of the third sequence units, so that the dimensions of all sequence units are the same, and then constructing an input sequence according to all sequence units; When the received input sequence is converted into a first transition sequence based on the self-attention mechanism, the attention weights of each fresh product in the input sequence for dates and weather characteristics whose corresponding dates are after the sales period of the fresh product are masked through a pre-constructed date masking mechanism, so that the attention weights of each fresh product for dates and weather characteristics whose corresponding dates are after the sales period of the fresh product are 0.
2. The method according to claim 1, characterized in that Using the plurality of training samples to train the multi-item order quantity prediction model includes: Dividing the plurality of training samples into a plurality of batches according to date binning and sequence length binning in sequence; Determine the date of each batch, and determine the training order of each batch according to the date of each batch; The multi-item order quantity prediction model is trained using each batch in turn according to the training order of each batch.
3. The method according to claim 1 or 2, characterized in that The training process for each training of the multi-product order quantity prediction model includes: Inputting a batch of training samples into the multi-product order quantity prediction model respectively; Obtaining multi-product order quantity prediction information corresponding to each training sample output by the multi-product order quantity prediction model; Calculate the prediction loss based on the multi-item order quantity prediction information and the multi-item order quantity actual information corresponding to each training sample; The model parameters of the multi-item order quantity prediction model are updated according to the predicted loss.
4. The method according to claim 1, characterized in that Performing feature alignment on the first sequence unit, each of the second sequence units, each of the fourth sequence units, and any of the third sequence units, comprises: Processing the first sequence unit by a first feature space alignment transformation matrix so that the dimension of the processed first sequence unit is the same as the dimension of the third sequence unit; Processing each of the second sequence units by a second feature space alignment transformation matrix so that the dimension of each processed second sequence unit is the same as the dimension of the third sequence unit; Each of the fourth sequence units is processed by a third feature space alignment transformation matrix, so that the dimension of each processed fourth sequence unit is the same as the dimension of the third sequence unit.
5. The method according to claim 1, characterized in that The date features of each store sales day include holiday category features and holiday location features. The holiday category features of each store sales day are used to indicate the holiday category corresponding to the store sales day; the holiday categories include non-holidays and multiple holidays; for any store sales day, when the holiday category features of the store sales day indicate that the holiday category corresponding to the store sales day is any holiday, the holiday location features of the store sales day are used to indicate on which day of the holiday the store sales day is located.
6. A method for predicting multi-item order quantities, characterized in that: The method comprises: Obtain the optimal sales progress characteristics of multiple fresh products with predicted order quantities; Inputting the optimal sales progress features of the multiple fresh commodities into a multi-product order quantity prediction model that has been pre-trained using the model training method described in any one of claims 1 to 5; Obtaining multi-item order quantity forecast information output by the multi-item order quantity forecast model; The order quantity forecast value of each of the fresh products is obtained from the multi-product order quantity forecast information.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
