<jupyter_start><jupyter_text>ucb.num_queries<jupyter_code>import pickle

acc = 0
ratings=pickle.load(open('data/sample_by_question_questions_article_ratings.pkl','rb'))

for loop in range(len(p_i)):
    if ratings[loop][0] in p_i[loop]:
        acc+=1
        
print(acc)
import random 

def make_prediction_oos():
    
    A = ucb.A
    b = ucb.b      
    # load the heldout data
    
    page_pca_features = pickle.load(open('data/infowave_allintents_title.pkl','rb'))
    all_pca_features = np.concatenate([v for k,v in page_pca_features.items()], 0)
    pca = PCA(n_components=5)
    pca.fit_transform(all_pca_features)
    X_pca = pca.transform(all_pca_features)
            
    heldoutsample_label = pickle.load(open('data/heldoutsample_by_question_article_ratings.pkl','rb'))
    heldoutsample_intent = pickle.load(open('data/heldoutsample_by_question_query_intents.pkl','rb'))

    query_ids = range(len(heldoutsample_intent))
    page_ids = range(ucb.num_articles)


    allscores=np.zeros((len(heldoutsample_intent),ucb.num_articles)) 
    

    for j in page_ids:
        for i in query_ids:
            # get the arm features given page id, and a query embeddings
            # though here I all queries are insample, I still use this out-of-sample arm function so it 
            # can be applied on held-out query data sets for validation in the future
            
            
            query_features = heldoutsample_intent[i]
            article_features=X_pca[j,:]
            arm_features = np.concatenate((query_features, article_features), axis=0)
            x_ta = arm_features.reshape(-1, 1)  # make a column vector
            A_a_inv = np.linalg.inv(A[j])
            theta_a = A_a_inv.dot(b[j])
            score_a = theta_a.T.dot(x_ta)
            allscores[i,j]=score_a  

    p_i_test = []
    rating_test=[]
    
    for i in query_ids:
        #p_i.append(np.argmax(allscores[i,:]))
        p_i.append(allscores[i,:].argsort()[::-1][:5])
        rating_test.append(heldoutsample_label[i,:].argsort()[::-1])
        
    return p_i_test, rating_test

p_i_test, rating_test = make_prediction_oos()
acc = 0
for loop in range(len(p_i_test)):
    if rating_test[loop][0] in p_i_test[loop]:
        acc+=1
        
print(acc)
    
ratings = pickle.load(open('./data/sample_by_question_questions_article_ratings.pkl','rb'))
ratings
ucb.dataset.get_uknown_items_of_user(1)
ucb.A
dataarray
import pickle
from sklearn.decomposition import PCA

url_features = pickle.load(open('data/infowave_allintents_title.pkl','rb'))
all_features = np.concatenate([v for k,v in url_features.items()], 0)
pca = PCA(n_components=5)
pca.fit_transform(all_features)
X_pca = pca.transform(all_features)

X_pca[1].transpose().shape
np.concatenate([v for k,v in url_features.items()], 0).shape

url_features.values().shape
import pickle

a = question_features['3 Rollovers, 1 was Roth but went into a pretax account. How to fix?']
a.shape




        
dict_q_mapping
import pickle

a = pickle.load(open("data/sample_by_question_query_intents.pkl","rb"))
a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11549660304108703, 'fraction_numerical': 0.006793917825946296, 'mean_word_length': 3.442528735632184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '527747', 'license': 'MIT', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1111, 'n_words': 204, 'path': '.ipynb_checkpoints/MainTraining-checkpoint.ipynb', 'repo_name': 'cyberyu/bandit_2ndrepo', 'size': '3091'}