Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function to get a coherence score #94

Closed
wants to merge 1 commit into from

Conversation

Viole-Grace
Copy link

Following the latest issue : #90

I have added a function to calculate coherence scores in _bertopic.py

tokens = [tokenizer_(doc) for doc in cleaned_documents]
dictionary = corpora.Dictionary(tokens)
corpus = [dictionary.doc2bow(token) for token in tokens]
topic_words_ = [[words for words, _ in self.get_topic(topic)] for topic in range(len(set(topics))-1)]
Copy link

@Amine-OMRI Amine-OMRI Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

topic_words_ = set([[words for words, _ in self.get_topic(topic)] for topic in range(len(set(topics))-1)])
use a set instead of a list to obtain unique words that will improve the NPMI score

"""

if coherence == None:
coherence = 'c_v'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def get_coherence_score(self, documents : List[str], coherence='c_v') -> float:
setting the defaul coherence to 'c_v'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoherenceModel uses gensim. Should I include gensim in the requirements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants