-
Notifications
You must be signed in to change notification settings - Fork 87
Add sample ML-based topic modeling support #170
base: master
Are you sure you want to change the base?
Conversation
tokenize articles
…r yet) 2. A path helper to assit import 3. modified token_pool to make it compatible with LDA model
… into topic_modelling
Changes Unknown when pulling a23aa13 on topic_modelling into ** on master**. |
Changes Unknown when pulling a23aa13 on topic_modelling into ** on master**. |
|
Hey Dongge, thanks for the PR! Good job on encapsulating both LDA libraries into classes! Also, it's great that you've put in effort into docstring'ing your methods - as you might have noticed, we don't write docstrings for our methods (but I suppose we should). Before you continue working on LDA, I'd like to merge this PR into Before the merge, I'd like you to consider making some additional changes in your branch. Some of these changes are common "good" practices used in software development, some others are just ways we like to do things. I hope that you won't feel overwhelmed by the huge list of changes. General:
Token pool:
LDA:
Side notes: The following is admittedly some copy-pasta from another pull request that I have reviewed recently :), but I hope that you will find it useful too: Admittedly, we're pretty far from "practice what you preach" when it comes to commit messages, but out of general curiosity, skim through the legendary How to Write a Git Commit Message page. I find that putting in more effort into my own commit messages becomes more and more important for me over time, as I constantly have to revisit my own code after months or years, so when committing some changes, I try to think of the "future me" (or some other developer) when trying to explain what my code is all about. One last strategy that I try to employ to do my future-self a favor is that I try to make my commits atomic, i.e. I avoid having "fix stuff" commits with changes over 10kLoC. While it takes more time to do all those separate commits, it:
Very promising work so far, Dongge, looking forward to your fixes! |
1. Made every variable and method priavte if possible 2. Reformatted code with Pycharm shortcut 3. Added tests for TokenPool (works well) and ModelGensim (does work due to 'no module named XXX' problem when model_gensim is calling its abstract parent) 4. Decoupled token_pool and model_* 5. Used if __name__ == '__main__' to give a simple demonstration on how to use each mehtod Model_* 1. Renamed mode_lda.py and model_lda2.py to model_gensim.py (which uses the Gensim package) and model_lda.py (which uses the LDA package) 2. Added a abstract parent class TopicModel.py 3. Moved some code from summarise() to add_stories() (a. better structure of code; b. improved performance) 4. Changed some constants to function arguments (e.g. total_topic_num, iteration_num, etc.) TokenPool 1. Added mc_root_path() when locating the stopwords file 2. Modified query in token pool: 1. added "INNER JOIN stories WHERE language='en'" to guarantee all stories are in English 2. added "LIMIT" and corresponding "SELECT DISTINCT ... ORDER BY..." to guarantee only fetch the required number of stroies (thus improves performance) 3. added "OFFSET" 3. Restructured token_pool.py, so that the stories are traversed only once (thus improves performance) 4. Decoupled DB from token_pool.py 5. Replace regex tokenization with nltk.tokenizer 6. Added nltk.stem.WordNetLemmatizer to lemmatize (which gives a better result than stemming) tokens
|
…ter efficiency and performance I will combine these two later
…en combined with tune_with_polynomial
… and cache dependencies
This allows more flexibility in Travis (i.e. use larger samples if we can run tests longer in Travis)
2. improve performance based on empirical results
added more comments
tokenize articles