Skip to content

Instantly share code, notes, and snippets.

View fxnnxc's full-sized avatar
🦊
Working from home

Bumjin Park fxnnxc

🦊
Working from home
View GitHub Profile
@fxnnxc
fxnnxc / check_generation_prompts.py
Last active April 16, 2024 07:49
Counter Factual Dataset
# Check whether generation prompts always contain the subject word
# This check is necessary as FactualGPT requires subject word.
from tqdm import tqdm
def check_dataset_generation_prompt_contains_subject(data):
# check whether generation prompts always contain the subject word
invalid_index = []
for i, d in tqdm(enumerate(data), total=len(data)):
subj = d['requested_rewrite']['subject']
target = d['requested_rewrite']['target_true']
import datetime
import argparse
import os
import random
import torch
import numpy as np
from omegaconf import OmegaConf
parser = argparse.ArgumentParser()
parser.add_argument("--save_dir")
# ----------- Load models
from PIL import Image
import requests
from transformers import CLIPProcessor, CLIPModel
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
def get_batches_of_text_input_ids(texts, batch_size=32):
outputs = []
@fxnnxc
fxnnxc / shell_combination.sh
Last active March 6, 2024 12:46
combination of arguments for shell script
# in MAC os : there is an error with declare -n
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# reload the terminal
a1=(200, 1e-3)
a2=(300, 1e-4)
a3=(400, 1e-5)
candidates=(a1 a2 a3)
for p in ${candidates[@]}
@fxnnxc
fxnnxc / csv_result.py
Created March 4, 2024 17:49
writing csv results in python
import csv
import numpy as np
import datetime
def append_right(values, length=10):
return [str(v)+" "*(length - len(str(v))) for v in values]
delimiter = '\t'
# write header
@fxnnxc
fxnnxc / mail_from_python.py
Last active August 21, 2023 11:40
Mailing from python for experiment results.
# -*- coding:utf-8 -*-
# Copyright to the Author : Bumjin Park
# Date : 2023.08.21
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
class Mail():
def __init__(self, sender=<type your email>, password=<type your password>):