<jupyter_start><jupyter_text>Select Attribute for prediction<jupyter_code>attribute = "gender"

attribuess = { "gender":    { 0 : "Female" ,    1: "Male"},
                "age"   :    { 0 : "Under25" ,   1: "Over25"},
                "children" : { 0 : "No" ,       1: "Yes"},
                "education": { 0 : "Degree", 1: "HighSchool" },
                "income" :   { 0 : "High" ,      1: "Low"},
                "political" :{ 0 : "Democrat", 1: "Republican"},
                "race" :     { 0 : "Afr. American",  1: "Caucasian"}
                 }<jupyter_output><empty_output><jupyter_text>Get list of popular users<jupyter_code>popular_df = pd.read_pickle("../auxiliary/users_with_over_200_DETAILS.pkl")
popular_df = popular_df.filter(['user_id','screen_name','name'])<jupyter_output><empty_output><jupyter_text>Load models<jupyter_code>model = keras.models.load_model(f"models/SocialVec_model_{attribute}.h5")
SocialVec_model_path = ("../models/item2vec_v3_350.model")
sv_model = Word2Vec.load(SocialVec_model_path)<jupyter_output><empty_output><jupyter_text>Auxilary functions<jupyter_code># possible values for by - 'user_id', 'screen_name'
VALID_BY = {'user_id', 'screen_name'}

def get_SocialVec_vector(account_list, by):
    if by not in VALID_BY:
        raise ValueError(f"parameter \'by\' must be one of {VALID_STATUS}")

    popular_account_list = pd.DataFrame(account_list,columns=[by]).merge(popular_df, on=[by],how='inner').user_id.tolist()
    
    model_array = []
    for account in popular_account_list:
        if account in sv_model.wv.vocab:
            model_array.append(account)
    
    return np.mean(sv_model.wv[model_array], axis=0)<jupyter_output><empty_output><jupyter_text>Prediction example by list of ids:This is a list of IDs of users that a user follows on Twitter.SocialVec can predict the user's attributes based on the users they follow.<jupyter_code>id_list = ['759251', '813286', '1434251', '2467791', '11178902', '11350892', '11856932', '13393052', '13793552', '14499829', '14776983', '15678511', '15846372', '16312576', '17291393', '17525171', '17783278', '17874544', '19638927', '19816859', '20015311', '20117923', '20609518', '20629645', '21094301', '23783240', '24216951', '25321854', '25527618', '26813101', '32767923', '34549808', '35771819', '36502037', '44949890', '46503181', '50374439', '52905639', '59522488', '72644483', '72904247', '80333792', '90173824', '91126478', '95731075', '97739866', '103686030', '107199276', '123015364', '135272779', '144925401', '145314369', '158848407', '180505807', '182199162', '204832963', '221912526', '232268199', '234538960', '250205792', '259382027', '259387453', '275315776', '354133033', '357683633', '407340870', '408151651', '431071870', '459786401', '460485003', '487144778', '487718304', '546447987', '552321387', '625022363', '736417956', '855103736', '892219807', '952624494', '974384082', '1120167192', '1128218821', '1180675964', '1344919338', '1388508253', '1604444052', '1621318627', '1654543044', '1660468830', '1674061298', '1950037290', '1959556592', '2161228906', '2187516343', '2233154425', '2269093894', '2282673787', '2318324798', '2369335940', '2370627199', '2736215883', '3092443319', '3096642344', '3226351612', '3407878233', '3683068757', '4435404613', '781222374414880768', '790659465951358976', '820378690920058880', '821520293122351104', '832089209007636480', '846137120209190912', '847154816593752064', '847198791031762944', '851506270280470528', '863087589531697152', '871164209140080640', '900810786720952320', '913203265466257408', '25071402', '241174677']


