AI Scope
138 subscribers
202 photos
22 videos
19 files
121 links
Download Telegram
دمای LLM چیه؟

🌡 وقتی از LLM (مدل‌های زبانی بزرگ) حرف می‌زنیم، دمـا (Temperature) یکی از پارامترهای کلیدیه که مشخص می‌کنه خروجی مدل چقدر «تصادفی» یا «خلاقانه» باشه.

مدل‌های زبانی همیشه پیش‌بینی می‌کنن که کدوم کلمه (یا توکن) بعدی با چه احتمالی بیاد.

دما این توزیع احتمالات رو دستکاری می‌کنه:

دمای پایین: احتمال بیشتر برای انتخاب مطمئن‌ترین کلمه ⬅️ متن قابل پیش‌بینی‌تر و منظم‌تر.

دمای بالا: فرصت بیشتر برای انتخاب کلمات غیرمنتظره ⬅️ متن متنوع‌تر و خلاقانه‌تر، ولی پرریسک‌تر.

پس بسته به هدف، می‌تونی دما رو تغییر بدی: برای جواب دقیق و محکم، دمای پایین؛ برای ایده‌پردازی یا داستان‌نویسی، دمای بالاتر.

What is LLM Temperature?

When we talk about LLMs (Large Language Models), temperature is a key parameter that controls how “random” the generated text will be.

LLMs predict the next token (word or part of a word) based on a probability distribution over possible tokens.
The temperature setting modifies that distribution:

Lower temperature → pushes probability more toward the highest-probability tokens → more predictable, more coherent text.

Higher temperature → flattens the distribution (or gives more chance to less probable tokens) → more variety, more creativity, but also risks of incoherence.

Why it matters: depending on your use case, you might want precision and consistency (e.g. factual answers, documentation) or you might want creativity (e.g. story-writing, brainstorming)


🦴 @scopeofai | #concepts
1
تنظیم دما

برای کنترل خروجی LLM فقط دما نیست، چندتا پارامتر مهم دیگه هم نقش دارن

🔹Temperature: دما مستقیماً میزان تصادفی بودن خروجی رو تعیین می‌کنه. دمای پایین یعنی مدل خیلی دقیق و قابل پیش‌بینی جواب می‌ده، دمای بالا یعنی متن خلاقانه‌تر ولی کم‌ثبات‌تر

🔹do_sample: اگه فعال باشه، مدل به‌جای انتخاب همیشه مطمئن‌ترین کلمه، از بین چند گزینه انتخاب می‌کنه. در واقع بدون فعال بودنش، تغییر دما هم بی‌فایده‌ست

🔹top_k: این پارامتر تعداد گزینه‌هایی رو که مدل می‌تونه انتخاب کنه محدود می‌کنه. عدد کم یعنی مدل محتاط‌تر و جواب‌ها قابل‌اعتمادتر. عدد بالا یعنی آزادی عمل بیشتر

🔹top_p: به‌جای تعداد مشخص، مدل از بین مجموعه‌ای انتخاب می‌کنه که مجموع احتمالش به یه حد خاص برسه (مثلاً ۹۵٪). این باعث میشه متن تنوع داشته باشه ولی پرت و پلا هم نشه


Configuring Temperature

To control LLM output, temperature isn’t the only factor. Several other parameters also shape the results:

Temperature: Directly controls the randomness of the output. Low values make the model very precise and predictable. Higher values add creativity but reduce stability.

do_sample: If enabled, the model samples from multiple possible tokens instead of always choosing the most likely one. Without this, temperature adjustments won’t matter.

top_k: Limits the model’s choices to the top k most probable tokens. A small value keeps it conservative and reliable; a larger value gives more freedom.

top_p: Instead of a fixed number, the model chooses from the smallest set of tokens whose cumulative probability passes a threshold (e.g., 95%). This keeps variety while avoiding nonsense.


🦴 @scopeofai | #concepts
1
کنترل خروجی فراتر از دما

دما تنها ابزار کنترل نیست. برای گرفتن خروجی دقیق‌تر، اینا هم کاربرد دارن:

❇️حداکثر طول (max length): جلوی پرحرفی یا بی‌راهه رفتن مدل رو می‌گیره.

✳️Stop sequences: به مدل می‌گه کجا متوقف بشه.

Frequency penalty: جلوی تکرار زیاد یه کلمه رو می‌گیره.

Presence penalty: تنوع ایجاد می‌کنه و باعث میشه مدل دنبال همون کلمات قبلی نره.

