3 from pathlib import Path
4 from similarities_helper import *
5 #from similarities_helper import similarities, lsi_column_similarities
6 from functools import partial
8 inpath = "/gscratch/comdata/users/nathante/competitive_exclusion_reddit/data/tfidf/comment_terms_compex.parquet/"
10 outfile='/gscratch/comdata/users/nathante/competitive_exclusion_reddit/data/similarity/comment_terms_compex_LSI'
11 n_components=[10,50,100]
12 included_subreddits="/gscratch/comdata/users/nathante/competitive_exclusion_reddit/data/included_subreddits.txt"
21 def lsi_similarities(inpath, term_colname, outfile, min_df=None, max_df=None, included_subreddits=None, topN=None, from_date=None, to_date=None, tfidf_colname='tf_idf',n_components=100,n_iter=5,random_state=1968,algorithm='arpack',lsi_model=None):
22 print(n_components,flush=True)
26 if type(n_components) == list:
27 lsi_model = Path(outfile) / f'{max(n_components)}_{term_colname}_LSIMOD.pkl'
29 lsi_model = Path(outfile) / f'{n_components}_{term_colname}_LSIMOD.pkl'
31 simfunc = partial(lsi_column_similarities,n_components=n_components,n_iter=n_iter,random_state=random_state,algorithm=algorithm,lsi_model_save=lsi_model)
33 return similarities(inpath=inpath, simfunc=simfunc, term_colname=term_colname, outfile=outfile, min_df=min_df, max_df=max_df, included_subreddits=included_subreddits, topN=topN, from_date=from_date, to_date=to_date, tfidf_colname=tfidf_colname)
35 # change so that these take in an input as an optional argument (for speed, but also for idf).
36 def term_lsi_similarities(inpath='/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet',outfile=None, min_df=None, max_df=None, included_subreddits=None, topN=None, from_date=None, to_date=None, algorithm='arpack', n_components=300,n_iter=5,random_state=1968):
38 res = lsi_similarities(inpath,
47 n_components=n_components,
52 def author_lsi_similarities(inpath='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',outfile=None, min_df=2, max_df=None, included_subreddits=None, topN=None, from_date=None, to_date=None,algorithm='arpack',n_components=300,n_iter=5,random_state=1968):
53 return lsi_similarities(inpath,
62 n_components=n_components
65 def author_tf_similarities(inpath='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',outfile=None, min_df=2, max_df=None, included_subreddits=None, topN=None, from_date=None, to_date=None,n_components=300,n_iter=5,random_state=1968):
66 return lsi_similarities(inpath,
75 tfidf_colname='relative_tf',
76 n_components=n_components,
81 if __name__ == "__main__":
82 fire.Fire({'term':term_lsi_similarities,
83 'author':author_lsi_similarities,
84 'author-tf':author_tf_similarities})