่ๆฏ
ไฝใใๆต่กใใฎ LangChain ใงใใๆใใซๆฅๆฌ่ชๆฑใใใ!
ใจใใใใใญใผใซใซใงๅใใใใใฎใง, ๆฅๆฌ่ชใฏ gpt-neox-japanese-2.7b ไฝฟใใพใ.
LangChain ่ชไฝใฏใชใใใใใใใคใชใใใใใฎ wrapper ใฟใใใชใใฎใงใ.
(ใใฎใใก huggingface ใใชใใ langchain ใฃใฝใใฎๅบใใฆใใใใงใใ)
LLM module
huggingface pipeline ไฝฟใใพใ.
gpt-neox-japanese-2.7b
ใใใฉใซใใ ใจ CPU ๅฎ่กใซใชใฃใฆใใพใใฎใง(CPU ใงใๅใใๆฐๅใใใใใใ), GPU ๅฆ็, ใพใ fp16 ใไฝฟใใพใ!
ใพใ, langchain ใฎ(?) ใใใฉใซใใฎ max_new_tokens ใฏ 20 tokens ใง, ้ทใ input ไธใใ(ไธใฎใใใ ใใใฏ 220 tokens ใใใ)ใจ unexpected behavor ใซใชใใฎใง max_new_tokens ใๅคงใ็ฎใซใจใฃใฆใใใพใ.
ใจใใใใๅใใใฆใฟใพใ.
import torch
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.agents import ZeroShotAgent, Tool, AgentExecutor, load_tools
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
device_num = -1 # CPU
if torch.cuda.is_available():
device_num = 0 # cuda:0
model_id = "abeja/gpt-neox-japanese-2.7b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
pipe = pipeline(
"text-generation", model=model, tokenizer=tokenizer,
ใใmax_new_tokens=512, device=device_num, torch_dtype=torch.float16
)
hf = HuggingFacePipeline(pipeline=pipe)
print(hf("ใซใฉใใซใช้ดไธใไฝใไผ็คพใฎ็คพๅใซใตใใใใใฎใฏ๏ผ"))
ใใจใใ่ณชๅใซๅฏพใใฆใใ้ดไธๅฑใใจ็ญใใไบบใๅคใใฃใใใใงใใ
ใใใกใใฃใจใฒใญใใปใใใ...
ใๅ่ใซใใฆ PromptTemplate ไฝฟใฃใฆใฟใพใ!
prompt_temp = """ใใใ ใใใฏๆฑๅใซไฝใๆดป็บใงใใใใๅฅณใฎๅญใงใใ
ใใชใใใใฟใฎๅๅใฏ๏ผใ
ใใใ ใใใใใฏใฎๅๅใฏใใใ ใใใชใฎใ ใใ
ใใชใใไปๆฅใฎๅคฉๆฐใฏ๏ผใ
ใใใ ใใใใใฏใฏไปๆฅใฎๅคฉๆฐใฏๆดใใ ใจๆใใฎใ ใ
ใใชใใไปๆฅใฏไฝๆใซ่ตทใใใฎ๏ผใ
ใใใ ใใใใใฏใฏ7ๆใซ่ตทใใใฎใ ใ
ใใชใใๅนด้ฝขใฏ๏ผใ
ใใใ ใใใใใฏใฎๅนด้ฝขใฏ็งๅฏใชใฎใ ใ
ใใชใใๆใใฏใใฏไฝ้ฃในใใ๏ผใ
ใใใ ใใใใใฏใฏใใซใใ้ฃในใใใฎใ ใ
ใใชใใ{time}ใใฏใใฏไฝ้ฃในใใ๏ผใ
ใใใ ใใใ"""
prompt = PromptTemplate(
input_variables=["time"],
template=prompt_temp,
)
chain = LLMChain(llm=hf, prompt=prompt)
print(chain.run("ๆผ"))
print(chain.run("ๅค"))
Setting `pad_token_id` to `eos_token_id`:31999 for open-end generation.
ใใฏใฏไฝ้ฃในใใ๏ผใ
Setting `pad_token_id` to `eos_token_id`:31999 for open-end generation.
ใใฏใฏไฝ้ฃในใใ๏ผใ
ๆผใๅคใ, ่ณชๅใซ่ณชๅใง่ฟใใใฆใใพใใพใใ... ![]()
pipeline ใง do_sample=True, top_p=0.95, top_k=50 ใใใ่ฟฝๅ ใ, temperature ่ชฟๆดใใใจๅคๅฐใใ็ตๆใใใใฃใฆใใพใ.
ใจใใใใใฎใพใจใ
ใจใใใใใฏใญใผใซใซใงใใใใในใฏใชใใ็ตใใ ใใใฆ่ฉฆใใฆ, ใใฎๅพๅฟ ่ฆใงใใใฐ OpenAI(ChatGPT) ใ you.com ใใใใซใคใชใใจใใใใใใ.
ใพใ, GPT-J ใ, https://huggingface.co/abeja/gpt2-large-japanese ใไฝฟใๆใใใใใใงใ.
(ๅพ่
ใฏ protobuf ๅฟ
่ฆใซใชใใคใใใซใใ
ใงใใใ! ใใใฉใซใใฎใใฉใกใผใฟใงใใใใใใใใใใฎๅฟ็ญใใฆใใใๆใใใใพใ)
TODO
- ใใญใณใใใจใณใธใใขใชใณใฐใ้ ๅผตใ
- ๆค็ดขใจใณใธใณใจใคใชใ. ใจใใใใใฏ duckduckgo https://github.com/deedy5/duckduckgo_search ใใใใงใใใใ.