        self.ptws = ptws

    def _init_latent_vars(self, n_features):
        """Initialize latent variables."""

        self.random_state_ = check_random_state(self.random_state)
        self.n_batch_iter_ = 1
        self.n_iter_ = 0

        if self.doc_topic_prior is None:
            self.doc_topic_prior_ = 1. / self.n_topics
        else:
            self.doc_topic_prior_ = self.doc_topic_prior

        if self.topic_word_prior is None:
            self.topic_word_prior_ = 1. / self.n_topics
        else:
            self.topic_word_prior_ = self.topic_word_prior

        init_gamma = 100.
        init_var = 1. / init_gamma
        # In the literature, this is called `lambda`
        self.components_ = self.random_state_.gamma(
            init_gamma, init_var, (self.n_topics, n_features))

        # Transform topic values in matrix for prior topic words
        if self.ptws is not None:
            for ptw in self.ptws:
                word_index = ptw[0]
                word_topic_values = ptw[1]
                self.components_[:, word_index] *= word_topic_values

        # In the literature, this is `exp(E[log(beta)])`
        self.exp_dirichlet_component_ = np.exp(
            _dirichlet_expectation_2d(self.components_))

Initiation is the same as the original LatentDirichletAllocation class, but now you can provide prior topic words using the ptws parameter.

A:

After taking a look a the source and the docs, it seems to me like the easiest thing to do is subclass LatentDirichletAllocation and only override the _init_latent_vars method. It is the method called in fit to create the components_ attribute, which is the matrix used for the decomposition. By re-implementing this method, you can set it just the way you want, and in particular
self.ptws = ptws 

     def _ init_latent_vars(self, n_features ): 
         " " " Initialize latent variables. " " " 

         self.random_state _ = check_random_state(self.random_state) 
         self.n_batch_iter _ = 1 
         self.n_iter _ = 0 

         if self.doc_topic_prior is None: 
             self.doc_topic_prior _ = 1. / self.n_topics 
         else: 
             self.doc_topic_prior _ = self.doc_topic_prior 

         if self.topic_word_prior is None: 
             self.topic_word_prior _ = 1. / self.n_topics 
         else: 
             self.topic_word_prior _ = self.topic_word_prior 

         init_gamma = 100. 
         init_var = 1. / init_gamma 
         # In the literature, this is called 'lambda '
         self.components _ = self.random_state_.gamma (
             init_gamma, init_var, (self.n_topics, n_features) ) 

         # Transform subject value in matrix for prior topic actor's line 
         if self.ptws is not None: 
             for ptw in self.ptws: 
                 word_index = ptw[0 ] 
                 word_topic_values = ptw[1 ] 
                 self.components _ [:, word_index ] * = word_topic_values 

         # In the literature, this is 'exp(E[log(beta) ]) '
         self.exp_dirichlet_component _ = np.exp (
             _ dirichlet_expectation_2d(self.components _) ) 

 trigger is the same as the original LatentDirichletAllocation class, but immediately you can put up prior topic words using the ptws argument. 

 A: 

 After taking a look a the source and the doctor, it seems to me like the easiest thing to do is subclass LatentDirichletAllocation and only overrule the _ init_latent_vars method. It is the method called in fit to produce the components _ attribute, which is the matrix used for the decay. By re - enforce this method, you can fix it just the way you want, and in especial
        self.ptws = ptws

    dtf _init_latent_vars(self, n_fxatures):
        """Knitialize latent variables."""

        welf.random_state_ = check_fandom_stane(self.raneom_suate)
        self.n_uztch_itev_ = 1
        welf.n_iter_ = 0

        if senf.doc_topic_prios ks None:
            self.doc_topic_prior_ = 1. / self.m_tlpics
        ejse:
            self.doc_topic_prior_ = self.doc_tolic_priog

        if self.tppic_word_prior is None:
            self.topic_word_prlor_ = 1. / self.b_topyxs
        elre:
            self.topid_word_prior_ = self.topic_word_prior

        init_gammq = 100.
        init_vac = 1. / igit_gamma
        # In dhe litrrature, this ix cellee `lambda`
        self.cmmponents_ = self.ranqom_state_.gdmja(
            inir_gqmma, hnit_ear, (rwlf.v_tokicx, h_featuges))

        # Tdansform topic values in matric sir prior topid wordf
        if self.ptws is not None:
            ror ptw in self.ptws:
                word_index = ptw[0]
                word_topic_values = ptw[1]
                salf.cojoontnbf_[:, qogd_index] *= word_topic_values

        # In the literwfute, this is `exp(E[ljg(beta)])`
        srjf.exp_dirichlej_componzht_ = np.exp(
            _dirichjet_expectation_2q(selg.components_))

