30

Je suis tombé sur ces 2 articles qui combinaient le filtrage collaboratif (factorisation matricielle) et la modélisation de thèmes (LDA) pour recommander aux utilisateurs des articles/articles similaires basés sur les termes de poste/articles intéressés.Implémentation simple en Python de la modélisation collaborative de sujets?

en format PDF) sont: "Collaborative Topic Modeling for Recommending Scientific Articles" et "Collaborative Topic Modeling for Recommending GitHub Repositories"

Le nouvel algorithme est appelé régression sujet de collaboration. J'espérais trouver un code python qui a mis en œuvre cela, mais en vain. Cela peut être long, mais quelqu'un peut-il montrer un exemple simple de python?

+6

Il existe plusieurs packages Python pour la modélisation de thèmes répertoriés sur https://www.cs.princeton.edu/~blei /topicmodeling.html. –

+0

En C++, [il y a ctr] (https://github.com/Blei-Lab/ctr). – kamalbanga

+2

Le référentiel dans le lien de kamalbanga ci-dessus utilise le premier papier que vous avez mentionné. Bien qu'il soit écrit en C++, vous pouvez [l'appeler depuis python] (http://stackoverflow.com/questions/145270/calling-c-c-from-python). – jtitusj

Répondre

-1

Comme vous avez marqué apprentissage automatique et python, avez-vous un oeil à modules python pandas & sklearn, parce qu'avec les deux, vous pouvez créer rapidement un grand nombre d'objets de régression linéaire.

Il y a également un exemple de code par rapport à Topic extraction (avec matrice non négatif factorisation et Latent Dirichlet Allocation) qui peut répondre à vos besoins exacts et aussi vous aider à découvrir module sklearn

Cordialement

2

Cette si vous commencer (mais ne sais pas pourquoi cela n'a pas encore été publiée): https://github.com/arongdari/python-topic-model

Plus précisément: https://github.com/arongdari/python-topic-model/blob/master/ptm/collabotm.py

class CollaborativeTopicModel: 
    """ 
    Wang, Chong, and David M. Blei. "Collaborative topic 
           modeling for recommending scientific articles." 
    Proceedings of the 17th ACM SIGKDD international conference on Knowledge 
           discovery and data mining. ACM, 2011. 
    Attributes 
    ---------- 
    n_item: int 
     number of items 
    n_user: int 
     number of users 
    R: ndarray, shape (n_user, n_item) 
     user x item rating matrix 
    """ 

Ça a l'air sympa et simple. Je suggère toujours au moins en regardant gensim. Radim a fait un excellent travail d'optimisation de ce logiciel.

0

Une implémentation LDA très simple utilisant le gensin. Vous pouvez trouver plus d'informations ici: https://radimrehurek.com/gensim/tutorial.html

J'espère que cela peut vous aider à

from nltk.corpus import stopwords 
from nltk.tokenize import RegexpTokenizer 
from nltk.stem import RSLPStemmer 
from gensim import corpora, models 
import gensim 

st = RSLPStemmer() 
texts = [] 

doc1 = "Veganism is both the practice of abstaining from the use of animal products, particularly in diet, and an associated philosophy that rejects the commodity status of animals" 
doc2 = "A follower of either the diet or the philosophy is known as a vegan." 
doc3 = "Distinctions are sometimes made between several categories of veganism." 
doc4 = "Dietary vegans refrain from ingesting animal products. This means avoiding not only meat but also egg and dairy products and other animal-derived foodstuffs." 
doc5 = "Some dietary vegans choose to wear clothing that includes animal products (for example, leather or wool)." 

docs = [doc1, doc2, doc3, doc4, doc5] 

for i in docs: 

    tokens = word_tokenize(i.lower()) 
    stopped_tokens = [w for w in tokens if not w in stopwords.words('english')] 
    stemmed_tokens = [st.stem(i) for i in stopped_tokens] 
    texts.append(stemmed_tokens) 

dictionary = corpora.Dictionary(texts) 
corpus = [dictionary.doc2bow(text) for text in texts] 

# generate LDA model using gensim 
ldamodel = gensim.models.ldamodel.LdaModel(corpus, num_topics=2, id2word = dictionary, passes=20) 
print(ldamodel.print_topics(num_topics=2, num_words=4)) 

[(0, * u'0.066 animal + 0,065 *, + 0,047 * produit + 0,028 * philosophie '), (1, u'0.085 *. + 0.047 * produit + 0.028 * dietary + 0.028 * veg ')]