# Function to automatically get relevant lda objects for plotting LDA visualization
def get_lda_objects(corpora, topics=4):
    
    """
    The function takes 2 inputs:
         - The corpus which is being used for LDA modelling
         - An integer which refers to the number of topics which should be plotted (defualt is 4)
        
    The function returns 3 variables:
        - Dictionary of the mapping of words and their identifications integer
        - Bag of words corpus based on the corpus input into the equation
        - LDA model with pre-specified number of topics
    
    A Random state of 13 has been added for reproducibililty of LDA model
    
    """
    
    # assigning dic to the dictionay mapping being created using gensim's Dictionary
    dic=gensim.corpora.Dictionary(corpora)
    
    # Bag of words generated by taking each word in the dictionary and using the doc2bow method from gensim's dictionary
    bow_corpus = [dic.doc2bow(doc) for doc in corpora]
    
    # LDA model being generated using the dictionary, bag of words and either 4 or a pre-specified number of topics 
    lda_model = gensim.models.LdaMulticore(bow_corpus, 
                                       num_topics = topics, 
                                       id2word = dic,                                    
                                       passes = 10,
                                       random_state=13,
                                       workers = 2)
    return lda_model, bow_corpus, dic
