Close Menu
    Trending
    • STOP Building Useless ML Projects – What Actually Works
    • Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025
    • The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z
    • Musk’s X appoints ‘king of virality’ in bid to boost growth
    • Why Entrepreneurs Should Stop Obsessing Over Growth
    • Implementing IBCS rules in Power BI
    • What comes next for AI copyright lawsuits?
    • Why PDF Extraction Still Feels LikeHack
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Artificial Intelligence»Semantically Compress Text to Save On LLM Costs | by Lou Kratz | Dec, 2024
    Artificial Intelligence

    Semantically Compress Text to Save On LLM Costs | by Lou Kratz | Dec, 2024

    Team_AIBS NewsBy Team_AIBS NewsDecember 21, 2024No Comments9 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    LLMs are nice… if they’ll match all your information

    Towards Data Science

    Picture by Christopher Burns on Unsplash

    Initially revealed at https://blog.developer.bazaarvoice.com on October 28, 2024.

    Massive language fashions are improbable instruments for unstructured textual content, however what in case your textual content doesn’t match within the context window? Bazaarvoice confronted precisely this problem when constructing our AI Evaluate Summaries function: thousands and thousands of consumer opinions merely received’t match into the context window of even newer LLMs and, even when they did, it could be prohibitively costly.

    On this submit, I share how Bazaarvoice tackled this drawback by compressing the enter textual content with out lack of semantics. Particularly, we use a multi-pass hierarchical clustering strategy that lets us explicitly regulate the extent of element we need to lose in trade for compression, whatever the embedding mannequin chosen. The ultimate method made our Evaluate Summaries function financially possible and set us as much as proceed to scale our enterprise sooner or later.

    Bazaarvoice has been gathering user-generated product opinions for practically 20 years so we have now rather a lot of information. These product opinions are utterly unstructured, various in size and content material. Massive language fashions are wonderful instruments for unstructured textual content: they’ll deal with unstructured information and determine related items of data amongst distractors.

    LLMs have their limitations, nonetheless, and one such limitation is the context window: what number of tokens (roughly the variety of phrases) might be put into the community directly. State-of-the-art massive language fashions, resembling Athropic’s Claude model 3, have extraordinarily massive context home windows of as much as 200,000 tokens. This implies you may match small novels into them, however the web remains to be an unlimited, every-growing assortment of information, and our user-generated product opinions are not any totally different.

    We hit the context window restrict whereas constructing our Evaluate Summaries function that summarizes the entire opinions of a particular product on our purchasers web site. Over the previous 20 years, nonetheless, many merchandise have garnered hundreds of opinions that shortly overloaded the LLM context window. In truth, we even have merchandise with thousands and thousands of opinions that might require immense re-engineering of LLMs to have the ability to course of in a single immediate.

    Even when it was technically possible, the prices can be fairly prohibitive. All LLM suppliers cost based mostly on the variety of enter and output tokens. As you strategy the context window limits for every product, of which we have now thousands and thousands, we will shortly run up cloud internet hosting payments in extra of six figures.

    To ship Evaluate Summaries regardless of these technical, and monetary, limitations, we centered on a quite easy perception into our information: Many opinions say the identical factor. In truth, the entire concept of a abstract depends on this: evaluate summaries seize the recurring insights, themes, and sentiments of the reviewers. We realized that we will capitalize on this information duplication to scale back the quantity of textual content we have to ship to the LLM, saving us from hitting the context window restrict and decreasing the working price of our system.

    To realize this, we wanted to determine segments of textual content that say the identical factor. Such a job is simpler mentioned than performed: usually individuals use totally different phrases or phrases to specific the identical factor.

    Thankfully, the duty of figuring out if textual content is semantically related has been an lively space of analysis within the pure language processing subject. The work by Agirre et. al. 2013 (SEM 2013 shared job: Semantic Textual Similarity. In Second Joint Convention on Lexical and Computational Semantics) even revealed a human-labeled information of semantically related sentences often known as the STS Benchmark. In it, they ask people to point if textual sentences are semantically related or dissimilar on a scale of 1–5, as illustrated within the desk beneath (from Cer et. al., SemEval-2017 Task 1: Semantic Textual Similarity Multilingual and Crosslingual Focused Evaluation):

    The STSBenchmark dataset is commonly used to judge how nicely a textual content embedding mannequin can affiliate semantically related sentences in its high-dimensional house. Particularly, Pearson’s correlation is used to measure how nicely the embedding mannequin represents the human judgements.

    Thus, we will use such an embedding mannequin to determine semantically related phrases from product opinions, after which take away repeated phrases earlier than sending them to the LLM.

    Our strategy is as follows:

    • First, product opinions are segmented the into sentences.
    • An embedding vector is computed for every sentence utilizing a community that performs nicely on the STS benchmark
    • Agglomerative clustering is used on all embedding vectors for every product.
    • An instance sentence — the one closest to the cluster centroid — is retained from every cluster to ship to the LLM, and different sentences inside every cluster are dropped.
    • Any small clusters are thought-about outliers, and people are randomly sampled for inclusion within the LLM.
    • The variety of sentences every cluster represents is included within the LLM immediate to make sure the burden of every sentiment is taken into account.

    This will likely appear simple when written in a bulleted listing, however there have been some devils within the particulars we needed to kind out earlier than we might belief this strategy.

    First, we had to make sure the mannequin we used successfully embedded textual content in an area the place semantically related sentences are shut, and semantically dissimilar ones are far-off. To do that, we merely used the STS benchmark dataset and computed the Pearson correlation for the fashions we desired to contemplate. We use AWS as a cloud supplier, so naturally we needed to judge their Titan Text Embedding fashions.

    Beneath is a desk exhibiting the Pearson’s correlation on the STS Benchmark for various Titan Embedding fashions:

    (Cutting-edge is seen here)

    So AWS’s embedding fashions are fairly good at embedding semantically related sentences. This was nice information for us — we will use these fashions off the shelf and their price is extraordinarily low.

    The subsequent problem we confronted was: how can we implement semantic similarity throughout clustering? Ideally, no cluster would have two sentences whose semantic similarity is lower than people can settle for — a rating of 4 within the desk above. These scores, nonetheless, don’t immediately translate to the embedding distances, which is what is required for agglomerative clustering thresholds.

    To cope with this situation, we once more turned to the STS benchmark dataset. We computed the distances for all pairs within the coaching dataset, and match a polynomial from the scores to the space thresholds.

    Picture by writer

    This polynomial lets us compute the space threshold wanted to satisfy any semantic similarity goal. For Evaluate Summaries, we chosen a rating of three.5, so practically all clusters comprise sentences which might be “roughly” to “principally” equal or extra.

    It’s price noting that this may be performed on any embedding community. This lets us experiment with totally different embedding networks as they develop into accessible, and shortly swap them out ought to we need with out worrying that the clusters could have semantically dissimilar sentences.

    Up so far, we knew we might belief our semantic compression, however it wasn’t clear how a lot compression we might get from our information. As anticipated, the quantity of compression different throughout totally different merchandise, purchasers, and industries.

    With out lack of semantic data, i.e., a tough threshold of 4, we solely achieved a compression ratio of 1.18 (i.e., an area financial savings of 15%).

    Clearly lossless compression wasn’t going to be sufficient to make this function financially viable.

    Our distance choice strategy mentioned above, nonetheless, supplied an attention-grabbing risk right here: we will slowly improve the quantity of data loss by repeatedly working the clustering at decrease thresholds for remaining information.

    The strategy is as follows:

    • Run the clustering with a threshold chosen from rating = 4. That is thought-about lossless.
    • Choose any outlying clusters, i.e., these with only some vectors. These are thought-about “not compressed” and used for the following section. We selected to re-run clustering on any clusters with dimension lower than 10.
    • Run clustering once more with a threshold chosen from rating = 3. This isn’t lossless, however not so dangerous.
    • Choose any clusters with dimension lower than 10.
    • Repeat as desired, constantly lowering the rating threshold.

    So, at every move of the clustering, we’re sacrificing extra data loss, however getting extra compression and never muddying the lossless consultant phrases we chosen in the course of the first move.

    As well as, such an strategy is extraordinarily helpful not just for Evaluate Summaries, the place we wish a excessive stage of semantic similarity at the price of much less compression, however for different use instances the place we could care much less about semantic data loss however need to spend much less on immediate inputs.

    In observe, there are nonetheless a considerably massive variety of clusters with solely a single vector in them even after dropping the rating threshold a lot of occasions. These are thought-about outliers, and are randomly sampled for inclusion within the last immediate. We choose the pattern dimension to make sure the ultimate immediate has 25,000 tokens, however no extra.

    The multi-pass clustering and random outlier sampling permits semantic data loss in trade for a smaller context window to ship to the LLM. This raises the query: how good are our summaries?

    At Bazaarvoice, we all know authenticity is a requirement for client belief, and our Evaluate Summaries should keep genuine to actually signify all voices captured within the opinions. Any lossy compression strategy runs the chance of mis-representing or excluding the customers who took time to writer a evaluate.

    To make sure our compression method was legitimate, we measured this immediately. Particularly, for every product, we sampled a lot of opinions, after which used LLM Evals to determine if the abstract was consultant of and related to every evaluate. This offers us a tough metric to judge and stability our compression in opposition to.

    Over the previous 20 years, we have now collected practically a billion user-generated opinions and wanted to generate summaries for tens of thousands and thousands of merchandise. Many of those merchandise have hundreds of opinions, and a few as much as thousands and thousands, that might exhaust the context home windows of LLMs and run the worth up significantly.

    Utilizing our strategy above, nonetheless, we lowered the enter textual content dimension by 97.7% (a compression ratio of 42), letting us scale this answer for all merchandise and any quantity of evaluate quantity sooner or later.
    As well as, the price of producing summaries for all of our billion-scale dataset lowered 82.4%. This consists of the price of embedding the sentence information and storing them in a database.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleAV Part 3 — Engineering Low-Latency Peer Discovery for Autonomous Vehicles | by Freedom Preetham | Autonomous Agents | Dec, 2024
    Next Article This AI is the Key to Unlocking Explosive Sales Growth in 2025
    Team_AIBS News
    • Website

    Related Posts

    Artificial Intelligence

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025
    Artificial Intelligence

    Implementing IBCS rules in Power BI

    July 1, 2025
    Artificial Intelligence

    Become a Better Data Scientist with These Prompt Engineering Tips and Tricks

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    These States Have the Most Private Jet Flights: New Data

    January 7, 2025

    Building a Modern Dashboard with Python and Gradio

    June 5, 2025

    Build Your Own OCR Engine for Wingdings

    December 11, 2024
    Our Picks

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025

    Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025

    July 1, 2025

    The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.