ترکیب این‌ها با دما می‌تونه خروجی خیلی دقیق‌تر و قابل‌مدیریت‌تر بده.

Controlling Output Beyond Temperature

Temperature isn't the only knob. To get output that better fits what you want, you often combine parameters and control mechanisms.


Here are other levers:

❇️Maximum length: how many tokens the model can output. Keeps responses from going off-tangent.

❇️Stop sequences: define sequences that tell the model, “stop here.” Handy for structured output: emails, lists, dialogues.

❇️Frequency penalty: penalizes tokens (words) that are used often in output; discourages repetition.

❇️Presence penalty: penalizes simply for whether a token has already appeared (not how many times). Helps ensure variety.


Combining these with temperature + sampling parameters gives you fine-grained control over what the LLM produces.


🦴 @scopeofai | #concepts
1
مقایسه خروجی با IBM Granite

برای روشن‌تر شدن موضوع، IBM با مدل Granite 3.1 یک مثال زده. پرامپت این بود:
«یک داستان بنویس درباره دانشمند داده‌ای که عاشق پایتون است.»

🔅 وقتی دما روی مقدار خیلی پایین (۰.۱) تنظیم شد، خروجی کاملاً امن و قابل پیش‌بینی بود؛ متن خشک بود و جزئیات زیادی نداشت.
وقتی دما روی متوسط (۰.۷۵) قرار گرفت، داستان زنده‌تر شد؛ توصیف‌ها بیشتر شدن و کمی خلاقیت به متن اضافه شد.

📈اما وقتی دما روی بالا (۱.۲۵) رفت، متن پر از ایده‌های غیرمنتظره شد؛ داستان تخیلی‌تر بود و گاهی از موضوع اصلی منحرف می‌شد.


Comparing Outputs with IBM Granite



To make this clearer, IBM tested its Granite 3.1 model with a simple prompt:
“Write a story about a data scientist who loves Python.”

At a very low temperature (0.1), the output was extremely safe and predictable. The story was dry, with little detail.
At a medium temperature (0.75), the story became richer. There were more vivid descriptions and a touch of creativity.
At a high temperature (1.25), the text was full of unexpected ideas. It felt more imaginative, but sometimes drifted away from the main topic


🦴 @scopeofai | #concepts
1👌1
کی از چه دمایی استفاده کنیم

💡کار دقیق و فکت‌محور (گزارش، خلاصه، متن رسمی): دمای پایین (0.1–0.4)

📝کار خلاقانه (شعر، داستان، ایده‌پردازی): دمای بالا (0.7–1.2)

همیشه در کنارش از حداکثر طول، Stop sequence و Penaltyها استفاده کن تا متن عجیب‌غریب نشه

بهترین نتیجه معمولاً از آزمایش و تعادل بین این عوامل به‌دست میاد

When to Use What

To wrap up, here are guidelines for what temperature + settings you might choose depending on your purpose:

For factual, precise work (e.g. reports, summaries, technical writing): use low temperature (0.1-0.4), minimal top_k or top_p, lower randomness.

For creative work (stories, brainstorming, poetry): use higher temperature (0.7-1.2+), allow more sampling, allow higher top_k / top_p.

Always combine with stop sequences, max length, and penalties to avoid repetition or straying.

Experiment: sometimes a moderate temperature + restrictions gives a sweet balance.


🦴 @scopeofai | #concepts
1👌1
ولی دونستن این مفاهیم بدون زدن پروژه های واقعی بی‌فایدست. تمرکزم اینه که به زودی متمرکزتر بشیم روی تفسیر این مفاهیم روی پروژه و دیتاست‌های واقعی
🫡3🤔1🥱1
Channel photo updated
🕊1
میدونم دلتون تنگ شده بود
3
پارامترها چی هستن

🔮 در مدل‌های هوش مصنوعی، پارامترها همون عددها و مقادیری هستن که تعیین می‌کنن سیستم چطور داده‌ها رو پردازش کنه.

می‌تونیم بگیم مثل تنظیمات داخلی هستن که وقتی مدل آموزش می‌بینه، تغییر می‌کنن و باعث می‌شن مدل بتونه اطلاعات رو بفهمه و جواب تولید کنه.

مثلاً می‌گن مدل GPT-4 صدها میلیارد پارامتر داره که با هم کار می‌کنن تا بتونه کلمه بعدی رو حدس بزنه و متن بسازه.

What Parameters Are