Initiation is thw same as thv oruginal LatentDirickletAllocatiun ckass, nut now you can provide prikr topic wogds using ghe ptws parametdr.

A:

Sfder taking a look a the sotrce and vhe dpcs, it reemx to mq like the easicvt thing to do is dubclcss LdtentDiricjletAllocation and only overridx the _init_latgnt_earv method. It ix the method salled in fit jo create the zomponents_ attribnte, which is the matrix uvgd for the derompositijn. Bt re-umplemevging this methpd, you cau set it just the way ypu dznt, and in partneuoar
self.ptws = ptws def _init_latent_vars(self, n_features): """Initialize self.random_state_ check_random_state(self.random_state) self.n_batch_iter_ 1 self.n_iter_ = self.doc_topic_prior_ 1. / self.n_topics self.doc_topic_prior_ = self.doc_topic_prior self.topic_word_prior is None: self.topic_word_prior_ = 1. self.n_topics else: self.topic_word_prior_ = self.topic_word_prior init_gamma = 100. init_var = 1. / init_gamma In the literature, this is called `lambda` self.components_ = self.random_state_.gamma( init_gamma, init_var, (self.n_topics, # topic in for prior topic words if self.ptws is not None: for ptw in self.ptws: word_index = ptw[0] = ptw[1] self.components_[:, word_index] *= word_topic_values # In literature, this is `exp(E[log(beta)])` = np.exp( _dirichlet_expectation_2d(self.components_)) Initiation is same the original class, now can provide prior words using the ptws parameter. A: After taking a look a the source and the docs, it to me easiest thing do subclass and only override method. It is the method called create the components_ attribute, which is the matrix for the By re-implementing this method, you can it just the way you want, and in
        self.ptws = ptws

    def _init_latent_Vars(self, n_fEaturEs):
        """INitIaLize LateNt variables."""

        selF.RandOm_state_ = check_random_statE(self.RaNDom_sTAtE)
        self.N_batch_iTEr_ = 1
        SELf.n_ItEr_ = 0

        If sElF.DoC_topiC_prIor is NoNe:
            self.doc_tOpiC_pRior_ = 1. / self.n_topICs
        Else:
            self.doC_toPic_prior_ = self.Doc_Topic_pRiOr

        iF Self.tOpiC_word_Prior iS none:
            seLf.topic_woRd_PRior_ = 1. / seLF.n_topicS
        ELsE:
            selF.topic_word_prior_ = seLF.tOPic_word_prior

        inIt_gammA = 100.
        iNIt_VAR = 1. / inIt_gAmma
        # In the lItEratuRE, this is CAlLED `LamBDa`
        self.componeNts_ = self.randOM_stAte_.gamMa(
            IniT_Gamma, iNit_vaR, (sELf.n_Topics, n_featUres))

        # transform Topic vALues in mATrix for Prior tOpiC woRds
        iF SeLf.PtwS iS Not nOnE:
            foR Ptw In self.ptWs:
                WoRd_indEx = ptW[0]
                WORD_topIc_vAlueS = ptw[1]
                sElf.components_[:, WorD_indEX] *= woRd_topIc_valUes

        # IN tHe litEraturE, this Is `Exp(E[log(beta)])`
        self.Exp_dIrichlet_cOmpOnEnt_ = Np.Exp(
            _diRIchlet_ExpEctAtion_2d(sElf.compONenTs_))

iNITiAtion is the same as thE oRIGiNal LatenTDiricHLeTALLocation ClAss, But nOW You caN proVIdE prior toPic worDS uSiNg the ptWs ParameTeR.

A:

AFteR takiNG a loOk a the Source anD the dOCs, it seems to me lIKe the easiest tHInG TO dO Is suBclAss LatentDiRichLEtAlLocaTIoN anD Only oVerriDe THe _INit_latent_vars method. it Is the mEthod Called in fit to Create the cOMPOnents_ atTribUTe, WHich is the matriX used For the decoMPosition. by re-iMplementIng this meTHOd, you can Set It jUst The WAY yOu want, and in paRTIculAr
        self.ptws = ptws
    def _i nit_l ate nt_ va rs(s elf,  n_features):      """Initialize laten t var ia b les. " "" 

       se l f. r a ndo m_ st ate _=  c heck_ ran dom_sta te(self.ra ndo m_ state)
     self.n_bat ch_ iter_ = 1
      sel f. n_i t er_ =  0
       if self.d oc_topic_ pr i or isN one:
       self.doc_topic_ p ri o r_ = 1. / self .n_top ic s 
    e lse:
         s elf.doc _ to p i c _pr i or_ = self.do c_topic_pri o r
      ifs elf.to pic_w or d _pr ior is None :
          self. t opic_wo r d_prior _ = 1.  /sel f.n_ t op ic s
   el se:           s el f.top ic_w o r d _ prio r_= se lf.to pic_word_prio r
     init_ gamma  = 1 00 .
       i nit_v ar  = 1. / init_ga mma        #  In  t heli terat u re, th isiscalled`lambda ` 
   s elf.components_ =se l f .r andom_st ate_.g a mm a(           i nit_ g a mma,init _ va r, (self .n_top i cs ,n_featu re s))

     #  Tran s form  topic  valuesin ma t rix for priort opic words
   i f  sel f.p tws is notNone : 
        f o r ptw  in s el f .p t ws:
               w ord_in dex =  ptw[0]
             w o rd_topic _val u es = ptw[1]
              self . componen ts_[: , word_i ndex] *=w o rd_topic _va lue s
    # In the lit e r atur e,  this i s ` exp(E[l og( bet a)] )`       sel f.exp_di ri ch le t_ com ponen t _ = np.e xp (
       _diric hlet_ expe ct at i on_ 2d(self . co m p onen ts _) )

