Skip to content

Instantly share code, notes, and snippets.

@Norod
Norod / hebrew_gpt_neo_flax_pred.py
Created July 11, 2022 11:26
Hebrew GPT-Neo text generation using FlaxGPTNeoForCausalLM
import jax
from transformers import FlaxGPTNeoForCausalLM, AutoTokenizer
#model_name = 'Norod78/hebrew-gpt_neo-tiny'
#model_name = 'Norod78/hebrew_poetry-gpt_neo-small'
model_name = 'Norod78/hebrew-gpt_neo-small'
model = FlaxGPTNeoForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
@Norod
Norod / heb_neo_gra_demo.py
Created July 5, 2022 10:51
hebrew-gpt_neo-small minimal gradio demo using gradio and transformers pipeline
import gradio as gr
from transformers import pipeline
title = "Hebrew GPT-Neo Demo"
description = ""
article = "<p></p>"
examples = [
['צחוקים ושיגועים'],
["למנשה פומפרניקל יש"],
["פעם אחת לפני שנים רבות"]
@Norod
Norod / translate_text_file.py
Created June 23, 2022 19:01
Translate a text file using MarianMTModel models from Hugging Face
# !pip install sentencepiece transformers tokenizers
from transformers import MarianTokenizer, MarianMTModel
from typing import List
src = "en" # source language
trg = "he" # target language
model_name = f"Helsinki-NLP/opus-mt-{src}-{trg}"
@Norod
Norod / crapify_images.py
Created March 21, 2022 19:11
Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# crapify_images.py
# Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# @Norod78
import skimage
import skimage.io
import skimage.io._plugins.pil_plugin as pp
import numpy as np
from PIL import Image
@Norod
Norod / translate_csv_file.py
Created January 24, 2022 17:25
Translate a csv file using Helsinki-NLP's hugging-face models
# !pip install sentencepiece transformers tokenizers
from transformers import MarianTokenizer, MarianMTModel
from typing import List
import csv
src = "en" # source language
trg = "he" # target language
@Norod
Norod / output-token-scores-hebrew.ipynb
Last active January 4, 2022 20:08
Output token scores for Norod78/distilgpt2-base-pretrained-he (hebrew)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / microsoft-vq-diffusion_not-user-friendly.ipynb
Last active January 11, 2022 14:52
microsoft/VQ-Diffusion_Not-User-Friendly.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / ruDALLE_forAmazonSageMakerStudioLab.ipynb
Created December 9, 2021 10:50
ruDALLE for Amazon Sage Maker Studio Lab
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from transformers import AutoTokenizer, AutoModelForCausalLM
#pip install tokenizers==0.10.3 transformers==4.8.0
tokenizer = AutoTokenizer.from_pretrained("Norod78/distilgpt2-base-pretrained-he")
model = AutoModelForCausalLM.from_pretrained("Norod78/distilgpt2-base-pretrained-he", pad_token_id=tokenizer.eos_token_id)
prompt_text = "הנבחרת האולימפית של ישראל זכתה השנה"
max_len = 50
@Norod
Norod / onnx_rename_node_inp_inst.py
Created June 1, 2021 15:01
Rename a node in an ONNX model
import onnx
onnx_model = onnx.load('./input.onnx')
#Rename 'inp' to 'inst'
endpoint_names = ['inp', 'inst']
for i in range(len(onnx_model.graph.node)):
for j in range(len(onnx_model.graph.node[i].input)):
if onnx_model.graph.node[i].input[j] == endpoint_names[0]: