piskvorky / gensim

Topic Modelling for Humans
https://radimrehurek.com/gensim
GNU Lesser General Public License v2.1
15.55k stars 4.37k forks source link

DTM tutorial steps extracted all the same topics for all timestamps #1602

Closed hedgy123 closed 6 years ago

hedgy123 commented 6 years ago

Hi,

I've tried following the DTM tutorial almost line by line to extract topics from a corpus. Using scikit-learn, I can see that there are distinct topics in the corpus, and also that the topics change as a function of time. However, dtm doesn't seem to produce anything that makes sense.

Here is my 4-member list of documents:

  documents = [[u'worth', u'deli', u'month', u'enjoy', u'bacon', u'second', u'street', u'even', u'new',u'ever', u'told', u'met', u'daughter', u'brought', u'spoke', u'would', u'asset', u'type', u'tell', u'phone', u'hold', u'room', u'work', u'fresher', u'give', u'household', u'want', u'keep', u'bag', u'end', u'thing', u'travel', u'hot', u'lay', u'third', u'alka', u'greet', u'green', u'enter', u'order', u'wine', u'better', u'easier', u'bread', u'meat', u'went', u'forgot', u'laid', u'got', u'free', u'local', u'tilapia', u'shopper', u'top', u'took', u'hadnt', u'matter', u'mind', u'manner', u'seen', u'seem', u'brandon', u'blue', u'though', u'regular', u'stood', u'make', u'layout', u'aldi', u'stop', u'watermelon', u'twice', u'bad', u'respond', u'best', u'said', u'away', u'yogurt', u'never', u'fault', u'tone', u'speak', u'bathroom', u'beef', u'much', u'save', u'n', u'dept', u'near', u'neat', u'gave', u'sushi', u'cant', u'im', u'ie', u'hand', u'butter', u'kept', u'contact', u'left', u'previous', u'spread', u'gift', u'cooler', u'right', u'old', u'deal', u'ice', u'discount', u'super', u'dinner', u'wrap', u'way', u'head', u'offer', u'upset', u'drive', u'check', u'floor', u'tie', u'smell', u'kroger', u'longer', u'loyal', u'time', u'mile', u'milk', u'anyway', u'item', u'team', u'guy', u'pork', u'sign', u'cost', u'patient', u'clerk', u'along', u'wait', u'box', u'shift', u'love', u'extra', u'prefer', u'market', u'visit', u'live', u'creamer', u'checkout', u'today', u'cashier', u'car', u'product', u'may', u'date', u'man', u'talk', u'still', u'thank', u'main', u'non', u'within', u'name', u'receipt', u'happen', u'correct', u'cart', u'california', u'card', u'care', u'place', u'think', u'frequent', u'first', u'one', u'long', u'ring', u'open', u'tomorrow', u'size', u'checker', u'wide', u'raincheck', u'nicer', u'say', u'saw', u'take', u'sure', u'price', u'knew', u'paid', u'seafood', u'later', u'sale', u'senior', u'shop', u'show', u'bright', u'ground', u'slow', u'enough', u'get', u'seldom', u'husband', u'across', u'sacker', u'come', u'restroom', u'pop', u'mark', u'ive', u'everyday', u'pay', u'trip', u'week', u'assist', u'fruit', u'without', u'reward', u'money', u'young', u'rest', u'speed', u'except', u'real', u'around', u'read', u'world', u'tend', u'either', u'perfer', u'highest', u'wheat', u'ok', u'act', u'road', u'coupon', u'strip', u'area', u'start', u'low', u'heb', u'regard', u'toilet', u'certain', u'incorrect', u'personnel', u'event', u'poor', u'wife', u'missouri', u'follow', u'smile', u'fav', u'fat', u'ticket', u'list', u'small', u'neighborhood', u'andor', u'past', u'section', u'prior', u'amount', u'pick', u'put', u'eye', u'two', u'particular', u'town', u'none', u'del', u'scan', u'gallon', u'huge', u'okay', u'rude', u'short', u'egg', u'help', u'paper', u'might', u'good', u'return', u'food', u'found', u'hard', u'expect', u'beyond', u'health', u'print', u'friday', u'guess', u'pleasant', u'quick', u'reason', u'ask', u'major', u'dont', u'feel', u'number', u'done', u'gourmet', u'least', u'store', u'relationship', u'park', u'kind', u'wasnt', u'sell', u'self', u'jonmark', u'reach', u'plan', u'clear', u'part', u'clean', u'fine', u'find', u'express', u'cheaper', u'cold', u'x', u'see', u'close', u'grocer', u'sold', u'water', u'last', u'mega', u'whole', u'point', u'ran', u'pm', u'citizen', u'understand', u'demand', u'look', u'frozen', u'bill', u'smart', u'error', u'higher', u'walmart', u'lower', u'person', u'cut', u'also', u'eager', u'easter', u'complaint', u'big', u'bit', u'like', u'lost', u'often', u'back', u'understood', u'run', u'question', u'fast', u'doubt', u'line', u'us', u'nice', u'lane', u'e', u'came', u'fresh', u'hello', u'code', u'go', u'sent', u'download', u'cell', u'let', u'great', u'larger', u'survey', u'app', u'use', u'next', u'sore', u'didnt', u'high', u'friendlier', u'instead', u'stand', u'watch', u'light', u'counter', u'move', u'lb', u'front', u'day', u'stock', u'special', u'red', u'que', u'could', u'david', u'lot', u'shelf', u'bother', u'need', u'pharmacist', u'request', u'hi', u'fact', u'bring', u'keyera', u'chicken', u'staff', u'fuel', u'familiar', u'closer', u'neither', u'bought', u'job', u'instant', u'etc', u'comment', u'gone', u'walk', u'commend', u'ad', u'treat', u'vanilla', u'ill', u'almost', u'began', u'cream', u'upon', u'center', u'well', u'thought', u'rush', u'less', u'half', u'match', u'know', u'desk', u'helpful', u'soft', u'church', u'home', u'although', u'justin', u'buy', u'brand', u'bagger', u'made', u'whether', u'wish', u'smooth', u'cake', u'problem'], [u'four', u'deli', u'enjoy', u'second', u'street', u'even', u'new', u'ever', u'told', u'met', u'cart', u'daughter', u'credit', u'brought', u'total', u'spoke', u'would', u'call', u'asset', u'recommend', u'tell', u'warm', u'must', u'room', u'work', u'give', u'want', u'end', u'turn', u'far', u'hot', u'mess', u'earlier', u'wrong', u'lot', u'greet', u'green', u'fan', u'order', u'wine', u'better', u'mgmt', u'bread', u'meat', u'roast', u'went', u'side', u'saturday', u'got', u'free', u'rang', u'shopper', u'top', u'listen', u'took', u'esta', u'ran', u'mind', u'ginger', u'manner', u'seen', u'seem', u'blue', u'regular', u'dog', u'came', u'layout', u'explain', u'aldi', u'stop', u'watermelon', u'bag', u'bad', u'steak', u'steam', u'best', u'said', u'away', u'muy', u'bien', u'yogurt', u'never', u'theresa', u'speak', u'much', u'life', u'xxx', u'worker', u'near', u'neat', u'k', u'cant', u'im', u'id', u'suggest', u'make', u'rain', u'hand', u'butter', u'kept', u'game', u'left', u'save', u'apart', u'gift', u'right', u'old', u'deal', u'ice', u'corn', u'discount', u'super', u'afternoon', u'way', u'head', u'offer', u'true', u'fort', u'later', u'drive', u'mold', u'trip', u'floor', u'na', u'til', u'roll', u'felt', u'weekend', u'phone', u'loyal', u'time', u'mile', u'milk', u'brown', u'level', u'item', u'team', u'quick', u'guy', u'round', u'pork', u'sign', u'cost', u'appear', u'clerk', u'address', u'along', u'wait', u'love', u'extra', u'prefer', u'visit', u'live', u'thru', u'checkout', u'today', u'cashier', u'car', u'soup', u'freezer', u'alway', u'product', u'may', u'floral', u'man', u'basket', u'talk', u'cold', u'still', u'mail', u'main', u'half', u'son', u'wont', u'name', u'en', u'receipt', u'year', u'girl', u'es', u'correct', u'card', u'care', u'thing', u'place', u'think', u'frequent', u'first', u'one', u'long', u'ring', u'open', u'size', u'given', u'plastic', u'checker', u'wide', u'pre', u'raincheck', u'say', u'saw', u'take', u'sure', u'price', u'knew', u'paid', u'seafood', u'sale', u'senior', u'shop', u'shot', u'slow', u'behind', u'get', u'husband', u'concern', u'across', u'sacker', u'come', u'por', u'squash', u'case', u'ive', u'restroom', u'pay', u'check', u'week', u'assist', u'fruit', u'without', u'reward', u'comment', u'outdoor', u'money', u'rest', u'brianna', u'rose', u'except', u'around', u'either', u'satisfecha', u'tube', u'broken', u'found', u'throw', u'ok', u'area', u'hey', u'start', u'low', u'heb', u'enough', u'younger', u'longer', u'asst', u'gone', u'ad', u'certain', u'personnel', u'event', u'poor', u'missouri', u'month', u'tx', u'program', u'smile', u'fall', u'list', u'small', u'neighborhood', u'past', u'pass', u'stood', u'section', u'full', u'reason', u'prior', u'amount', u'pick', u'ask', u'select', u'eye', u'two', u'particular', u'none', u'hour', u'learn', u'clutter', u'prompt', u'scan', u'huge', u'rather', u'rude', u'soda', u'reflect', u'short', u'began', u'help', u'soon', u'paper', u'late', u'friendliest', u'might', u'good', u'return', u'food', u'bigger', u'fish', u'hard', u'expect', u'todo', u'friday', u'guess', u'pleasant', u'dont', u'feel', u'number', u'interact', u'least', u'storm', u'store', u'option', u'deshawn', u'kind', u'toward', u'wasnt', u'self', u'also', u'part', u'cereal', u'fine', u'find', u'access', u'express', u'cheaper', u'breast', u'set', u'see', u'bare', u'sea', u'close', u'sold', u'water', u'last', u'mega', u'whole', u'load', u'point', u'sweet', u'throughout', u'due', u'pm', u'gal', u'understand', u'look', u'frozen', u'bill', u'pack', u'pound', u'kroger', u'belong', u'tiljuanna', u'higher', u'walmart', u'older', u'spent', u'person', u'spend', u'cut', u'eager', u'app', u'complaint', u'big', u'redeem', u'bit', u'often', u'back', u'pet', u'though', u'per', u'run', u'bc', u'within', u'question', u'fast', u'line', u'us', u'nice', u'clean', u'lane', u'e', u'fresh', u'hello', u'go', u'young', u'lower', u'sent', u'booth', u'download', u'cell', u'chose', u'let', u'great', u'larger', u'survey', u'opinion', u'use', u'next', u'meet', u'didnt', u'high', u'bend', u'six', u'instead', u'stock', u'farm', u'watch', u'ronald', u'counter', u'houston', u'move', u'perfect', u'lo', u'coupon', u'weber', u'front', u'day', u'red', u'que', u'could', u'put', u'keep', u'sack', u'fair', u'system', u'shelf', u'need', u'gluten', u'pharmacist', u'face', u'fact', u'bring', u'chicken', u'staff', u'fuel', u'local', u'hope', u'familiar', u'rush', u'werent', u'twice', u'stuff', u'state', u'bought', u'job', u'thank', u'etc', u'co', u'walk', u'cent', u'vanilla', u'ripe', u'almost', u'cream', u'difficult', u'upon', u'center', u'well', u'thought', u'usual', u'less', u'bell', u'add', u'citizen', u'match', u'know', u'desk', u'like', u'dept', u'page', u'home', u'although', u'justin', u'three', u'scanner', u'buy', u'brand', u'bagger', u'eat', u'made', u'wish', u'problem', u'threw', u'special', u'sick', u'stay'], [u'four', u'hate', u'restock', u'worth', u'deli', u'frozen', u'enjoy', u'almond', u'bacon', u'second', u'street', u'ill', u'even', u'new', u'ever', u'told', u'men', u'met', u'brought', u'spoke', u'would', u'call', u'type', u'tell', u'hurt', u'phone', u'must', u'word', u'room', u'work', u'ms', u'mr', u'fresher', u'give', u'want', u'end', u'turn', u'hot', u'mess', u'earlier', u'wrong', u'greet', u'order', u'feedback', u'oven', u'better', u'easier', u'interrupt', u'one', u'bank', u'bread', u'meat', u'went', u'side', u'forgot', u'got', u'free', u'rang', u'shopper', u'top', u'took', u'esta', u'ran', u'raw', u'manner', u'seen', u'seem', u'though', u'regular', u'came', u'teresa', u'layout', u'explain', u'stop', u'bar', u'bad', u'best', u'said', u'away', u'gentleman', u'yogurt', u'never', u'speak', u'beef', u'three', u'beer', u'much', u'dept', u'near', u'neat', u'cant', u'im', u'id', u'suggest', u'make', u'split', u'hand', u'butter', u'kept', u'left', u'yet', u'previous', u'ham', u'save', u'gave', u'night', u'sacker', u'right', u'old', u'deal', u'bottom', u'ice', u'discount', u'dinner', u'wan', u'wal', u'gift', u'way', u'head', u'true', u'sale', u'face', u'check', u'floor', u'na', u'smell', u'roll', u'felt', u'diet', u'younger', u'faster', u'loyal', u'fact', u'time', u'mild', u'milk', u'row', u'item', u'quick', u'guy', u'round', u'pork', u'sign', u'run', u'clerk', u'slow', u'wait', u'box', u'bob', u'love', u'extra', u'prefer', u'super', u'visit', u'live', u'today', u'cashier', u'car', u'soup', u'kym', u'sunday', u'product', u'may', u'date', u'man', u'basket', u'talk', u'cold', u'still', u'group', u'thank', u'mail', u'gel', u'non', u'half', u'son', u'name', u'rock', u'pizza', u'el', u'receipt', u'es', u'correct', u'cart', u'card', u'care', u'thing', u'place', u'think', u'frequent', u'first', u'fast', u'ring', u'open', u'size', u'plastic', u'checker', u'wide', u'bag', u'say', u'saw', u'tshey', u'greek', u'note', u'take', u'green', u'sure', u'normal', u'price', u'paid', u'seafood', u'senior', u'shop', u'shot', u'bright', u'label', u'enough', u'get', u'across', u'come', u'por', u'turkey', u'mark', u'mart', u'case', u'ive', u'clutter', u'buyl', u'pay', u'trip', u'week', u'without', u'money', u'flavor', u'except', u'around', u'read', u'traffic', u'either', u'satisfecha', u'tube', u'wheat', u'broken', u'found', u'comparison', u'act', u'road', u'coupon', u'area', u'start', u'low', u'heb', u'expect', u'toilet', u'certain', u'file', u'fill', u'incorrect', u'personnel', u'event', u'trash', u'u', u'missouri', u'lack', u'dollar', u'month', u'tx', u'program', u'smile', u'woman', u'far', u'fat', u'list', u'small', u'neighborhood', u'andor', u'past', u'stood', u'section', u'public', u'movement', u'full', u'theresa', u'search', u'ahead', u'amount', u'pick', u'select', u'eye', u'two', u'taken', u'diamond', u'particular', u'none', u'hour', u'prompt', u'scan', u'accept', u'huge', u'rather', u'sandwich', u'okay', u'rude', u'short', u'egg', u'help', u'soon', u'paper', u'might', u'good', u'return', u'food', u'weight', u'fish', u'hard', u'finish', u'beyond', u'todo', u'shipment', u'friday', u'pleasant', u'reason', u'put', u'teach', u'fruit', u'dont', u'feel', u'number', u'smaller', u'done', u'miss', u'interact', u'least', u'station', u'jed', u'store', u'part', u'kind', u'cleaner', u'wasnt', u'self', u'reach', u'clean', u'fine', u'find', u'express', u'cheaper', u'silk', u'courteous', u'see', u'close', u'sold', u'water', u'last', u'mega', u'whole', u'point', u'sweet', u'throughout', u'belt', u'due', u'pm', u'look', u'pack', u'kroger', u'higher', u'walmart', u'lower', u'older', u'spent', u'person', u'spend', u'patel', u'cut', u'big', u'bit', u'often', u'back', u'pet', u'patient', u'within', u'question', u'long', u'line', u'checkout', u'us', u'nice', u'competitor', u'ago', u'lane', u'inout', u'fresh', u'hello', u'go', u'young', u'sent', u'cell', u'rotten', u'let', u'great', u'larger', u'survey', u'app', u'use', u'next', u'salad', u'didnt', u'kassidi', u'process', u'high', u'friendlier', u'instead', u'stand', u'counter', u'move', u'meatseafood', u'perfect', u'la', u'willing', u'holiday', u'front', u'day', u'stock', u'special', u'que', u'could', u'ask', u'keep', u'sack', u'floral', u'lot', u'shelf', u'bother', u'neel', u'need', u'mix', u'pharmacist', u'bring', u'chicken', u'longer', u'staff', u'jar', u'fuel', u'hope', u'familiar', u'rush', u'werent', u'stuff', u'grab', u'salmon', u'closer', u'state', u'bought', u'job', u'etc', u'comment', u'gone', u'walk', u'respect', u'ad', u'decent', u'treat', u'almost', u'cream', u'drink', u'center', u'well', u'thought', u'usual', u'less', u'bell', u'match', u'know', u'desk', u'like', u'soft', u'italian', u'home', u'avoid', u'although', u'buy', u'gluten', u'brand', u'hi', u'bagger', u'eat', u'also', u'made', u'wish', u'cake', u'problem', u'display', u'girl'], [u'worth', u'deli', u'school', u'enjoy', u'bacon', u'second', u'street', u'even', u'new', u'ever', u'told', u'never', u'credit', u'brought', u'total', u'spoke', u'would', u'call', u'type', u'tell', u'oscar', u'phone', u'hold', u'must', u'room', u'work', u'ms', u'give', u'want', u'end', u'thing', u'greet', u'order', u'better', u'easier', u'bread', u'meat', u'went', u'got', u'free', u'small', u'rang', u'shopper', u'listen', u'took', u'manner', u'seen', u'seem', u'though', u'regular', u'came', u'teresa', u'layout', u'earn', u'bag', u'bad', u'best', u'said', u'away', u'gentleman', u'yogurt', u'speak', u'bathroom', u'beef', u'three', u'much', u'life', u'worker', u'meyer', u'n', u'dept', u'near', u'neat', u'cant', u'im', u'make', u'rain', u'hand', u'butter', u'kept', u'contact', u'left', u'yet', u'save', u'gave', u'gift', u'night', u'right', u'old', u'deal', u'ice', u'corn', u'discount', u'super', u'dinner', u'nixon', u'son', u'wal', u'way', u'war', u'head', u'offer', u'true', u'sale', u'door', u'download', u'check', u'na', u'nd', u'til', u'felt', u'diet', u'longer', u'loyal', u'time', u'mile', u'milk', u'veg', u'brown', u'cool', u'item', u'quick', u'yall', u'pork', u'cost', u'appear', u'current', u'clerk', u'water', u'wait', u'love', u'extra', u'prefer', u'visit', u'live', u'thru', u'checkout', u'today', u'cashier', u'effort', u'car', u'product', u'may', u'floral', u'man', u'basket', u'still', u'thank', u'non', u'name', u'receipt', u'year', u'space', u'cart', u'card', u'place', u'think', u'first', u'one', u'long', u'ring', u'open', u'checker', u'wide', u'coconut', u'raincheck', u'sad', u'say', u'saw', u'take', u'sure', u'price', u'knew', u'seafood', u'later', u'drive', u'senior', u'shop', u'show', u'bright', u'corner', u'ground', u'slow', u'enough', u'black', u'get', u'behind', u'across', u'come', u'turkey', u'case', u'ive', u'etc', u'pay', u'trip', u'week', u'finish', u'assist', u'fruit', u'without', u'reward', u'comment', u'money', u'flavor', u'real', u'around', u'isiss', u'either', u'found', u'ok', u'stand', u'luck', u'road', u'mart', u'area', u'start', u'low', u'heb', u'regard', u'taylor', u'ad', u'cream', u'peak', u'wife', u'missouri', u'month', u'children', u'program', u'th', u'smile', u'woman', u'far', u'list', u'yasmin', u'neighborhood', u'tea', u'cash', u'past', u'pass', u'section', u'full', u'theresa', u'pick', u'put', u'eye', u'two', u'diamond', u'dion', u'particular', u'glad', u'none', u'learn', u'accept', u'huge', u'rather', u'okay', u'rude', u'short', u'help', u'paper', u'might', u'good', u'food', u'pregnant', u'fish', u'hard', u'expect', u'beyond', u'event', u'hill', u'friday', u'pleasant', u'reason', u'ask', u'dont', u'feel', u'number', u'least', u'store', u'park', u'part', u'kind', u'toward', u'wasnt', u'sell', u'self', u'lit', u'also', u'reach', u'clear', u'mylnn', u'clean', u'gold', u'fine', u'find', u'express', u'see', u'close', u'sold', u'last', u'mega', u'whole', u'bell', u'sweet', u'church', u'belt', u'due', u'pm', u'look', u'frozen', u'budget', u'pack', u'kroger', u'higher', u'walmart', u'lower', u'person', u'five', u'patel', u'easter', u'big', u'bit', u'often', u'back', u'run', u'question', u'fast', u'line', u'us', u'nice', u'helpful', u'lane', u'e', u'fresh', u'hello', u'go', u'young', u'access', u'let', u'great', u'larger', u'survey', u'app', u'use', u'next', u'sort', u'salad', u'meet', u'didnt', u'high', u'instead', u'toddler', u'stock', u'stop', u'counter', u'move', u'bunch', u'perfect', u'lb', u'coupon', u'front', u'day', u'circular', u'lentil', u'special', u'could', u'keep', u'date', u'accent', u'lot', u'shelf', u'need', u'pharmacist', u'upset', u'fact', u'chicken', u'staff', u'fuel', u'local', u'hope', u'familiar', u'werent', u'closer', u'bought', u'job', u'walk', u'scanner', u'main', u'ripe', u'almost', u'upon', u'center', u'well', u'thought', u'usual', u'less', u'obtain', u'citizen', u'know', u'like', u'onion', u'home', u'buy', u'brand', u'bagger', u'made', u'wish', u'cake', u'problem', u'threw', u'display', u'monday']]

