<?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 yashwanth reddy on Medium]]></title>
        <description><![CDATA[Stories by yashwanth reddy on Medium]]></description>
        <link>https://medium.com/@byashwanth77?source=rss-db03e389c8ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PCXxpWUuY3X0xXxO</url>
            <title>Stories by yashwanth reddy on Medium</title>
            <link>https://medium.com/@byashwanth77?source=rss-db03e389c8ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:10:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@byashwanth77/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[How Dense Retrievers Were Born And Where SBERT Missed the Mark]]></title>
            <link>https://medium.com/@byashwanth77/how-dense-retrievers-were-born-and-where-sbert-missed-the-mark-27f175862254?source=rss-db03e389c8ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/27f175862254</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[sentence-transformers]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[yashwanth reddy]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 10:43:51 GMT</pubDate>
            <atom:updated>2025-07-17T10:43:51.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZE2AhGh4TPpGzP-g.jpg" /></figure><p>If you clicked on this blog then you either know, worked on or heard about sentence transformers. Back in 2019 the paper on Sentence BERT(SBERT) was released by <a href="https://arxiv.org/abs/1908.10084">Nils Reimers el.al</a> , and it changed the game for getting sentence level semantics. It was so popular that it became the go-to model for semantic similarity tasks across the industry and academia.</p><p>But it has its flaws too, one of the major reason we need sentence embeddings is <strong>dense retrieval tasks.</strong></p><p>Please have a look at <a href="https://medium.com/biased-algorithms/contrastive-learning-explained-9343b3a67513">contrastive learning</a> to have a complete understanding of the blog</p><p><em>Ill explain a little bit about </em><strong><em>dense retrieval</em></strong><em> and </em><strong><em>cosine similarity</em></strong><em>, please skip the next section if you are already familiar with it.</em></p><h3>What is dense retrieval?</h3><p>We all know how ground breaking vector embeddings are, it gave us the power to create contextualized vector representation of words, even more so after transformers. It shifted from static to dynamic embeddings and now we are at the same embeddings but which encapsulates the context in a whole sentence.</p><p>Now say you have an essay, you break it in to sentence chunks and pass it through your SBERT(I’ll be calling sentence transformer made using BERT as SBERT from now), Now we have a big matrix that contains the embedding representation of our sentences. Now Iwant a specific information from my essay and Icall my question as “query”. We also pass this query from the same SBERT and get the embeddings for the same.</p><h4>Cosine similarity</h4><p>Now that we<strong> </strong>have query and dense matrix, we want to find the most relevant sentence for our query, and since we have embeddings as vectors and each dense vector is of same size, finding the cosine similarity for the dense vectors would gives information on how sementically similar they are.</p><p>query-sentence pair which are very sementically similar will have higher cosine similarity (~1) and pairs which are very distinct will be far away in vector space and have lower score (~0)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9tRtA4gs7qe5MBYvmxMBg.png" /><figcaption>Please note that just like the query part we are also havine embeddings for the dense matrix part, i just visualized the text</figcaption></figure><p>Note: Please remember the above output we got are just the cosine similarity scores and not the relevance scores</p><p>And this ladies and gentle men is called dense retrieval. You retrieve the most relevant sentence for your query using dense vectors and cosine similarity, but cosine similarity alone can only capture semantic closeness, not task specific relevance, unless the model is trained with retrieval optimized objectives like <strong>contrastive learning with hard negatives</strong>.</p><h3>The problem</h3><p>Looking clearly of what i said above, its important to note that two most important things when it comes to dense retrieval, <strong>Semantic similarity</strong> and <strong>Relevance</strong>. Below are the main reason why SBERT was not made keeping dense retrieval in mind</p><h4>1. Answers Semantic similarity, but not relevance</h4><p>Take the query and sentences from the above flow chart for example, our query is only being answered by the 2nd sentence, which has a very good cosine scores of 0.92, BUT, the third sentence also have a very high score even though it is not answering our query.</p><p>This is where relevance comes in play. The third sentence is semanticaly similar to the query but it is not relevant and will have a lower relevance score.</p><p>When the SBERT paper first released the authors wanted it to be a “Universal sentence encoder”, so they put 3 methods for producing sentence embeddings:</p><ol><li><strong>Classification Objective function</strong>: This method produces sentence embeddings if we are having NLI datasets (<a href="https://nlp.stanford.edu/projects/snli/">SNLI</a> is used here). The model here learns to identify positive (entailment) and negative(Contradiction and neutral) judgements between the sentence and the query, But we are not pushing away the negatives, this causes the embedding space to cluster up, making dense retrieval VERY problematic</li><li><strong>Regression objective function</strong>: This is to produce sentence embeddings if we are dealing with <a href="https://github.com/brmson/dataset-sts">STS</a> type datasets. Here we are training the weights to either maximize or minimise the cosine similarity scores, same case here we are competely ignoring the relevance.</li><li><strong>Triplet Objective function</strong>: Similar to contrastive learning but with major drawbacks. We are training the model to minimize and maximize the euclidian distance for positives and negatives respectively, Which is very sensitive to scale. Morever we are using margin as a cutoff for positves and negatives which is very situation depending and finally we are taking only one negative for each anchor, which again only helps in sementic similarity but not relevance</li></ol><p>So pretty much all the methods are made for semantic similarity specific and not task specific retrieval.</p><h4><strong>2. Pretrain-Fine tuning discrepency</strong></h4><p>The biggest issue that paved a path to current dense retrievers. The pretrain-fine tuning discrepency is caused by the masked tokens during pretraining as a result of MLM.</p><ol><li><strong>Issues during fine-tuning</strong></li></ol><p>In a BERT model, we do unsupervised pretraining, which involve randomly masking(about 10–15%) the tokens and training the model to predict those with the help of bidrectional attention, But when we are fine tuning the same Pretrained BERT model, we are no more using masks, but instead have labels. This is very new for our BERT model, because our model was trained on “fill in the blanks” objective and it trained the weights and understood patterns according to that. Because of this the model has to learn this way of prediction all the way from scratch. Which given the limited data we have for fine tuning(most of the times), would be very hard to imporve its performance.</p><p><strong>2.</strong> <strong>Independency assumption</strong></p><p>Unlike Auto-regressors(Gpt, gemini etc), BERT predicts each masked token independently in its Masked Language Modeling objective(MLM. This means BERT assumes the masked tokens are conditionally independent of each other, even though they may share context(Due to self-attention).</p><p>This above situation causes problems for SBERT as they heavily rely on contextual similaties of tokens.</p><p><strong>3. Less training signals</strong></p><p>As<strong> </strong>i mentioned earlier, BERT masks about 10%-15% of the tokens and train to predict them and the <strong>Training signals </strong>are only as a result of these few tokens, and the rest of the tokens are not being used(only used in attention), as a result we the contextual embeddings can be undertrained, the pre training can be inefficient and takes a very long time to cover the vocabulary.</p><h4><strong>Current situation</strong></h4><p>A lot of papers had been released that used SBERT as a base, and much improvement has been made to tackle the problems with SBERT for dense retrieval. Papers like SimCSE (paper where the contrastive learning was introduced in nlp), RetroMAE, DPR, BGE etc are published to produce a Dense retrieval specific model.</p><p>In fact, this current blog was written to be a base for my next blog, which is on RetroMAE, Which forms the foundation of the current best dense retrieval model( BGE M3 retro), pretty much all the BGE models.</p><p><strong>References</strong></p><p>This blogs was a ammalgamtion of few research papers. Those are being linked below for your convinience.</p><ol><li><a href="https://arxiv.org/abs/1906.08237">XLNet: Generalized Autoregressive Pretraining for Language Understanding</a>. Zhilin Yang et al.</li><li><a href="https://arxiv.org/abs/1908.10084">Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Nils Reimers et al.</a></li><li><a href="https://arxiv.org/abs/2104.08821">SimCSE: Simple Contrastive Learning of Sentence Embeddings</a>. Tianyu Gao et al.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27f175862254" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forecasting Using Xgboost (lag and decomposition)]]></title>
            <link>https://medium.com/@byashwanth77/forecasting-using-xgboost-lag-and-decomposition-864815bd98c5?source=rss-db03e389c8ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/864815bd98c5</guid>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[xgboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[decomposition]]></category>
            <category><![CDATA[time-series-forecasting]]></category>
            <dc:creator><![CDATA[yashwanth reddy]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 06:17:57 GMT</pubDate>
            <atom:updated>2025-04-04T07:44:54.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1ADpk9qnqVSAoZ6T" /></figure><p>We all know how powerful Xgboost is as a machine learning model, for those who dont, you will find out in this blog. Before starting with Xgboost, lets start witht the “Gradient boost” topic. For those who are already familiar with the topic of gradient descent, this will be a breeze through.</p><h3><strong>Gradient Boosting</strong></h3><p>The gradient boosting as the name suggest, is similar to the classic gradient descent but, we using the previous tree prediction as the parameter instead of weights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*PZjnfEb9_Alc8CtJZj-QYA.png" /><figcaption>(i). The left side shows the gradient descent wrt weights and rights shows with predicted value</figcaption></figure><p>We consider the ouput we get from the gradient boost gradient as “<strong>residuals”. </strong>Now, We have to remember that xgboost is a part of “Decision Trees” family in machine learning. So the trees are bound to come here. If you followed through everything that was discussed so far, you must have come to the conclusion that, “Oh, so xgboost has both gradient descent like a regression model and decison trees ?” and thats completely correct. Xgboost is the favourite child of both the gradient descent and tree like models. But , make sure you have lots of data!</p><p>So coming back, the <strong>residual</strong> data we got from the gradient are passed through decision trees. The reason im saying “trees” instead of “tree” is because we are using a tree for each iteration. So for the first iteration, we want to pass the residuals to the tree,for that we need to find the gradient, which would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*WMlRYu_uxaMWDzhyZ5PkOA.png" /></figure><p>The <em>y_hat</em> here the prediction from previous tree, but for the first tree there is no previous, so we usually use the mean of <em>y_i </em>and vola! we have the gradient. Now we push these residuals into the tree and get the predictions. This whole process is termed in by one word, <em>Tm. </em>So our final equation would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*34ukTEhTCF7pis5jAfByuw.png" /></figure><p>The <em>v</em> here is like the learning rate that we have in gradient descent, we dont want the model to overfit, so we take the process slow and steady. Now, this is only for one tree, we repeat this process for n trees, so the final equation would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*Jfq4U54E6_OZsD-Ak4SHig.png" /></figure><p>Tadaaa! Now you understood the fundation behind the best machine learning model. Xgboost runs exactly like this but with few extra steps for maximum precison, that includes double differentiation(Newton boosting), samplying, Regularization etc. I would suggest you to go through this video by <a href="https://www.youtube.com/c/joshstarmer">Statsquest</a> on <a href="https://www.youtube.com/watch?v=OtD8wVaFm6E">Xgboost</a>, there are 4 parts covering xgboost regression and classification.</p><p>Now coming to the main topic, Xgboost was never ment to be used for Time series forecasting, because based on what you understood from above, we are not looking into how the current data point is dependent on the previous data points. Not to be confused that using the residuals of previous tree might look like moving averages, but here we are using the same residual of same data point to update itself, but in , moving averages we are using the residuals of previous data points with added weights to predict the new point. THIS is where the temporal dependency comes, which the xgboost lacks.</p><p><strong>Please go though this </strong><a href="https://github.com/Giga1025/Optimal_Time_series_forecastings/blob/main/Xgboost_lag_and_decompose.ipynb"><strong>code</strong></a><strong> to properly understand the content below</strong></p><h3><strong>What are we gonna do?</strong></h3><p>The temporal dependecy comes in place when a prediction is made based on the previous data points, now why cant we give the previous data points as features to xgboost? These new features are called “<strong>lags”. </strong>Combined with that lets add another feature called “<strong>Rolling mean” </strong>which as the name suggests, takes the mean of last n values as we go through the data set. You can understand these from the example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OMpP4Un5Fkudzrilb3i0Q.png" /></figure><p>We have ‘NAN’ here because these data points dont have sufficient values before them to meet the criteria for lags and rolling mean.</p><p>Now, we have enough features to ACTUALLY do time series forecasting with Xgboost. We can do the usual prediction process to get a proper forecasting.</p><h3>Another way</h3><p>We can also do the forecasting using the <a href="https://machinelearningmastery.com/decompose-time-series-data-trend-seasonality/"><strong>decomposition</strong></a><strong> </strong>method to split the data into seasonal, trend and residuals. Having seasonality and trend in the data makes it non-stationary, which the ml models like Xgboost cant predict. So we can split them apart, make the xgboost model predict on residual data(leftover data after de-trending and de-seasoning).</p><p>After we predict the residual data using xgboost, we can add over the seasonality and trend back to the prediction to make it complete.</p><h3>Why are we doing this?</h3><p>You might be wondering why go through all the trouble to make xgboost useful for TSF, which it is not good at without adding features. Well, This whole process is to show just how POWERFUL xgboost, from testing it was seen that Xgboost was out performing models such as SARIMA, ARIMA and AR, whose whole purpose was time series forecasting.</p><h3>Lag vs Decomposition</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*GQXKXYJ03AW7jCLpM_IDOA.png" /></figure><p>It all comes down to this, Model with lag has high R² score than decompose model and decompose has better rmse than lag.</p><h4>Why high R² score model with lags</h4><ul><li>Due to availability of lag features, there is temporal dependency in the model, which preserves the natural variance.</li><li>But if the lag based predictions are slightly off, ths will lead to more RMSE, so we have to choose the lags carefully checking the ACP and PACP plots.</li></ul><h4>Why Lower RMSE for model with decomposition</h4><ul><li>During de trending the the trend is smoothened, this will lead to the data not have high fluctuations</li><li>Since the Xgboost is explicitly trained on the residual data, it misses some variance that the lag features captures and that explains decomposition model R² being less than lag model</li></ul><p>The best way to have high R² and low RMSE is to decompose the data and add lag features to it. By doing so we are compensating the defects in both the models.</p><h3>Should we use Xgboost for Time series forecasting?</h3><p>The main agenda for this blog is not convince one to use xgboost for time series forecasting, as you had seen above, it needs a lot of extra steps. The whole process can be easily done by advanced neural networks such as LSTM, GRU and Transformers.</p><p>This blog is to just to show the way, IF a mad lad like me wants to use Xgboost for a time series forecsting!</p><h3>What can be done to improve the model even more</h3><p>Well, given the effort we had gone through so far, to further better the model, we can add extra features like Weather, Lighting etc. By doing so the decompose model would heavily benifit from that.</p><h3>Conclusion</h3><p>To conclude, YES, we CAN use Xgboost for time series forecasting, once again Xgboost showed why it is the king of Machine learning algorithms!</p><p>Few more blogs will be posted shortly to show how neural networks eaze down the whole process of forecasting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=864815bd98c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>