Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titsuki/raku-algorithm-lda
A Raku Latent Dirichlet Allocation implementation
https://github.com/titsuki/raku-algorithm-lda
lda perl6 raku rakulang
Last synced: 11 days ago
JSON representation
A Raku Latent Dirichlet Allocation implementation
- Host: GitHub
- URL: https://github.com/titsuki/raku-algorithm-lda
- Owner: titsuki
- License: artistic-2.0
- Created: 2018-11-26T04:01:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-05T03:58:50.000Z (over 3 years ago)
- Last Synced: 2024-11-05T18:56:46.466Z (about 2 months ago)
- Topics: lda, perl6, raku, rakulang
- Language: C
- Homepage:
- Size: 40 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/titsuki/raku-Algorithm-LDA.svg?branch=master)](https://travis-ci.org/titsuki/raku-Algorithm-LDA)
NAME
====Algorithm::LDA - A Raku Latent Dirichlet Allocation implementation.
SYNOPSIS
========EXAMPLE 1
---------use Algorithm::LDA;
use Algorithm::LDA::Formatter;
use Algorithm::LDA::LDAModel;my @documents = (
"a b c",
"d e f",
);
my ($documents, $vocabs) = Algorithm::LDA::Formatter.from-plain(@documents);
my Algorithm::LDA $lda .= new(:$documents, :$vocabs);
my Algorithm::LDA::LDAModel $model = $lda.fit(:num-topics(3), :num-iterations(500));$model.topic-word-matrix.say; # show topic-word matrix
$model.document-topic-matrix; # show document-topic matrix
$model.log-likelihood.say; # show likelihood
$model.nbest-words-per-topic.say # show nbest words per topicEXAMPLE 2
---------use Algorithm::LDA;
use Algorithm::LDA::Formatter;
use Algorithm::LDA::LDAModel;# Note: You can get AP corpus as follows:
# $ wget "https://github.com/Blei-Lab/lda-c/blob/master/example/ap.tgz?raw=true" -O ap.tgz
# $ tar xvzf ap.tgzmy @vocabs = "./ap/vocab.txt".IO.lines;
my @documents = "./ap/ap.dat".IO.lines;
my $documents = Algorithm::LDA::Formatter.from-libsvm(@documents);my Algorithm::LDA $lda .= new(:$documents, :@vocabs);
my Algorithm::LDA::LDAModel $model = $lda.fit(:num-topics(20), :num-iterations(500));$model.topic-word-matrix.say; # show topic-word matrix
$model.document-topic-matrix; # show document-topic matrix
$model.log-likelihood.say; # show likelihood
$model.nbest-words-per-topic.say # show nbest words per topicDESCRIPTION
===========Algorithm::LDA is a Raku Latent Dirichlet Allocation implementation.
CONSTRUCTOR
-----------### new
Defined as:
submethod BUILD(:$!documents!, :$!vocabs! is raw) { }
Constructs a new Algorithm::LDA instance.
METHODS
-------### fit
Defined as:
method fit(Int :$num-iterations = 500, Int :$num-topics!, Num :$alpha = 0.1e0, Num :$beta = 0.1e0, Int :$seed --> Algorithm::LDA::LDAModel)
Returns an Algorithm::LDA::LDAModel instance.
* `:$num-ierations` is the number of iterations for gibbs sampler
* `:$num-topics!` is the number of topics
* `alpha` is the prior for theta distribution (i.e., document-topic distribution)
* `beta` is the prior for phi distribution (i.e., topic-word distribution)
* `seed` is the seed for srand
AUTHOR
======titsuki
COPYRIGHT AND LICENSE
=====================Copyright 2018 titsuki
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
The algorithm is from:
* Blei, David M., Andrew Y. Ng, and Michael I. Jordan. "Latent dirichlet allocation." Journal of machine Learning research 3.Jan (2003): 993-1022.
* Li, Wei, and Andrew McCallum. "Pachinko allocation: DAG-structured mixture models of topic correlations." Proceedings of the 23rd international conference on Machine learning. ACM, 2006.
* Wallach, Hanna M., et al. "Evaluation methods for topic models." Proceedings of the 26th annual international conference on machine learning. ACM, 2009.
* Minka, Thomas. "Estimating a Dirichlet distribution." (2000): 4.