Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
1
Indexable
Never
def input_evalution(input_processed_text,tenant_id, df_train_mtrx,tfidf_vector,df_act):
    print("Into Input Evaluation function")
    text=input_processed_text
    print("Text : ",text)
    tfidf_vector=tfidf_vector
    print("TFIDF Vector : ",tfidf_vector)
    tenant_id = tenant_id
    print("Tenant ID Inside INput Evaluation : ",tenant_id)
    df_train_mtrx=df_train_mtrx
    print("DF Train Matrix : ",df_train_mtrx)
    
    input_tfidf=tfidf_vector.transform([text])
    print("Input TF IDF : ",input_tfidf)
    x=input_tfidf.todense()
    print("X : ",x)
    df_tst = pd.DataFrame(x)
    #print("Df Test Input Evaluation : ",df_tst)
    ## Replacing Nan values in matrix with 0
    df_train_mtrx_nan=np.isnan(df_train_mtrx)
    #print("DF Train MAtrix Nan : ",df_train_mtrx_nan)
    df_train_mtrx[df_train_mtrx_nan] = 0

    scr=cosine_similarity(df_train_mtrx, df_tst)
    print("Cosine Similarity : ",scr)

Here if you see we are getting tenant_id , and now we want to filter the df_train_mtrx by tenant_id and get only relevant matching records with tenant_id , for eg if tenant_id is 32, so only relevant records should be present.

Can we create a new matrix by filtering with tenant id on df_train_mtrx and then calculate the cosine similarity for for df_tst.