Views
No views yet
1model = AutoModelForCausalLM.from_pretrained(
2 "kanxxyc/JPNsensei-V2", low_cpu_mem_usage=True,
3 return_dict=True,torch_dtype=torch.bfloat16,
4 device_map= {"": 0}
5)
6tokenizer = AutoTokenizer.from_pretrained("kanxxyc/JPNsensei-V2")
7device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8model = model.to(device)
9
10text_generation_pipeline = transformers.pipeline(
11 model=model,
12 tokenizer=tokenizer,
13 task="text-generation",
14 pad_token_id=tokenizer.eos_token_id,
15 temperature=0.2,
16 do_sample=True,
17 repetition_penalty=1.1,
18 max_new_tokens=1024,
19
20)
21
22mistral_llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
23prompt_template = """
24### Instruction: Given a title and a question, your task is to generate an appropriate answer based on the context provided, using simple English to explain any Japanese language-related queries.
25
26### title:
27{title}
28
29### question:
30{question}
31
32### answer:
33"""
34prompt = PromptTemplate(
35 input_variables=["title", "question"],
36 template=prompt_template,
37)
38
39
40llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
41
42