1493 lines
48 KiB
HTML
1493 lines
48 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fa" dir="rtl">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>مفهوم Context Size در مدلهای زبانی | تحلیل جامع</title>
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
|
||
|
||
:root {
|
||
--primary: #1a365d;
|
||
--primary-light: #2c5282;
|
||
--accent: #c9a961;
|
||
--accent-dark: #a8893f;
|
||
--bg: #faf9f6;
|
||
--card-bg: #ffffff;
|
||
--text: #1a202c;
|
||
--text-muted: #4a5568;
|
||
--border: #e2e8f0;
|
||
--success: #38a169;
|
||
--danger: #e53e3e;
|
||
--warning: #dd6b20;
|
||
--purple: #6b46c1;
|
||
--purple-light: #805ad5;
|
||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||
}
|
||
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
|
||
body {
|
||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.9;
|
||
font-size: 15px;
|
||
padding: 30px 15px;
|
||
}
|
||
|
||
.document-container {
|
||
max-width: 950px;
|
||
margin: 0 auto;
|
||
background: var(--card-bg);
|
||
box-shadow: var(--shadow);
|
||
border-radius: 12px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.document-header {
|
||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||
color: white;
|
||
padding: 50px 40px 40px;
|
||
position: relative;
|
||
border-bottom: 4px solid var(--accent);
|
||
}
|
||
|
||
.document-header::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0; right: 0;
|
||
width: 200px; height: 200px;
|
||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||
border-radius: 50%;
|
||
transform: translate(50%, -50%);
|
||
}
|
||
|
||
.header-top {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 30px;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
.company-badge {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.company-logo {
|
||
width: 60px; height: 60px;
|
||
background: var(--accent);
|
||
border-radius: 12px;
|
||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 28px;
|
||
font-weight: 800;
|
||
color: var(--primary);
|
||
}
|
||
|
||
.doc-meta {
|
||
text-align: left;
|
||
font-size: 12px;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.doc-meta div { margin-bottom: 3px; }
|
||
|
||
.document-title {
|
||
text-align: center;
|
||
position: relative;
|
||
z-index: 1;
|
||
padding: 20px 0;
|
||
}
|
||
|
||
.document-title .label {
|
||
display: inline-block;
|
||
background: rgba(201,169,97,0.2);
|
||
color: var(--accent);
|
||
padding: 4px 16px;
|
||
border-radius: 20px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
margin-bottom: 15px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-title h1 {
|
||
font-size: 28px;
|
||
font-weight: 800;
|
||
margin-bottom: 10px;
|
||
letter-spacing: -0.5px;
|
||
}
|
||
|
||
.document-title h2 {
|
||
font-size: 16px;
|
||
font-weight: 400;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.document-body {
|
||
padding: 40px;
|
||
}
|
||
|
||
.intro-text {
|
||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin-bottom: 35px;
|
||
font-size: 14px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.section {
|
||
margin-bottom: 40px;
|
||
page-break-inside: avoid;
|
||
}
|
||
|
||
.section-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 2px solid var(--border);
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.section-number {
|
||
width: 50px; height: 50px;
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 800;
|
||
font-size: 20px;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.section-title { flex: 1; }
|
||
|
||
.section-title h3 {
|
||
font-size: 19px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 2px;
|
||
}
|
||
|
||
.section-title .subtitle {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.section-content {
|
||
padding-right: 10px;
|
||
}
|
||
|
||
.section-content p {
|
||
margin-bottom: 12px;
|
||
text-align: justify;
|
||
}
|
||
|
||
.section-content p.no-indent { text-indent: 0; }
|
||
|
||
.section-content h4 {
|
||
margin-top: 25px;
|
||
color: var(--primary);
|
||
font-size: 16px;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.section-content ul, .section-content ol {
|
||
padding-right: 25px;
|
||
margin-top: 10px;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.section-content ul li, .section-content ol li {
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.highlight-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #f6e05e;
|
||
border-right: 4px solid var(--accent);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.highlight-box strong {
|
||
color: var(--accent-dark);
|
||
}
|
||
|
||
.info-box {
|
||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||
border: 1px solid #90cdf4;
|
||
border-right: 4px solid var(--primary-light);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.success-box {
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
border: 1px solid #9ae6b4;
|
||
border-right: 4px solid var(--success);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.warning-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #fbd38d;
|
||
border-right: 4px solid var(--warning);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.purple-box {
|
||
background: linear-gradient(to left, #faf5ff, #f3e8ff);
|
||
border: 1px solid #d6bcfa;
|
||
border-right: 4px solid var(--purple);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.styled-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
margin: 20px 0;
|
||
background: white;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||
}
|
||
|
||
.styled-table thead {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
}
|
||
|
||
.styled-table th {
|
||
padding: 14px 16px;
|
||
text-align: right;
|
||
font-weight: 600;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.styled-table td {
|
||
padding: 13px 16px;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
}
|
||
|
||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||
|
||
.styled-table .highlight-row {
|
||
background: #fffaf0 !important;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.comparison-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 20px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.comparison-card {
|
||
background: #f8fafc;
|
||
border: 2px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 20px;
|
||
position: relative;
|
||
}
|
||
|
||
.comparison-card.recommended {
|
||
border-color: var(--success);
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
}
|
||
|
||
.comparison-card .card-badge {
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 20px;
|
||
background: var(--success);
|
||
color: white;
|
||
padding: 3px 12px;
|
||
border-radius: 15px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.comparison-card h4 {
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 15px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 2px solid var(--border);
|
||
margin-top: 0;
|
||
}
|
||
|
||
.comparison-card.recommended h4 {
|
||
border-bottom-color: var(--success);
|
||
}
|
||
|
||
.comparison-card ul {
|
||
list-style: none;
|
||
padding: 0;
|
||
}
|
||
|
||
.comparison-card ul li {
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.comparison-card ul li:last-child { border-bottom: none; }
|
||
|
||
.comparison-card ul li .value {
|
||
font-weight: 600;
|
||
color: var(--primary);
|
||
}
|
||
|
||
.quote-box {
|
||
background: linear-gradient(135deg, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
position: relative;
|
||
}
|
||
|
||
.quote-box::before {
|
||
content: '"';
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 15px;
|
||
font-size: 60px;
|
||
color: var(--accent);
|
||
opacity: 0.3;
|
||
font-family: Georgia, serif;
|
||
}
|
||
|
||
.quote-box p {
|
||
font-style: italic;
|
||
color: var(--text-muted);
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.quote-box .source {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
text-align: left;
|
||
font-style: normal;
|
||
}
|
||
|
||
.stats-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 15px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.stat-card {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 20px;
|
||
border-radius: 10px;
|
||
text-align: center;
|
||
box-shadow: 0 4px 12px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.stat-card .stat-value {
|
||
font-size: 22px;
|
||
font-weight: 800;
|
||
margin-bottom: 5px;
|
||
color: var(--accent);
|
||
line-height: 1.3;
|
||
}
|
||
|
||
.stat-card .stat-label {
|
||
font-size: 12px;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.stat-card.purple {
|
||
background: linear-gradient(135deg, var(--purple), var(--purple-light));
|
||
}
|
||
|
||
.timeline {
|
||
position: relative;
|
||
padding: 20px 0;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.timeline::before {
|
||
content: '';
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 0;
|
||
bottom: 0;
|
||
width: 3px;
|
||
background: var(--border);
|
||
transform: translateX(50%);
|
||
}
|
||
|
||
.timeline-item {
|
||
display: flex;
|
||
margin-bottom: 20px;
|
||
position: relative;
|
||
}
|
||
|
||
.timeline-item:nth-child(odd) {
|
||
flex-direction: row-reverse;
|
||
}
|
||
|
||
.timeline-content {
|
||
width: 45%;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 15px;
|
||
position: relative;
|
||
}
|
||
|
||
.timeline-item:nth-child(odd) .timeline-content {
|
||
margin-left: 5%;
|
||
}
|
||
|
||
.timeline-item:nth-child(even) .timeline-content {
|
||
margin-right: 5%;
|
||
}
|
||
|
||
.timeline-dot {
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 20px;
|
||
width: 16px;
|
||
height: 16px;
|
||
background: var(--accent);
|
||
border: 3px solid white;
|
||
border-radius: 50%;
|
||
transform: translateX(50%);
|
||
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
||
z-index: 1;
|
||
}
|
||
|
||
.timeline-content h5 {
|
||
font-size: 14px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.timeline-content p {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
margin-bottom: 0 !important;
|
||
}
|
||
|
||
.reference-list {
|
||
list-style: none;
|
||
padding: 0;
|
||
margin: 20px 0;
|
||
}
|
||
|
||
.reference-list li {
|
||
background: #f8fafc;
|
||
border-right: 3px solid var(--primary-light);
|
||
padding: 15px 20px;
|
||
margin-bottom: 10px;
|
||
border-radius: 6px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.reference-list li strong {
|
||
color: var(--primary);
|
||
display: block;
|
||
margin-bottom: 5px;
|
||
}
|
||
|
||
.reference-list li .ref-source {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
margin-top: 5px;
|
||
}
|
||
|
||
.conclusion-box {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 30px;
|
||
border-radius: 12px;
|
||
margin: 30px 0;
|
||
text-align: center;
|
||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||
}
|
||
|
||
.conclusion-box h3 {
|
||
font-size: 22px;
|
||
font-weight: 800;
|
||
margin-bottom: 15px;
|
||
color: var(--accent);
|
||
}
|
||
|
||
.conclusion-box p {
|
||
font-size: 14px;
|
||
line-height: 1.8;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.conclusion-box .highlight {
|
||
background: rgba(201,169,97,0.2);
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-top: 20px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-footer {
|
||
background: var(--primary);
|
||
color: white;
|
||
padding: 25px 40px;
|
||
text-align: center;
|
||
font-size: 12px;
|
||
margin-top: 40px;
|
||
}
|
||
|
||
.document-footer .footer-brand {
|
||
font-weight: 700;
|
||
color: var(--accent);
|
||
margin-bottom: 5px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.footer-divider {
|
||
width: 60px;
|
||
height: 2px;
|
||
background: var(--accent);
|
||
margin: 10px auto;
|
||
}
|
||
|
||
.page-info {
|
||
text-align: center;
|
||
padding: 15px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
border-top: 1px solid var(--border);
|
||
margin-top: 30px;
|
||
}
|
||
|
||
.code-block {
|
||
background: #1a202c;
|
||
color: #e2e8f0;
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
font-family: 'Courier New', monospace;
|
||
font-size: 13px;
|
||
direction: ltr;
|
||
text-align: left;
|
||
margin: 15px 0;
|
||
overflow-x: auto;
|
||
line-height: 1.7;
|
||
border-right: 4px solid var(--accent);
|
||
}
|
||
|
||
.code-block .comment { color: #68d391; }
|
||
.code-block .keyword { color: #f6ad55; }
|
||
.code-block .string { color: #fbd38d; }
|
||
.code-block .number { color: #90cdf4; }
|
||
|
||
.token-viz {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
margin: 15px 0;
|
||
direction: ltr;
|
||
justify-content: flex-start;
|
||
}
|
||
|
||
.token {
|
||
display: inline-block;
|
||
padding: 6px 12px;
|
||
border-radius: 6px;
|
||
font-family: 'Courier New', monospace;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: white;
|
||
}
|
||
|
||
.token-1 { background: #2c5282; }
|
||
.token-2 { background: #38a169; }
|
||
.token-3 { background: #dd6b20; }
|
||
.token-4 { background: #805ad5; }
|
||
.token-5 { background: #c53030; }
|
||
.token-6 { background: #2b6cb0; }
|
||
.token-7 { background: #276749; }
|
||
.token-8 { background: #b7791f; }
|
||
|
||
.context-diagram {
|
||
background: #f7fafc;
|
||
border: 2px dashed var(--primary-light);
|
||
border-radius: 12px;
|
||
padding: 25px 20px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.context-diagram-title {
|
||
text-align: center;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 20px;
|
||
font-size: 15px;
|
||
}
|
||
|
||
.context-bar {
|
||
display: flex;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||
margin-bottom: 20px;
|
||
direction: rtl;
|
||
}
|
||
|
||
.context-segment {
|
||
padding: 20px 10px;
|
||
text-align: center;
|
||
color: white;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
align-items: center;
|
||
gap: 4px;
|
||
min-height: 80px;
|
||
}
|
||
|
||
.context-segment .seg-title {
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.context-segment .seg-tokens {
|
||
font-size: 11px;
|
||
opacity: 0.85;
|
||
direction: ltr;
|
||
}
|
||
|
||
.seg-system { background: linear-gradient(135deg, #2c5282, #1a365d); flex: 1.5; }
|
||
.seg-history { background: linear-gradient(135deg, #38a169, #276749); flex: 3; }
|
||
.seg-rag { background: linear-gradient(135deg, #dd6b20, #b7791f); flex: 2.5; }
|
||
.seg-prompt { background: linear-gradient(135deg, #805ad5, #6b46c1); flex: 1; }
|
||
.seg-output { background: linear-gradient(135deg, #c53030, #9b2c2c); flex: 2; }
|
||
|
||
.context-total {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: var(--text-muted);
|
||
padding-top: 15px;
|
||
border-top: 1px solid var(--border);
|
||
}
|
||
|
||
.context-total strong {
|
||
color: var(--primary);
|
||
font-size: 15px;
|
||
}
|
||
|
||
.lost-middle-viz {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin: 20px 0;
|
||
direction: ltr;
|
||
}
|
||
|
||
.attention-bar {
|
||
flex: 1;
|
||
height: 50px;
|
||
border-radius: 8px;
|
||
background: linear-gradient(90deg, #38a169 0%, #f6e05e 20%, #e53e3e 50%, #f6e05e 80%, #38a169 100%);
|
||
position: relative;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 10px;
|
||
color: white;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
|
||
}
|
||
|
||
@media print {
|
||
body { background: white; padding: 0; }
|
||
.document-container { box-shadow: none; border-radius: 0; }
|
||
.section { page-break-inside: avoid; }
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.document-body { padding: 25px 20px; }
|
||
.document-header { padding: 30px 20px; }
|
||
.comparison-grid { grid-template-columns: 1fr; }
|
||
.stats-grid { grid-template-columns: 1fr; }
|
||
.header-top { flex-direction: column; gap: 15px; }
|
||
.doc-meta { text-align: center; }
|
||
.context-bar { flex-direction: column; }
|
||
.timeline::before { right: 20px; }
|
||
.timeline-item, .timeline-item:nth-child(odd) { flex-direction: row; }
|
||
.timeline-content { width: 85%; }
|
||
.timeline-item:nth-child(odd) .timeline-content { margin-left: 15%; }
|
||
.timeline-item:nth-child(even) .timeline-content { margin-right: 15%; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<div class="document-container">
|
||
|
||
<header class="document-header">
|
||
<div class="header-top">
|
||
<div class="company-badge">
|
||
<div class="company-logo">AI</div>
|
||
</div>
|
||
<div class="doc-meta">
|
||
<div>شماره مستند: AI-DOC-1405-002</div>
|
||
<div>نسخه: ۱.۰</div>
|
||
<div>تاریخ تهیه: مهر ۱۴۰۵</div>
|
||
<div>طبقهبندی: آموزشی</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="document-title">
|
||
<span class="label">TECHNICAL ANALYSIS</span>
|
||
<h1>مفهوم Context Size در مدلهای زبانی</h1>
|
||
<h2>تحلیل جامع، چالشها، تکنیکهای مدیریت و مقایسه مدلها</h2>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="document-body">
|
||
|
||
<div class="intro-text">
|
||
<strong>خواننده گرامی،</strong><br>
|
||
این مستند بهعنوان تحلیلی جامع و مبتنی بر دادههای فنی و تجربیات عملی، مفهوم Context Size (اندازه بافت) را در مدلهای زبانی بزرگ (LLMs) بررسی مینماید. هدف از تهیه این مستند، ارائه درکی عمیق از این مفهوم کلیدی، چالشهای مرتبط با آن، و تکنیکهای مؤثر برای مدیریت بهینه آن است.
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 1 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱</div>
|
||
<div class="section-title">
|
||
<h3>تعریف ساده Context Size</h3>
|
||
<div class="subtitle">Simple Definition</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p><strong>Context Size</strong> (یا Context Window / Context Length) به حداکثر تعداد توکنهایی گفته میشود که یک مدل زبانی میتواند در یک لحظه «ببیند» و پردازش کند. این شامل تمام ورودیها (پرامپت + تاریخچه چت + اسناد) و خروجی تولیدشده است.</p>
|
||
|
||
<div class="highlight-box">
|
||
<strong>تعریف کلیدی:</strong> Context Size = حداکثر توکنهای قابل پردازش در یک لحظه = ورودی + خروجی
|
||
</div>
|
||
|
||
<p>به بیان ساده، Context Size مانند «حافظه کاری» (Working Memory) یک انسان است. همانطور که شما در یک مکالمه فقط میتوانید تعداد محدودی از جملات اخیر را به خاطر بسپارید، مدل زبانی نیز فقط میتواند تعداد محدودی توکن را در یک زمان پردازش کند.</p>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته مهم:</strong> هر چیزی که در Context باشد، مدل میتواند به آن توجه کند. هر چیزی که خارج از Context باشد، برای مدل وجود ندارد و بهطور کامل فراموش میشود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 2 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۲</div>
|
||
<div class="section-title">
|
||
<h3>توکن چیست؟</h3>
|
||
<div class="subtitle">What is a Token?</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>قبل از درک Context Size باید بدانیم <strong>توکن</strong> چیست:</p>
|
||
|
||
<ul>
|
||
<li>توکن کوچکترین واحد متنی است که مدل پردازش میکند</li>
|
||
<li>لزوماً برابر کلمه نیست</li>
|
||
<li>تقریباً:
|
||
<ul>
|
||
<li><strong>انگلیسی:</strong> ۱ توکن ≈ ۰.۷۵ کلمه (۱۰۰۰ توکن ≈ ۷۵۰ کلمه)</li>
|
||
<li><strong>فارسی:</strong> هر کلمه معمولاً ۲-۴ توکن (به دلیل توکنایزرهای ضعیفتر برای فارسی)</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>مثال عملی از توکنسازی:</h4>
|
||
|
||
<p class="no-indent"><strong>متن انگلیسی:</strong> "Hello world"</p>
|
||
<div class="token-viz">
|
||
<span class="token token-1">Hello</span>
|
||
<span class="token token-2">world</span>
|
||
</div>
|
||
<p class="no-indent" style="font-size: 13px; color: var(--text-muted);">→ ۲ توکن</p>
|
||
|
||
<p class="no-indent"><strong>متن فارسی:</strong> "سلام دنیا"</p>
|
||
<div class="token-viz">
|
||
<span class="token token-3">سلام</span>
|
||
<span class="token token-4">دنیا</span>
|
||
</div>
|
||
<p class="no-indent" style="font-size: 13px; color: var(--text-muted);">→ ممکن است ۳-۵ توکن شود (بسته به توکنایزر)</p>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠️ هشدار مهم:</strong> مدلهای زبانی برای زبان فارسی بهینه نشدهاند. یک متن فارسی ممکن است ۲ تا ۳ برابر بیشتر از معادل انگلیسی خود توکن مصرف کند. این یعنی Context Size مؤثر برای فارسیزبانان بهمراتب کمتر است.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 3 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۳</div>
|
||
<div class="section-title">
|
||
<h3>چرا Context Size مهم است؟</h3>
|
||
<div class="subtitle">Why Does It Matter?</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>مدل زبانی مثل یک <strong>حافظه کاری محدود</strong> عمل میکند:</p>
|
||
|
||
<ol>
|
||
<li><strong>هر چیزی که در Context باشد</strong> → مدل میتواند به آن توجه کند</li>
|
||
<li><strong>هر چیزی که خارج از Context باشد</strong> → برای مدل وجود ندارد (فراموش میشود)</li>
|
||
</ol>
|
||
|
||
<p>این یعنی اگر مکالمهای طولانی شود و از حد Context رد شود، پیامهای قدیمیتر حذف میشوند. این پدیده را <strong>Truncation</strong> (قطع) مینامند.</p>
|
||
|
||
<div class="stats-grid">
|
||
<div class="stat-card">
|
||
<div class="stat-value">حافظه<br>محدود</div>
|
||
<div class="stat-label">مدل فقط Context فعلی را میبیند</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">فراموشی<br>تدریجی</div>
|
||
<div class="stat-label">پیامهای قدیمی حذف میشوند</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">تأثیر<br>مستقیم</div>
|
||
<div class="stat-label">بر کیفیت پاسخ و دقت</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 4 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۴</div>
|
||
<div class="section-title">
|
||
<h3>محتوای Context شامل چه چیزهایی است؟</h3>
|
||
<div class="subtitle">Context Window Composition</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>Context Window از چند بخش تشکیل شده است که همه آنها از یک بودجه مشترک مصرف میکنند:</p>
|
||
|
||
<div class="context-diagram">
|
||
<div class="context-diagram-title">ساختار Context Window</div>
|
||
<div class="context-bar">
|
||
<div class="context-segment seg-system">
|
||
<span class="seg-title">System Prompt</span>
|
||
<span class="seg-tokens">500 tokens</span>
|
||
</div>
|
||
<div class="context-segment seg-history">
|
||
<span class="seg-title">تاریخچه مکالمه</span>
|
||
<span class="seg-tokens">3,000 tokens</span>
|
||
</div>
|
||
<div class="context-segment seg-rag">
|
||
<span class="seg-title">اسناد RAG</span>
|
||
<span class="seg-tokens">2,500 tokens</span>
|
||
</div>
|
||
<div class="context-segment seg-prompt">
|
||
<span class="seg-title">پرامپت کاربر</span>
|
||
<span class="seg-tokens">200 tokens</span>
|
||
</div>
|
||
<div class="context-segment seg-output">
|
||
<span class="seg-title">پاسخ مدل</span>
|
||
<span class="seg-tokens">1,800 tokens</span>
|
||
</div>
|
||
</div>
|
||
<div class="context-total">
|
||
مجموع مصرفشده: <strong>8,000 توکن</strong> | فضای باقیمانده: <strong>0 توکن</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>بخش</th>
|
||
<th>توضیح</th>
|
||
<th>مصرف معمول</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>System Prompt</strong></td>
|
||
<td>دستورالعملهای پایه، شخصیت مدل، قوانین</td>
|
||
<td>۱۰۰ - ۱,۰۰۰ توکن</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>تاریخچه مکالمه</strong></td>
|
||
<td>پیامهای قبلی کاربر و مدل</td>
|
||
<td>متغیر (میتواند خیلی بزرگ شود)</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>اسناد RAG</strong></td>
|
||
<td>محتوای بازیابیشده از پایگاه دانش</td>
|
||
<td>۱,۰۰۰ - ۱۰,۰۰۰+ توکن</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>پرامپت فعلی</strong></td>
|
||
<td>سؤال یا درخواست فعلی کاربر</td>
|
||
<td>۵۰ - ۵۰۰ توکن</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>پاسخ مدل</strong></td>
|
||
<td>خروجی تولیدشده توسط مدل</td>
|
||
<td>۱۰۰ - ۴,۰۰۰+ توکن</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته کلیدی:</strong> ورودی + خروجی هر دو از این بودجه مصرف میکنند. اگر Context شما ۸K توکن باشد و ۷K آن ورودی باشد، فقط ۱K برای پاسخ مدل باقی میماند.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 5 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۵</div>
|
||
<div class="section-title">
|
||
<h3>مقایسه Context Size مدلهای معروف</h3>
|
||
<div class="subtitle">Model Comparison</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>مدلهای مختلف Context Size های بسیار متفاوتی دارند:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>مدل</th>
|
||
<th>Context Size</th>
|
||
<th>معادل تقریبی</th>
|
||
<th>کاربرد مناسب</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>GPT-3</td>
|
||
<td style="direction: ltr; text-align: left;">2K - 4K</td>
|
||
<td>~ ۱,۵۰۰ - ۳,۰۰۰ کلمه</td>
|
||
<td>مکالمات کوتاه</td>
|
||
</tr>
|
||
<tr>
|
||
<td>GPT-3.5 Turbo</td>
|
||
<td style="direction: ltr; text-align: left;">4K - 16K</td>
|
||
<td>~ ۳,۰۰۰ - ۱۲,۰۰۰ کلمه</td>
|
||
<td>چتبات عمومی</td>
|
||
</tr>
|
||
<tr>
|
||
<td>GPT-4</td>
|
||
<td style="direction: ltr; text-align: left;">8K - 32K</td>
|
||
<td>~ ۶,۰۰۰ - ۲۴,۰۰۰ کلمه</td>
|
||
<td>تحلیل اسناد متوسط</td>
|
||
</tr>
|
||
<tr>
|
||
<td>GPT-4 Turbo</td>
|
||
<td style="direction: ltr; text-align: left;">128K</td>
|
||
<td>~ ۹۶,۰۰۰ کلمه (یک کتاب)</td>
|
||
<td>تحلیل اسناد بزرگ</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>GPT-4o</strong></td>
|
||
<td style="direction: ltr; text-align: left;"><strong>128K</strong></td>
|
||
<td>~ ۹۶,۰۰۰ کلمه</td>
|
||
<td>مولتیمودال + اسناد بزرگ</td>
|
||
</tr>
|
||
<tr>
|
||
<td>Claude 3.5 Sonnet</td>
|
||
<td style="direction: ltr; text-align: left;">200K</td>
|
||
<td>~ ۱۵۰,۰۰۰ کلمه</td>
|
||
<td>تحلیل اسناد بسیار بزرگ</td>
|
||
</tr>
|
||
<tr>
|
||
<td>Claude 3 Opus</td>
|
||
<td style="direction: ltr; text-align: left;">200K</td>
|
||
<td>~ ۱۵۰,۰۰۰ کلمه</td>
|
||
<td>پژوهش و تحلیل عمیق</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>Gemini 1.5 Pro</strong></td>
|
||
<td style="direction: ltr; text-align: left;"><strong>1M - 2M</strong></td>
|
||
<td>~ ۷۵۰,۰۰۰ - ۱,۵۰۰,۰۰۰ کلمه</td>
|
||
<td>تحلیل کل کتابخانهها</td>
|
||
</tr>
|
||
<tr>
|
||
<td>Llama 3.1</td>
|
||
<td style="direction: ltr; text-align: left;">128K</td>
|
||
<td>~ ۹۶,۰۰۰ کلمه</td>
|
||
<td>مدل باز (Self-hosted)</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="purple-box">
|
||
<strong>🚀 روند رشد:</strong> Context Size مدلها در چند سال اخیر بهطور نمایی رشد کرده است. از ۲K در GPT-3 (سال ۲۰۲۰) به ۲M در Gemini 1.5 (سال ۲۰۲۴) — یعنی <strong>۱۰۰۰ برابر</strong> افزایش در کمتر از ۵ سال!
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 6 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۶</div>
|
||
<div class="section-title">
|
||
<h3>چالشهای Context Size</h3>
|
||
<div class="subtitle">Challenges & Limitations</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
|
||
<h4>۱. هزینه محاسباتی</h4>
|
||
<ul>
|
||
<li>پیچیدگی Attention به صورت <strong>O(n²)</strong> است</li>
|
||
<li>دو برابر کردن Context = چهار برابر محاسبات</li>
|
||
<li>هزینه API معمولاً بر اساس توکن محاسبه میشود</li>
|
||
</ul>
|
||
|
||
<div class="code-block">
|
||
<span class="comment">// پیچیدگی محاسباتی Attention</span>
|
||
<span class="keyword">for</span> each token i:
|
||
<span class="keyword">for</span> each token j:
|
||
attention[i][j] = softmax(Q[i] · K[j] / √d)
|
||
|
||
<span class="comment">// n = تعداد توکنها</span>
|
||
<span class="comment">// پیچیدگی = O(n²)</span>
|
||
<span class="comment">// n=4K → 16M operations</span>
|
||
<span class="comment">// n=8K → 64M operations (۴ برابر!)</span>
|
||
<span class="comment">// n=128K → 16B operations (۱۰۲۴ برابر!)</span>
|
||
</div>
|
||
|
||
<h4>۲. مسئله "Lost in the Middle"</h4>
|
||
<p>تحقیقات نشان داده مدلها:</p>
|
||
<ul>
|
||
<li>اطلاعات <strong>ابتدا و انتهای</strong> Context را خوب میبینند</li>
|
||
<li>اطلاعات <strong>وسط</strong> Context را ممکن است نادیده بگیرند</li>
|
||
</ul>
|
||
|
||
<div class="lost-middle-viz">
|
||
<div class="attention-bar">
|
||
<span>توجه بالا</span>
|
||
<span>توجه پایین</span>
|
||
<span>توجه بالا</span>
|
||
</div>
|
||
</div>
|
||
<p class="no-indent" style="text-align: center; font-size: 12px; color: var(--text-muted);">توزیع توجه مدل در Context های بزرگ (U-Shape)</p>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠️ نتیجه عملی:</strong> اگر میخواهید اطلاعات مهم را در Context بگذارید، آنها را در ابتدا یا انتها قرار دهید، نه در وسط!
|
||
</div>
|
||
|
||
<h4>۳. کیفیت در Context های بزرگ</h4>
|
||
<ul>
|
||
<li>افزایش Context لزوماً به معنای دقت بالاتر نیست</li>
|
||
<li>مدل ممکن است در Context های خیلی بزرگ گیج شود</li>
|
||
<li>پدیده "Context Rot" — افت کیفیت با افزایش طول</li>
|
||
</ul>
|
||
|
||
<h4>۴. حافظه GPU</h4>
|
||
<ul>
|
||
<li>Context بزرگ = VRAM بیشتر</li>
|
||
<li>KV Cache میتواند حافظه زیادی مصرف کند</li>
|
||
<li>مثال: Llama 3.1 70B با 128K Context نیاز به ~۴۰GB VRAM دارد</li>
|
||
</ul>
|
||
|
||
<div class="stats-grid">
|
||
<div class="stat-card">
|
||
<div class="stat-value">O(n²)</div>
|
||
<div class="stat-label">پیچیدگی Attention</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">U-Shape</div>
|
||
<div class="stat-label">توزیع توجه</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">VRAM</div>
|
||
<div class="stat-label">محدودیت سختافزاری</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 7 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۷</div>
|
||
<div class="section-title">
|
||
<h3>تکنیکهای مدیریت Context</h3>
|
||
<div class="subtitle">Context Management Techniques</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>برای استفاده بهینه از Context Size محدود، تکنیکهای متعددی وجود دارد:</p>
|
||
|
||
<h4>۱. Summarization (خلاصهسازی)</h4>
|
||
<p>وقتی مکالمه طولانی میشود، پیامهای قدیمی را خلاصه میکنند.</p>
|
||
<div class="code-block">
|
||
<span class="comment">// به جای نگه داشتن 100 پیام قدیمی:</span>
|
||
<span class="keyword">summary</span> = model.summarize(old_messages)
|
||
new_context = [summary] + recent_messages
|
||
|
||
<span class="comment">// نتیجه: کاهش چشمگیر توکنها با حفظ اطلاعات کلیدی</span>
|
||
</div>
|
||
|
||
<h4>۲. Sliding Window</h4>
|
||
<p>فقط N پیام آخر نگه داشته میشود.</p>
|
||
<div class="code-block">
|
||
<span class="comment">// پنجره لغزان</span>
|
||
context = last_n_messages(messages, n=<span class="number">10</span>)
|
||
|
||
<span class="comment">// قدیمیترین پیامها حذف میشوند</span>
|
||
<span class="comment">// ساده اما ممکن است اطلاعات مهم را از دست بدهد</span>
|
||
</div>
|
||
|
||
<h4>۳. RAG (Retrieval Augmented Generation)</h4>
|
||
<p>به جای گذاشتن همه اسناد، فقط مرتبطترین بخشها بازیابی میشوند.</p>
|
||
<div class="code-block">
|
||
<span class="comment">// 1. تبدیل سؤال به بردار</span>
|
||
query_vector = embed(user_question)
|
||
|
||
<span class="comment">// 2. جستجوی شباهت در پایگاه دانش</span>
|
||
relevant_docs = vector_db.search(query_vector, top_k=<span class="number">5</span>)
|
||
|
||
<span class="comment">// 3. تزریق فقط اسناد مرتبط به Context</span>
|
||
context = relevant_docs + user_question
|
||
</div>
|
||
|
||
<h4>۴. Chunking</h4>
|
||
<p>اسناد بزرگ را به قطعات کوچکتر تقسیم میکنند.</p>
|
||
<ul>
|
||
<li><strong>Fixed-size Chunking:</strong> تقسیم بر اساس تعداد کاراکتر/توکن</li>
|
||
<li><strong>Semantic Chunking:</strong> تقسیم بر اساس معنا و پاراگراف</li>
|
||
<li><strong>Recursive Chunking:</strong> تقسیم سلسلهمراتبی</li>
|
||
</ul>
|
||
|
||
<h4>۵. Prompt Compression</h4>
|
||
<p>فشردهسازی پرامپتها برای صرفهجویی در توکن.</p>
|
||
<ul>
|
||
<li>حذف کلمات تکراری و غیرضروری</li>
|
||
<li>استفاده از اختصارات</li>
|
||
<li>تبدیل جملات طولانی به کوتاه</li>
|
||
</ul>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>تکنیک</th>
|
||
<th>مزیت اصلی</th>
|
||
<th>محدودیت</th>
|
||
<th>کاربرد مناسب</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>Summarization</strong></td>
|
||
<td>حفظ اطلاعات کلیدی</td>
|
||
<td>ممکن است جزئیات از دست برود</td>
|
||
<td>مکالمات طولانی</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Sliding Window</strong></td>
|
||
<td>ساده و سریع</td>
|
||
<td>فراموشی اطلاعات قدیمی</td>
|
||
<td>چتباتهای عمومی</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>RAG</strong></td>
|
||
<td>دقت بالا + مقیاسپذیری</td>
|
||
<td>نیاز به زیرساخت برداری</td>
|
||
<td>سیستمهای دانشمحور</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Chunking</strong></td>
|
||
<td>مدیریت اسناد بزرگ</td>
|
||
<td>ممکن است ارتباطات از دست برود</td>
|
||
<td>پردازش اسناد</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Prompt Compression</strong></td>
|
||
<td>صرفهجویی مستقیم توکن</td>
|
||
<td>ریسک از دست دادن معنا</td>
|
||
<td>همه کاربردها</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 8 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۸</div>
|
||
<div class="section-title">
|
||
<h3>مثال عملی محاسبه Context</h3>
|
||
<div class="subtitle">Practical Example</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>فرض کنید Context Size مدل <strong>۸K توکن</strong> است:</p>
|
||
|
||
<div class="context-diagram">
|
||
<div class="context-diagram-title">محاسبه دقیق مصرف Context</div>
|
||
<div class="context-bar">
|
||
<div class="context-segment seg-system" style="flex: 0.5;">
|
||
<span class="seg-title">System</span>
|
||
<span class="seg-tokens">500</span>
|
||
</div>
|
||
<div class="context-segment seg-history" style="flex: 3;">
|
||
<span class="seg-title">History</span>
|
||
<span class="seg-tokens">3,000</span>
|
||
</div>
|
||
<div class="context-segment seg-rag" style="flex: 2.5;">
|
||
<span class="seg-title">RAG</span>
|
||
<span class="seg-tokens">2,500</span>
|
||
</div>
|
||
<div class="context-segment seg-prompt" style="flex: 0.2;">
|
||
<span class="seg-title">Prompt</span>
|
||
<span class="seg-tokens">200</span>
|
||
</div>
|
||
<div class="context-segment seg-output" style="flex: 1.8;">
|
||
<span class="seg-title">Output</span>
|
||
<span class="seg-tokens">1,800</span>
|
||
</div>
|
||
</div>
|
||
<div class="context-total">
|
||
مجموع: <strong>8,000 توکن</strong> | وضعیت: <strong style="color: var(--danger);">تکمیل شده (Full)</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>بخش</th>
|
||
<th>توکن</th>
|
||
<th>درصد</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>System Prompt</td>
|
||
<td style="direction: ltr; text-align: left;">500</td>
|
||
<td>۶.۲۵٪</td>
|
||
</tr>
|
||
<tr>
|
||
<td>تاریخچه چت</td>
|
||
<td style="direction: ltr; text-align: left;">3,000</td>
|
||
<td>۳۷.۵٪</td>
|
||
</tr>
|
||
<tr>
|
||
<td>سند RAG</td>
|
||
<td style="direction: ltr; text-align: left;">2,500</td>
|
||
<td>۳۱.۲۵٪</td>
|
||
</tr>
|
||
<tr>
|
||
<td>پرامپت کاربر</td>
|
||
<td style="direction: ltr; text-align: left;">200</td>
|
||
<td>۲.۵٪</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>جمع ورودی</strong></td>
|
||
<td style="direction: ltr; text-align: left;"><strong>6,200</strong></td>
|
||
<td><strong>۷۷.۵٪</strong></td>
|
||
</tr>
|
||
<tr>
|
||
<td>فضای باقیمانده برای پاسخ</td>
|
||
<td style="direction: ltr; text-align: left;">1,800</td>
|
||
<td>۲۲.۵٪</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠️ هشدار:</strong> اگر پاسخ مدل از ۱,۸۰۰ توکن بیشتر شود، <strong>قطع میشود</strong> (truncation). این یعنی ممکن است پاسخ مدل ناقص بماند.
|
||
</div>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ راهحل:</strong> برای جلوگیری از truncation، یا Context Size را افزایش دهید، یا ورودی را کاهش دهید (مثلاً با خلاصهسازی تاریخچه یا کاهش اسناد RAG).
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 9 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۹</div>
|
||
<div class="section-title">
|
||
<h3>KV Cache و ارتباطش با Context</h3>
|
||
<div class="subtitle">KV Cache & Memory Optimization</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>هنگام تولید توکن به توکن، مدل <strong>Key-Value Cache</strong> میسازد تا محاسبات تکراری نکند:</p>
|
||
|
||
<ul>
|
||
<li>Context بزرگتر → KV Cache بزرگتر</li>
|
||
<li>برای Context های خیلی بزرگ (مثل ۱M توکن) تکنیکهایی مثل موارد زیر استفاده میشود:</li>
|
||
</ul>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>تکنیک</th>
|
||
<th>توضیح</th>
|
||
<th>تأثیر</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>Flash Attention</strong></td>
|
||
<td>محاسبه Attention بهینهشده در حافظه</td>
|
||
<td>سرعت + کاهش حافظه</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Multi-Query Attention (MQA)</strong></td>
|
||
<td>اشتراک KV بین همه هدها</td>
|
||
<td>کاهش شدید حافظه</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Grouped-Query Attention (GQA)</strong></td>
|
||
<td>اشتراک KV بین گروههایی از هدها</td>
|
||
<td>تعادل حافظه/کیفیت</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>RoPE Scaling</strong></td>
|
||
<td>تغییر مقیاس موقعیتهای چرخشی</td>
|
||
<td>افزایش Context بدون آموزش مجدد</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته فنی:</strong> KV Cache برای Context های بزرگ میتواند چندین گیگابایت حافظه مصرف کند. به همین دلیل، بهینهسازی آن یکی از مهمترین چالشهای مهندسی LLM است.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==================== SECTION 10 ==================== -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱۰</div>
|
||
<div class="section-title">
|
||
<h3>نتیجهگیری و جمعبندی</h3>
|
||
<div class="subtitle">Conclusion</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>مفهوم</th>
|
||
<th>توضیح</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>Context Size</strong></td>
|
||
<td>حداکثر توکنهای قابل پردازش در یک لحظه</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>شامل</strong></td>
|
||
<td>ورودی (System + History + RAG + Prompt) + خروجی</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>واحد</strong></td>
|
||
<td>توکن (نه کلمه، نه کاراکتر)</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>محدودیت اصلی</strong></td>
|
||
<td>حافظه، هزینه، کیفیت، پیچیدگی O(n²)</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>راهحلها</strong></td>
|
||
<td>RAG، Summarization، Chunking، Sliding Window</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="conclusion-box">
|
||
<h3>🎯 نکته کلیدی نهایی</h3>
|
||
<p><strong>Context Size بزرگتر همیشه بهتر نیست!</strong></p>
|
||
<p>کیفیت بازیابی اطلاعات، ساختار پرامپت، و مدیریت هوشمندانه Context مهمتر از صرفاً بزرگ بودن آن است.</p>
|
||
<div class="highlight">
|
||
<strong>💎 فرمول موفقیت:</strong><br>
|
||
Context بهینه + RAG مؤثر + پرامپت ساختارمند + مدیریت حافظه = بهترین نتیجه
|
||
</div>
|
||
</div>
|
||
|
||
<h4>موضوعات پیشنهادی برای مطالعه بیشتر:</h4>
|
||
<ul>
|
||
<li>نحوه پیادهسازی RAG در عمل</li>
|
||
<li>KV Cache و بهینهسازی حافظه GPU</li>
|
||
<li>تکنیکهای Prompt Engineering برای Context های بزرگ</li>
|
||
<li>مقایسه توکنایزرهای مختلف برای زبان فارسی</li>
|
||
<li>معماریهای Long-Context (مثل Ring Attention و Sparse Attention)</li>
|
||
</ul>
|
||
|
||
<div class="info-box">
|
||
<strong>📚 منابع پیشنهادی:</strong>
|
||
<ul style="padding-right: 20px; margin-top: 10px;">
|
||
<li>مقاله اصلی "Attention Is All You Need" (Vaswani et al., 2017)</li>
|
||
<li>مقاله "Lost in the Middle" (Liu et al., 2023)</li>
|
||
<li>مستندات رسمی OpenAI، Anthropic و Google AI</li>
|
||
<li>دورههای تخصصی LLM Engineering</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="page-info">
|
||
این مستند آموزشی بوده و جهت درک بهتر مفهوم Context Size در مدلهای زبانی تهیه شده است. استفاده از آن با ذکر منبع آزاد است.
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<footer class="document-footer">
|
||
<div class="footer-brand">طراحی و تدوین: تحلیل جامع مفاهیم هوش مصنوعی</div>
|
||
<div class="footer-divider"></div>
|
||
<div>تاریخ تهیه: مهر ۱۴۰۵ | نسخه: ۱.۰ | طبقهبندی: آموزشی</div>
|
||
</footer>
|
||
|
||
</div>
|
||
|
||
</body>
|
||
</html> |