Skip to content

Instantly share code, notes, and snippets.

@nbertagnolli
nbertagnolli / tool_calling_chat_gpt.ipynb
Created December 5, 2023 04:34
Simple jupyter notebook showing how to do some tool calling in GPT.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nbertagnolli
nbertagnolli / mnist_dropout.ipynb
Last active January 7, 2022 23:55
A notebook describing how to implement dropout in pytorch from scratch. For the associated article https://medium.com/p/67f08a87ccff/edit.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nbertagnolli
nbertagnolli / true_dropout.py
Last active January 7, 2022 23:56
A real implementation of dropout with proper normalization.
class TrueDropout(torch.nn.Module):
def __init__(self, p: float=0.5):
super(TrueDropout, self).__init__()
self.p = p
if self.p < 0 or self.p > 1:
raise ValueError("p must be a probability")
def forward(self, x):
if self.training:
@nbertagnolli
nbertagnolli / mlp_mnist.py
Created January 1, 2022 21:14
A simple mlp mnist model using custom dropout class
class MNISTModel(torch.nn.Module):
def __init__(self):
super(MNISTModel, self).__init__()
self.layer_1 = nn.Linear(28 * 28, 512)
self.layer_2 = nn.Linear(512, 512)
self.layer_3 = nn.Linear(512, 10)
self.dropout = Dropout(.5)
def forward(self, x):
@nbertagnolli
nbertagnolli / dropout_basic.py
Last active January 7, 2022 23:56
The most basic form of dropout
class Dropout(torch.nn.Module):
def __init__(self, p: float=0.5):
super(Dropout, self).__init__()
self.p = p
if self.p < 0 or self.p > 1:
raise ValueError("p must be a probability")
def forward(self, x):
if self.training:
FROM python:3.8
RUN mkdir /ui
COPY requirements.txt /ui
COPY . /ui
WORKDIR /ui
RUN apt-get update && apt-get install -y build-essential libapr1-dev libssl-dev openssh-client
# Install all necessary libraries into a pyenv environment
FROM python:3.8
# Setup the api directory for your project code
RUN mkdir /api
COPY . /api
COPY requirements.txt /api
WORKDIR /api
# Install all necessary libraries into a pyenv environment
version: '3.8'
services:
movie-app-api:
image: movie-app-api
ports:
- 8000:8000
volumes:
- ./api:/api
networks:
- bridge_network
import streamlit as st
import requests
import json
url = "http://localhost:8000/review/predict"
# Write out the header for the page
st.write("# Movie Review Analyzer")
# Accept user text input
from fastapi import FastAPI
from pydantic import BaseModel
# Initialize the FastAPI App
app = FastAPI()
# Create a Data Model so FastAPI can read the data from the request.
class Review(BaseModel):
text: str