diff --git a/Genel-1/cross-attn_llm.ipynb b/Genel-1/cross-attn_llm.ipynb index cd5560d..13b2c38 100644 --- a/Genel-1/cross-attn_llm.ipynb +++ b/Genel-1/cross-attn_llm.ipynb @@ -61,7 +61,7 @@ " div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model)) # Divisor term\n", " pe[:, 0::2] = torch.sin(position * div_term) # Sine for even indices\n", " pe[:, 1::2] = torch.cos(position * div_term) # Cosine for odd indices\n", - " pe = pe.unsqueeze(0) # Batch boyutu ekle\n", + " pe = pe.unsqueeze(0) # Add batch dimension\n", " self.register_buffer('pe', pe) # Register the positional encoding as a buffer\n", "\n", " def forward(self, x):\n", @@ -74,7 +74,7 @@ " def __init__(self, features: int, dropout: float) -> None:\n", " super().__init__()\n", " self.dropout = nn.Dropout(dropout) # Dropout layer\n", - " self.norm = LayerNormalization(features) # Katman normalizasyonu\n", + " self.norm = LayerNormalization(features) # Layer normalization\n", "\n", " def forward(self, x, sublayer):\n", " # Residual connection: x + dropout(sublayer(norm(x)))\n", @@ -100,10 +100,10 @@ " # Compute attention scores: (Q * K^T) / sqrt(d_k)\n", " attention_scores = (query @ key.transpose(-2, -1)) / math.sqrt(d_k)\n", " if mask is not None:\n", - " attention_scores.masked_fill_(mask == 0, -1e9) # Maskeli yerleri -āˆž yap\n", - " attention_scores = attention_scores.softmax(dim=-1) # Softmax uygula\n", + " attention_scores.masked_fill_(mask == 0, -1e9) # Set masked positions to -āˆž\n", + " attention_scores = attention_scores.softmax(dim=-1) # Apply softmax\n", " if dropout is not None:\n", - " attention_scores = dropout(attention_scores) # Dropout uygula\n", + " attention_scores = dropout(attention_scores) # Apply dropout\n", " return (attention_scores @ value), attention_scores # Output and attention scores\n", "\n", " def forward(self, q, k, v, mask):\n", @@ -140,13 +140,13 @@ " def __init__(self, features: int, layers: nn.ModuleList) -> None:\n", " super().__init__()\n", " self.layers = layers # Encoder blocks\n", - " self.norm = LayerNormalization(features) # Son katman normalizasyonu\n", + " self.norm = LayerNormalization(features) # Final layer normalization\n", "\n", " def forward(self, x, mask):\n", " # Apply all encoder blocks\n", " for layer in self.layers:\n", " x = layer(x, mask)\n", - " return self.norm(x) # Son katman normalizasyonu\n", + " return self.norm(x) # Final layer normalization\n", "\n", "\n", "class DecoderBlock(nn.Module):\n", @@ -171,13 +171,13 @@ " def __init__(self, features: int, layers: nn.ModuleList) -> None:\n", " super().__init__()\n", " self.layers = layers # Decoder blocks\n", - " self.norm = LayerNormalization(features) # Son katman normalizasyonu\n", + " self.norm = LayerNormalization(features) # Final layer normalization\n", "\n", " def forward(self, x, encoder_output, src_mask, tgt_mask):\n", " # Apply all decoder blocks\n", " for layer in self.layers:\n", " x = layer(x, encoder_output, src_mask, tgt_mask)\n", - " return self.norm(x) # Son katman normalizasyonu\n", + " return self.norm(x) # Final layer normalization\n", "\n", "\n", "class ProjectionLayer(nn.Module):\n", @@ -197,20 +197,20 @@ " self.decoder = decoder # Decoder layer\n", " self.src_embed = src_embed # Source embedding layer\n", " self.tgt_embed = tgt_embed # Target embedding layer\n", - " self.src_pos = src_pos # Kaynak konumsal kodlama\n", - " self.tgt_pos = tgt_pos # Hedef konumsal kodlama\n", + " self.src_pos = src_pos # Source positional encoding\n", + " self.tgt_pos = tgt_pos # Target positional encoding\n", " self.projection_layer = projection_layer # Projection layer\n", "\n", " def encode(self, src, src_mask):\n", - " # Kaynak diziyi kodla\n", + " # Encode the source sequence\n", " src = self.src_embed(src) # Embedding layer\n", - " src = self.src_pos(src) # Konumsal kodlama\n", + " src = self.src_pos(src) # Positional encoding\n", " return self.encoder(src, src_mask) # Encoder layer\n", "\n", " def decode(self, encoder_output: torch.Tensor, src_mask: torch.Tensor, tgt: torch.Tensor, tgt_mask: torch.Tensor):\n", " # Decode the target sequence\n", " tgt = self.tgt_embed(tgt) # Embedding layer\n", - " tgt = self.tgt_pos(tgt) # Konumsal kodlama\n", + " tgt = self.tgt_pos(tgt) # Positional encoding\n", " return self.decoder(tgt, encoder_output, src_mask, tgt_mask) # Decoder layer\n", "\n", " def project(self, x):\n", @@ -224,8 +224,8 @@ " tgt_embed = InputEmbeddings(d_model, tgt_vocab_size) # Target embedding\n", "\n", " # Build the positional encoding layers\n", - " src_pos = PositionalEncoding(d_model, src_seq_len, dropout) # Kaynak konumsal kodlama\n", - " tgt_pos = PositionalEncoding(d_model, tgt_seq_len, dropout) # Hedef konumsal kodlama\n", + " src_pos = PositionalEncoding(d_model, src_seq_len, dropout) # Source positional encoding\n", + " tgt_pos = PositionalEncoding(d_model, tgt_seq_len, dropout) # Target positional encoding\n", "\n", " # Build the encoder blocks\n", " encoder_blocks = []\n", @@ -379,7 +379,7 @@ " print(f\"Train loader sample count: {len(train_loader)}, Validation loader sample count: {len(valid_loader)}\")\n", " return train_loader, valid_loader, tokenizer.get_vocab_size()\n", "\n", - "# Transformer Modeli\n", + "# Transformer Model\n", "def build_transformer(src_vocab_size, tgt_vocab_size, src_seq_len, tgt_seq_len, d_model, N, h, dropout, d_ff):\n", " print(\"Building the Transformer model...\")\n", " # Embedding layers\n", @@ -387,7 +387,7 @@ " tgt_embed = InputEmbeddings(d_model, tgt_vocab_size)\n", " print(\"Embedding layers created.\")\n", "\n", - " # Konumsal kodlama\n", + " # Positional encoding\n", " src_pos = PositionalEncoding(d_model, src_seq_len, dropout)\n", " tgt_pos = PositionalEncoding(d_model, tgt_seq_len, dropout)\n", " print(\"Positional encoding layers created.\")\n", @@ -422,7 +422,7 @@ " projection_layer = ProjectionLayer(d_model, tgt_vocab_size)\n", " print(\"Projection layer created.\")\n", "\n", - " # Transformer modeli\n", + " # Transformer model\n", " transformer = Transformer(\n", " encoder=encoder,\n", " decoder=decoder,\n", diff --git a/Genel-1/moe.ipynb b/Genel-1/moe.ipynb index 0de701f..c5d051b 100644 --- a/Genel-1/moe.ipynb +++ b/Genel-1/moe.ipynb @@ -309,7 +309,7 @@ "import torch\n", "from torch.nn.utils.rnn import pad_sequence\n", "\n", - "# Hiperparametreler\n", + "# Hyperparameters\n", "embed_dim = 16\n", "num_heads = 2\n", "ff_hidden_dim = 32\n", @@ -317,7 +317,7 @@ "num_epochs = 10\n", "batch_size = 2\n", "\n", - "# Model, Loss ve Optimizasyon\n", + "# Model, Loss, and Optimization\n", "model = TransformerWithMoE(vocab_size, embed_dim, num_heads, ff_hidden_dim, num_experts)\n", "criterion = nn.CrossEntropyLoss()\n", "optimizer = optim.Adam(model.parameters(), lr=0.001)\n", diff --git a/Genel-3/DAPO.ipynb b/Genel-3/DAPO.ipynb index b2418fd..4c352f8 100644 --- a/Genel-3/DAPO.ipynb +++ b/Genel-3/DAPO.ipynb @@ -137,7 +137,7 @@ " \"\"\"\n", " if length <= max_length:\n", " return base_reward\n", - " # Sigmoid fonksiyon ile ceza: -1 + 2/(1+exp(-steepness*(length-max_length)))\n", + " # Sigmoid function penalty: -1 + 2/(1+exp(-steepness*(length-max_length)))\n", " penalty = -1 + 2 / (1 + math.exp(-steepness * (length - max_length)))\n", " return base_reward + penalty\n", "\n", @@ -176,7 +176,7 @@ "from torch.optim import AdamW\n", "from datasets import load_dataset\n", "\n", - "# Model ve Tokenizer\n", + "# Model and Tokenizer\n", "model_name = \"gpt2\"\n", "model = GPT2LMHeadModel.from_pretrained(model_name)\n", "tokenizer = GPT2TokenizerFast.from_pretrained(model_name)\n", @@ -184,7 +184,7 @@ "# Define the PAD token\n", "tokenizer.pad_token = tokenizer.eos_token # Use the EOS token for padding\n", "\n", - "# Dataset Loadme ve Tokenize Etme\n", + "# Load and tokenize the dataset\n", "dataset = load_dataset(\"wikitext\", \"wikitext-2-raw-v1\", split=\"train\")\n", "dataset = dataset.select(range(2000)) # Take a small subset\n", "\n", @@ -198,7 +198,7 @@ "data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)\n", "dataloader = DataLoader(tokenized_dataset, batch_size=4, shuffle=True, collate_fn=data_collator)\n", "\n", - "# Training Parametreleri\n", + "# Training parameters\n", "epochs = 3\n", "optimizer = AdamW(model.parameters(), lr=5e-5)\n", "num_training_steps = epochs * len(dataloader)\n", diff --git a/Genel-3/SmolVLM-Stratch.ipynb b/Genel-3/SmolVLM-Stratch.ipynb index e91567a..dd94dc8 100644 --- a/Genel-3/SmolVLM-Stratch.ipynb +++ b/Genel-3/SmolVLM-Stratch.ipynb @@ -76,7 +76,7 @@ " Compresses a patch into the specified number of tokens.\n", " \n", " Args:\n", - " patch (np.array): 512x512x3 boyutunda yama.\n", + " patch (np.array): 512x512x3-sized patch.\n", " num_tokens (int): Number of tokens to generate (default 64).\n", " \n", " Returns:\n", @@ -233,11 +233,11 @@ " patches.append(patch)\n", " return torch.stack(patches)\n", "\n", - "# 2. SmolVLM benzeri model (SigLIP + Llama)\n", + "# 2. SmolVLM-like model (SigLIP + Llama)\n", "class SmolVLM(nn.Module):\n", " def __init__(self, vision_model_name=\"google/siglip-base-patch16-224\", language_model_name=\"meta-llama/Llama-2-7b-hf\"):\n", " super(SmolVLM, self).__init__()\n", - " # SigLIP vizyon modeli\n", + " # SigLIP vision model\n", " self.vision_model = SiglipVisionModel.from_pretrained(vision_model_name)\n", " self.processor = SiglipProcessor.from_pretrained(vision_model_name)\n", " \n", @@ -265,7 +265,7 @@ " vision_outputs = self.vision_model(**inputs)\n", " vision_tokens = vision_outputs.last_hidden_state # [num_patches, seq_len, hidden_size]\n", " \n", - " # Projeksiyon ile dil modeline uyarla\n", + " # Align with the language model via projection\n", " vision_tokens = self.proj(vision_tokens) # [num_patches, seq_len, llama_hidden_size]\n", " \n", " # Combine the patches and add \n", diff --git a/Genel-3/compare_attention_Vs_mla.ipynb b/Genel-3/compare_attention_Vs_mla.ipynb index 0a70413..db40fca 100644 --- a/Genel-3/compare_attention_Vs_mla.ipynb +++ b/Genel-3/compare_attention_Vs_mla.ipynb @@ -132,10 +132,10 @@ " data = data[:num_batches * batch_size] # Drop the remaining samples\n", " data = data.view(num_batches, batch_size, seq_len, d_model)\n", " \n", - " print(f\"Veri boyutu: {data.shape} (num_batches, batch_size, seq_len, d_model)\")\n", + " print(f\"Data shape: {data.shape} (num_batches, batch_size, seq_len, d_model)\")\n", " return data\n", "\n", - "# Performans testi\n", + "# Performance test\n", "def run_performance_test(data, d_model=512, num_heads=8, latent_dims=[128, 64]):\n", " mha = MultiHeadAttention(d_model, num_heads)\n", " mla_models = {dim: MultiHeadLatentAttention(d_model, num_heads, dim) for dim in latent_dims}\n", @@ -196,7 +196,7 @@ " diff = torch.mean(torch.abs(mha_out - mla_out)).item()\n", " print(f\"Average output difference between {label} and MHA: {diff:.6f}\")\n", "\n", - "# Ana fonksiyon\n", + "# Main function\n", "def main():\n", " print(\"Preparing the dataset...\")\n", " data = prepare_data(batch_size=32, seq_len=128, d_model=512)\n", @@ -342,8 +342,8 @@ " test_data = test_data[:num_test_batches * batch_size].view(num_test_batches, batch_size, seq_len)\n", " test_labels = test_labels[:num_test_batches * batch_size].view(num_test_batches, batch_size)\n", " \n", - " print(f\"Training veri boyutu: {train_data.shape}\")\n", - " print(f\"Test veri boyutu: {test_data.shape}\")\n", + " print(f\"Training data shape: {train_data.shape}\")\n", + " print(f\"Test data shape: {test_data.shape}\")\n", " return (train_data, train_labels), (test_data, test_labels)\n", "\n", "# Train the model (detailed output)\n", @@ -426,7 +426,7 @@ " print(f\" - Total Number of Samples: {total}\")\n", " return accuracy, avg_loss\n", "\n", - "# Ana fonksiyon\n", + "# Main function\n", "def main():\n", " batch_size, seq_len, d_model, num_heads = 32, 128, 512, 8\n", " latent_dim = 128\n", @@ -435,13 +435,13 @@ " (train_data, train_labels), (test_data, test_labels) = prepare_data(batch_size, seq_len)\n", " \n", " # Build the models\n", - " print(\"\\n=== MHA Modeli ===\")\n", + " print(\"\\n=== MHA Model ===\")\n", " mha_model = SentimentClassifier(d_model, num_heads, \"MHA\")\n", " mha_total_params, mha_trainable_params = count_parameters(mha_model)\n", " print(f\"Total number of parameters: {mha_total_params:,}\")\n", " print(f\"Number of trainable parameters: {mha_trainable_params:,}\")\n", " \n", - " print(\"\\n=== MLA Modeli ===\")\n", + " print(\"\\n=== MLA Model ===\")\n", " mla_model = SentimentClassifier(d_model, num_heads, \"MLA\", latent_dim)\n", " mla_total_params, mla_trainable_params = count_parameters(mla_model)\n", " print(f\"Total Number of Parameters: {mla_total_params:,}\")\n", @@ -631,9 +631,9 @@ " test_data = test_data[:num_test_batches * batch_size].view(num_test_batches, batch_size, seq_len)\n", " test_labels = test_labels[:num_test_batches * batch_size].view(num_test_batches, batch_size)\n", " \n", - " print(f\"Training veri boyutu: {train_data.shape}\")\n", - " print(f\"Validation veri boyutu: {val_data.shape}\")\n", - " print(f\"Test veri boyutu: {test_data.shape}\")\n", + " print(f\"Training data shape: {train_data.shape}\")\n", + " print(f\"Validation data shape: {val_data.shape}\")\n", + " print(f\"Test data shape: {test_data.shape}\")\n", " return (train_data, train_labels), (val_data, val_labels), (test_data, test_labels)\n", "\n", "# Train and validate the model (detailed per batch)\n", @@ -748,9 +748,9 @@ " print(f\" - Total Number of Samples: {total}\")\n", " return accuracy, avg_loss\n", "\n", - "# Ana fonksiyon\n", + "# Main function\n", "def main():\n", - " # Hiperparametreler\n", + " # Hyperparameters\n", " batch_size, seq_len, d_model, num_heads = 32, 128, 512, 8\n", " epochs = 1\n", " lr = 0.0001 # Reduced for slower learning\n", @@ -760,7 +760,7 @@ " (train_data, train_labels), (val_data, val_labels), (test_data, test_labels) = prepare_data(batch_size, seq_len)\n", " \n", " # Print hyperparameters\n", - " print(\"\\n=== Hiperparametreler ===\")\n", + " print(\"\\n=== Hyperparameters ===\")\n", " print(f\"Batch Size: {batch_size}\")\n", " print(f\"Sequence Length: {seq_len}\")\n", " print(f\"Model Dimension: {d_model}\")\n", @@ -768,8 +768,8 @@ " print(f\"Epochs: {epochs}\")\n", " print(f\"Learning Rate: {lr}\")\n", " \n", - " # MHA Modeli\n", - " print(\"\\n=== MHA Modeli ===\")\n", + " # MHA Model\n", + " print(\"\\n=== MHA Model ===\")\n", " mha_model = SentimentClassifier(d_model, num_heads, \"MHA\")\n", " mha_total_params, mha_trainable_params = count_parameters(mha_model)\n", " print(f\"Total number of parameters: {mha_total_params:,}\")\n", @@ -782,7 +782,7 @@ " # MLA models (different latent_dim values)\n", " mla_results = {}\n", " for latent_dim in latent_dims:\n", - " print(f\"\\n=== MLA Modeli (latent_dim={latent_dim}) ===\")\n", + " print(f\"\\n=== MLA Model (latent_dim={latent_dim}) ===\")\n", " mla_model = SentimentClassifier(d_model, num_heads, \"MLA\", latent_dim)\n", " mla_total_params, mla_trainable_params = count_parameters(mla_model)\n", " print(f\"Total Number of Parameters: {mla_total_params:,}\")\n", @@ -1100,9 +1100,9 @@ " test_data = test_data[:num_test_batches * batch_size].view(num_test_batches, batch_size, seq_len)\n", " test_labels = test_labels[:num_test_batches * batch_size].view(num_test_batches, batch_size)\n", " \n", - " print(f\"Training veri boyutu: {train_data.shape}\")\n", - " print(f\"Validation veri boyutu: {val_data.shape}\")\n", - " print(f\"Test veri boyutu: {test_data.shape}\")\n", + " print(f\"Training data shape: {train_data.shape}\")\n", + " print(f\"Validation data shape: {val_data.shape}\")\n", + " print(f\"Test data shape: {test_data.shape}\")\n", " return (train_data, train_labels), (val_data, val_labels), (test_data, test_labels)\n", "\n", "# Train the model\n", @@ -1212,7 +1212,7 @@ " print(f\" - Total Number of Samples: {total}\")\n", " return accuracy, avg_loss\n", "\n", - "# Ana fonksiyon\n", + "# Main function\n", "def main():\n", " batch_size, seq_len, d_model, num_heads = 32, 128, 512, 8\n", " epochs = 1\n", @@ -1222,7 +1222,7 @@ " print(\"Preparing the dataset...\")\n", " (train_data, train_labels), (val_data, val_labels), (test_data, test_labels) = prepare_data(batch_size, seq_len)\n", " \n", - " print(\"\\n=== Hiperparametreler ===\")\n", + " print(\"\\n=== Hyperparameters ===\")\n", " print(f\"Batch Size: {batch_size}\")\n", " print(f\"Sequence Length: {seq_len}\")\n", " print(f\"Model Dimension: {d_model}\")\n", @@ -1240,7 +1240,7 @@ " \n", " results = {}\n", " for name, model in models.items():\n", - " print(f\"\\n=== {name} Modeli ===\")\n", + " print(f\"\\n=== {name} Model ===\")\n", " total_params, trainable_params = count_parameters(model)\n", " print(f\"Total Number of Parameters: {total_params:,}\")\n", " print(f\"Number of trainable parameters: {trainable_params:,}\")\n", @@ -1383,7 +1383,7 @@ " output = torch.stack(outputs, dim=1)\n", " return self.dropout(output) + x # Residual connection\n", "\n", - "# LLM Modeli\n", + "# LLM Model\n", "class CustomLLM(nn.Module):\n", " def __init__(self, vocab_size, d_model, num_heads, latent_dim, num_layers=2, dropout=0.1):\n", " super(CustomLLM, self).__init__()\n", @@ -1611,7 +1611,7 @@ " \n", " return accuracy, avg_loss\n", "\n", - "# Ana fonksiyon\n", + "# Main function\n", "def main():\n", " batch_size, seq_len, d_model, num_heads = 32, 128, 512, 8\n", " epochs = 2 # Increased to allow more epochs\n", @@ -1622,7 +1622,7 @@ " print(\"Preparing the dataset...\")\n", " (train_data, train_labels), (val_data, val_labels), (test_data, test_labels, test_texts), vocab_size, tokenizer = prepare_data(batch_size, seq_len)\n", " \n", - " print(\"\\n=== Hiperparametreler ===\")\n", + " print(\"\\n=== Hyperparameters ===\")\n", " print(f\"Batch Size: {batch_size}\")\n", " print(f\"Sequence Length: {seq_len}\")\n", " print(f\"Model Dimension: {d_model}\")\n", @@ -1636,7 +1636,7 @@ " # Build the model\n", " model = CustomLLM(vocab_size, d_model, num_heads, latent_dim, num_layers)\n", " total_params, trainable_params = count_parameters(model)\n", - " print(f\"\\n=== CustomLLM Modeli ===\")\n", + " print(f\"\\n=== CustomLLM Model ===\")\n", " print(f\"Total Number of Parameters: {total_params:,}\")\n", " print(f\"Number of trainable parameters: {trainable_params:,}\")\n", " \n", diff --git a/Genel-4/DyT_vs_RMSNorm.ipynb b/Genel-4/DyT_vs_RMSNorm.ipynb index 3b1432d..e0b4737 100644 --- a/Genel-4/DyT_vs_RMSNorm.ipynb +++ b/Genel-4/DyT_vs_RMSNorm.ipynb @@ -169,7 +169,7 @@ " training_time = end_time - start_time\n", " return training_time, accuracy\n", "\n", - "# Veri Seti ve DataLoader (CIFAR-10)\n", + "# Dataset and DataLoader (CIFAR-10)\n", "transform = transforms.Compose([\n", " transforms.Resize((224, 224)),\n", " transforms.ToTensor(),\n", @@ -183,12 +183,12 @@ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "num_epochs = 1\n", "\n", - "# RMSNorm Modeli\n", + "# RMSNorm Model\n", "model_rms = SimpleViT(norm_layer='RMSNorm')\n", "optimizer_rms = optim.Adam(model_rms.parameters(), lr=0.001)\n", "criterion = nn.CrossEntropyLoss()\n", "\n", - "# DyT Modeli\n", + "# DyT Model\n", "model_dyt = SimpleViT(norm_layer='DyT', init_alpha=0.5)\n", "optimizer_dyt = optim.Adam(model_dyt.parameters(), lr=0.001)\n", "\n", @@ -350,7 +350,7 @@ " training_time = end_time - start_time\n", " return training_time, accuracy\n", "\n", - "# Veri Seti ve DataLoader (CIFAR-10)\n", + "# Dataset and DataLoader (CIFAR-10)\n", "transform = transforms.Compose([\n", " transforms.Resize((224, 224)),\n", " transforms.ToTensor(),\n", @@ -364,12 +364,12 @@ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "num_epochs = 2\n", "\n", - "# RMSNorm Modeli\n", + "# RMSNorm Model\n", "model_rms = SimpleViT(norm_layer='RMSNorm')\n", "optimizer_rms = optim.Adam(model_rms.parameters(), lr=0.001)\n", "criterion = nn.CrossEntropyLoss()\n", "\n", - "# DyT Modeli\n", + "# DyT Model\n", "model_dyt = SimpleViT(norm_layer='DyT', init_alpha=0.5)\n", "optimizer_dyt = optim.Adam(model_dyt.parameters(), lr=0.001)\n", "\n", @@ -398,4 +398,4 @@ "outputs": [] } ] -} +} \ No newline at end of file diff --git "a/Genel-4/Projeksiyon_Katmanlar\304\261.ipynb" "b/Genel-4/Projeksiyon_Katmanlar\304\261.ipynb" index 90d75e0..b15a106 100644 --- "a/Genel-4/Projeksiyon_Katmanlar\304\261.ipynb" +++ "b/Genel-4/Projeksiyon_Katmanlar\304\261.ipynb" @@ -32,11 +32,11 @@ "import torch\n", "import torch.nn as nn\n", "\n", - "# Model parametreleri\n", - "d_model = 64 # Modelin gizli boyutu\n", - "d_ff = 256 # Besleme ileri (feed-forward) boyutu\n", + "# Model parameters\n", + "d_model = 64 # Model hidden dimension\n", + "d_ff = 256 # Feed-forward dimension\n", "seq_len = 10 # Length of the input sequence\n", - "batch_size = 8 # Batch boyutu" + "batch_size = 8 # Batch size" ], "metadata": { "id": "wpPyAbV0zfeE" @@ -48,7 +48,7 @@ "cell_type": "code", "source": [ "# Input tensor (example data)\n", - "input_tensor = torch.rand(batch_size, seq_len, d_model) # Rastgele veri" + "input_tensor = torch.rand(batch_size, seq_len, d_model) # Random data" ], "metadata": { "id": "kDYRBKL6zgmz" @@ -85,7 +85,7 @@ " attention_weights = torch.softmax(attention_scores, dim=-1)\n", " attention_output = torch.matmul(attention_weights, v)\n", "\n", - " # Output Projeksiyon\n", + " # Output Projection\n", " output = self.o_proj(attention_output)\n", "\n", " # Feed-forward layer\n", @@ -116,8 +116,8 @@ "model = ProjectionLayers(d_model=d_model, d_ff=d_ff)\n", "output_tensor = model(input_tensor)\n", "\n", - "print(\"Input Boyutu: \", input_tensor.shape)\n", - "print(\"Output Boyutu: \", output_tensor.shape)\n" + "print(\"Input Shape: \", input_tensor.shape)\n", + "print(\"Output Shape: \", output_tensor.shape)\n" ] } ] diff --git a/Genel-4/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb b/Genel-4/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb index 45d3d85..0487624 100644 --- a/Genel-4/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb +++ b/Genel-4/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb @@ -452,7 +452,7 @@ " generate_and_print_sample(model, tokenizer, device, prompt)\n", "\n", "#####################################\n", - "# Ana Fonksiyon\n", + "# Main Function\n", "#####################################\n", "\n", "def main():\n", @@ -1008,7 +1008,7 @@ " context = context.transpose(1,2).contiguous().view(batch, seq_len, emb_dim)\n", " return self.out_proj(context)\n", "\n", - "# 3. FlashAttention benzeri Attention (placeholder)\n", + "# 3. FlashAttention-like attention (placeholder)\n", "def flash_attention(Q, K, V):\n", " scores = torch.matmul(Q, K.transpose(-2, -1)) / math.sqrt(Q.size(-1))\n", " attn = torch.softmax(scores, dim=-1)\n", @@ -1035,7 +1035,7 @@ " context = context.transpose(1,2).contiguous().view(batch, seq_len, emb_dim)\n", " return self.out_proj(context)\n", "\n", - "# 4. Multi-Query Attention: Keys & Values tek projeksiyon\n", + "# 4. Multi-Query Attention: Keys & Values single projection\n", "class MultiQueryAttention(nn.Module):\n", " def __init__(self, emb_dim, n_heads, dropout):\n", " super().__init__()\n", @@ -1092,7 +1092,7 @@ "#############################################\n", "# --- FFN variants ---\n", "#############################################\n", - "# 1. Standart FFN\n", + "# 1. Standard FFN\n", "class StandardFFN(nn.Module):\n", " def __init__(self, emb_dim, expansion=4, dropout=0.1):\n", " super().__init__()\n", @@ -1183,11 +1183,11 @@ "def model_summary(model):\n", " total_params = sum(p.numel() for p in model.parameters())\n", " trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)\n", - " print(f\"Toplam Parametre: {total_params:,}\")\n", + " print(f\"Total Parameters: {total_params:,}\")\n", " print(f\"Trainable parameters: {trainable:,}\")\n", "\n", "#############################################\n", - "# --- Ek: Greedy Decoding Fonksiyonu ---\n", + "# --- Appendix: Greedy Decoding Function ---\n", "#############################################\n", "def greedy_decode(model, start_token, max_length, device):\n", " model.eval()\n", @@ -1210,7 +1210,7 @@ " model.to(device)\n", " optimizer = optim.AdamW(model.parameters(), lr=1e-4)\n", " loss_fn = nn.CrossEntropyLoss()\n", - " # Dummy dataset: rastgele token dizileri\n", + " # Dummy dataset: random token sequences\n", " for epoch in range(epochs):\n", " model.train()\n", " dummy_input = torch.randint(0, config.vocab_size, (8, config.max_length), device=device)\n", @@ -1336,7 +1336,7 @@ "from reportlab.pdfgen import canvas\n", "\n", "#############################################\n", - "# Turkish-Alpaca Veri Seti ve Tokenizer\n", + "# Turkish-Alpaca Dataset and Tokenizer\n", "#############################################\n", "class TurkishAlpacaDataset:\n", " def __init__(self, config):\n", @@ -1347,7 +1347,7 @@ "\n", " # Create tokenizer\n", " self.vocab = defaultdict(lambda: len(self.vocab))\n", - " self.vocab[''] = 0 # Padding token'i ekle\n", + " self.vocab[''] = 0 # Add the padding token\n", "\n", " # Tokenize all the data\n", " self.tokenize_data()\n", @@ -1360,7 +1360,7 @@ " self.config = config\n", "\n", " def tokenize_data(self):\n", - " # Instruction ve Output'u tokenize et\n", + " # Tokenize the instruction and output\n", " self.tokenized_instructions = []\n", " self.tokenized_outputs = []\n", "\n", @@ -1434,7 +1434,7 @@ "\n", " print(f\"\\n{'='*40}\")\n", " print(f\"šŸ {model.name} is starting training...\")\n", - " print(f\"šŸ”¢ Toplam Token Count: {len(dataset.vocab)}\")\n", + " print(f\"šŸ”¢ Total Token Count: {len(dataset.vocab)}\")\n", " print(f\"āš™ļø Hardware in use: {'GPU' if device.type=='cuda' else 'CPU'}\")\n", " print(f\"{'='*40}\\n\")\n", "\n", @@ -1474,7 +1474,7 @@ " targets = targets.view(-1) # Reshape targets\n", " loss = loss_fn(logits, targets)\n", "\n", - " # Metrik Hesaplama\n", + " # Metric calculation\n", " preds = torch.argmax(logits, dim=-1)\n", " mask = targets != 0\n", " correct = (preds[mask] == targets[mask]).sum().item()\n", @@ -1488,7 +1488,7 @@ " generated = greedy_decode(model, input_token, max_length=config.max_length, device=device)\n", " generated_sentence = ' '.join([dataset.inverse_vocab.get(t, \"?\") for t in generated])\n", "\n", - " print(f\"\\n⭐ Final Performans ⭐\")\n", + " print(f\"\\n⭐ Final Performance ⭐\")\n", " print(f\"|{'Metric':<15}|{'Value':<15}|\")\n", " print(f\"|{'-'*15}|{'-'*15}|\")\n", " print(f\"|{'Loss':<15}|{loss.item():.3f}|\")\n", @@ -1512,7 +1512,7 @@ "#############################################\n", "def save_results_to_pdf(metrics, model_name):\n", " # Create the PDF file\n", - " pdf_path = f\"{model_name}_degerlendirme.pdf\"\n", + " pdf_path = f\"{model_name}_evaluation.pdf\"\n", " c = canvas.Canvas(pdf_path, pagesize=A4)\n", " width, height = A4\n", "\n", @@ -1520,10 +1520,10 @@ " c.setFont(\"Helvetica-Bold\", 16)\n", " c.drawString(50, height - 50, f\"Model Evaluation Report: {model_name}\")\n", "\n", - " # Metrikler\n", + " # Metrics\n", " c.setFont(\"Helvetica\", 12)\n", " y = height - 80\n", - " c.drawString(50, y, \"šŸ“Š Performans Metrikleri\")\n", + " c.drawString(50, y, \"šŸ“Š Performance Metrics\")\n", " y -= 20\n", " c.drawString(50, y, f\"Total Number of Parameters: {metrics['parameters']:,}\")\n", " y -= 20\n", @@ -1543,7 +1543,7 @@ " c.drawString(50, y, f\"Example {i+1}: {output}\")\n", " y -= 20\n", "\n", - " # PDF'i kaydet\n", + " # Save the PDF\n", " c.save()\n", " print(f\"šŸ“„ Saved the report for {model_name} as a PDF: {pdf_path}\")\n", "\n", @@ -1604,9 +1604,9 @@ " config = Config()\n", " device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "\n", - " # Test Edilecek Modeller\n", + " # Models to Evaluate\n", " experiments = [\n", - " {'attn': 'standard', 'ffn': 'standard', 'name': 'Standart Model'},\n", + " {'attn': 'standard', 'ffn': 'standard', 'name': 'Standard Model'},\n", " {'attn': 'rope', 'ffn': 'standard', 'name': 'RoPE Dikkat'},\n", " {'attn': 'alibi', 'ffn': 'moe', 'name': 'ALiBi + MoE'},\n", " {'attn': 'multiquery', 'ffn': 'moe', 'name': 'Multi-Query MoE'}\n", @@ -1631,7 +1631,7 @@ "\n", " # Compare all results\n", " print(\"\\nšŸ“Š Comparison of All Models:\")\n", - " print(f\"|{'Model':<20}|{'Parametre':<10}|{'Accuracy':<10}|{'Perplexity':<12}|\")\n", + " print(f\"|{'Model':<20}|{'Parameters':<10}|{'Accuracy':<10}|{'Perplexity':<12}|\")\n", " print(f\"|{'-'*20}|{'-'*10}|{'-'*10}|{'-'*12}|\")\n", " for name, metrics in results:\n", " print(f\"|{name:<20}|{metrics['parameters']:<10,}|{metrics['accuracy']:<10.1%}|{metrics['perplexity']:<12.2f}|\")" diff --git a/Genel-4/llada.ipynb b/Genel-4/llada.ipynb index 0f003e1..cc608b3 100644 --- a/Genel-4/llada.ipynb +++ b/Genel-4/llada.ipynb @@ -85,7 +85,7 @@ "id": "0708a4b5", "metadata": {}, "source": [ - "## 3. PyTorch Dataset ve DataLoader\n", + "## 3. PyTorch Dataset and DataLoader\n", "Convert instruction and response pairs into tensors." ] }, @@ -258,7 +258,7 @@ "id": "12708af5", "metadata": {}, "source": [ - "## 9. Test: Herhangi Bir Soru ile Modeli Deneyin\n", + "## 9. Test: Try the Model with Any Question\n", "In the cell below, set the `test_instruction` variable to any question to view the model's answer." ] }, @@ -282,7 +282,7 @@ "id": "caed78d5", "metadata": {}, "source": [ - "## 10. Modelin Test Edilmesi\n", + "## 10. Testing the Model\n", "The cell below measures how accurately the model can produce responses on the test data. As a simple accuracy metric, it computes how closely the generated response matches the original response token by token." ] }, diff --git a/Genel-5/DyT_vs_RMSNorm.ipynb b/Genel-5/DyT_vs_RMSNorm.ipynb index 3b1432d..e0b4737 100644 --- a/Genel-5/DyT_vs_RMSNorm.ipynb +++ b/Genel-5/DyT_vs_RMSNorm.ipynb @@ -169,7 +169,7 @@ " training_time = end_time - start_time\n", " return training_time, accuracy\n", "\n", - "# Veri Seti ve DataLoader (CIFAR-10)\n", + "# Dataset and DataLoader (CIFAR-10)\n", "transform = transforms.Compose([\n", " transforms.Resize((224, 224)),\n", " transforms.ToTensor(),\n", @@ -183,12 +183,12 @@ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "num_epochs = 1\n", "\n", - "# RMSNorm Modeli\n", + "# RMSNorm Model\n", "model_rms = SimpleViT(norm_layer='RMSNorm')\n", "optimizer_rms = optim.Adam(model_rms.parameters(), lr=0.001)\n", "criterion = nn.CrossEntropyLoss()\n", "\n", - "# DyT Modeli\n", + "# DyT Model\n", "model_dyt = SimpleViT(norm_layer='DyT', init_alpha=0.5)\n", "optimizer_dyt = optim.Adam(model_dyt.parameters(), lr=0.001)\n", "\n", @@ -350,7 +350,7 @@ " training_time = end_time - start_time\n", " return training_time, accuracy\n", "\n", - "# Veri Seti ve DataLoader (CIFAR-10)\n", + "# Dataset and DataLoader (CIFAR-10)\n", "transform = transforms.Compose([\n", " transforms.Resize((224, 224)),\n", " transforms.ToTensor(),\n", @@ -364,12 +364,12 @@ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "num_epochs = 2\n", "\n", - "# RMSNorm Modeli\n", + "# RMSNorm Model\n", "model_rms = SimpleViT(norm_layer='RMSNorm')\n", "optimizer_rms = optim.Adam(model_rms.parameters(), lr=0.001)\n", "criterion = nn.CrossEntropyLoss()\n", "\n", - "# DyT Modeli\n", + "# DyT Model\n", "model_dyt = SimpleViT(norm_layer='DyT', init_alpha=0.5)\n", "optimizer_dyt = optim.Adam(model_dyt.parameters(), lr=0.001)\n", "\n", @@ -398,4 +398,4 @@ "outputs": [] } ] -} +} \ No newline at end of file diff --git "a/Genel-5/Projeksiyon_Katmanlar\304\261.ipynb" "b/Genel-5/Projeksiyon_Katmanlar\304\261.ipynb" index 90d75e0..b15a106 100644 --- "a/Genel-5/Projeksiyon_Katmanlar\304\261.ipynb" +++ "b/Genel-5/Projeksiyon_Katmanlar\304\261.ipynb" @@ -32,11 +32,11 @@ "import torch\n", "import torch.nn as nn\n", "\n", - "# Model parametreleri\n", - "d_model = 64 # Modelin gizli boyutu\n", - "d_ff = 256 # Besleme ileri (feed-forward) boyutu\n", + "# Model parameters\n", + "d_model = 64 # Model hidden dimension\n", + "d_ff = 256 # Feed-forward dimension\n", "seq_len = 10 # Length of the input sequence\n", - "batch_size = 8 # Batch boyutu" + "batch_size = 8 # Batch size" ], "metadata": { "id": "wpPyAbV0zfeE" @@ -48,7 +48,7 @@ "cell_type": "code", "source": [ "# Input tensor (example data)\n", - "input_tensor = torch.rand(batch_size, seq_len, d_model) # Rastgele veri" + "input_tensor = torch.rand(batch_size, seq_len, d_model) # Random data" ], "metadata": { "id": "kDYRBKL6zgmz" @@ -85,7 +85,7 @@ " attention_weights = torch.softmax(attention_scores, dim=-1)\n", " attention_output = torch.matmul(attention_weights, v)\n", "\n", - " # Output Projeksiyon\n", + " # Output Projection\n", " output = self.o_proj(attention_output)\n", "\n", " # Feed-forward layer\n", @@ -116,8 +116,8 @@ "model = ProjectionLayers(d_model=d_model, d_ff=d_ff)\n", "output_tensor = model(input_tensor)\n", "\n", - "print(\"Input Boyutu: \", input_tensor.shape)\n", - "print(\"Output Boyutu: \", output_tensor.shape)\n" + "print(\"Input Shape: \", input_tensor.shape)\n", + "print(\"Output Shape: \", output_tensor.shape)\n" ] } ] diff --git a/Genel-5/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb b/Genel-5/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb index 45d3d85..0487624 100644 --- a/Genel-5/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb +++ b/Genel-5/Transformer_Attention_FFN_Varyantlari_Performans_T.ipynb @@ -452,7 +452,7 @@ " generate_and_print_sample(model, tokenizer, device, prompt)\n", "\n", "#####################################\n", - "# Ana Fonksiyon\n", + "# Main Function\n", "#####################################\n", "\n", "def main():\n", @@ -1008,7 +1008,7 @@ " context = context.transpose(1,2).contiguous().view(batch, seq_len, emb_dim)\n", " return self.out_proj(context)\n", "\n", - "# 3. FlashAttention benzeri Attention (placeholder)\n", + "# 3. FlashAttention-like attention (placeholder)\n", "def flash_attention(Q, K, V):\n", " scores = torch.matmul(Q, K.transpose(-2, -1)) / math.sqrt(Q.size(-1))\n", " attn = torch.softmax(scores, dim=-1)\n", @@ -1035,7 +1035,7 @@ " context = context.transpose(1,2).contiguous().view(batch, seq_len, emb_dim)\n", " return self.out_proj(context)\n", "\n", - "# 4. Multi-Query Attention: Keys & Values tek projeksiyon\n", + "# 4. Multi-Query Attention: Keys & Values single projection\n", "class MultiQueryAttention(nn.Module):\n", " def __init__(self, emb_dim, n_heads, dropout):\n", " super().__init__()\n", @@ -1092,7 +1092,7 @@ "#############################################\n", "# --- FFN variants ---\n", "#############################################\n", - "# 1. Standart FFN\n", + "# 1. Standard FFN\n", "class StandardFFN(nn.Module):\n", " def __init__(self, emb_dim, expansion=4, dropout=0.1):\n", " super().__init__()\n", @@ -1183,11 +1183,11 @@ "def model_summary(model):\n", " total_params = sum(p.numel() for p in model.parameters())\n", " trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)\n", - " print(f\"Toplam Parametre: {total_params:,}\")\n", + " print(f\"Total Parameters: {total_params:,}\")\n", " print(f\"Trainable parameters: {trainable:,}\")\n", "\n", "#############################################\n", - "# --- Ek: Greedy Decoding Fonksiyonu ---\n", + "# --- Appendix: Greedy Decoding Function ---\n", "#############################################\n", "def greedy_decode(model, start_token, max_length, device):\n", " model.eval()\n", @@ -1210,7 +1210,7 @@ " model.to(device)\n", " optimizer = optim.AdamW(model.parameters(), lr=1e-4)\n", " loss_fn = nn.CrossEntropyLoss()\n", - " # Dummy dataset: rastgele token dizileri\n", + " # Dummy dataset: random token sequences\n", " for epoch in range(epochs):\n", " model.train()\n", " dummy_input = torch.randint(0, config.vocab_size, (8, config.max_length), device=device)\n", @@ -1336,7 +1336,7 @@ "from reportlab.pdfgen import canvas\n", "\n", "#############################################\n", - "# Turkish-Alpaca Veri Seti ve Tokenizer\n", + "# Turkish-Alpaca Dataset and Tokenizer\n", "#############################################\n", "class TurkishAlpacaDataset:\n", " def __init__(self, config):\n", @@ -1347,7 +1347,7 @@ "\n", " # Create tokenizer\n", " self.vocab = defaultdict(lambda: len(self.vocab))\n", - " self.vocab[''] = 0 # Padding token'i ekle\n", + " self.vocab[''] = 0 # Add the padding token\n", "\n", " # Tokenize all the data\n", " self.tokenize_data()\n", @@ -1360,7 +1360,7 @@ " self.config = config\n", "\n", " def tokenize_data(self):\n", - " # Instruction ve Output'u tokenize et\n", + " # Tokenize the instruction and output\n", " self.tokenized_instructions = []\n", " self.tokenized_outputs = []\n", "\n", @@ -1434,7 +1434,7 @@ "\n", " print(f\"\\n{'='*40}\")\n", " print(f\"šŸ {model.name} is starting training...\")\n", - " print(f\"šŸ”¢ Toplam Token Count: {len(dataset.vocab)}\")\n", + " print(f\"šŸ”¢ Total Token Count: {len(dataset.vocab)}\")\n", " print(f\"āš™ļø Hardware in use: {'GPU' if device.type=='cuda' else 'CPU'}\")\n", " print(f\"{'='*40}\\n\")\n", "\n", @@ -1474,7 +1474,7 @@ " targets = targets.view(-1) # Reshape targets\n", " loss = loss_fn(logits, targets)\n", "\n", - " # Metrik Hesaplama\n", + " # Metric calculation\n", " preds = torch.argmax(logits, dim=-1)\n", " mask = targets != 0\n", " correct = (preds[mask] == targets[mask]).sum().item()\n", @@ -1488,7 +1488,7 @@ " generated = greedy_decode(model, input_token, max_length=config.max_length, device=device)\n", " generated_sentence = ' '.join([dataset.inverse_vocab.get(t, \"?\") for t in generated])\n", "\n", - " print(f\"\\n⭐ Final Performans ⭐\")\n", + " print(f\"\\n⭐ Final Performance ⭐\")\n", " print(f\"|{'Metric':<15}|{'Value':<15}|\")\n", " print(f\"|{'-'*15}|{'-'*15}|\")\n", " print(f\"|{'Loss':<15}|{loss.item():.3f}|\")\n", @@ -1512,7 +1512,7 @@ "#############################################\n", "def save_results_to_pdf(metrics, model_name):\n", " # Create the PDF file\n", - " pdf_path = f\"{model_name}_degerlendirme.pdf\"\n", + " pdf_path = f\"{model_name}_evaluation.pdf\"\n", " c = canvas.Canvas(pdf_path, pagesize=A4)\n", " width, height = A4\n", "\n", @@ -1520,10 +1520,10 @@ " c.setFont(\"Helvetica-Bold\", 16)\n", " c.drawString(50, height - 50, f\"Model Evaluation Report: {model_name}\")\n", "\n", - " # Metrikler\n", + " # Metrics\n", " c.setFont(\"Helvetica\", 12)\n", " y = height - 80\n", - " c.drawString(50, y, \"šŸ“Š Performans Metrikleri\")\n", + " c.drawString(50, y, \"šŸ“Š Performance Metrics\")\n", " y -= 20\n", " c.drawString(50, y, f\"Total Number of Parameters: {metrics['parameters']:,}\")\n", " y -= 20\n", @@ -1543,7 +1543,7 @@ " c.drawString(50, y, f\"Example {i+1}: {output}\")\n", " y -= 20\n", "\n", - " # PDF'i kaydet\n", + " # Save the PDF\n", " c.save()\n", " print(f\"šŸ“„ Saved the report for {model_name} as a PDF: {pdf_path}\")\n", "\n", @@ -1604,9 +1604,9 @@ " config = Config()\n", " device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "\n", - " # Test Edilecek Modeller\n", + " # Models to Evaluate\n", " experiments = [\n", - " {'attn': 'standard', 'ffn': 'standard', 'name': 'Standart Model'},\n", + " {'attn': 'standard', 'ffn': 'standard', 'name': 'Standard Model'},\n", " {'attn': 'rope', 'ffn': 'standard', 'name': 'RoPE Dikkat'},\n", " {'attn': 'alibi', 'ffn': 'moe', 'name': 'ALiBi + MoE'},\n", " {'attn': 'multiquery', 'ffn': 'moe', 'name': 'Multi-Query MoE'}\n", @@ -1631,7 +1631,7 @@ "\n", " # Compare all results\n", " print(\"\\nšŸ“Š Comparison of All Models:\")\n", - " print(f\"|{'Model':<20}|{'Parametre':<10}|{'Accuracy':<10}|{'Perplexity':<12}|\")\n", + " print(f\"|{'Model':<20}|{'Parameters':<10}|{'Accuracy':<10}|{'Perplexity':<12}|\")\n", " print(f\"|{'-'*20}|{'-'*10}|{'-'*10}|{'-'*12}|\")\n", " for name, metrics in results:\n", " print(f\"|{name:<20}|{metrics['parameters']:<10,}|{metrics['accuracy']:<10.1%}|{metrics['perplexity']:<12.2f}|\")" diff --git a/Genel-5/llada.ipynb b/Genel-5/llada.ipynb index 0f003e1..cc608b3 100644 --- a/Genel-5/llada.ipynb +++ b/Genel-5/llada.ipynb @@ -85,7 +85,7 @@ "id": "0708a4b5", "metadata": {}, "source": [ - "## 3. PyTorch Dataset ve DataLoader\n", + "## 3. PyTorch Dataset and DataLoader\n", "Convert instruction and response pairs into tensors." ] }, @@ -258,7 +258,7 @@ "id": "12708af5", "metadata": {}, "source": [ - "## 9. Test: Herhangi Bir Soru ile Modeli Deneyin\n", + "## 9. Test: Try the Model with Any Question\n", "In the cell below, set the `test_instruction` variable to any question to view the model's answer." ] }, @@ -282,7 +282,7 @@ "id": "caed78d5", "metadata": {}, "source": [ - "## 10. Modelin Test Edilmesi\n", + "## 10. Testing the Model\n", "The cell below measures how accurately the model can produce responses on the test data. As a simple accuracy metric, it computes how closely the generated response matches the original response token by token." ] }, diff --git a/Genel-5/modern_llm_components.py b/Genel-5/modern_llm_components.py index f11c641..0f867f4 100644 --- a/Genel-5/modern_llm_components.py +++ b/Genel-5/modern_llm_components.py @@ -120,7 +120,7 @@ def forward(self, x: torch.Tensor, mask: Optional[torch.Tensor] = None): k = self.wk(x).view(bsz, seq_len, self.n_kv_heads, self.head_dim) v = self.wv(x).view(bsz, seq_len, self.n_kv_heads, self.head_dim) - # RoPE uygula + # Apply RoPE cos, sin = self.rope(x, seq_len) q, k = apply_rotary_pos_emb(q, k, cos, sin) diff --git a/Image - Patch/pixel-unshuffle.ipynb b/Image - Patch/pixel-unshuffle.ipynb index 5e16e64..c95f3df 100644 --- a/Image - Patch/pixel-unshuffle.ipynb +++ b/Image - Patch/pixel-unshuffle.ipynb @@ -36,7 +36,7 @@ " new_W = W // scale_factor\n", " new_C = C * (scale_factor ** 2)\n", " \n", - " # Pixel unshuffle uygula\n", + " # Apply pixel unshuffle\n", " unshuffled = F.pixel_unshuffle(image, scale_factor)\n", " return unshuffled, (B, new_C, new_H, new_W)" ] @@ -84,14 +84,14 @@ " )\n", " \n", " def forward(self, x):\n", - " # 1. Pixel unshuffle uygula\n", + " # 1. Apply pixel unshuffle\n", " x_unshuffled, shape_info = apply_pixel_unshuffle(x, self.unshuffle_factor)\n", " \n", " # 2. Reshape into tokens (Batch, Tokens, Channels)\n", " B, C, H, W = x_unshuffled.shape\n", " tokens = x_unshuffled.reshape(B, C, H * W).permute(0, 2, 1)\n", " \n", - " # 3. MLP ile token mapping uygula\n", + " # 3. Apply MLP-based token mapping\n", " mapped_tokens = self.mlp(tokens)\n", " \n", " return mapped_tokens, (H, W), shape_info" @@ -138,7 +138,7 @@ " # Token bilgisi\n", " axes[2].text(0.1, 0.5, \n", " f'Token Count: {token_info[\"num_tokens\"]}\\n'\n", - " f'Token Boyutu: {token_info[\"token_dim\"]}\\n'\n", + " f'Token Dimension: {token_info[\"token_dim\"]}\\n'\n", " f'Unshuffle Factor: {token_info[\"unshuffle_factor\"]}\\n'\n", " f'Original Pixel Count: {token_info[\"original_pixels\"]}\\n'\n", " f'Reduction Ratio: {token_info[\"reduction_ratio\"]:.1f}x',\n", @@ -335,7 +335,7 @@ " # Adaptive unshuffle factor\n", " unshuffle_factor = self.analyze_complexity(x)\n", " \n", - " # Pixel unshuffle uygula\n", + " # Apply pixel unshuffle\n", " x_unshuffled, shape_info = apply_pixel_unshuffle(x, unshuffle_factor)\n", " \n", " # Convert to tokens\n", @@ -414,7 +414,7 @@ " \n", " # Create tokens for each scale\n", " for scale in self.scales:\n", - " # Pixel unshuffle uygula\n", + " # Apply pixel unshuffle\n", " x_unshuffled, shape_info = apply_pixel_unshuffle(x, scale)\n", " _, C, H, W = x_unshuffled.shape\n", " \n", @@ -443,7 +443,7 @@ " stacked_tokens = torch.stack(aligned_tokens, dim=2) # (B, num_tokens, num_scales, token_dim)\n", " B, num_tokens, num_scales, token_dim = stacked_tokens.shape\n", " \n", - " # Attention ile scale fusion\n", + " # Fuse scales with attention\n", " fused_tokens = stacked_tokens.view(B * num_tokens, num_scales, token_dim)\n", " fused_output, _ = self.scale_fusion(fused_tokens, fused_tokens, fused_tokens)\n", " \n", @@ -493,7 +493,7 @@ " self.text_dim = text_dim\n", " self.fusion_dim = fusion_dim\n", " \n", - " # Vision token mapper (mevcut pixel unshuffle kullanarak)\n", + " # Vision token mapper (using the existing pixel unshuffle)\n", " self.vision_mapper = EfficientTokenMapper()\n", " \n", " # Text embedding (simple example)\n", @@ -1022,7 +1022,7 @@ "## šŸš€ Suggested next steps\n", "\n", "### Short term (1-2 weeks)\n", - "1. **Benchmark Testing**: Standart dataset'lerde performance testi\n", + "1. **Benchmark Testing**: Performance evaluation on standard datasets\n", "2. **Fine-tuning Pipeline**: Adapt for specific tasks\n", "3. **Memory Optimization**: Gradient checkpointing, mixed precision\n", "4. **Validation**: Test with real image datasets\n", @@ -1039,7 +1039,7 @@ "3. **Research Contributions**: Academic paper writing\n", "4. **Open Source Release**: Community contribution\n", "\n", - "## šŸ’” Pratik Uygulamalar\n", + "## šŸ’” Practical Applications\n", "\n", "### Projects you can start right away:\n", "1. **Image Search Engine**: Search images using token similarity\n", @@ -1048,7 +1048,7 @@ "4. **Satellite Imagery**: Geographic feature detection\n", "5. **Fashion/E-commerce**: Product similarity matching\n", "\n", - "### Gerekli Kaynaklar:\n", + "### Required Resources:\n", "- **Dataset**: ImageNet, COCO, custom data\n", "- **Compute**: GPU cluster for training\n", "- **Evaluation**: Standard metrics, human evaluation\n",