Slide 15
Slide 15 text
Run microsoft/Phi-3.5-mini-4k-instruct locally
input_text = """¥
Convert the following plain text to Table format of Markdown. Show only a Result(Solution) of the conversion.
Column are "#", "Name", "Height", "Weight". Automatically assign sequential numbers.
---
Kohei MATSUSHITA 173cm 64kg
Kazunto GODA 177.5cm 68kg
---
"""
from transformers import AutoModelForCausalLM, AutoTokenizer
# モデルとトークナイザーのロード
model_name = "microsoft/Phi-3-mini-4k-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# テキストをトークン化
inputs = tokenizer(input_text, return_tensors="pt")
input_ids = inputs["input_ids"]
attention_mask = inputs["attention_mask"]
# テキスト生成
output = model.generate(input_ids, attention_mask=attention_mask, max_new_tokens=128)
# 生成結果をデコードして表示
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_text)
プロンプトと
データ
実装
run.py
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: