File size: 1,013 Bytes
795d8c0
1eb055a
795d8c0
1eb055a
 
 
795d8c0
1eb055a
 
 
795d8c0
1eb055a
 
795d8c0
1eb055a
 
795d8c0
1eb055a
 
 
795d8c0
1eb055a
 
795d8c0
1eb055a
 
795d8c0
1eb055a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import torch
from transformers import AutoTokenizer, AutoModel

# تنظیمات مدل
model_name = "HooshvareLab/bert-fa-zwnj-base"
model_dir = "./models/HooshvareLab/bert-fa-zwnj-base"

# بارگذاری مدل و توکنایزر
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)

# جمله مورد نظر برای تست
text = "این یک جمله تستی برای مدل embedding فارسی است."

# توکنایز کردن جمله و ایجاد تنسور ورودی
inputs = tokenizer(text, return_tensors="pt")

# دریافت خروجی مدل (embedding)
with torch.no_grad():
    outputs = model(**inputs)

# استخراج embedding از خروجی مدل
last_hidden_states = outputs.last_hidden_states

# نمایش ابعاد (shape) تنسور خروجی
print("Shape of the embedding tensor:", last_hidden_states.shape)

# نمایش بخشی از تنسور خروجی
print("Sample embedding values:", last_hidden_states[0, 0, :10])