Giter Site home page Giter Site logo

topic-model-tutorial's People

Contributors

derekgreene avatar timoflesch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

topic-model-tutorial's Issues

(NMF) calculating coherence in NMF generates different outputs each time when method is called

I am trying to calculate the coherence value on each topic but each time when I run my code it generates different values.

It will be a great help if anyone can answer this.

Thank you in advance

def build_w2c(self, raw_documents):
    docgen = TokenGenerator(raw_documents, self.stop_words)
    new_list = []
    for each in docgen.documents:
        new_list.append(each.split(" "))
    # print(new_list)
    # Build the word2vec model
    self.w2v_model = gensim.models.Word2Vec(size=500, min_count=0.0005, sg=1)
    self.w2v_model.build_vocab(sentences=new_list)
    return self.w2v_model

def get_descriptor(self, all_terms, H, topic_index, top):
    # reverse sort the values to sort the indices
    top_indices = np.argsort(H[topic_index, :])[::-1]
    # now get the terms corresponding to the top-ranked indices
    top_terms = []
    for term_index in top_indices[0:top]:
        top_terms.append(all_terms[term_index])
    return top_terms
def get_coherence(self, k, terms, H):
    k_values = []
    term_rankings = []
    coherences = []
    dict = {}
    for topic_index in range(1, k):
        print(topic_index)
        descriptor = self.get_descriptor(terms , H, topic_index, 10)
        term_rankings.append(descriptor)
    # Now calculate the coherence based on our Word2vec model
    #coherence = self.calculate_coherence(term_rankings)
        coherences.append(self.calculate_coherence(term_rankings))
        print("K=%02d: Coherence=%.4f" % (topic_index, coherences[-1]))
        k_values.append(topic_index)
        dict[topic_index] = coherences[-1]
    max_key = max(dict, key=dict.get)
    return k_values, coherences, max_key

def calculate_coherence(self, term_rankings):
    overall_coherence = 0.0
    for topic_index in range(len(term_rankings)):
        # check each pair of terms
        pair_scores = []
        for pair in combinations(term_rankings[topic_index], 2):
            pair_scores.append(self.w2v_model.similarity(pair[0], pair[1]))
        # get the mean for all pairs in this topic
        topic_score = sum(pair_scores) / len(pair_scores)
        overall_coherence += topic_score
    # get the mean score across all topics
    return overall_coherence / len(term_rankings)

here is my code that I have used in my project.

Output Required:
Each time when I run my code coherence should be the same.

if you can help me to resolve this approach it would be a great help
thank you so much.

Data reference

Can you please give the reference of how the text data has been collected?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.