This is a viewer only at the moment see the article on how this works.
To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk
This is a preview from the server running through my markdig pipeline
Sunday, 09 November 2025
यदि आप इस ब्लॉग का अनुसरण कर रहे हैं, तो आप जानते हैं कि मैं मशीन अनुवाद के साथ पागल हूँ।मैं के बारे में लिखा है, आसानMटी का प्रयोग कर रहा हैपृष्ठभूमि अनुवाद सेवाएँ बनाएं, और भीआसान सुधार**लेकिन मुझे एहसास हुआ कि मैं वास्तव में कभी नहीं समझाया है
कैसे
तंत्रिका मशीन अनुवाद हुड के नीचे काम करता है.
ध्यान दीजिए: यह एआई / एक तरीका है जो कि $००,००० के साथ मेरे परीक्षणों का हिस्सा है।
कृत्रिम तंत्रिका नेटवर्क क्या हैं और कैसे वे सीख रहे हैं
क्या "सामान्यता" का अर्थ है एआई (प्रयोगक: यह ध्यान देने के बारे में नहीं है)
graph LR
A[Source Sentence] --> B[Convert to Numbers]
B --> C[Neural Network Processing]
C --> D[Convert to Words]
D --> E[Translated Sentence]
एनकोडर- टोनर डिजाइन कैसे काम करता है
आप एक गणित व्यक्ति नहीं कर रहे हैं अगर चिंता मत करो - मैं इसे व्यावहारिक और दृश्य के रूप में संभव रूप से रखना होगा.
कोर इडिना: यह अनुवाद नंबर क्रिंग के रूप में किया गया है
निर्माण ब्लॉक के साथ शुरू करते हैं.
graph LR
I1[Input 1] -->|weight: 0.8| N[Neuron]
I2[Input 2] -->|weight: -0.3| N
I3[Input 3] -->|weight: 0.5| N
N --> O[Output]
style N stroke-width:4px
आर्टिक न्यूक्लीयल नेटवर्क: बुनियाद
public class Neuron
{
private double[] weights;
private double bias;
public double Activate(double[] inputs)
{
// Step 1: Multiply each input by its weight and sum them
double sum = bias;
for (int i = 0; i < inputs.Length; i++)
{
sum += inputs[i] * weights[i];
}
// Step 2: Apply activation function (tanh keeps values between -1 and 1)
return Math.Tanh(sum);
}
}
तंत्रिका मशीन अनुवाद को समझने से पहले, हमें कृत्रिम तंत्रिका संजाल को समझने की ज़रूरत है.Math.Tanhफैंसी नाम के बावजूद, वे वास्तव में अपने कोर पर बहुत सरल कर रहे हैं.
कृत्रिम रसायन एक गणितीय क्रिया है कि:
graph LR
subgraph Input Layer
I1[Input 1]
I2[Input 2]
I3[Input 3]
end
subgraph Hidden Layer 1
H1[Neuron 1]
H2[Neuron 2]
H3[Neuron 3]
H4[Neuron 4]
end
subgraph Hidden Layer 2
H5[Neuron 5]
H6[Neuron 6]
H7[Neuron 7]
end
subgraph Output Layer
O1[Output 1]
O2[Output 2]
end
I1 --> H1 & H2 & H3 & H4
I2 --> H1 & H2 & H3 & H4
I3 --> H1 & H2 & H3 & H4
H1 --> H5 & H6 & H7
H2 --> H5 & H6 & H7
H3 --> H5 & H6 & H7
H4 --> H5 & H6 & H7
H5 --> O1 & O2
H6 --> O1 & O2
H7 --> O1 & O2
बहुत से इनपुट को रखता है
के कुछ C# कोड के साथ यह ठोस बनाने के लिए:
graph TD
A[Start with Random Weights] --> B[Feed in Training Example]
B --> C[Network Makes Prediction]
C --> D{Is Prediction Correct?}
D -->|No| E[Calculate Error]
E --> F[Adjust Weights Slightly]
F --> B
D -->|Yes| G[Try Next Example]
G --> B
style E stroke-width:2px
style F stroke-width:2px
सक्रिय फ़ंक्शन (इस मामले में)**) क्या तंत्रिका नेटवर्क दिलचस्प बनाता है.**यह गैर- लाइन का परिचय करता है, जटिल पैटर्न सीखने के लिए नेटवर्क को खोजने की अनुमति देता है.
इसके बिना, कोई बात नहीं कि आप एक साथ इकट्ठा कितने तंत्रिकाओं, आप सिर्फ एक फैंसी लीनियर फ़ंक्शन होगा.
public class SimpleNeuralNetwork
{
private double learningRate = 0.01;
private Neuron[] neurons;
public void Train(TrainingExample[] examples, int epochs)
{
for (int epoch = 0; epoch < epochs; epoch++)
{
foreach (var example in examples)
{
// Forward pass: make a prediction
double prediction = Predict(example.Input);
// Calculate error
double error = example.ExpectedOutput - prediction;
// Backward pass: adjust weights
// (simplified - real networks use backpropagation)
AdjustWeights(error * learningRate);
}
}
}
}
नेटवर्क से**जादू जब आप हजारों या लाखों कोशिकाओं को परतों में एक साथ कनेक्ट होता है:**प्रत्येक परत इनपुट का प्रतिरूप "सही" है, और अधिक जटिल पैटर्न निकाल रहे हैं।
आरंभिक परतों का पता लगाया जा सकता है "यह एक क्रिया है" या "यह शब्द पुराना है"
बाद की परतों में इन्हें "चकण" में शामिल किया जा रहा है कल के मौसम के बारे में एक औपचारिक सवाल के रूप में"
// Don't do this!
var wordToNumber = new Dictionary<string, int>
{
{"cat", 1},
{"dog", 2},
{"king", 3},
{"queen", 4},
{"man", 5},
{"woman", 6}
};
नेटवर्क कैसे सीखें: प्रशिक्षण प्रक्रिया
नेटवर्क उन्हें उदाहरणों से सीखते हैं!इस प्रक्रिया को काल किया जाएगाअनुपात चार्ट
public class WordEmbedding
{
// Each word is represented by a vector of floats
private Dictionary<string, float[]> embeddings;
public float[] GetEmbedding(string word)
{
return embeddings[word]; // e.g., [0.2, -0.5, 0.8, 0.1, ...]
}
// Calculate similarity between two words
public double Similarity(string word1, string word2)
{
var vec1 = GetEmbedding(word1);
var vec2 = GetEmbedding(word2);
// Cosine similarity: how "aligned" are the vectors?
return CosineSimilarity(vec1, vec2);
}
private double CosineSimilarity(float[] a, float[] b)
{
double dot = 0, magA = 0, magB = 0;
for (int i = 0; i < a.Length; i++)
{
dot += a[i] * b[i];
magA += a[i] * a[i];
magB += b[i] * b[i];
}
return dot / (Math.Sqrt(magA) * Math.Sqrt(magB));
}
}
graph TD
subgraph "2D Projection of 300D Space"
King[King<br/>0.8, 0.6]
Queen[Queen<br/>0.75, 0.55]
Man[Man<br/>0.3, 0.2]
Woman[Woman<br/>0.25, 0.15]
Dog[Dog<br/>-0.6, 0.4]
Cat[Cat<br/>-0.65, 0.38]
end
King -.similar.-> Queen
Man -.similar.-> Woman
Dog -.similar.-> Cat
King -.same vector.-> Man
Queen -.same vector.-> Woman
प्रत्येक गलत जवाब के लिए, नेटवर्क आंकड़े बाहर "कौन वज़न इस त्रुटि के लिए सबसे जिम्मेदार थे?" और उन्हें थोड़ा कमजोर करता है।king - man + woman ≈ queen
public float[] AnalogicalReasoning(string a, string b, string c)
{
// king - man + woman = ?
var vecA = GetEmbedding(a); // king
var vecB = GetEmbedding(b); // man
var vecC = GetEmbedding(c); // woman
var result = new float[vecA.Length];
for (int i = 0; i < vecA.Length; i++)
{
result[i] = vecA[i] - vecB[i] + vecC[i];
}
// Find the word closest to this vector
return FindClosestWord(result); // Should return "queen"
}
यहाँ C# में एक सरल संस्करण है:
graph LR
A["The cat sat on the mat"] --> B[Train Neural Network]
B --> C["cat → [0.1, 0.5, -0.3, ...]"]
B --> D["sat → [0.2, -0.1, 0.4, ...]"]
B --> E["mat → [0.15, 0.45, -0.25, ...]"]
वास्तविक तंत्रिका नेटवर्क एक अधिक जटिल एल्गोरिथ्म का उपयोग करते हैं जो कहा जाता है
लेकिन यह सिद्धांत वही है: गलतियों से सबक सीखिए ।
graph TD
subgraph English
E1[The]
E2[cat]
E3[sat]
E4[on]
E5[the]
E6[mat]
end
subgraph French
F1[Le]
F2[chat]
F3[s'est assis]
F4[sur]
F5[le]
F6[tapis]
end
E2 -. focus 90% .-> F2
E3 -. focus 70% .-> F3
E4 -. focus 80% .-> F4
E6 -. focus 85% .-> F6
E1 -. focus 30% .-> F1
शब्द एम्बेडिंग: भाषा को गणित में लागू किया जा सकता हैअब हम अपनी पहली बड़ी चुनौती पर गौर करते हैं: हम शब्दों को एक तंत्रिका नेटवर्क में कैसे भरते हैं?
एक-Hin एनकोडिंग के साथ समस्या
public class AttentionMechanism
{
// Calculate attention weights for each source word
public double[] CalculateAttention(
float[] currentTargetState, // Where we are in translation
float[][] sourceWordStates) // All source words
{
int sourceLength = sourceWordStates.Length;
double[] scores = new double[sourceLength];
// Step 1: Calculate relevance scores
for (int i = 0; i < sourceLength; i++)
{
scores[i] = DotProduct(currentTargetState, sourceWordStates[i]);
}
// Step 2: Convert to probabilities (softmax)
return Softmax(scores);
}
public float[] ApplyAttention(
double[] attentionWeights,
float[][] sourceWordStates)
{
// Create weighted average of source words
int dim = sourceWordStates[0].Length;
float[] result = new float[dim];
for (int i = 0; i < sourceWordStates.Length; i++)
{
for (int j = 0; j < dim; j++)
{
result[j] += (float)(attentionWeights[i] * sourceWordStates[i][j]);
}
}
return result;
}
private double[] Softmax(double[] scores)
{
double[] result = new double[scores.Length];
double sum = 0;
for (int i = 0; i < scores.Length; i++)
{
result[i] = Math.Exp(scores[i]);
sum += result[i];
}
for (int i = 0; i < scores.Length; i++)
{
result[i] /= sum;
}
return result;
}
private double DotProduct(float[] a, float[] b)
{
double sum = 0;
for (int i = 0; i < a.Length; i++)
{
sum += a[i] * b[i];
}
return sum;
}
}
बेवकूफ तरीका है "एक-टोन एनकोडिंग" - प्रत्येक शब्द को एक अद्वितीय संख्या नियत करें:
सदिश
graph TD
subgraph "English (Source)"
E1[The]
E2[agreement]
E3[on]
E4[the]
E5[European]
E6[Economic]
E7[Area]
end
subgraph "German (Target)"
G1[Das]
G2[Abkommen]
G3[über]
G4[den]
G5[Europäischen]
end
E1 -->|0.8| G1
E2 -->|0.9| G2
E3 -->|0.6| G3
E4 -->|0.3| G3
E5 -->|0.85| G5
E6 -->|0.7| G5
संख्या, आमतौर पर 300-1000 आयाम की.
यहाँ क्या है जादुई जादू - वे निरंतर रिश्ता धारण करते हैं:**प्रसिद्ध उदाहरण:**उन्नति करना कैसे सीखा जाता है?
graph LR
subgraph "Self-Attention for 'bank'"
B[bank]
R[river]
W[water]
F[fish]
end
B -.high attention.-> R
B -.high attention.-> W
B -.medium attention.-> F
एक सरल कार्य पर एक तंत्रिका नेटवर्क को प्रशिक्षित करने के द्वारा सीखा जाता है: " आसपास के शब्दों का प्रतिनिधित्व करें."
अरबों वाक्यों को प्रशिक्षित करने के बाद, शब्दों जो समान संदर्भों के साथ अंत में दिखाई देते हैं. "Cont" और "Cet" दोनों के पास "ट" दिखाई देता है, "कोमो", "कोज़", "कोज़", तो उनका अंत एक साथ बंद हो जाता है.ध्यान दें: खेल बदलने वालायहाँ एक गंभीर अन्तर्दृष्टि है: जब " बिल्ली की छाती पर बैठा हुआ है" फ्रेंच के लिए, अलग स्रोत शब्द अलग लक्ष्य शब्दों के लिए:
graph LR
subgraph Encoder
E1[Word Embeddings] --> E2[Self-Attention Layer 1]
E2 --> E3[Self-Attention Layer 2]
E3 --> E4[Self-Attention Layer N]
E4 --> E5[Contextual Representations]
end
subgraph Decoder
D1[Previous Translations] --> D2[Self-Attention]
D2 --> D3[Cross-Attention to Encoder]
D3 --> D4[Feed Forward]
D4 --> D5[Next Word Prediction]
end
E5 -.provides context.-> D3
एक यांत्रिकी है जो प्रत्येक आउटपुट शब्द को बनाने के दौरान नेटवर्क "फ़ॉल" को इनपुट के विभिन्न भागों पर "फ़ॉल करें" की अनुमति देता है.
public class TransformerEncoder
{
private WordEmbedding wordEmbedding;
private SelfAttentionLayer[] layers;
public float[][] Encode(string[] sourceWords)
{
// Step 1: Convert words to embeddings
float[][] embeddings = sourceWords
.Select(w => wordEmbedding.GetEmbedding(w))
.ToArray();
// Step 2: Add positional encoding (so network knows word order)
float[][] withPositions = AddPositionalEncoding(embeddings);
// Step 3: Apply multiple self-attention layers
float[][] representations = withPositions;
foreach (var layer in layers)
{
representations = layer.Forward(representations);
}
return representations; // Contextual representations for each word
}
private float[][] AddPositionalEncoding(float[][] embeddings)
{
// Add position-specific patterns so network knows word order
// (transformers don't naturally understand sequence order)
int sequenceLength = embeddings.Length;
int embeddingDim = embeddings[0].Length;
for (int pos = 0; pos < sequenceLength; pos++)
{
for (int i = 0; i < embeddingDim; i++)
{
double angle = pos / Math.Pow(10000, (2.0 * i) / embeddingDim);
// Use sine for even dimensions, cosine for odd
embeddings[pos][i] += (float)(i % 2 == 0 ? Math.Sin(angle) : Math.Cos(angle));
}
}
return embeddings;
}
}
ध्यान कैसे कार्य करता है
वृद्धि में प्रतिशत बदलता है (वे योग १ से १)
public class TransformerDecoder
{
private WordEmbedding targetEmbedding;
private SelfAttentionLayer[] selfAttentionLayers;
private CrossAttentionLayer[] crossAttentionLayers;
private FeedForwardLayer[] feedForwardLayers;
public string[] Decode(float[][] encodedSource, int maxLength)
{
List<string> translation = new List<string>();
translation.Add("<START>"); // Special token to begin
while (translation.Count < maxLength)
{
// Get next word
string nextWord = GenerateNextWord(encodedSource, translation.ToArray());
if (nextWord == "<END>") break; // Stop token
translation.Add(nextWord);
}
return translation.Skip(1).ToArray(); // Remove <START> token
}
private string GenerateNextWord(float[][] encodedSource, string[] partialTranslation)
{
// Step 1: Embed the partial translation
float[][] targetEmbeddings = partialTranslation
.Select(w => targetEmbedding.GetEmbedding(w))
.ToArray();
// Step 2: Self-attention on target words
float[][] selfAttended = ApplySelfAttention(targetEmbeddings);
// Step 3: Cross-attention to source (this is where translation happens!)
float[][] crossAttended = ApplyCrossAttention(selfAttended, encodedSource);
// Step 4: Feed forward
float[] finalState = ApplyFeedForward(crossAttended[^1]); // Last position
// Step 5: Predict next word
return PredictWord(finalState);
}
private string PredictWord(float[] state)
{
// Convert state to probability distribution over all possible words
Dictionary<string, double> wordProbabilities = CalculateWordProbabilities(state);
// Return most likely word (or sample from distribution)
return wordProbabilities.OrderByDescending(kv => kv.Value).First().Key;
}
}
इन निर्भरताओं पर आधारित स्रोत शब्दों का परिमाण औसत बनाता है
sequenceDiagram
participant Input as Source Sentence
participant Encoder
participant Decoder
participant Output as Translation
Input->>Encoder: "The cat sat"
Encoder->>Encoder: Build representations
Encoder->>Decoder: Encoded states
Decoder->>Decoder: Generate [START]
Decoder->>Output: Emit START token
Decoder->>Decoder: Attend to "The" → Generate "Le"
Decoder->>Output: "Le"
Decoder->>Decoder: Attend to "cat" → Generate "chat"
Decoder->>Output: "chat"
Decoder->>Decoder: Attend to "sat" → Generate "s'est assis"
Decoder->>Output: "s'est assis"
Decoder->>Decoder: Generate [END]
Output->>Output: "Le chat s'est assis"
जब अगस्त १९९२ में यूरोपीय आर्थिक क्षेत्र पर हस्ताक्षर किया गया था, तो ध्यान इस तरह दिखता है:
public class TranslationTrainer
{
private TransformerEncoder encoder;
private TransformerDecoder decoder;
private double learningRate = 0.0001;
public void Train(ParallelCorpus corpus, int epochs)
{
foreach (var epoch in Enumerable.Range(0, epochs))
{
double totalLoss = 0;
int batchCount = 0;
foreach (var batch in corpus.GetBatches(batchSize: 32))
{
// Forward pass
var predictions = new List<string[]>();
var losses = new List<double>();
foreach (var pair in batch)
{
// Encode source
var encoded = encoder.Encode(pair.Source);
// Try to decode target
var predicted = decoder.Decode(encoded, pair.Target.Length);
// Calculate loss (how different is prediction from target?)
double loss = CalculateLoss(predicted, pair.Target);
losses.Add(loss);
}
// Backward pass: adjust weights
double avgLoss = losses.Average();
UpdateWeights(avgLoss);
totalLoss += avgLoss;
batchCount++;
}
Console.WriteLine($"Epoch {epoch}: Average Loss = {totalLoss / batchCount}");
}
}
private double CalculateLoss(string[] predicted, string[] target)
{
// Cross-entropy loss: how far off were our word predictions?
double loss = 0;
for (int i = 0; i < Math.Min(predicted.Length, target.Length); i++)
{
if (predicted[i] != target[i])
{
loss += 1.0; // Simplified - real loss is more nuanced
}
}
return loss / target.Length;
}
private void UpdateWeights(double loss)
{
// Backpropagation: adjust all weights in encoder and decoder
// to reduce the loss (simplified here)
// Real implementation uses automatic differentiation
}
}
एनकोडर- डोदर
graph TD
A[10M Sentence Pairs] --> B[Initial Random Weights]
B --> C[Epoch 1: Loss = 5.2]
C --> D[Epoch 2: Loss = 3.8]
D --> E[Epoch 3: Loss = 2.1]
E --> F[Epoch 10: Loss = 0.8]
F --> G[Epoch 20: Loss = 0.3]
G --> H[Trained Model!]
style A stroke-width:2px
style H stroke-width:4px
अब हम इसे सब एक साथ रख सकते हैं!
वाक्य में इसकी स्थिति (प्रचलित एनकोडिंग से)
graph TD
subgraph "1. Encoding"
A1[The] --> E1[emb: 0.2, -0.1, ...]
A2[cat] --> E2[emb: 0.5, 0.3, ...]
A3[sat] --> E3[emb: -0.1, 0.4, ...]
A4[on] --> E4[emb: 0.1, -0.2, ...]
A5[the] --> E5[emb: 0.2, -0.1, ...]
A6[mat] --> E6[emb: 0.4, 0.2, ...]
end
subgraph "2. Self-Attention in Encoder"
E1 & E2 & E3 & E4 & E5 & E6 --> SA[Self-Attention]
SA --> C1[ctx: 0.3, 0.1, ...]
SA --> C2[ctx: 0.6, 0.4, ...]
SA --> C3[ctx: -0.2, 0.5, ...]
end
subgraph "3. Decoding"
D1[START] --> G1[Le]
C2 -.attend.-> G1
G1 --> G2[chat]
C2 -.attend.-> G2
G2 --> G3[s'est assis]
C3 -.attend.-> G3
end
डिकोडर: अनुवाद तैयार किया जा रहा है
var theEmbedding = encoder.GetEmbedding("The");
// [0.2, -0.1, 0.3, 0.05, ..., 0.1] (300 dimensions)
टिकर अनुवाद एक समय में एक शब्द तैयार करता है:
var catEmbedding = encoder.GetEmbedding("cat");
// [0.5, 0.3, -0.2, 0.4, ..., 0.15] (300 dimensions)
पूरा अनुवाद प्रक्रिया:
// "cat" attends to other words
var catAttention = attention.CalculateAttention(catEmbedding, allWordEmbeddings);
// [0.1, 0.3, 0.2, 0.05, 0.1, 0.25]
// High attention to "sat" (0.3) and "mat" (0.25)
var catContextual = attention.ApplyAttention(catAttention, allWordEmbeddings);
// Weighted average incorporating context
अनुवाद मॉडल सिखाया जा रहा है
var decoderState = decoder.InitialState();
अनुवाद मॉडल सिखाने के लिए तीन बातें की ज़रूरत होती है:
// Attend to source
var sourceAttention = crossAttention.Calculate(decoderState, encodedSource);
// [0.8, 0.05, 0.05, 0.02, 0.05, 0.03]
// Strong focus on "The" (0.8)
var nextWordProbs = decoder.PredictNextWord(decoderState, sourceAttention);
// {"Le": 0.85, "La": 0.08, "Les": 0.04, ...}
var firstWord = "Le";
समानांतर कोरेसिपिस
decoderState = decoder.UpdateState(decoderState, "Le");
var sourceAttention = crossAttention.Calculate(decoderState, encodedSource);
// [0.05, 0.9, 0.02, 0.01, 0.01, 0.01]
// Strong focus on "cat" (0.9)
var nextWordProbs = decoder.PredictNextWord(decoderState, sourceAttention);
// {"chat": 0.92, "chien": 0.03, ...}
var secondWord = "chat";
: दोनों भाषाओं में लाखों वाक्य जोड़े
Final translation: "Le chat s'est assis sur le tapis"
: "क्या गलत" हमारी भविष्यवाणी थी?
graph LR
subgraph "Old: Recurrent Neural Networks"
R1[Word 1] --> R2[Word 2]
R2 --> R3[Word 3]
R3 --> R4[Word 4]
end
subgraph "New: Transformers"
T1[Word 1] -.attend.-> T2[Word 2]
T1 -.attend.-> T3[Word 3]
T1 -.attend.-> T4[Word 4]
T2 -.attend.-> T3
T2 -.attend.-> T4
T3 -.attend.-> T4
end
प्रशिक्षण समय
© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.