Skip to content

Instantly share code, notes, and snippets.

@y-lan
y-lan / longest_japanese_tokens_gpt4o.py
Last active May 14, 2024 16:12 — forked from ctlllll/longest_chinese_tokens_gpt4o.py
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
#https://github.com/openai/tiktoken/blob/c0ba74c238d18b4824c25f3c27fc8698055b9a76/tiktoken/model.py#L9
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
from datasets import Dataset, DatasetDict
import pandas as pd
train_ratio = 0.9
tdf = df.sample(frac=train_ratio, random_state=14)
vdf = df.drop(tdf.index)
tds = Dataset.from_pandas(tdf, preserve_index=False)
vds = Dataset.from_pandas(vdf, preserve_index=False)
@y-lan
y-lan / langchain_llm_logging.py
Last active September 4, 2023 14:24
Save the prompt and response with LLMs in LangChain
from typing import Any, Dict, List, Optional
from uuid import UUID
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import LLMResult
import json
import time
class LLMLoggingCallbackHandler(BaseCallbackHandler):
@y-lan
y-lan / llm_logging.py
Created September 4, 2023 10:37
Save the prompt and response with LLMs
from typing import Any, Dict, List, Optional
from uuid import UUID
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import LLMResult
import json
import time
class LLMLoggingCallbackHandler(BaseCallbackHandler):
@y-lan
y-lan / count_llama_tokens.py
Last active July 20, 2023 14:16
Count Llama Tokens
from transformers import LlamaTokenizer
tokenizer = LlamaTokenizer.from_pretrained('decapoda-research/llama-7b-hf')
def count(text):
return len(tokenizer(text)['input_ids'])
def parallel_count(texts):
from joblib import Parallel, delayed
results = Parallel(n_jobs=-1)(delayed(count)(text) for text in texts)

2023-03-26

#1

Up to 80 percent of workers could see jobs impacted by AI

(AIによって最大80%の労働者の仕事が影響を受ける可能性がある)

米国の労働者の80%が、ChatGPTと呼ばれるAIチャットボットの導入によって、少なくとも10%の業務に影響を受ける可能性があると、OpenAIとペンシルバニア大学の研究者が主張している。研究者たちは、高収入の仕事ほどGPTによる影響を受けやすいと結論づけたが、ほとんどの業界で影響が及ぶと予測している。研究は、GPTまたはGPTパワードシステムへのアクセスが、人間が業務を実行する時間を少なくとも50%短縮するかどうかを測定する「露出」を調べた。研究者たちは、露出がGPTによる完全な自動化を意味するわけではないと強調した。研究によると、数学者、通訳、会計士、法律秘書、作家などの職業が最も高い露出率を持っている。一方、鉄道整備作業員、調理師、メカニック、床屋、肉詰め作業員、石工などの低賃金の仕事には、露出がないとされた。

@y-lan
y-lan / beta_bandit.py
Created March 24, 2016 06:42 — forked from stucchio/beta_bandit.py
Beta-distribution Bandit
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@y-lan
y-lan / presto_kill_all.js
Last active April 18, 2016 04:21
Presto UI js
function kill(u) {
var rq = d3.selectAll('.query-row')[0].filter(function(d, i) {
var owner = d.querySelector('div.col-md-3.col-lg-3 div.row:nth-child(2)').textContent.trim();
return (d.querySelector('div.col-md-4.col-lg-3 div.row:nth-child(2)').textContent === 'RUNNING') &&
(u === undefined || owner == u);
}).map(function(d,i){
return d.dataset['reactid'].split('$')[1]; })
console.log(rq)
@y-lan
y-lan / 0_reuse_code.js
Created November 1, 2015 05:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console