PlaiFon 3B Chat

English-Thai small lm

Usage

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from transformers import pipeline

model_id="wannaphong/plaifon-3b-chat"

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="cuda",
)
tokenizer = AutoTokenizer.from_pretrained(model_id,use_fast=False)

pipe=pipeline("text-generation",model=model,tokenizer=tokenizer)

Chat

q="แมวคืออะไร"
chat = [
    {"role": "user", "content": q}
]
response = pipe(chat, max_new_tokens=4096)
print(response[0]["generated_text"][-1]["content"])

Output:

แมว (Cat) เป็นสัตว์เลี้ยงลูกด้วยนมในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือและสิงโต แมวเป็นสัตว์ที่มีขนปกคลุมร่างกาย มีหูที่สามารถปรับทิศทางได้ มีตาที่สามารถมองเห็นในที่มืดได้ดี และมีเล็บที่สามารถปรับเปลี่ยนรูปทรงได้ตามความเหมาะสมในการจับเหยื่อหรือปีนป่าย

แมวเป็นสัตว์ที่มีความฉลาดและสามารถเรียนรู้ได้เร็ว แมวสามารถจดจำเจ้าของได้และมีความผูกพันกับเจ้าของอย่างลึกซึ้ง แมวเป็นสัตว์ที่มีความเป็นอิสระสูงและมักจะใช้เวลาส่วนใหญ่ในการนอนหลับหรือเล่นกับของเล่น

แมวเป็นสัตว์ที่มีความสำคัญต่อมนุษย์ในหลายด้าน เช่น เป็นสัตว์เลี้ยงที่ช่วยควบคุมประชากรหนูและสัตว์อื่นๆ ที่เป็นศัตรูพืช และยังเป็นสัตว์ที่มีความสวยงามและน่ารัก ทำให้เป็นที่นิยมในการเลี้ยงเป็นสัตว์เลี้ยงในบ้าน

แมวมีหลายสายพันธุ์ เช่น แมวไทย แมวเปอร์เซีย แมวอเมริกันช็อตแฮร์ แมวเบงกอล และแมวสกอตติชโฟลด์ เป็นต้น แต่ละสายพันธุ์มีลักษณะและพฤติกรรมที่แตกต่างกันไป ทำให้การเลี้ยงแมวเป็นเรื่องที่ต้องใช้ความรักและความเอาใจใส่ในการดูแลอย่างเหมาะสม

Thinking:

chat = [
    {"role": "user", "content": "แมวคืออะไร"}
]

text = tokenizer.apply_chat_template(
    chat,
    tokenize=False,
    add_generation_prompt=True,
    # tools=tool,
    enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)#.strip()+"\n<think>"
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

# conduct text completion
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=4096
)
index=0
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist() 
# thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=False).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=False).strip("\n")

# print("thinking content:", thinking_content)
print("content:", content)

Output:

ได้เลย ผู้ใช้ถามว่า "แมวคืออะไร" ซึ่งแปลว่า "แมวคืออะไร" ในภาษาไทย ฉันต้องอธิบายว่าแมวคือสัตว์เลี้ยงลูกด้วยนมที่เป็นสัตว์เลี้ยงลูกด้วยนมที่มีขน อยู่ในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือและสิงโต แมวมีลักษณะเด่นคือมีหูที่แหลมคม ดวงตาที่ใหญ่ และเล็บที่แหลมคม พวกมันมีความฉลาดและสามารถฝึกฝนได้ แมวมีหลายสายพันธุ์ เช่น แมวบ้าน แมวป่า และแมวป่า แมวมีบทบาทสำคัญในวัฒนธรรมและเป็นสัตว์เลี้ยงที่นิยมมาก ฉันควรระบุว่าแมวเป็นสัตว์ที่มีความเป็นอิสระและมีพฤติกรรมที่น่าสนใจ อาจเพิ่มข้อมูลเกี่ยวกับการดูแลแมวและการเลี้ยงแมวเพื่อให้ครอบคลุมทุกแง่มุม ฉันต้องแน่ใจว่าคำตอบชัดเจนและครอบคลุมประเด็นหลักโดยไม่ใช้คำศัพท์ทางเทคนิคที่ซับซ้อนเกินไป ตรวจสอบว่ามีข้อมูลใดที่ขาดหายไปหรือไม่ เช่น บทบาทของแมวในวัฒนธรรม หรือความแตกต่างระหว่างแมวบ้านกับแมวป่า ดีแล้ว นี่ควรจะครอบคลุมทุกอย่างที่จำเป็นแล้ว
</think>

