0
import gensim
from gensim.models.doc2vec import TaggedDocument
taggeddocs = []
tag2tweetmap = {}
for index,i in enumerate(cleaned_tweets):
    if len(i) > 2: # Non empty tweets
        tag = u'SENT_{:d}'.format(index)
        sentence = TaggedDocument(words=gensim.utils.to_unicode(i).split(), tags=[tag])
        tag2tweetmap[tag] = i
        taggeddocs.append(sentence)
model = gensim.models.Doc2Vec(taggeddocs, dm=0, alpha=0.025, size=20, min_alpha=0.025, min_count=0)
for epoch in range(60):
    if epoch % 20 == 0:
        print('Now training epoch %s' % epoch)
   model.train(taggeddocs,total_examples=model.corpus_count,epochs=model.iter)
   model.alpha -= 0.002  
   model.min_alpha = model.alpha  
from sklearn.cluster import KMeans
dataSet = model.syn0
kmeansClustering = KMeans(n_clusters=6)
centroidIndx = kmeansClustering.fit_predict(dataSet)
topic2wordsmap = {}
for i, val in enumerate(dataSet):
    tag = model.docvecs.index_to_doctag(i)
    topic = centroidIndx[i]
    if topic in topic2wordsmap.keys():
        for w in (tag2tweetmap[tag].split()):
             topic2wordsmap[topic].append(w)
        else:
            topic2wordsmap[topic] = []
for i in topic2wordsmap:
    words = topic2wordsmap[i]
    print("Topic {} has words {}".format(i, words[:5]))

So I was trying to find out the most commonly used words and list of topics using doc2vec method. it's the attribute error, say that "Doc2Vec has no attribute syn0", I don't know what to do about it.

Dylan
  • 11
  • 2
  • 1
    Do not add code image link, copy/past your code – Pratik Prajapati Mar 04 '18 at 07:05
  • As per the comment above, please paste your code into your question directly. Also detail in your question the steps you have taken to attempt to solve the problem you are facing. Please see [How to ask a good question](https://stackoverflow.com/help/how-to-ask) in the help section of StackOverflow. – Ankush Mar 04 '18 at 07:07
  • The answer is going to depend on what version of `gensim` you're using. Also, your training's choice of `alpha`, `min_alpha`, and manual looping calls to `train()` is totally muddled & destructive. Wherever you learned/copied it from is a poor reference source – ignore it and find a better one. – gojomo Mar 05 '18 at 21:29

1 Answers1

0

I found this doc2vec tutorial may be give you some clue about your problem.

https://medium.com/@mishra.thedeepak/doc2vec-simple-implementation-example-df2afbbfbad5

Deepak Mishra
  • 25
  • 1
  • 7