Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 248483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:20:48+00:00 2026-05-11T21:20:48+00:00

I would like to implement Latent Semantic Analysis (LSA) in PHP in order to

  • 0

I would like to implement Latent Semantic Analysis (LSA) in PHP in order to find out topics/tags for texts.

Here is what I think I have to do. Is this correct? How can I code it in PHP? How do I determine which words to chose?

I don’t want to use any external libraries. I’ve already an implementation for the Singular Value Decomposition (SVD).

  1. Extract all words from the given text.
  2. Weight the words/phrases, e.g. with tf–idf. If weighting is too complex, just take the number of occurrences.
  3. Build up a matrix: The columns are some documents from the database (the more the better?), the rows are all unique words, the values are the numbers of occurrences or the weight.
  4. Do the Singular Value Decomposition (SVD).
  5. Use the values in the matrix S (SVD) to do the dimension reduction (how?).

I hope you can help me. Thank you very much in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:20:48+00:00Added an answer on May 11, 2026 at 9:20 pm

    LSA links:

    • Landauer (co-creator) article on LSA
    • the R-project lsa user guide

    Here is the complete algorithm. If you have SVD, you are most of the way there. The papers above explain it better than I do.

    Assumptions:

    • your SVD function will give the singular values and singular vectors in descending order. If not, you have to do more acrobatics.

    M: corpus matrix, w (words) by d (documents) (w rows, d columns). These can be raw counts, or tfidf or whatever. Stopwords may or may not be eliminated, and stemming may happen (Landauer says keep stopwords and don’t stem, but yes to tfidf).

    U,Sigma,V = singular_value_decomposition(M)
    
    U:  w x w
    Sigma:  min(w,d) length vector, or w * d matrix with diagonal filled in the first min(w,d) spots with the singular values
    V:  d x d matrix
    
    Thus U * Sigma * V = M  
    #  you might have to do some transposes depending on how your SVD code 
    #  returns U and V.  verify this so that you don't go crazy :)
    

    Then the reductionality…. the actual LSA paper suggests a good approximation for the basis is to keep enough vectors such that their singular values are more than 50% of the total of the singular values.

    More succintly… (pseudocode)

    Let s1 = sum(Sigma).  
    total = 0
    for ii in range(len(Sigma)):
        val = Sigma[ii]
        total += val
        if total > .5 * s1:
            return ii
    

    This will return the rank of the new basis, which was min(d,w) before, and we’ll now approximate with {ii}.

    (here, ‘ -> prime, not transpose)

    We create new matrices: U’,Sigma’, V’, with sizes w x ii, ii x ii, and ii x d.

    That’s the essence of the LSA algorithm.

    This resultant matrix U’ * Sigma’ * V’ can be used for ‘improved’ cosine similarity searching, or you can pick the top 3 words for each document in it, for example. Whether this yeilds more than a simple tf-idf is a matter of some debate.

    To me, LSA performs poorly in real world data sets because of polysemy, and data sets with too many topics. It’s mathematical / probabilistic basis is unsound (it assumes normal-ish (Gaussian) distributions, which don’t makes sense for word counts).

    Your mileage will definitely vary.

    Tagging using LSA (one method!)

    1. Construct the U’ Sigma’ V’ dimensionally reduced matrices using SVD and a reduction heuristic

    2. By hand, look over the U’ matrix, and come up with terms that describe each “topic”. For example, if the the biggest parts of that vector were “Bronx, Yankees, Manhattan,” then “New York City” might be a good term for it. Keep these in a associative array, or list. This step should be reasonable since the number of vectors will be finite.

    3. Assuming you have a vector (v1) of words for a document, then v1 * t(U’) will give the strongest ‘topics’ for that document. Select the 3 highest, then give their “topics” as computed in the previous step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The call to stop the service returns as soon as… May 12, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Using 0x450 as the SystemSoundID works for me at the… May 12, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer You can remove the title attribute from your HTML element… May 12, 2026 at 4:31 pm

Related Questions

I am trying to implement a decorator chain for my data-access based on IRepository.
I'm trying to differentiate between two (or more) UITouch objects on the iPhone. Specifically,
We have a system at my work that is basically a message-driven state machine.
I'd like to save my files using the primary key of the entry. Here

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.