Spaces:
Runtime error
Runtime error
updates
Browse filesFiles changed (5)
24 unmodified lines2526272829303124 unmodified linesif submitted:# bodyrender_body(platforms, number_papers, 5, query_input, show_preview, start_year, end_year, hyperparams)# '''# bar = (# Bar()24 unmodified lines2526272829303132333424 unmodified linesif submitted:# bodyrender_body(platforms, number_papers, 5, query_input,show_preview, start_year, end_year,hyperparams,hyperparams['standardization'])# '''# bar = (# Bar()
2 unmodified lines34567833 unmodified lines424344454647483 unmodified lines52535455565735 unmodified lines939495969798991001011021032 unmodified linesfrom ..utils import __create_model__import numpy as npfrom sklearn.cluster import KMeansfrom yellowbrick.cluster import KElbowVisualizerfrom .clusters import ClusterList33 unmodified linesprint(f'>>> finished dimension reduction...')return embeddingsdef __3_clustering__(self, embeddings, return_cluster_centers = False, max_k: int =10):''':param embeddings: Nxd3 unmodified linesreturn embeddingselse:print(f'>>> start clustering...')model = KMeans()visualizer = KElbowVisualizer(model, k=(2, max_k+1), metric='silhouette', timings=False, locate_elbow=False35 unmodified linesreturn clustersdef __call__(self, documents: List[str], max_k:int):print(f'>>> pipeline starts...')x = self.__1_generate_word_embeddings__(documents)x = self.__2_dimenstion_reduction__(x)clusters = self.__3_clustering__(x,max_k=max_k)outputs = self.__4_keywords_extraction__(clusters, documents)print(f'>>> pipeline finished!\n')return outputs2 unmodified lines345678933 unmodified lines434445464748493 unmodified lines5354555657585960616263646566676835 unmodified lines1041051061071081091101111121131142 unmodified linesfrom ..utils import __create_model__import numpy as npfrom sklearn.cluster import KMeansfrom sklearn.preprocessing import StandardScalerfrom yellowbrick.cluster import KElbowVisualizerfrom .clusters import ClusterList33 unmodified linesprint(f'>>> finished dimension reduction...')return embeddingsdef __3_clustering__(self, embeddings, return_cluster_centers = False, max_k: int =10, standarization = False):''':param embeddings: Nxd3 unmodified linesreturn embeddingselse:print(f'>>> start clustering...')######## new: standarization ########if standarization:print(f'>>> start standardization...')scaler = StandardScaler()embeddings = scaler.fit_transform(embeddings)print(f'>>> finished standardization...')######## new: standarization ########model = KMeans()visualizer = KElbowVisualizer(model, k=(2, max_k+1), metric='silhouette', timings=False, locate_elbow=False35 unmodified linesreturn clustersdef __call__(self, documents: List[str], max_k:int, standarization = False):print(f'>>> pipeline starts...')x = self.__1_generate_word_embeddings__(documents)x = self.__2_dimenstion_reduction__(x)clusters = self.__3_clustering__(x,max_k=max_k,standarization=standarization)outputs = self.__4_keywords_extraction__(clusters, documents)print(f'>>> pipeline finished!\n')return outputs
48 unmodified lines4950515253545556575859606162635 unmodified lines697071727374756 unmodified lines828384858687885 unmodified lines9495969798991005 unmodified lines10610710810911011111248 unmodified linesmax_k: int,platforms: List[str] = ['IEEE', 'Arxiv', 'Paper with Code'],loading_ctx_manager = None,):for platform in platforms:if loading_ctx_manager:with loading_ctx_manager():clusters, articles = self.__platformPipeline__(platform,query,num_papers,start_year,end_year,max_k)else:clusters, articles = self.__platformPipeline__(platform, query, num_papers, start_year, end_year,max_k)clusters.sort()yield clusters,articles5 unmodified linesnum_papers: int,start_year: int,end_year: int,max_k: int) -> (ClusterList,ArticleList):@st.cache(hash_funcs={Tokenizer: Tokenizer.__hash__},allow_output_mutation=True)6 unmodified linesarticles = ArticleList.parse_ieee_articles(self.literature_search.ieee(query, start_year, end_year, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k)clusters = self.__postprocess_clusters__(clusters)return clusters, articles5 unmodified linesarticles = ArticleList.parse_arxiv_articles(self.literature_search.arxiv(query, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k)clusters = self.__postprocess_clusters__(clusters)return clusters, articles5 unmodified linesarticles = ArticleList.parse_pwc_articles(self.literature_search.paper_with_code(query, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k)clusters = self.__postprocess_clusters__(clusters)return clusters, articles48 unmodified lines495051525354555657585960616263645 unmodified lines70717273747576776 unmodified lines848586878889905 unmodified lines969798991001011025 unmodified lines10810911011111211311448 unmodified linesmax_k: int,platforms: List[str] = ['IEEE', 'Arxiv', 'Paper with Code'],loading_ctx_manager = None,standardization = False):for platform in platforms:if loading_ctx_manager:with loading_ctx_manager():clusters, articles = self.__platformPipeline__(platform,query,num_papers,start_year,end_year,max_k,standardization)else:clusters, articles = self.__platformPipeline__(platform, query, num_papers, start_year, end_year,max_k,standardization)clusters.sort()yield clusters,articles5 unmodified linesnum_papers: int,start_year: int,end_year: int,max_k: int,standardization) -> (ClusterList,ArticleList):@st.cache(hash_funcs={Tokenizer: Tokenizer.__hash__},allow_output_mutation=True)6 unmodified linesarticles = ArticleList.parse_ieee_articles(self.literature_search.ieee(query, start_year, end_year, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k,standardization)clusters = self.__postprocess_clusters__(clusters)return clusters, articles5 unmodified linesarticles = ArticleList.parse_arxiv_articles(self.literature_search.arxiv(query, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k,standardization)clusters = self.__postprocess_clusters__(clusters)return clusters, articles5 unmodified linesarticles = ArticleList.parse_pwc_articles(self.literature_search.paper_with_code(query, num_papers)) # ArticleListabstracts = articles.getAbstracts() # List[str]clusters = self.cluster_pipeline(abstracts,max_k,standardization)clusters = self.__postprocess_clusters__(clusters)return clusters, articles
54 unmodified lines5556575859606117 unmodified lines7980818283848554 unmodified linespaperInGeneral.markdown(paperInGeneral_md)def render_body(platforms, num_papers, num_papers_preview, query_input, show_preview:bool, start_year, end_year, hyperparams: dict):tmp = st.empty()if query_input != '':17 unmodified lines)model = LiteratureResearchTool(config)generator = model(query_input, num_papers, start_year, end_year, max_k=hyperparams['max_k'], platforms=platforms)for i,plat in enumerate(platforms):clusters, articles = next(generator)st.markdown(f'''# {i+1} {plat} Results''')54 unmodified lines5556575859606117 unmodified lines7980818283848554 unmodified linespaperInGeneral.markdown(paperInGeneral_md)def render_body(platforms, num_papers, num_papers_preview, query_input, show_preview:bool, start_year, end_year, hyperparams: dict, standardization = False):tmp = st.empty()if query_input != '':17 unmodified lines)model = LiteratureResearchTool(config)generator = model(query_input, num_papers, start_year, end_year, max_k=hyperparams['max_k'], platforms=platforms, standardization=standardization)for i,plat in enumerate(platforms):clusters, articles = next(generator)st.markdown(f'''# {i+1} {plat} Results''')
2 unmodified lines345678960 unmodified lines7071727374757677789 unmodified lines88899091922 unmodified lines# from .utils import PACKAGE_ROOTfrom lrt.utils.functions import templateAPP_VERSION = 'v1.2.0'def render_sidebar():icons = f'''60 unmodified lineswith st.sidebar:st.markdown('## Adjust hyperparameters')with st.expander('Clustering Options'):dr = st.selectbox('1) Dimension Reduction', options=['none', 'pca'], index=0)tmp = min(number_papers,15)max_k = st.slider('2) Max number of clusters', 2,tmp , tmp//2)with st.expander('Keyphrases Generation Options'):model_cpt = st.selectbox(label='Model checkpoint', options=template.keywords_extraction.keys(),index=0)9 unmodified linesreturn platforms, number_papers, start_year, end_year, dict(dimension_reduction= dr,max_k = max_k,model_cpt = model_cpt)2 unmodified lines345678960 unmodified lines707172737475767778799 unmodified lines8990919293942 unmodified lines# from .utils import PACKAGE_ROOTfrom lrt.utils.functions import templateAPP_VERSION = 'v1.3.0'def render_sidebar():icons = f'''60 unmodified lineswith st.sidebar:st.markdown('## Adjust hyperparameters')with st.expander('Clustering Options'):standardization = st.selectbox('1) Standardization before clustering', options=['no', 'yes'], index=0 )dr = st.selectbox('2) Dimension reduction', options=['none', 'pca'], index=0)tmp = min(number_papers,15)max_k = st.slider('3) Max number of clusters', 2,tmp , tmp//2)with st.expander('Keyphrases Generation Options'):model_cpt = st.selectbox(label='Model checkpoint', options=template.keywords_extraction.keys(),index=0)9 unmodified linesreturn platforms, number_papers, start_year, end_year, dict(dimension_reduction= dr,max_k = max_k,model_cpt = model_cpt,standardization = True if standardization == 'yes' else False)
app.py+4-1
lrt/clustering/clustering_pipeline.py+14-3
lrt/lrt.py+8-6
widgets/body.py+2-2
widgets/sidebar.py+6-4