#NEWLINE# @ celery . task ( ) #NEWLINE# def run_topic_modeling( username , folder_id , ex_id ) : #NEWLINE# #INDENT# d = Folder . query . get ( folder_id ) #NEWLINE# ex = Experiment . query . get ( ex_id ) #NEWLINE# set_tm_status ( username , folder_id , ex , 'inprogress' ) #NEWLINE# db . session . commit ( ) #NEWLINE# exinfo = ex . getExInfo ( ) #NEWLINE# datafile = d . wordcount_path ( ) #NEWLINE# vocabfile = d . vocab_path ( ) #NEWLINE# vocab = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# idx = 0 #NEWLINE# vv = [ x . strip ( ) for x in open ( vocabfile , 'r' ) ] #NEWLINE# for v in vv : #NEWLINE# #INDENT# vocab [ idx ] = v #NEWLINE# idx += 1 #NEWLINE# #UNINDENT# lines = [ x . strip ( ) . split ( ',' ) for x in open ( datafile , 'r' ) ] #NEWLINE# docrange = [ ] #NEWLINE# word_id = [ ] #NEWLINE# word_count = [ ] #NEWLINE# start = 0 #NEWLINE# cur = ( - 1 ) #NEWLINE# curD = ( - 1 ) #NEWLINE# for l in lines : #NEWLINE# #INDENT# cur += 1 #NEWLINE# word_id . append ( int ( l [ 1 ] ) ) #NEWLINE# word_count . append ( int ( l [ 2 ] ) ) #NEWLINE# dID = int ( l [ 0 ] ) #NEWLINE# if ( curD == ( - 1 ) ) : #NEWLINE# #INDENT# curD = dID #NEWLINE# #UNINDENT# if ( curD != dID ) : #NEWLINE# #INDENT# docrange . append ( [ start , ( cur - 1 ) ] ) #NEWLINE# start = ( cur - 1 ) #NEWLINE# curD = dID #NEWLINE# #UNINDENT# #UNINDENT# docrange . append ( [ start , ( cur + 1 ) ] ) #NEWLINE# data = WordsData ( word_id , word_count , docrange , len ( vocab ) , vocab , len ( docrange ) ) #NEWLINE# a = { #NEWLINE# #INDENT# 'tm_id' : str ( d . id ) , #NEWLINE# 'username' : username , #NEWLINE# #UNINDENT# } #NEWLINE# hmodel = bnpy . Run . run ( data , 'HDPModel' , 'Mult' , 'VB' , doSaveToDisk = False , K = exinfo . nTopics , nLap = 100 , initname = 'randomfromprior' , customFuncPath = 'refinery/webapp/' , customFuncArgs = json . dumps ( a ) ) #NEWLINE# "\n                          moves='birth,merge', birthPerLap=10,                           mergePerLap=10, nFreshLap=25)\n    " #NEWLINE# exinfo . viz_data = getModelState ( hmodel [ 0 ] , hmodel [ 1 ] , 100 ) #NEWLINE# set_tm_status ( username , folder_id , ex , 'finish' ) #NEWLINE# db . session . commit ( )