emdeddings = get_SocialVec_vector(id_list,'user_id')
prediction = model.predict(emdeddings.reshape(1, 100))
print (f"Attribute: {attribute}. Predicted class: {attribuess[attribute][prediction[0][0].round()]}, classification score: {prediction[0][0]:.2f}")<jupyter_output><empty_output><jupyter_text>Prediction example by list of user names:<jupyter_code>username_list = ['madisonbeer',	'FifthHarmony',	'ltsQueenB',	'selenagomez',	'rihanna',	'sza',	'SabrinaAnnLynn',	'LittleMix',	'taylorswift13',	'justinbieber',	'Kehlani',	'MariahCarey',	'zaralarsson',	'Anitta',	'destinyschild',	'ShawnMendes',	'alinabaraz',	'Meghan_Trainor',	'BrunoMars',	'Zendaya',	'JoJogirandi',	'NathanSykes',	'ladygaga',	'BebeRexha',	'HaileeSteinfeld',	'charlieputh',	'Mabel',	'LanaDelRey',	'lorde',	'Adele',	'britneyspears',	'JessieJ',	'VictoriaJustice',	'Fergie',	'theweeknd',	'bridgitmendler',	'ToveLo',	'samsmith',	'xtina',	'nickjonas',	'MirandaCosgrove',	'JordinSparks',	'RealWhitney',	'ciara',	'onedirection',	'Labrinth',	'kesha_army',	'jtimberlake',	'KekePalmer',	'JLo',	'VanessaHudgens',	'DoveCameron',	'carlyraejepsen',	'DBradbery',	'CassieSuper',	'elliegoulding',	'AvrilLavigne',	'AaliyahHaughton',	'realobietrice',	'Statquo',	'drdre',	'hopsin',	'TRICKTRICKGS',	'nasrinuri',	'logic_magazine',	'JColeNC',	'kendricklamar',	'TechN9ne',	'thegame',	'Tip',	'DMX',	'bobatl',	'icecube',	'G_Eazy',	'therealredman',	'youcancallmeLV',	'MobbDeep',	'SnoopDogg',	'BustaRhymes',	'ImmortalTech',	'lmkidcudi',	'Ludacris',	'ltsDrrake',	'JoeBudden',	'MacMilIIer',	'ChrisWebby']

