Views
No views yet


pipeline() function from 🤗 Transformers:1# pip install transformers>=4.34
2# pip install accelerate
3
4import torch
5from transformers import pipeline
6
7pipe = pipeline("text-generation", model="yentinglin/Taiwan-LLM-7B-v2.1-chat", torch_dtype=torch.bfloat16, device_map="auto")
8
9# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
10messages = [
11 {
12 "role": "system",
13 "content": "你是一個人工智慧助理",
14 },
15 {"role": "user", "content": "東北季風如何影響台灣氣候?"},
16]
17prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
18outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
19print(outputs[0]["generated_text"])


@misc{lin2023taiwan,
title={Taiwan LLM: Bridging the Linguistic Divide with a Culturally Aligned Language Model},
author={Yen-Ting Lin and Yun-Nung Chen},
year={2023},
eprint={2311.17487},
archivePrefix={arXiv},
primaryClass={cs.CL}
}