### Install required Python packages Source: https://github.com/autosurveys/autosurvey/blob/main/README.md Install the Python packages listed in requirements.txt using pip. ```sh pip install -r requirements.txt ``` -------------------------------- ### Unzip the database archive Source: https://github.com/autosurveys/autosurvey/blob/main/README.md Unzip the downloaded database archive into the ./database/ directory. ```sh unzip database.zip -d ./database/ ``` -------------------------------- ### Clone the AutoSurvey repository Source: https://github.com/autosurveys/autosurvey/blob/main/README.md Clone the AutoSurvey repository from GitHub and navigate into the project directory. ```sh git clone https://github.com/AutoSurveys/AutoSurvey.git cd AutoSurvey ``` -------------------------------- ### Generate survey with main.py Source: https://github.com/autosurveys/autosurvey/blob/main/README.md Command to generate a survey on a given topic. Output is saved to the directory specified by --saving_path (default ./output/). Requires an API key and URL for the model. ```sh python main.py --topic "LLMs for education" --gpu 0 --saving_path ./output/ --model gpt-4o-2024-05-13 --section_num 7 --subsection_len 700 --rag_num 60 --outline_reference_num 1500 --db_path ./database --embedding_model nomic-ai/nomic-embed-text-v1 --api_url https://api.openai.com/v1/chat/completions --api_key sk-xxxxxx ``` -------------------------------- ### Evaluate generated survey with evaluation.py Source: https://github.com/autosurveys/autosurvey/blob/main/README.md Command to evaluate a previously generated survey on a given topic. The survey must be present in the --saving_path directory (default ./output/). Evaluation results are saved to the same directory. ```sh python evaluation.py --topic "LLMs for education" --gpu 0 --saving_path ./output/ --model gpt-4o-2024-05-13 --db_path ./database --embedding_model nomic-ai/nomic-embed-text-v1 --api_url https://api.openai.com/v1/chat/completions --api_key sk-xxxxxx ``` -------------------------------- ### Get embeddings for a list of texts using the embedding model Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Encodes a list of texts in batches, prefixing each with 'search_document: ' for the embedding model. Returns a numpy array of embeddings. Used to embed paper titles and abstracts. ```python def get_embeddings(text_l, batch_size=32): res = [] for i in trange(0, len(text_l), batch_size): batch_text = ['search_document: ' + _ for _ in text_l[i:i+batch_size]] res.append(embedding_model.encode(batch_text)) return np.concatenate(res,axis=0) ``` -------------------------------- ### Sample Paper Data Output Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Shows the output of the previous command, displaying the first three papers with their metadata. ```json Result: [('1', {'id': '1811.06122v1', 'title': 'The case for shifting the Renyi Entropy', 'url': 'http://arxiv.org/pdf/1811.06122v1', 'date': '2018-11-14', 'abs': 'We introduce a variant of the R\'enyi entropy definition that aligns it with\nthe well-known H\"older mean: in the new formulation, the r-th order R\'enyi\nEntropy is the logarithm of the inverse of the r-th order H\"older mean. This\nbrings about new insights into the relationship of the R\'enyi entropy to\nquantities close to it, like the information potential and the partition\nfunction of statistical mechanics. We also provide expressions that allow us to\ncalculate the R\'enyi entropies from the Shannon cross-entropy and the escort\nprobabilities. Finally, we discuss why shifting the R\'enyi entropy is fruitful\nin some applications.', 'cat': 'cs.IT', 'authors': ['Francisco José Valverde-Albacete', 'Carmen Peláez-Moreno']}), ('2', {'id': '1811.06115v1', 'title': 'Deep Learning in the Wavelet Domain', 'url': 'http://arxiv.org/pdf/1811.06115v1', 'date': '2018-11-14', 'abs': "This paper examines the possibility of, and the possible advantages to\nlearning the filters of convolutional neural networks (CNNs) for image analysis\nin the wavelet domain. We are stimulated by both Mallat's scattering transform\nand the idea of filtering in the Fourier domain. It is important to explore new\nspaces in which to learn, as these may provide inherent advantages that are not\navailable in the pixel space. However, the scattering transform is limited by\nits inability to learn in between scattering orders, and any Fourier domain\nfiltering is limited by the large number of filter parameters needed to get\nlocalized filters. Instead we consider filtering in the wavelet domain with\nlearnable filters. The wavelet space allows us to have local, smooth filters\nwith far fewer parameters, and learnability can give us flexibility. We present\na novel layer which takes CNN activations into the wavelet space, learns\nparameters and returns to the pixel space. This allows it to be easily dropped\nin to any neural network without affecting the structure. As part of this work,\nwe show how to pass gradients through a multirate system and give preliminary\nresults.", 'cat': 'cs.CV', 'authors': ['Fergal Cotter', 'Nick Kingsbury']}), ('3', {'id': '1811.06114v2', 'title': 'Prophet Inequalities for I.I.D. Random Variables from an Unknown\n Distribution', 'url': 'http://arxiv.org/pdf/1811.06114v2', 'date': '2018-11-14', 'abs': '...'})] ``` -------------------------------- ### Import Required Libraries Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Imports necessary libraries for JSON handling, FAISS, PyTorch, NumPy, tqdm, and Sentence Transformers. ```python import json import faiss import torch import numpy as np from tqdm import trange from sentence_transformers import SentenceTransformer ``` -------------------------------- ### Create FAISS indexes for titles and abstracts Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Creates IndexFlatL2 indexes for title and abstract embeddings and adds the embeddings to them. ```python title_index = faiss.IndexFlatL2(title_embeddings.shape[1]) title_index.add(title_embeddings) abs_index = faiss.IndexFlatL2(abs_embeddings.shape[1]) abs_index.add(abs_embeddings) ``` -------------------------------- ### Save FAISS indexes to local .index files Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Writes the title and abstract indexes to 'titles.index' and 'abstracts.index', converting from GPU to CPU if necessary. ```python faiss.write_index(faiss.index_gpu_to_cpu(title_index), 'titles.index') faiss.write_index(faiss.index_gpu_to_cpu(abs_index), 'abstracts.index') ``` -------------------------------- ### Display First 10 Papers Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Displays the first 10 entries from the papers list to inspect the data structure. ```python papers_l[:10] ``` -------------------------------- ### Read the Pre-prepared JSON File Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Reads a JSON file containing paper information in TinyDB format. Each index corresponds to a single paper. ```python with open('./database/arxiv_paper_db.json','r') as f: papers = json.loads(f.read()) papers_l = list(papers['cs_paper_info'].items()) ``` -------------------------------- ### Load the Embedding Model Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Loads a SentenceTransformer model from a local path and moves it to a CUDA device. Requires a GPU for execution. ```python embedding_model = "./model/nomic-embed-text-v1" embedding_model = SentenceTransformer(embedding_model, trust_remote_code=True) embedding_model.to(torch.device('cuda')) ``` -------------------------------- ### Extract titles and abstracts from papers list Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Builds lists of paper titles and abstracts from the papers_l structure, where each paper is a tuple with index and metadata. ```python title_l = [paper[1]['title'] for paper in papers_l] abs_l = [paper[1]['abs'] for paper in papers_l] ``` -------------------------------- ### Save paper ID to index mapping as JSON Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Creates a dictionary mapping paper IDs to their integer index and saves it to './paperid_to_index.json'. ```python paperid_2_index = {} for paper in papers_l: paper_id = paper[1]['id'] index = paper[0] paperid_2_index[paper_id] = int(index) with open('./paperid_to_index.json', 'w') as f: json.dump(paperid_2_index, f, indent=4) ``` -------------------------------- ### Progress output from embedding computation Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Shows the progress bar output from the embedding computation, indicating 16803 items processed at 29.31 it/s. ```text 100%|██████████| 16803/16803 [09:33<00:00, 29.31it/s] ``` -------------------------------- ### Compute abstract embeddings Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Calls get_embeddings on the abstract list to produce abs_embeddings. ```python abs_embeddings = get_embeddings(abs_l) ``` -------------------------------- ### Compute title embeddings Source: https://github.com/autosurveys/autosurvey/blob/main/build_database.ipynb Calls get_embeddings on the title list to produce title_embeddings. ```python title_embeddings = get_embeddings(title_l) ```