Skip to content

Instantly share code, notes, and snippets.

View shreyansh26's full-sized avatar
👨‍🎓
Always Learning

Shreyansh Singh shreyansh26

👨‍🎓
Always Learning
View GitHub Profile
import json
import sentencepiece as spm
import sentencepiece.sentencepiece_model_pb2 as sp_pb2
from google.protobuf.json_format import MessageToDict
PATH = "tokenizer.model"
s = spm.SentencePieceProcessor(model_file=PATH)
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("distilgpt2")
model = AutoModelForCausalLM.from_pretrained("distilgpt2")
inputs = tok(["Hello how"], return_tensors="pt")
len_inp = len(inputs.input_ids[0])
print(len_inp)
generated = model.generate(**inputs, do_sample=False, max_new_tokens=10)
@shreyansh26
shreyansh26 / pos_embed.py
Created April 24, 2023 06:29 — forked from huchenxucs/pos_embed.py
T5 relative positional embedding
import math
import torch
import torch.nn as nn
from torch.nn import functional as F
class RelativePositionBias(nn.Module):
def __init__(self, bidirectional=True, num_buckets=32, max_distance=128, n_heads=2):
super(RelativePositionBias, self).__init__()
self.bidirectional = bidirectional
@shreyansh26
shreyansh26 / LinearLayer.py
Created April 12, 2023 15:42 — forked from RafayAK/LinearLayer.py
Class for Linear Layer
import numpy as np # import numpy library
from util.paramInitializer import initialize_parameters # import function to initialize weights and biases
class LinearLayer:
"""
This Class implements all functions to be executed by a linear layer
in a computational graph
Args:
#!/usr/bin/python
from z3 import *
s = [BitVec("s[%d]" % i,32)for i in range(0,8)]
# shouldve
z3_solver = Solver()
flag = ""
for i in range(0,len(s)):
if(strlen(input) != 23) {
print_wrong;
return 0;
}
if((input[4] ^ 0x6c) != 0) {
print_wrong;
return 0;
}
if(input[3] + 1 != input[6]) {
from PIL import Image
image_enc = open('encoded_img', 'r').readlines()
print(image_enc)
pixels = []
for row in image_enc:
row = row.strip()
row = row.split('+')
#!/usr/bin/python3
img = bytearray(open('matrix_modified.bmp', 'rb').read())
key = "matrix"
new_f = []
for i, x in enumerate(img):
new_f.append(hex(ord(key[i%6]) ^ x))

Keybase proof

I hereby claim:

  • I am shreyansh26 on github.
  • I am shreyansh26 (https://keybase.io/shreyansh26) on keybase.
  • I have a public key ASAoslMXqpms4-sn1xknNjBcBKZKk3Erypeh7HONCGuE0go

To claim this, I am signing this object:

#include <stdio.h>
#include <stdlib.h>
int main() {
int start = 1573776000; // 15th Nov 2019, 00:00 UTC
int end = 1573948800; // // 17th Nov 2019, 00:00 UTC
for(int i=start; i<end; i++) {
srand(i);
int a = rand();