
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
lda-topic-model
Advanced tools
lda-topic-model is an implementation of LDA for node.js. It extracts topics from a collection of text documents and then associates the documents with their respective topics. The model is trained by going through each word of every text documents and sampling a topic for that word. Intially the topics are all randomely assigned words from the documents. This is repeated hundreds of times.
In natural language processing, latent Dirichlet allocation (LDA) is a generative statistical model that allows sets of observations to be explained by unobserved groups that explain why some parts of the data are similar. For example, if observations are words collected into documents, it posits that each document is a mixture of a small number of topics and that each word's presence is attributable to one of the document's topics. LDA is an example of a topic model.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
npm install lda-topic-model
const LDA = requrie('lda-topic-model');
const document = [
{
id: '1',
text: 'I love doing topic modelling! It helps me find qualitative data from my text much faster'
},
{
id: '2',
text: 'You should really try LDA topic modelling to save time and do work for you'
}
];
const options = {
displayingStopwords: false,
language: 'en',
numberTopics: 2,
sweeps: 100,
stem: true,
};
const lda = new Lda(options, document, dictionary);
console.log(lda.getTopicWords());
// gets the topics, topic words, and topic scores
// [
// {id: 0, topicText: love, topic, modelling, score: 0.5},
// {id: 1, topicText: try, topic, modelling, score: 0.5}
// ]
console.log(lda.getDocuments());
// gets the documents and words belonging to each topic
// [
// {
// topics: 0,
// documents: [
// {
// id: '1',
// text: 'I love doing topic modelling! It helps me find //qualitative data from my text much faster'
// score: 0.2
// }
// ],
// documentVocab: [
// {
// word: love,
// count: 1,
// stopword: no,
// specificity: 1
// },
// {
// word: topic,
// count: 2,
// stopword: no,
// specificity: 0
// }
// ],
// {
// topics: 1,
// documents: [
// {
// id: '2',
// text: 'You should really try LDA topic modelling to save time and do work for you'
// score: 0.21
// }
// ],
// documentVocab: [
// {
// word: try,
// count: 1,
// stopword: no,
// specificity: 1
// },
// {
// word: topic,
// count: 2,
// stopword: no,
// specificity: 0
// }
// ]
// }
// }
// ]
console.log(lda.getVocab());
// gets the words counts and vocab of documents
// [
// {
// word: try,
// count: 1,
// stopword: no,
// specificity: 1
// },
// {
// word: topic,
// count: 2,
// stopword: no,
// specificity: 0
// },
// {
// word: modelling,
// count: 2,
// stopword: no,
// specificity: 0
// }
// ]
To run the algorithm on corpus of text use the following code
const lda = new Lda(options, document, dictionary);
The constructor has three parameters
There are 5 optional settings that you can configure before running LDA
getVocab()
{
displayingStopwords: false,
language: 'en',
numberTopics: 10,
sweeps: 100,
stem: true,
}
The body of the document should be as below
[
{
id: '1',
text: 'I love doing topic modelling! It helps me find qualitative data from my text much faster'
},
{
id: '2',
text: 'You should really try LDA topic modelling to save time and do work for you'
}
]
Based on https://github.com/primaryobjects/lda and https://github.com/mimno/jsLDA implementations
FAQs
LDA topic modelling in javascript for node.js
We found that lda-topic-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.