This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from umap import UMAP | |
| from sentence_transformers import SentenceTransformer | |
| # Load the universal sentence encoder | |
| # Stay well clear of the direct Hugging Face API which is grim | |
| sample_size = 30000 | |
| model = SentenceTransformer('all-mpnet-base-v2') | |
| embeddings = model.encode(sentences[:sample_size]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datasets import load_dataset | |
| from sentence_transformers import SentenceTransformer | |
| import numpy as np | |
| import pandas as pd | |
| selected_dataset = 'ag_news' | |
| sample_size = 6000 | |
| dataset = load_dataset(selected_dataset) | |
| dataset_df = pd.DataFrame(dataset['train']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fastapi import FastAPI, Path | |
| from utils import create_connection, sql_to_df | |
| import pandas as pd | |
| app = FastAPI() | |
| @app.get("/query/{query_name}") | |
| async def root( | |
| query_name: str = Path( | |
| title="Query name of the query to run", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| import plotly.express as px | |
| def create_connection(db_file): | |
| """ create a database connection to the SQLite database | |
| specified by the db_file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| def create_connection(db_file): | |
| """ create a database connection to the SQLite database | |
| specified by the db_file | |
| :param db_file: database file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamlit as st | |
| import os | |
| import requests | |
| vector_db_host = os.environ.get('VECTOR_DB_HOST') | |
| # queries the DB to get the options | |
| collections = [ | |
| record["name"] | |
| for record in requests.get(f"{vector_db_host}/collections").json()["result"][ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamlit as st | |
| import requests | |
| import os | |
| vector_db_host = os.environ.get('VECTOR_DB_HOST') | |
| request = st.text_input("request") | |
| response = requests.get(f"{vector_db_host}/{request}").json() | |
| st.json(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import numpy as np | |
| import torch | |
| import torch.nn as nn | |
| def enable_dropout(model): | |
| """ Function to enable the dropout layers during test-time | |
| From https://stackoverflow.com/questions/63285197/measuring-uncertainty-using-mc-dropout-on-pytorch | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def return_dropout_model(model, with_dropout=True): | |
| model = model.to(device) | |
| if with_dropout: | |
| print('Dropout still on.') | |
| feats_list = list(model.features) | |
| new_feats_list = [] | |
| for feat in feats_list: | |
| new_feats_list.append(feat) | |
| # Add a drop out layer after every |