Then I do:

 class DTMcorpus(corpora.textcorpus.TextCorpus):

     def get_texts(self):
         return self.input

   def __len__(self):
        return len(self.input)

corpus = DTMcorpus(documents)
time_seq = [2,2]

and

model = DtmModel(dtm_path, corpus, time_seq, num_topics=10,
              id2word=corpus.dictionary, initialize_lda=True)

everything seems to run ok, so finally I print out the first 3 topics from the first time slice:

topics1 = model.show_topic(topicid=0, time=0, num_words=10)
topics2 = model.show_topic(topicid=1,time=0,num_words=10)
topics3 = model.show_topic(topicid=2,time=0,num_words=10)

which gives me

([(0.0013106159895150723, u'per'),
(0.0013106159895150723, u'access'),
(0.0013106159895150723, u'saturday'),
(0.0013106159895150723, u'es'),
(0.0013106159895150723, u'concern'),
(0.0013106159895150723, u'throughout'),
(0.0013106159895150723, u'appear'),
(0.0013106159895150723, u'pet'),
(0.0013106159895150723, u'tube'),
(0.0013106159895150723, u'muy')],
[(0.0013106159895150723, u'per'),
(0.0013106159895150723, u'access'),
(0.0013106159895150723, u'saturday'),
(0.0013106159895150723, u'es'),
(0.0013106159895150723, u'concern'),
(0.0013106159895150723, u'throughout'),
(0.0013106159895150723, u'appear'),
(0.0013106159895150723, u'pet'),
(0.0013106159895150723, u'tube'),
(0.0013106159895150723, u'muy')],
[(0.0013106159895150717, u'per'),
(0.0013106159895150717, u'access'),
(0.0013106159895150717, u'saturday'),
(0.0013106159895150717, u'es'),
(0.0013106159895150717, u'concern'),
(0.0013106159895150717, u'throughout'),
(0.0013106159895150717, u'appear'),
(0.0013106159895150717, u'pet'),
(0.0013106159895150717, u'tube'),
(0.0013106159895150717, u'muy')])   

I also get the exact same topics for any other time slice.

Could you please help. Thank you!

menshikh-iv commented 6 years ago

I reproduced your problem, but we have the wrapper for DTM (not our implementation), original code from blei-lab/dtm. You need to create an issue in original repository.