In AI models, parameters are the numerical values that guide how the system processes information. They’re the internal “settings” that adjust as the model learns, shaping how it interprets data and produces responses. For example, GPT-4 is estimated to have hundreds of billions of parameters working together to predict words and generate text.
1🔥1
دو نوع اصلی پارامتر

1⃣پارامترهای ساختاری: اینا مشخص می‌کنن مدل چه شکلی ساخته بشه؛ یعنی لایه‌های نورون‌های مصنوعی چطور چیده و به هم وصل بشن. می‌شه گفت مثل نقشه یا اسکلت اصلی مدلن

2⃣پارامترهای رفتاری: اینا تعیین می‌کنن مدل وقتی داده می‌گیره چطور رفتار کنه؛ مثل میزان واکنش‌پذیری، انعطاف و نوع جواب‌هایی که می‌ده. این پارامترها باعث می‌شن مدل بسته به نوع داده ورودی یا حتی اتصال به اینترنت، رفتار متفاوتی نشون بده

Two Key Types of Parameters

Construction Parameters – These define the model’s architecture: how layers of artificial neurons are arranged, connected, and weighted. Think of them as the blueprint or skeleton that gives the model its structure.
Behavior Parameters – These govern how the model acts when given input. They control responsiveness, adaptability, and output style. Behavior parameters influence whether a model gives concise answers, creative dialogue, or factual recall, depending on the data it receives and how it’s connected to external sources.
1🔥1
پارامترها چطور یاد می‌گیرن و چرا مهمن

🅾 وقتی یک مدل هوش مصنوعی آموزش می‌بینه، داده‌ها رو حفظ نمی‌کنه بلکه پارامترهاش رو تنظیم می‌کنه.

💡هر پارامتر بسته به اینکه پیش‌بینی مدل چقدر درست یا غلط بوده، کمی تغییر می‌کنه. با میلیون‌ها یا حتی میلیاردها بار تکرار این فرایند، مدل یاد می‌گیره روابط پیچیده بین کلمات، تصویرها یا صداها رو درک کنه.

به همین دلیل معمولاً به پارامترها می‌گن «حافظه» یا «دانش» مدل.

هرچقدر مدل پارامترهای بیشتری داشته باشه (و بهتر آموزش دیده باشه)، درک عمیق‌تری از الگوهای ظریف مثل لحن، مفهوم، یا حتی احساسات در متن پیدا می‌کنه.


How Parameters Learn and Why They Matter

When an AI model trains, it doesn’t memorize data — it adjusts its parameters.
Each parameter slightly changes based on how correct or wrong the model’s predictions are. Through millions or even billions of these small adjustments, the model learns complex relationships between words, images, or sounds.

That’s why parameters are often called the “memory” or “knowledge” of a model. The more parameters a model has (and the better it’s trained), the more subtle patterns it can understand — like tone, context, and even emotions in text.
1🔥1
🕹 کتابخونه Numpy یه کتابخونه قدرتمند و پراستفاده پایتونه برای محاسبات عددی و کار با آرایه‌ها.
توی یادگیری ماشین هم استفاده ميشه زیاد.

برای آشنایی باهاش و کاربردش توی یادگیری ماشین این مقاله رو می‌تونید بخونید:

https://madewithml.com/courses/foundations/numpy/
👍31
گوگل کولب چیه؟

گوگل کولَب مثل یه دفترچه آنلاین رایگانه که می‌تونی توی مرورگر خودت باهاش کد پایتون بنویسی و اجرا کنی. بدون اینکه لازم باشه چیزی نصب کنی.

کافیه با اکانت گوگل وارد بشی، یه "notebook" جدید باز کنی، کد بنویسی، روی اجرا بزنی و همون‌جا نتیجه رو ببینی.
چیزی که کولب رو خاص می‌کنه اینه:

1⃣ رایگان بهت GPU یا TPU می‌ده
2⃣ همه‌چیز روی Google Drive ذخیره می‌شه و می‌تونی دفترت رو مثل یه فایل Google Docs با بقیه به اشتراک بذاری.


Think of Google Colab like a free online notebook where you can write and run Python code in your browser — no installation needed.

You log in with your Google account, open a new “notebook”, type code into a cell, hit run, and see results immediately.

What makes it really helpful: (1) It gives you access to faster hardware (GPUs/TPUs) for free, so you can experiment with heavier tasks than your
(2) Everything is saved in your Google Drive and you can share the notebook with someone else like you share a Google Doc.
3
⚠️ ماشین‌های کولب موقتی هستن

وقتی یه نوت‌بوک جدید توی گوگل کولب باز می‌کنی، گوگل یه ماشین مجازی (Virtual Machine) بهت می‌ده که فقط تا وقتی فعالی وجود داره.

