Skip to content

Instantly share code, notes, and snippets.

View shresthakamal's full-sized avatar
🏠
Working from home

Kamal Shrestha shresthakamal

🏠
Working from home
View GitHub Profile
@shresthakamal
shresthakamal / cors.py
Last active January 21, 2025 17:07
FAST API Response and Request [LEARN]
"""CORS or "Cross-Origin Resource Sharing" refers to the situations when a frontend running in a browser has JavaScript code that communicates with a backend, and the backend is in a different "origin" than the frontend.
Origin
An origin is the combination of protocol (http, https), domain (myapp.com, localhost, localhost.tiangolo.com), and port (80, 443, 8080).
So, all these are different origins:
http://localhost
@shresthakamal
shresthakamal / react-native-start.js
Created March 12, 2024 02:15
Basic React Native Application commands - Starting emulator - Creating Application
// Create an application
npx create-expo-app rate-repository-app --template expo-template-blank@sdk-50
// Note, that the @sdk-50 sets the project's Expo SDK version to 50, which supports React Native version 0.73.
// Install dependencies
npx expo install react-native-web@~0.19.6 [email protected] @expo/metro-runtime@~3.1.1
// Start the emulator
@shresthakamal
shresthakamal / retreivals.py
Created March 2, 2024 13:32
Vector Store based retreivals
# Load docs
from langchain.document_loaders import WebBaseLoader
loader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/")
data = loader.load()
# Split
from langchain.text_splitter import RecursiveCharacterTextSplitter
text_splitter = RecursiveCharacterTextSplitter(chunk_size = 500, chunk_overlap = 0)
all_splits = text_splitter.split_documents(data)
@shresthakamal
shresthakamal / tmux
Created February 28, 2024 10:50
Tmux Server Commands
Show all tmux sessions
$ tmux ls
Start a new session
$ tmux
Start a new named session
$ tmux new -s <myname>
@shresthakamal
shresthakamal / basics_bert.py
Created February 24, 2024 08:37
Basics of BERT with good generalizations and rule of thumbs
https://colab.research.google.com/drive/1yFphU6PW9Uo6lmDly_ud9a6c4RCYlwdX#scrollTo=Mq2PKplWfbFv
https://mccormickml.com/2019/05/14/BERT-word-embeddings-tutorial/#31-running-bert-on-our-text
# -*- coding: utf-8 -*-
"""BERT Word Embeddings v2.ipynb
Automatically generated by Colaboratory.
Original file is located at
@shresthakamal
shresthakamal / pydantic._usage.py
Created February 21, 2024 04:39
Pydantic Usage [similar to dataclasses]
"""
Basic example showing how to read and validate data from a file using Pydantic.
"""
import json
from typing import List, Optional
import pydantic
@shresthakamal
shresthakamal / dataclasses.py
Created February 21, 2024 04:11
Data Class Guides in Python >=3.10
import random
import string
from dataclasses import dataclass, field
def generate_id() -> str:
return "".join(random.choices(string.ascii_uppercase, k=12))
"""
@shresthakamal
shresthakamal / .pre-commit-config.yaml
Last active November 3, 2024 06:16
Sample pre-commit hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: requirements-txt-fixer
@shresthakamal
shresthakamal / finetunning-BERT.py
Created February 20, 2023 08:56
Standard Finetunning Steps
# standard steps to follow for finetunning BERT
# 1. Load the pre-trained model
# 2. Tokenize the input
# 3. Convert the tokens to their index numbers in the BERT vocabulary
# 4. Set all of the model’s parameters to their gradients to zero
# 5. Run the forward pass, calculate the loss, and perform a backward pass to calculate the gradients
# 6. Clip the the gradients to 1.0. It helps in preventing the exploding gradient problem
# 7. Update the model’s parameters
# 8. Update the learning rate.
# 9. Clear the calculated gradients
@shresthakamal
shresthakamal / text-processing.py
Created February 20, 2023 08:38
Common Text Processing Steps in NLP
# standard pre-processing steps for text processing
# 1. lower case
# 2. remove punctuation
# 3. remove stop words
# 4. remove numbers
# 5. remove short words
# 6. lemmatize
# 7. stem
# 8. remove non-ascii characters
# 9. remove extra spaces