emdeddings = get_SocialVec_vector(username_list,'screen_name')
prediction = model.predict(emdeddings.reshape(1, 100))
print (f"Predicted class: {attribuess[attribute][prediction[0][0].round()]}, classification score: {prediction[0][0]:.2f}")<jupyter_output><empty_output><jupyter_text>Loop through all models<jupyter_code>id_list = ['12',	'5215',	'10350',	'13666',	'746323',	'774096',	'782310',	'783214',	'813286',	'816653',	'939091',	'1145991',	'2110241',	'2142731',	'2803191',	'3533231',	'3819701',	'4641021',	'4992791',	'5746402',	'5746452',	'5868402',	'6539272',	'6899022',	'7144422',	'7855062',	'8267732',	'8515852',	'8518802',	'8880932',	'9027932',	'9566562',	'9934462',	'10191272',	'10668202',	'11415252',	'11457552',	'11518842',	'11532962',	'11789832',	'11900172',	'12091452',	'12299242',	'12427372',	'12666842',	'13197402',	'13247252',	'13727212',	'14097392',	'14120151',	'14286920',	'14316226',	'14372486',	'14482447',	'14622002',	'14637199',	'14685758',	'14695435',	'14742222',	'14749606',	'14962763',	'15227791',	'15285521',	'15394051',	'15492359',	'15639302',	'15693493',	'15788402',	'15948437',	'15948668',	'15972075',	'16070716',	'16109987',	'16134540',	'16288972',	'16343608',	'16350166',	'16527570',	'16786960',	'16866902',	'16998020',	'17003765',	'17017716',	'17173207',	'17371109',	'17467036',	'17503180',	'17617070',	'17689864',	'17804297',	'17814635',	'17834236',	'17997789',	'18267528',	'18318677',	'18384527',	'18435258',	'18498684',	'18530185',	'18576537',	'18600746',	'18602481',	'18656830',	'18794294',	'18999261',	'19058681',	'19147756',	'19278682',	'19436506',	'19604140',	'20054833',	'20175513',	'20248824',	'20314832',	'20333461',	'20536157',	'20609518',	'20759856',	'20851583',	'21246360',	'21452168',	'22209176',	'24518962',	'24751413',	'25283065',	'25768384',	'26541509',	'26765003',	'27230728',	'27457788',	'27831488',	'27961877',	'28016498',	'28299819',	'29527296',	'29657619',	'30220083',	'30261067',	'30313925',	'30364057',	'30600062',	'30714435',	'30824673',	'30918471',	'30992735',	'31127729',	'31839540',	'31959965',	'32187854',	'32394533',	'32475011',	'32857286',	'32937363',	'33271878',	'33893647',	'34714943',	'35031708',	'35342621',	'35714839',	'36392966',	'36440780',	'36624724',	'36937995',	'37389101',	'37516414',	'37759563',	'38816847',	'39022533',	'39227313',	'39265056',	'39335056',	'39482323',	'40000662',	'40656797',	'41573981',	'42399845',	'42467023',	'42819952',	'43197818',	'44302805',	'45099966',	'45295375',	'45529940',	'45612245',	'45813273',	'45867343',	'46342682',	'46661844',	'46847109',	'47040514',	'47181372',	'47311701',	'47708890',	'47821985',	'47873024',	'48081518',	'48436234',	'48478726',	'48501623',	'48927113',	'49258481',	'49259042',	'49556565',	'49913605',	'50308323',	'50368413',	'50393960',	'50427254',	'50997224',	'51037171',	'51629130',	'51636779',	'52672963',	'52992670',	'53224493',	'54153603',	'54846519',	'54964143',	'56111650',	'57107167',	'57535118',	'58737746',	'59540650',	'60012117',	'61415503',	'61559439',	'62082091',	'62581962',	'63081789',	'63146190',	'63292897',	'63642511',	'64228804',	'65449403',	'66074283',	'66369206',	'66786078',	'67182352',	'69590040',	'69832179',	'70456698',	'71041908',	'72036635',	'76525772',	'78789634',	'80316147',	'82282572',	'82680149',	'84287043',	'85781031',	'86895762',	'87315607',	'89028456',	'92629998',	'93200004',	'93937897',	'93957809',	'95438524',	'96565035',	'98744822',	'104265534',	'107135644',	'114562409',	'114894966',	'115034742',	'115485051',	'116126280',	'117007076',	'117467092',	'122303383',	'122410793',	'122415055',	'130430155',	'131294858',	'132634312',	'136879221',	'138840988',	'139322371',	'143453881',	'145851433',	'147190009',	'153966123',	'154280902',	'156804673',	'158743698',	'165302999',	'165709814',	'165879997',	'167326889',	'169689723',	'172214420',	'175098387',	'175675929',	'177542979',	'177912908',	'180505807',	'180710035',	'181170415',	'181613510',	'183305551',	'185260477',	'192920667',	'193629687',	'194066925',	'195368220',	'197697723',	'205311290',	'206075826',	'207665930',	'211483507',	'212868561',	'216256233',	'216939636',	'218315534',	'224161598',	'224811526',	'228367582',	'233384112',	'235479402',	'238674939',	'243235100',	'254107028',	'263571890',	'280457780',	'281326158',	'287610527',	'307215458',	'307259678',	'314765296',	'315023242',	'316291431',	'317177234',	'320734293',	'326013630',	'328447836',	'341218443',	'348437934',	'358185808',	'370564325',	'382806976',	'389214426',	'393271504',	'397145040',	'401812842',	'403511277',	'412219206',	'414344520',	'415514364',	'426533453',	'426736503',	'437235053',	'448199438',	'461300470',	'475988505',	'478956538',	'485547966',	'486925719',	'490521144',	'503992119',	'514082785',	'514646075',	'532297687',	'542503609',	'551723155',	'561365549',	'582251088',	'623499849',	'630053052',	'702302583',	'702437971',	'704825179',	'747822822',	'757303975',	'773526500',	'785240803',	'807924134',	'870848335',	'887089058',	'893081574',	'905788424',	'949597896',	'962130295',	'965027346',	'1076321995',	'1179469664',	'1308239858',	'1316023094',	'1330457336',	'1339835893',	'1343932878',	'1378279002',	'1412461099',	'1430346577',	'1472331595',	'1536791610',	'1567869552',	'1849423920',	'2150685024',	'2180579797',	'2291694662',	'2297568343',	'2353879531',	'2375907092',	'2382923779',	'2434552658',	'2443570872',	'2457671952',	'2465737627',	'2552064793',	'2561784308',	'2705883470',	'2746969362',	'2760345626',	'2798204480',	'2858259506',	'2879887914',	'2895770934',	'2900258011',	'2900440577',	'2946300174',	'2949131574',	'2950689631',	'3013253012',	'3018996741',	'3020114984',	'3119672637',	'3165759859',	'3178567381',	'3240518502',	'3243028244',	'3277045910',	'3282859598',	'3289609770',	'3304973233',	'3995179834',	'4009506983',	'4038351723',	'4115184972',	'4127000969',	'4150108651',	'4194417913',	'4296263602',	'4715743993',	'4773933934',	'702802855372128000']
emdeddings = get_SocialVec_vector(id_list,'user_id')



for attribute in list(attribuess.keys()):
    print (attribute)
    model = keras.models.load_model(f"models/SocialVec_model_{attribute}.h5")
    
    prediction = model.predict(emdeddings.reshape(1, 100))
    print (f"Attribute: {attribute}. Predicted class: {attribuess[attribute][prediction[0][0].round()]}, classification score: {prediction[0][0]:.2f}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20955625436757513, 'fraction_numerical': 0.43780573025856045, 'mean_word_length': 8.819039451114923, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '91703', 'license': 'MIT', 'n_tokens_mistral': 8249, 'n_tokens_neox': 5334, 'n_words': 837, 'path': 'classification/classification_example.ipynb', 'repo_name': 'nirlotan/social2vec', 'size': '11448'}