اگه تب رو ببندی یا چند دقیقه کاری نکنی، اون ماشین پاک می‌شه. یعنی هرچیزی که نصب کردی یا دانلود کردی از بین می‌ره.

اما مهندسین هوش مصنوعی یه راه‌حل دارن:

درایو گوگل خودشون رو وصل می‌کنن و فایل‌های مهم مثل مدل یا داده‌ها رو اون‌جا ذخیره می‌کنن:

from google.colab import drive
drive.mount('/content/drive')

یه اسکریپت آماده دارن که هر بار نوت‌بوک اجرا می‌شه، خودش به‌صورت خودکار کتابخونه‌ها رو نصب کنه:

!pip install -q torch transformers datasets

به این ترتیب، هر بار که ماشین کولب از نو شروع بشه، فقط چند ثانیه طول می‌کشه تا دوباره مثل قبل آمادهٔ کار بشه.


Colab’s machines are temporary

When you open a Colab notebook, Google gives you a virtual machine (VM) that exists only while your session is active. Once you close the tab or stay idle too long, it gets deleted — including everything you installed or downloaded.
But AI engineers bypass that:

They connect their Google Drive and store checkpoints or model weights there (drive.mount('/content/drive')).

They also create setup scripts that reinstall all dependencies automatically each time the notebook starts (!pip install -q torch transformers datasets).
So every time the VM restarts, it rebuilds itself in seconds.
3
کولب GPU واقعی می‌ده بهت


جی‌پی‌یوهایی که کولب می‌ده واقعی‌ان، نه شبیه‌سازی‌شده. معمولاً مدل‌هایی مثل Tesla T4
، P100 یا در نسخهٔ Pro+ مدل A100 هستن.
می‌تونی ببینی چه GPU بهت داده با دستور:

!nvidia-smi


ولی یه محدودیت داره. حافظهٔ GPU معمولاً بین ۱۲ تا ۱۶ گیگابایته. اگه موقع آموزش مدل با خطای “CUDA out of memory” روبه‌رو شدی (یعنی حافظه پر شده)، باید این کارو کنی:

import torch, gc
gc.collect()
torch.cuda.empty_cache()


این دستورها حافظهٔ اضافی GPU رو پاک می‌کنن تا دوباره بتونی آموزش رو ادامه بدی.
همچنین مهندسین حرفه‌ای معمولاً اندازهٔ batch size رو کمتر می‌کنن (تعداد نمونه‌هایی که هم‌زمان پردازش می‌شن) یا از قابلیت precision ترکیبی استفاده می‌کنن:

with torch.cuda.amp.autocast():
...


این باعث می‌شه حافظهٔ GPU کمتر مصرف بشه ولی سرعت آموزش تقریباً همون بمونه.


Colab gives real GPUs, but you have to manage memory smartl

yColab’s free GPU isn’t fake — it’s an actual NVIDIA card like Tesla T4, P100, or A100 (Pro + only). You can check which one you got with

:!nvidia-sm


iBut VRAM is limited (12–16 GB). So if your model crashes with “CUDA out of memory,” pros do this

:import torch, g
cgc.collect(
)torch.cuda.empty_cache(


That clears leftover memory.
They also lower the batch size (how many samples are processed at once) or use torch.cuda.amp.autocast() for mixed precision to save VRAM while training large models
5
کش KV توی ترنسفورمرها

🧠 مدل‌های زبانی بزرگ وقتی می‌خوان یه جمله رو بنویسن، باید برای هر کلمه‌ی جدید همه‌ی کلمه‌های قبلی رو هم دوباره بررسی کنن تا معنی درست دربیاد.
این کار اگه هر بار از اول انجام بشه، خیلی کند میشه.

اینجاست که کش KV کمک می‌کنه.
مدل وقتی بار اول جمله رو می‌خونه، برای هر کلمه دو تا چیز درست می‌کنه:

▫️Key (کلید) که نشون میده اون کلمه چه اطلاعاتی داره

▫️Value (مقدار) که مشخص می‌کنه اون اطلاعات چطوری باید استفاده بشن

مدل اینا رو نگه می‌داره توی حافظه،
و دفعه‌ی بعد فقط برای کلمه‌ی جدید محاسبه می‌کنه، نه برای همه‌ی قبلیا.

نتیجه اینه که مدل خیلی سریع‌تر کار می‌کنه و منابعش کمتر درگیر می‌شن مخصوصاً وقتی متن طولانیه.
2