แมว (Cat) คือสัตว์เลี้ยงลูกด้วยนมที่มีขน อยู่ในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือ สิงโต และแมวป่า แมวมีลักษณะเด่นคือมีหูที่แหลมคม ดวงตาที่ใหญ่ และเล็บที่แหลมคม พวกมันมีความฉลาด สามารถฝึกฝนได้ และมีพฤติกรรมที่น่าสนใจ เช่น การเล่น การนอนหลับ และการล่าสัตว์ แมวมีหลายสายพันธุ์ เช่น แมวบ้าน (Domestic Cat) ที่เลี้ยงเป็นสัตว์เลี้ยง แมวป่า (Wild Cat) ที่อาศัยอยู่ในธรรมชาติ และแมวป่า (Feral Cat) ที่อาศัยอยู่ในพื้นที่ที่ไม่มีมนุษย์ดูแล แมวมีบทบาทสำคัญในวัฒนธรรมและเป็นสัตว์เลี้ยงที่นิยมมากทั่วโลก แมวมักถูกเลี้ยงเป็นสัตว์เลี้ยงในบ้าน แต่ก็มีบางสายพันธุ์ที่ถูกเลี้ยงในป่าหรือที่อยู่อาศัยของมนุษย์ แมวมีความเป็นอิสระและมีความสัมพันธ์ที่ดีกับมนุษย์ แต่ก็มีพฤติกรรมที่ต้องการการดูแลและฝึกฝนอย่างเหมาะสมเพื่อให้พวกมันมีสุขภาพดีและมีความสุขในชีวิตประจำวัน<|im_end|>

Tool

tool=[
  {
    "type": "function",
    "function": {
      "name": "get_current_temperature",
      "description": "Get current temperature at a location.",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The location to get the temperature for, in the format \"City, State, Country\"."
          },
          "unit": {
            "type": "string",
            "enum": [
              "celsius",
              "fahrenheit"
            ],
            "description": "The unit to return the temperature in. Defaults to \"celsius\"."
          }
        },
        "required": [
          "location"
        ]
      }
    }
  },
  {
    "type": "function",
    "function": {
      "name": "get_temperature_date",
      "description": "Get temperature at a location and date.",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The location to get the temperature for, in the format \"City, State, Country\"."
          },
          "date": {
            "type": "string",
            "description": "The date to get the temperature for, in the format \"Year-Month-Day\"."
          },
          "unit": {
            "type": "string",
            "enum": [
              "celsius",
              "fahrenheit"
            ],
            "description": "The unit to return the temperature in. Defaults to \"celsius\"."
          }
        },
        "required": [
          "location",
          "date"
        ]
      }
    }
  }
]
chat = [
    {"role": "user",  "content": "อุณหภูมิที่กรุงเทพเป็นเท่าไร"}
]

text = tokenizer.apply_chat_template(
    chat,
    tokenize=False,
    add_generation_prompt=True,
    tools=tool,
    enable_thinking=False # Switches between thinking and non-thinking modes. Default is True.
).strip()
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

# conduct text completion
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=4096
)
index=0
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist() 
# thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=False).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=False).strip("\n")

# print("thinking content:", thinking_content)
print("content:", content)

Output:

content: <tool_call>
{"name": "get_current_temperature", "arguments": "{\"location\": \"กรุงเทพ\", \"unit\": \"celsius\"}"}
</tool_call><|im_end|>

Downloads last month
-
Safetensors
Model size
4B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for wannaphong/plaifon-3b-chat

Base model

Qwen/Qwen2.5-7B
Finetuned
sail/Sailor2-8B
Finetuned
sail/Sailor2-3B
Finetuned
(1)
this model
Quantizations
1 model