LSTM multiple timeseries

Erfan: <p>hello, i will appreciate if you help me to solve my problem.<br>
i want to use LSTM for below data structure. i want to predict next rating of review.<br>
first: business rating (1-5 stars)<br>
Business_1 = [1, 3, 4, 5, 2, 4, 1, 1, 4, 5, 2, 1]<br>
Business_2 = [3, 3, 2, 2, 3, 4, 5, 2, 4, 1, 5, 4]<br>
Business_3 = [3, 2, 1, 2, 1, 4, 5, 2, 1, 1, 2, 4]<br>
.<br>
.<br>
.<br>
Business_N = [3, 2, 1, 1, 1, 5, 3, 3, 3, 2, 1, 1]</p>
<p>my project is not univariate and it’s multivariate. so besides of rating we have other numerical features.</p>
<p>I want to predict next rating based on sequence length: L.<br>
I want a model to use all business rating at the same time. I don’t want to use one by one ratings.</p>
<p>Business_1 = [1, 3, 4, 5, 2, 4, 1, 1, 4, 5, 2, 1]<br>
convert to L=7<br>
data, label<br>
[1, 3, 4, 5, 2, 4, 1], [1]<br>
[3, 4, 5, 2, 4, 1, 1], [4]<br>
[4, 5, 2, 4, 1, 1, 4], [5]<br>
[5, 2, 4, 1, 1, 4, 5], [2]<br>
[2, 4, 1, 1, 4, 5, 2], [1]</p>
<p>the top data structure is 5<em>7</em>Features</p>
<p>now i consider all business. so the data structure will be:<br>
N: total number of business<br>
i think the shape of data structure like: N* 5<em>7</em>Features</p>
<p>My question is:</p>
<p>How should I use this data structure in LSTM? i want model consider all business at the same time and predict future business rating based on business.</p>
<p>thanks for helping me in advance.</p>

AbdulsalamBande: <p>I believe a custom LSTM training is not necessary; a standard LSTM model should suffice. In essence, to predict the next rating for any business, simply input the last seven ratings into the model. In training, the below custom function can prepare your data for a business.</p>
<pre><code class="lang-auto">def create_sequences(data, seq_length=7):
    sequences = []
    labels = []
    for i in range(len(data) - seq_length):
        sequences.append(data[i:i+seq_length])
        labels.append(data[i+seq_length])
    return np.array(sequences), np.array(labels)
</code></pre>

Erfan: <p>thanks, but my question is about LSTM model. I want a model to consider all business in the same time.<br>
for example, the model can consider business 1 data and train and in the next level consider business 2 and update weights and so on. but i want a model to train all business in the same time and consider all of them</p>

J_Johnson: <p>Sounds like you are looking for a transformer or some version of self-attention. Have you read the paper “Attention is All You Need”(2017), yet?</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://arxiv.org/abs/1706.03762">
  <header class="source">
      <img src="https://static.arxiv.org/static/browse/0.3.4/images/icons/favicon-32x32.png" class="site-icon" width="" height="">

      <a href="https://arxiv.org/abs/1706.03762" target="_blank" rel="noopener nofollow ugc">arXiv.org</a>
  </header>

  <article class="onebox-body">
    <img src="https://static.arxiv.org/static/browse/0.3.4/images/arxiv-logo-fb.png" class="thumbnail" width="" height="">

<h3><a href="https://arxiv.org/abs/1706.03762" target="_blank" rel="noopener nofollow ugc">Attention Is All You Need</a></h3>

  <p>The dominant sequence transduction models are based on complex recurrent or
convolutional neural networks in an encoder-decoder configuration. The best
performing models also connect the encoder and decoder through an attention
mechanism. We propose...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>The individual reviews can be treated as tokens and assigned an encoding vector of length 5 to allow the model to learn the relationships between review ratings. Here is a good tutorial on Transformers you might find useful:</p>
<p><a href="https://pytorch.org/tutorials/beginner/transformer_tutorial.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/tutorials/beginner/transformer_tutorial.html</a></p>