Skip to main content
. 2024 Nov 20;13(22):3697. doi: 10.3390/foods13223697
Algorithm 2 Sentiment prediction model training algorithm.
  • Require: 

    Dateset Data={xn}; The expected number of hidden layers N; The number of pre-training iterations is T

  • Ensure: 

    Optimization results; Sentiment prediction; Weights

  •  1:

    Collect early-stage user comments on food public sentiment, analyze them, calculate the number of negative and positive sentiments, and use them as the training dataset Data.

  •  2:

    Collect user sentiment feedback on current food public sentiment within the initial time period t.

  •  3:

    Set the weight of odd-numbered terms as ξ, Sparsity parameter p; Initialize the matrix and random bias vector.

  •  4:

    Greedy layer-wise algorithm training for hidden layers.

  •  5:

    Train the first layer using Algorithm 1. The input dataset is the training dataset Data.

  •  6:

    Starting from the second layer, use the output of the hidden layer as the input for the next layer, obtaining the encoding-decoding matrix and bias vector for the next hidden layer.

  •  7:

    Utilize backpropagation combined with gradient optimization techniques to perform top-down layered adjustments of parameters across the entire neural network.

  •  8:

    Based on the data collected from step 2, make predictions to obtain overall positive and negative results.

  •  9:

    Construct the weight quantifier: ϑ is the number of positive comments and ω is the number of negative comments

    If the prediction result is positive:

    Public sentiment index ε=1+ϑϑ+ω, increase recommendation weight

    If the prediction result is negative:

    Public sentiment index ε=1ωϑ+ω, decrease recommendation weight

    If the prediction result is neutral(ϑ=ω):

    Public sentiment index ε=1.