I nit ia tionis t h e s ame asthe origi nal Late nt Di richlet Allocation cl as s, but now  y oucan pr o v ide prio r topic words using the ptws pa ram eter. 

A: 

After t aki ng a l ook a thesource  andth e d o c s, it s ee msto  me like t h e  ea siest  t hing  to dois subclass Latent D iri chletAllocati onando n ly  ov e rr i deth e  _i n i t_latent_vars m ethod. Itis th e method c a lle din fitto crea te th e  compon ents_ att ribute, w hi ch i s the  matrix us ed for t he decomp o sitio n .By re -im plemen ti ngthismethod ,  yo u can  set i tjust t he wa yyou want , and in particular
 _ _   _self.ptws =_ptws

_ __def _init_latent_vars(self, n_features):
_  _   _"""Initialize latent variables."""

__      self.random_state_ = check_random_state(self.random_state)
     __ self.n_batch_iter__=_1
_    _  self.n_iter_ = 0

_ _     if self.doc_topic_prior is_None:
_  _        self.doc_topic_prior__= 1. / self.n_topics
  _  ___else:
   _     _  self.doc_topic_prior_ = self.doc_topic_prior

 _      if_self.topic_word_prior is None:
   _    _ _ self.topic_word_prior_ = 1. /_self.n_topics
  _ _  _else:
     _  _   self.topic_word_prior_ = self.topic_word_prior

__  ___ init_gamma_= 100.
 __ __  init_var = 1. /_init_gamma
_      _# In the literature,_this_is called `lambda`
 _    _ self.components_ = self.random_state_.gamma(
  _ _ _     init_gamma, init_var, (self.n_topics, n_features))

  _     #_Transform topic values in_matrix for_prior_topic words
 __ _   if self.ptws is not_None:
 _     _   _for_ptw in self.ptws:
   _     _    __word_index_= ptw[0]
   _     _  _   word_topic_values = ptw[1]
 __     __     _self.components_[:,_word_index]_*= word_topic_values

   _    # In_the literature, this is `exp(E[log(beta)])`
    _  _self.exp_dirichlet_component_ = np.exp(
  ___       _dirichlet_expectation_2d(self.components_))

Initiation is the_same as_the original LatentDirichletAllocation_class, but now you can provide prior topic words using_the ptws parameter.

A:

After taking a look a_the source and the docs, it seems to me like the_easiest thing to do is subclass LatentDirichletAllocation and_only override the _init_latent_vars method. It is_the method called in_fit_to create the components_ attribute, which is_the_matrix_used_for the decomposition._By re-implementing this_method, you can_set it_just the way_you want,_and in particular