<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jaskaran Singh on Medium]]></title>
        <description><![CDATA[Stories by Jaskaran Singh on Medium]]></description>
        <link>https://medium.com/@jaskaran_singh_29?source=rss-f00c11617126------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CGzc9nC7OxmHMvp-rUBPsQ.jpeg</url>
            <title>Stories by Jaskaran Singh on Medium</title>
            <link>https://medium.com/@jaskaran_singh_29?source=rss-f00c11617126------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:45:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaskaran_singh_29/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Metadata generation for automated content processing for Media and Entertainment companies — A demo]]></title>
            <link>https://medium.com/mediaagility-sparks/metadata-generation-for-automated-content-processing-for-media-and-entertainment-companies-a-demo-2f55788dec1a?source=rss-f00c11617126------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f55788dec1a</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[metadata]]></category>
            <category><![CDATA[media-and-entertainment]]></category>
            <category><![CDATA[digital-transformation]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Jaskaran Singh]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 06:56:35 GMT</pubDate>
            <atom:updated>2021-03-09T10:13:43.251Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Metadata generation for automated content processing for Media and Entertainment companies — A demo</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9MBEz5s3Yd_E5TLXNi20Q.png" /></figure><p>Do you know what your content knows?</p><p>As a Media and Entertainment company, this is a question you might come across often. You might also know the answer: if you process your content, you can unearth insights and achieve better outcomes. But getting insights from data is easier said than done. There are many challenges that you can come across while dealing with data:</p><ol><li>Efficient data processing</li><li>Tagging of data</li><li>Data search</li><li>Reuse of content</li></ol><p>AI technologies are helping to flip the script by making the processing of data easier and more efficient. One way of making more sense of your data is to generate metadata.</p><p>Metadata, simply put, is data about your audio, video, text — what is it about, when was it created, what does it hold, and more. The tags could be about the actors, genres, plots, locations, languages, themes, actions, and so on.</p><p>Metadata opens up a huge opportunity to discover and repurpose content, optimize workflows around program scheduling, content moderation, and localization, and recommend contextual media content feeds to your audience.</p><p><a href="https://www.mediaagility.com/"><strong><em>MediaAgility</em></strong></a>, a premier digital consultancy, has developed an AI-powered demo for generating metadata, and below are the screenshots of how the demo works for two use cases: (a) detecting objects and understanding scenes and (b) detecting actors.</p><h3><strong>Use case 1: Detecting objects and understanding scenes</strong></h3><p>Here, you can see that we have detected different objects and their corresponding occurrences in the video. If we click on ‘chair’ in the list of objects below the video, we will reach the specific scene where the chair is present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JYIe5ciWwq9ivg3I" /><figcaption>Detecting objects and understanding scenes</figcaption></figure><p>This helps in detecting the scenes which might be unsuitable for children. For example, scenes where the characters are drinking alcohol or are smoking.</p><p>Another application is — when we detect brand logos in a scene, we can use that information for time-based advertising.</p><h3><strong>Use case 2: Detecting actors</strong></h3><p>When we detect actors in a video, we could determine the total duration of each actor and track them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K9VNGvWeNLnse5jq" /><figcaption>Detecting actors</figcaption></figure><p>In the above screenshot, several characters in the episode have been detected and recognized along with their emotions in every scene. We can even determine the overall sentiment of any scene by detecting the emotions of the actors. This could further help in determining the genre of the video.</p><p>Below is a chart that visualizes just two emotions, joy and anger. We can use this to compare the sentiments in each frame. We can observe that whenever joy ‘score’ is high, anger ‘score’ is low, and vice versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EOFnX-S5SZwI5HDO" /></figure><p>See the demo live in action in this video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfJwQkRbZ-s0%3Fstart%3D132%26feature%3Doembed%26start%3D132&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfJwQkRbZ-s0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfJwQkRbZ-s0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a90b9f7972c002b54cccc581a3ed2a1/href">https://medium.com/media/3a90b9f7972c002b54cccc581a3ed2a1/href</a></iframe><p>Which use case resonated the most with your needs? Share in the comments.</p><p>Get tech insights and digital recommendations delivered to your inbox —</p><p><a href="https://www.mediaagility.com/newsletter-subscription/">Stay in the know with MediaAgility&#39;s newsletter - MediaAgility</a></p><p>Post script: Snippets from Friends TV series used to train the model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f55788dec1a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mediaagility-sparks/metadata-generation-for-automated-content-processing-for-media-and-entertainment-companies-a-demo-2f55788dec1a">Metadata generation for automated content processing for Media and Entertainment companies — A demo</a> was originally published in <a href="https://medium.com/mediaagility-sparks">MediaAgility Sparks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simpler and effective implementation of LSTM demonstrated with a sales prediction model]]></title>
            <link>https://medium.com/mediaagility-sparks/a-simpler-and-effective-implementation-of-lstm-demonstrated-with-a-sales-prediction-model-6c430ec64860?source=rss-f00c11617126------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c430ec64860</guid>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[predictive-model]]></category>
            <category><![CDATA[digital-transformation]]></category>
            <dc:creator><![CDATA[Jaskaran Singh]]></dc:creator>
            <pubDate>Tue, 14 Apr 2020 06:40:22 GMT</pubDate>
            <atom:updated>2020-09-17T10:19:10.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nukrZzIzKICTAfST" /><figcaption>Figure 1: LSTM Architecture</figcaption></figure><p>Long short-term memory (LSTM) is an artificial recurrent neural network (RNN) architecture used widely in deep learning. These networks classify, process, and make predictions based on time-series datasets that could contain hidden information between important events.</p><p>Unlike the standard feed-forward neural networks, LSTMs have feedback connections. Along with processing single data points, like images, LSTM can also process entire sequences of data, like - speech and video. They can also be applied to tasks such as connected, unsegmented handwriting recognition</p><p>While studying LSTM, I came across long-winded codes that increased the complexity of model training. Through this post, I intend to share a shorter, simpler yet effective implementation of LSTMs for training a predictive model with historic current-hour sales data.</p><p>Before starting the development of the sales prediction model, let me take you through the high-level steps to train any kind of a model,</p><ul><li>Identifying the problem and deciding if resolving it through Machine Learning is feasible.</li><li>Gathering good amount of data and data exploration.</li><li>Cleaning the data and performing feature engineering, if required.</li><li>Designing the model by defining its architecture, what features will it accept, and the functions and filters needed to train the model.</li><li>Evaluating trained model and changing the parameters to improve the accuracy of model.</li></ul><p>In the context of the problem I have chosen, this is how the result of each step looks like -</p><ul><li><strong>Finding the problem:</strong> The problem statement is — To predict the next hour sales of a store based on the current hour sales data and to implement the model using LSTM.</li><li><strong>Gathering data and exploration:</strong> I got basic liquor sales data from <a href="https://www.kaggle.com/markusschmitz/liquor-small">here</a>. I made some modifications in data for direct use. To reduce the complexity of the dataset for the blog, I reduced the huge raw data of multiple stores to just one store’s data. To access this data, please refer to my <a href="https://github.com/jass-singh/Simple_LSTM_Implementation"><strong>git repo</strong></a>. Read the ‘LiquorSales.csv’ file using pandas library.</li></ul><pre>df = pd.read_csv(&#39;LiquorSales.csv&#39;)<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*vQ1fA1N5hoFd695RuxlhqA.png" /><figcaption>Table 1: Liquor Sales Data set preview</figcaption></figure><ul><li><strong>Cleaning the data and feature engineering : </strong>The code below was used to customize the data. As the data was already customized, so cleaning of data wasn’t required. From Table 1, we can easily determine that hour, date, and month are categorical features, whereas quantity column is a continuous feature. So, I performed feature engineering over these two feature types using one-hot encoding and normalization, respectively.</li></ul><pre><strong># Max and min values help in feature normalization.<br></strong>max_quantity = df[&#39;quantity&#39;].max()<br>min_quantity = df[&#39;quantity&#39;].min()</pre><pre><strong># Perform One-hot encoding on categorical columns and normalize continuous column.<br></strong>df = pd.get_dummies(data=df, columns = [&#39;hour&#39;, &#39;date&#39;,&#39;month&#39;])<br><strong># Normalize the continuous column.<br></strong>df[&#39;quantity&#39;] = (df[&#39;quantity&#39;]-min_quantity)/(max_quantity-min_quantity)</pre><pre>df_quan = pd.DataFrame(columns=[&#39;quantity&#39;])<br>df_quan.quantity = df.quantity</pre><pre>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfd1-YjP35ibq456j1vwYA.png" /><figcaption>Table 2: Features after one-hot encoding and normalization</figcaption></figure><p>Before starting to design the model, I distributed the data into training, validation and test with the following code.</p><pre>df_x = df.to_numpy()<br>df_y = df_quan.to_numpy()</pre><pre><strong># separate into train validation and testing data.</strong></pre><pre>x_train, x_test, y_train, y_test = train_test_split(df_x, df_y, test_size=0.2, shuffle= False)</pre><pre>x_train, x_val, y_train, y_val = train_test_split(x_train, y_train, test_size=0.25, shuffle= False)</pre><pre>x_train = x_train[:-1]<br>x_val = x_val[:-1]<br>x_test = x_test[:-1]</pre><pre>y_train = y_train[1:]<br>y_val = y_val[1:]<br>y_test = y_test[1:]</pre><pre>print(x_train.shape, x_val.shape, x_test.shape,<br>      y_train.shape, y_val.shape, y_test.shape)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*1i209emicxr-FMbMUmPuiA.png" /><figcaption>Output</figcaption></figure><p>To train the LSTM model, I converted the data into a 3D array with these attributes — (samples, timesteps, features).</p><pre>train_x = x_train.reshape((x_train.shape[0], 1, x_train.shape[1]))<br>test_x = x_test.reshape((x_test.shape[0], 1, x_test.shape[1]))<br>val_x = x_val.reshape((x_val.shape[0], 1, x_val.shape[1]))</pre><pre>print(train_x.shape, val_x.shape, test_x.shape,<br>      y_train.shape, y_val.shape, y_test.shape)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*eI83NY72shh6rcZ4qtX7FQ.png" /><figcaption>Output</figcaption></figure><ul><li><strong>Designing the model:</strong> I designed a basic LSTM model to train effectively on my prepared data. These were the parameters that I used to train the model,</li></ul><p><strong>Epoch :</strong> It is the number of times the learning algorithm will go through the entire training dataset. I took 1500 as the epoch value.</p><p><strong>Batch Size : </strong>It is the number of samples to go through before updating the internal model parameters. I took 256 as the batch size.</p><p><strong>Learning Rate :</strong> It helps to control by how much to change the model with respect to the estimated error after each time the model weights are updated. I took a small learning rate of 0.003.</p><p><strong>Decay :</strong> The amount by which the learning rate changes over training epochs is termed as the learning rate decay. Since my data was simple and clean, I took the decay value as 0.</p><p><strong>Neurons :</strong> Here neurons are the number of hidden units inside the LSTM cell. Also it could be considered as the positive integer with the dimensionality of the output space. I could have taken these neurons as 1, but since the input was of 68 features, I considered a higher number of 17 for neurons.</p><p><strong>Output Neurons :</strong> Here output neurons are considered as the number of output units. In this case, the model output is the prediction of the quantity of liquor sold in the next hour. This is done with the help of DENSE function in keras to link LSTM output units with dense layer at the end. Therefore, I set it as 1.</p><p><strong>Dropout : </strong>It is a technique where randomly selected neurons are ignored during training. It is used when a model overfits. I took the dropout as 0 since mine was a simple model.</p><p>I chose Adam optimizer for our model. It requires very little memory and is computationally efficient. It is recommended to use A<a href="https://arxiv.org/abs/1412.6980">dam Optimizer</a> for regression models.</p><pre><strong># Setting parameters for model and begin training<br></strong>epoch = 1500<br>batch = 256<br>decay = 0 <br>learning_rate = 0.003<br>neurons = 17<br>dropout = 0<br>output_neurons = 1<br>version = 0</pre><pre><strong># Name of model file to be saved<br></strong>file_path = &quot;./Liquor_ckpt&quot; \<br>            + &quot;_V&quot; + str(version) \<br>            + &quot;_L1_&quot; + str(neurons) \<br>            + &quot;_Dro1_&quot; + str(dropout) \<br>            + &quot;_De1_&quot; + str(output_neurons) \<br>            + &quot;a.hdf5&quot;</pre><pre><strong># Model architecture<br></strong>model = Sequential()<br>model.add(LSTM(neurons, input_shape=(1, train_x.shape[2]), return_sequences=False, name=&#39;L1&#39;))</pre><pre><strong># We could add dropout in layers if model overfits.</strong><br># model.add(Dropout(dropout,  name=&#39;Dro1&#39;))  <br>model.add(Dense(output_neurons, name=&#39;De1&#39;))</pre><pre><strong># We could add activation function for better learning of model.<br></strong># model.add(Activation(&#39;relu&#39;))</pre><pre>adam = optimizers.Adam(lr=learning_rate, decay=decay)<br>model.compile(loss=&#39;mean_squared_error&#39;, optimizer=adam)</pre><pre><strong># Using checkpoint to save only 1 model that fits best on validation data.</strong><br>checkpoint = ModelCheckpoint(file_path, monitor=&#39;val_loss&#39;, verbose=1, save_best_only=True, mode=&#39;auto&#39;, period=1)<br>history = model.fit(train_x, y_train, batch_size=batch, epochs=epoch, verbose=2, validation_data=(val_x, y_val), callbacks=[checkpoint])</pre><ul><li><strong>Evaluate trained model: </strong>I evaluated the convergence of the model by plotting the epochs vs loss graph.</li></ul><pre><strong># Plot epoch loss graph<br></strong>plt.plot(history.history[&#39;loss&#39;], label=&#39;train&#39;)<br>plt.plot(history.history[&#39;val_loss&#39;], label=&#39;test&#39;<br>plt.legend()<br>plt.figure(figsize=(10,8),dpi=80)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*enY3v__9o-zkdnc2M16MxA.png" /><figcaption>Figure 2: Epoch loss graph</figcaption></figure><p>Then I predicted the quantity which could be sold in the next hour. Using the test data, I also plotted a graph of actual sold VS sales prediction.</p><pre><strong># Load Model<br></strong># file_path = &quot;Liquor_ckpt_V0_L1_17_Dro1_0_De1_1a.hdf5&quot;<br>model1 = load_model(file_path)<br>predicted = model1.predict(test_x)</pre><pre><strong># Reconstruct original values<br></strong>test_y1 = (y_test * (max_quantity-min_quantity)) + min_quantity<br>pred_Model_1 = (predicted * (max_quantity-min_quantity)) <br>               + min_quantity<br>plt.figure(figsize=(20,5),dpi=80)<br>plt.plot(test_y1[:200], &#39;r&#39;,label=&#39;Actual&#39;)<br>plt.plot(pred_Model_1[:200], &#39;g&#39;, label=&#39;Predicted&#39;)<br>plt.legend()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cc39k-kbaobwIjzSadL1ZQ.png" /><figcaption>Figure 3: Actual and predicted values.</figcaption></figure><p>Then, I calculated the R2 score to check the accuracy of the model.</p><pre>score = r2_score(test_y1, pred_Model_1)<br>print(&#39;r2 score for model 1 : &#39;,score)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*LXZCjeRPRenp4LazxS8A_A.png" /><figcaption>Output</figcaption></figure><p>The model achieved a really good <strong>R2 score</strong> of <strong>0.998 </strong>that meant the model was trained well with the selected simple and clean dataset.</p><p>You can access the <strong>source code, data set,</strong> and <strong>trained model</strong> you can get it <a href="https://github.com/jass-singh/Simple_LSTM_Implementation"><strong>here</strong></a>.</p><p>If you plan to work on complex data, you could do any of the following tweaks to the parameters to achieve a well-trained model,</p><ol><li>Changing epoch for training until the model reaches convergence.</li><li>Changing batch size depending on the system where training is to be executed.</li><li>Tweaking learning rate and learning rate decay.</li><li>Introduce dropout layer.</li><li>Introduce activation function.</li><li>Introduce more LSTM and Dense layers and much more.</li></ol><p>If you like the post, drop a few claps and suggest ideas for complex LSTM implementation that you would like to see in the later posts in the comment section.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F2yeclu%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F2yeclu&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/626ba5b434b779a50ed7c6dbc014bd08/href">https://medium.com/media/626ba5b434b779a50ed7c6dbc014bd08/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c430ec64860" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mediaagility-sparks/a-simpler-and-effective-implementation-of-lstm-demonstrated-with-a-sales-prediction-model-6c430ec64860">A simpler and effective implementation of LSTM demonstrated with a sales prediction model</a> was originally published in <a href="https://medium.com/mediaagility-sparks">MediaAgility Sparks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>