Skip to content

Instantly share code, notes, and snippets.

View biranchi2018's full-sized avatar

Biranchi biranchi2018

  • Bangalore, India
View GitHub Profile
@biranchi2018
biranchi2018 / learn_gpt2.py
Last active May 21, 2026 01:09
GPT2 Model
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("distilgpt2")
model = AutoModelForCausalLM.from_pretrained("distilgpt2", output_hidden_states=True)
print(model)
print(model.lm_head)
print(model.transformer.wte) # Dimensions are: (Number of tokens in vocabulary, dimension of model)
print(model.transformer.wte(torch.tensor(464)))
@biranchi2018
biranchi2018 / remove_widgets.py
Created May 15, 2026 02:42
Remove 'metadata.widgets' entry from Google Colab notebook
%%writefile remove_widgets.py
# pip install nbformat
import nbformat
from nbformat import v4
import glob
def remove_widgets_metadata(notebook_path):
"""Removes the 'metadata.widgets' entry from the notebook, preserving cell outputs."""
@biranchi2018
biranchi2018 / gradio_all.py
Created November 30, 2023 03:44
My Gradio Gists
Gradio :
=========
pip install gradio
=============================================================
@biranchi2018
biranchi2018 / post_request.py
Created November 30, 2023 03:35
POST Requests
POST Requests :
===================
import requests
url = 'https://clothing-model.default.kubeflow.mlbookcamp.com/v1/models/clothing-model:predict'
data = {
"instances": [
@biranchi2018
biranchi2018 / async_await.py
Created June 5, 2021 13:03
Async await in Python
from asyncio import run
async def sum():
total = 0
for i in range(0,10):
print(f'i : {i}')
total += i
return total
@biranchi2018
biranchi2018 / download.py
Last active June 5, 2021 12:56
Download a file using Python
import requests
url = 'https://www.facebook.com/favicon.ico'
r = requests.get(url, allow_redirects=True)
with open('facebook.ico', 'wb') as f:
f.write(r.content)
@biranchi2018
biranchi2018 / bigram_tokens.py
Last active August 21, 2019 07:01
NLP - Calculating Bigram Tokens
import nltk
nltk.download('punkt')
import itertools
text = "today is 'Nayan's birthday. she loves ice cream. she is also fond of cream cake. we will celebrate her birthday with ice cream cake"
sentences = nltk.sent_tokenize(text)
words = [nltk.word_tokenize(sent) for sent in sentences]
print(words)
Tensorflow Object Detection API :
==================================
https://www.youtube.com/watch?v=COlbP62-B-U&index=1&list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku
https://github.com/tensorflow/models/tree/master/research/object_detection
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
@biranchi2018
biranchi2018 / LabelImg.txt
Created December 1, 2018 22:16
Steps for Installing LabelImg
Steps for Installing LabelImg :
=================================
Step 1.
git clone https://github.com/tzutalin/labelImg
Step 2.
sudo pip3 install pyqt5 lxml
Step 3.
@biranchi2018
biranchi2018 / FaceLandmarkDetection.py
Created July 17, 2018 21:50
Face Landmark Detection
from imutils import face_utils
import dlib
import cv2
import time
# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor
cap = cv2.VideoCapture(0)