Chapterبەش 6 · Lectureوانە 6.1

Probability in Computing: Speech, Predictive Text and Riskبەکارهێنانی ئەگەر لە بواری کۆمپیوتەردا: ئاخاوتن، پێشبینیی دەق و مەترسی

How computers use probability: speech recognition picks the most probable text (Bayes, hidden Markov models, today's neural networks), predictive text ranks next words by conditional probability, six fields of computer science that depend on probability, earthquake hazard as probabilities of shaking rather than predictions, and pseudo-random numbers in Python: a Monte Carlo estimate of π, and why secrets, not random, protects passwords and codes.

چۆن بەکار دەهێنن: گونجاوترین دەق هەڵدەبژێرێت (، و ئەمڕۆ)، وشەی دواتر بە ڕیز دەکات، شەش بواری زانستی کە پشت بە دەبەستن، مەترسیی بوومەلەرزە وەک لەرزین نەک پێشبینی، هەروەها لە Pythonـدا: خەمڵاندنی π بە و بۆچی secrets، نەک random، و کۆدەکان دەپارێزێت.

29 min read30 خولەک خوێندنەوە · 22 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain how speech recognition and predictive text choose the most probable text or word.
  • Estimate a next-word probability from counts and update it when a letter is typed.
  • Name six fields of computer science that use probability, with an example of each.
  • Interpret a seismic hazard curve and turn "2% in 50 years" into a yearly probability.
  • Use pseudo-random numbers for a Monte Carlo estimate and explain why secrets must be used for security.
  • ڕوون بکەیتەوە و چۆن گونجاوترین دەق یان وشە هەڵدەبژێرن.
  • وشەی دواتر لە ژمارەکانەوە بخەمڵێنیت و کاتێک پیتێک دەنووسرێت نوێی بکەیتەوە.
  • شەش بواری زانستی ناو بهێنیت کە بەکار دەهێنن، بە نموونەیەک بۆ هەر یەکێک.
  • لێک بدەیتەوە و «دوو لە سەد لە پەنجا ساڵدا» بکەیت بە ساڵانە.
  • بۆ خەمڵاندنێکی بەکار بهێنیت و ڕوون بکەیتەوە بۆچی دەبێت secrets بۆ بەکار بهێنرێت.

Guessing, weighing risk and using chanceمەزەندەکردن، هەڵسەنگاندنی مەترسی و بەکارهێنانی ڕێکەوت

You have learned to count outcomes, to combine events, to update a probability with new information and to describe random variables. This last chapter shows the same tools at work inside computers. Probability enters computing in three main ways:

فێربوویت بژمێریت، پێکەوە ببەستیت، بە زانیاریی نوێ نوێ بکەیتەوە و وەسف بکەیت. ئەم بەشە کۆتاییە هەمان ئامرازەکان لە ناو لە کاردا نیشان دەدات. بە سێ ڕێگای سەرەکی دێتە ناو :

  • Choosing the most probable answer when the input is unclear: what did the speaker say, which word will you type next?
  • Measuring risk when the future cannot be known: how strongly may the ground shake here in the next 50 years?
  • Using randomness on purpose: simulations, games, fast algorithms and secret keys.
  • هەڵبژاردنی گونجاوترین وەڵام کاتێک ڕوون نییە: قسەکەر چی گوت، وشەی داهاتووت چییە؟
  • پێوانی کاتێک داهاتوو نازانرێت: لە پەنجا ساڵی داهاتوودا زەوی لێرە چەند بەهێز دەلەرزێت؟
  • بەکارهێنانی ڕێکەوت بە مەبەست: ، یاری، خێرا و .

Each screen links back to the lesson where the tool was taught, so you can look again when you need to.

هەر پەڕەیەک بۆ ئەو وانەیە هەیە کە ئامرازەکەی تێدا فێرکرا، بۆ ئەوەی هەر کاتێک پێویست بوو بگەڕێیتەوە سەری.

Quick checkپشکنینی خێراA program throws 100,000 random points into a square to estimate the number π. Which of the three ways is this? 100 000100\,000 خاڵی هەڕەمەکی دەخاتە ناو چوارگۆشەیەکەوە بۆ خەمڵاندنی ژمارەی π. ئەمە کام لە سێ ڕێگاکەیە؟

Speech recognition: the most probable textناسینەوەی ئاخاوتن: گونجاوترین دەق

When you dictate a message or talk to a voice assistant, speech recognition software turns your speech into text or commands. The microphone gives it only a sound signal, and the same word sounds different with every voice, accent, speed and background noise. So the software can never be sure. It makes the best guess: the text with the highest probability, given the sound.

کاتێک نامەیەک بە دەنگ دەنووسیت یان قسە لەگەڵ دەکەیت، قسەکانت دەکات بە دەق یان فەرمان. تەنها دەنگی دەداتێ. هەمان وشەش بە هەر دەنگ، شێوەزار، خێرایی و ژاوەژاوێکی دەوروبەر جیاواز دەبیسترێت. بۆیە هەرگیز دڵنیا نابێت. باشترین مەزەندە دەکات: ئەو دەقەی کە بە پێی دەنگەکە بەرزترین هەیە.

It works in steps. The signal is cut into tiny pieces called frames, one every 10 milliseconds. Statistical models estimate, for each piece, the probability of each possible small unit of speech: a phoneme (one of the small sounds that tell words apart, like the /k/ of cat) or a whole word. Then the system compares possible words and phrases, computes the probability of each, and outputs the most probable one.

بە هەنگاو کار دەکات. دەبڕدرێت بۆ پارچەی زۆر بچووک کە پێیان دەگوترێت پارچە، هەر دە میلیچرکە پارچەیەک. مۆدێلە ئامارییەکان بۆ هەر پارچەیەک هەر یەکەیەکی بچووکی ئاخاوتن دەخەمڵێنن: (یەکێک لەو دەنگە بچووکانەی وشەکان لە یەک جیا دەکەنەوە، وەک /k/ لە cat) یان وشەیەکی تەواو. پاشان سیستەمەکە وشە و دەستەواژە گونجاوەکان بەراورد دەکات، هەر یەکێکیان حیساب دەکات و گونجاوترینیان دەکاتە .

Diagram in three panels joined by arrows. First panel, the sound: a wave cut by dashed lines into tiny frames. Second panel, possible texts: "an ice cream" with a long bar and "an I scream" with a tiny bar; the bar shows how probable each text is. Third panel, output: "an ice cream", the most probable text. Under the panels: the two texts sound almost the same; the language model knows which words usually go together.هێڵکاری لە سێ بەش کە بە تیر بەیەکەوە بەستراون. بەشی یەکەم، دەنگەکە: شەپۆلێک کە بە هێڵی پچڕپچڕ بۆ پارچەی زۆر بچووک دابەش کراوە. بەشی دووەم، دەقە گونجاوەکان: «an ice cream» بە ستوونێکی درێژ و «an I scream» بە ستوونێکی زۆر کورت؛ ستوونەکە نیشان دەدات هەر دەقێک چەند ئەگەری هەیە. بەشی سێیەم، دەرخستە: «an ice cream»، گونجاوترین دەق. لە ژێر بەشەکاندا: هەردوو دەقەکە دەنگیان زۆر لە یەک دەچێت؛ مۆدێلی زمان دەزانێت کام وشانە زۆرجار پێکەوە دێن.
Sound in, the most probable text outدەنگ دێتە ژوورەوە، گونجاوترین دەق دەردەچێتCêIT
Quick checkپشکنینی خێراWhy does speech recognition use probability instead of a fixed table of "this sound = this word"?بۆچی بەکار دەهێنێت لە جیاتی خشتەیەکی جێگیری «ئەم دەنگە = ئەم وشەیە»؟

Speech recognition: the most probable textناسینەوەی ئاخاوتن: گونجاوترین دەق

Two probabilities, multiplied: Bayes at workدوو ئەگەر، لێکدراو: سەلمێنراوی بەیز لە کاردا

A recogniser asks two questions about every possible text: does it match the sound? and is it something people actually say? The acoustic model answers the first, the language model the second. Bayes' theorem joins them:

سیستەمی ناسینەوە دوو پرسیار دەربارەی هەر دەقێکی گونجاو دەکات: ئایا لەگەڵ دەنگەکە دەگونجێت؟ و ئایا خەڵک بەڕاستی شتی وا دەڵێن؟ وەڵامی یەکەم دەداتەوە و وەڵامی دووەم. هەردووکیان پێکەوە دەبەستێت:

W^=arg⁡max⁡WP(W∣sound)=arg⁡max⁡W  P(sound∣W) P(W)\hat{W} = \arg\max_{W} P(W \mid \text{sound}) = \arg\max_{W} \; P(\text{sound} \mid W)\, P(W)

Read arg⁡max⁡W\arg\max_W as "the text WW that makes this largest". By Bayes' theorem, P(W∣sound)=P(sound∣W) P(W)/P(sound)P(W \mid \text{sound}) = P(\text{sound} \mid W)\,P(W) / P(\text{sound}); the bottom P(sound)P(\text{sound}) is the same for every candidate, so it cannot change which one wins and is left out.

arg⁡max⁡W\arg\max_W بەم شێوەیە بخوێنەوە: «ئەو دەقەی WW کە ئەمە گەورەترین دەکات». بەپێی سەلمێنراوی بەیز، P(W∣sound)=P(sound∣W) P(W)/P(sound)P(W \mid \text{sound}) = P(\text{sound} \mid W)\,P(W) / P(\text{sound})؛ بەشی خوارەوە، P(sound)P(\text{sound})، بۆ هەموو دەقە گونجاوەکان وەک یەکە، بۆیە ناتوانێت بگۆڕێت کامیان دەباتەوە و لادەبرێت.

Made-up numbers for one short recording, to show the ideaژمارەی دەستکرد بۆ یەک تۆماری کورت، بۆ نیشاندانی بیرۆکەکە
Possible textدەقی گونجاوMatches the sound P(sound∣W)P(\text{sound} \mid W)گونجان لەگەڵ دەنگ P(sound∣W)P(\text{sound} \mid W)Common in language P(W)P(W)باو لە زماندا P(W)P(W)Productلێکدان
an ice cream0.300.300.00040.00040.000120.00012
an I scream0.320.320.0000010.0000010.000000320.00000032

an I scream matches the sound a little better (0.32 against 0.30), but people almost never write it. The product decides: 0.00012/0.00000032=3750.00012 / 0.00000032 = 375, so an ice cream is 375 times more probable and becomes the output.

⁦an I scream⁩ کەمێک باشتر لەگەڵ دەنگەکە دەگونجێت (⁦0.32⁩ بەرامبەر ⁦0.30⁩)، بەڵام خەڵک بە دەگمەن دەینووسن. لێکدانەکە بڕیار دەدات: 0.00012/0.00000032=3750.00012 / 0.00000032 = 375، کەواتە ⁦an ice cream⁩ 375375 جار زیاترە و دەبێتە .

Quick checkپشکنینی خێراWhy can the recogniser leave out P(sound)P(\text{sound}) when it compares possible texts?بۆچی سیستەمی ناسینەوە دەتوانێت P(sound)P(\text{sound}) لاببات کاتێک دەقە گونجاوەکان بەراورد دەکات؟

Speech recognition: the most probable textناسینەوەی ئاخاوتن: گونجاوترین دەق

Hidden Markov models: the classic methodمۆدێلی شاراوەی مارکۆڤ: ڕێگا کلاسیکییەکە

From the 1980s to the 2000s most recognisers used a hidden Markov model (HMM). It describes speech as a chain of states, one for each sound or word. The states are hidden: the computer never hears "/k/" directly; it only receives the signal. The model holds two kinds of probabilities:

لە ساڵانی هەشتاکانەوە تا ساڵانی دووهەزارەکان زۆربەی سیستەمەکانی ناسینەوە ⁦(HMM)⁩یان بەکار دەهێنا. ئاخاوتن وەک زنجیرەیەک دۆخ وەسف دەکات، بۆ هەر دەنگێک یان وشەیەک دۆخێک. دۆخەکان شاراوەن: هەرگیز ڕاستەوخۆ «/k/» نابیستێت؛ تەنها وەردەگرێت. دوو جۆر لەخۆ دەگرێت:

  • Transition probabilities: from one state, how likely is the next one? Stay in /k/, or move on to /æ/?
  • Emission probabilities: in a given state, how likely is each piece of sound that the microphone records?
  • گواستنەوە: لە دۆخێکەوە، دۆخی دواتر چەند هەیە؟ لە /k/دا بمێنێتەوە یان بچێتە سەر /æ/؟
  • دەرچوون: لە دۆخێکی دیاریکراودا، هەر پارچەیەکی ئەو دەنگەی تۆماری دەکات چەند هەیە؟
Diagram: three circles in a row for the sounds /k/, /æ/ and /t/ of the word cat, the hidden states. Each circle has a loop arrow labelled 0.6 (stay in the same sound) and an arrow to the next circle labelled 0.4 (move on); the last arrow leads to the end. Dashed lines go down from each circle to three small boxes with wave pictures: the observed 10-millisecond frames of sound. A note says the numbers are made up for illustration.هێڵکاری: سێ بازنە لە ڕیزێکدا بۆ دەنگەکانی /k/ و /æ/ و /t/ی وشەی cat، کە دۆخە شاراوەکانن. هەر بازنەیەک تیرێکی بازنەیی هەیە بە 0.6 (لە هەمان دەنگدا مانەوە) و تیرێک بۆ بازنەی دواتر بە 0.4 (چوونە پێشەوە)؛ دوایین تیر دەچێتە کۆتایی. هێڵی پچڕپچڕ لە هەر بازنەیەکەوە دەچنە خوارەوە بۆ سێ سندووقی بچووک بە وێنەی شەپۆل: پارچە دە میلیچرکەییە بینراوەکانی دەنگ. تێبینییەک دەڵێت ژمارەکان تەنها بۆ ڕوونکردنەوەن.
An HMM for one word: hidden sounds (top) produce the frames we observe (bottom) بۆ یەک وشە: دەنگە شاراوەکان (سەرەوە) ئەو پارچانە بەرهەم دەهێنن کە دەیانبینین (خوارەوە)CêIT

The HMM cuts the signal into frames and computes the probability that each frame belongs to each sound unit. To recognise a word, the system compares the input with the HMMs of all possible words or phrases, computes the probability of each, and outputs the one with the highest probability. A path through the states is a chain of steps, so its probability is a product of probabilities. "Markov" means the next state depends only on the current one, an idea named after the Russian mathematician Andrey Markov.

دەبڕێت بۆ پارچە و ئەوە حیساب دەکات کە هەر پارچەیەک سەر بە هەر یەکەیەکی دەنگی بێت. بۆ ناسینەوەی وشەیەک، سیستەمەکە لەگەڵ هەموو وشە یان دەستەواژە گونجاوەکان بەراورد دەکات، هەر یەکێکیان حیساب دەکات و ئەوەیان دەکاتە کە بەرزترین هەیە. ڕێڕەوێک بە ناو دۆخەکاندا زنجیرەیەک هەنگاوە، بۆیە لێکدانی چەند ئەگەرێکە. «مارکۆڤ» واتە دۆخی دواتر تەنها پشت بە دۆخی ئێستا دەبەستێت؛ ئەم بیرۆکەیە ناوی بیرکاریزانی ڕووسی ئەندرێی مارکۆڤی لێنراوە.

Quick checkپشکنینی خێراIn the picture the model starts in /k/. What is the probability that it stays in /k/ for exactly two frames and then moves to /æ/?لە وێنەکەدا لە /k/ەوە دەست پێ دەکات. ئەوە چەندە کە ڕێک بۆ دوو پارچە لە /k/دا بمێنێتەوە و پاشان بچێتە سەر /æ/؟

Hidden Markov Model Clearly Explained! Part - 5Normalized Nerd · Englishئینگلیزی · 718K viewsبینین · 12K likesلایک

A hidden Markov model: hidden states you cannot see, transition and emission probabilities, and finding the most likely hidden sequence.

: دۆخە شاراوەکان کە نایانبینیت، گواستنەوە و دەرچوون، هەروەها دۆزینەوەی گونجاوترین زنجیرەی دۆخە شاراوەکان.

Whole video: Markov chains recap (0:37), hidden states (1:55), the probability of a scenario (3:11), the most likely hidden sequence (5:19).

هەموو ڤیدیۆکە: پێداچوونەوەی زنجیرەی مارکۆڤ ⁦(0:37)⁩، دۆخە شاراوەکان ⁦(1:55)⁩، سیناریۆیەک ⁦(3:11)⁩، گونجاوترین زنجیرەی شاراوە ⁦(5:19)⁩.

Speech recognition: the most probable textناسینەوەی ئاخاوتن: گونجاوترین دەق

Today: neural networks, still probabilitiesئەمڕۆ: تۆڕە دەمارییەکان، بەڵام هەر ئەگەر

The main point of the note still holds. A neural recogniser also ends with probabilities: for every short piece of sound it gives a probability to each possible letter, word piece or word, and the system outputs the most probable text. It is still a best guess, which is why dictation sometimes writes a word that sounds right but is wrong. How neural networks learn is explained in Neural networks, deep learning and generative AI.

خاڵی سەرەکیی تێبینییەکە هێشتا ڕاستە. بۆ ناسینەوەش لە کۆتاییدا دەدات: بۆ هەر پارچەیەکی کورتی دەنگ دەداتە هەر پیت، پارچە وشە یان وشەیەکی گونجاو و سیستەمەکە گونجاوترین دەق دەکاتە . هێشتا باشترین مەزەندەیە، بۆیە نووسینی دەنگی هەندێک جار وشەیەک دەنووسێت کە دەنگی دروستە بەڵام خۆی هەڵەیە. چۆنیەتی فێربوونی لە تۆڕە دەمارییەکان، فێربوونی قووڵ و ژیریی دەستکردی بەرهەمهێنەر ڕوون کراوەتەوە.

The course essay's examples of voice assistants, and why one of them was retired, are discussed in What is statistics?.

نموونەکانی نامیلکەی خولەکە بۆ و هۆی وەستاندنی یەکێکیان لە ئامار چییە؟ باس کراون.

Quick checkپشکنینی خێراA modern phone uses a neural network, not an HMM, to recognise speech. Which statement is true?مۆبایلێکی نوێ بۆ بەکار دەهێنێت، نەک . کام ڕستە ڕاستە؟

Predictive text: guessing your next wordپێشبینیی دەق: مەزەندەکردنی وشەی داهاتووت

Smartphones use probability every time you type. The predictive text feature reads what you have typed so far and suggests the next word, choosing the words with the highest probability of coming next. Here is the owner's own phone: after typing Th, the keyboard offers Th (the letters as typed), The and Thanks.

هەر جارێک دەنووسیت بەکار دەهێنن. تایبەتمەندیی ئەوە دەخوێنێتەوە کە تا ئێستا نووسیوتە و وشەی دواتر پێشنیار دەکات؛ ئەو وشانە هەڵدەبژێرێت کە بەرزترین هەیە دواتر بێن. ئەمە مۆبایلی خاوەنی سایتەکەیە: دوای نووسینی Th، Th (پیتەکان وەک نووسراون)، The و Thanks پێشنیار دەکات.

Predictive text on an iPhone after typing "Th" لە iPhoneـێکدا دوای نووسینی «Th»Course material

The course note gives a whole-word example. If you have typed I am going to the, the program computes the probability of every word that could follow, using its language model. If store is the word that most often follows in that context, store is suggested first.

تێبینییەکەی خولەکە نموونەیەکی وشەی تەواو دەهێنێتەوە. گەر ئەم وشانەت نووسیبێت: ⁦I am going to the⁩، بە خۆی هەموو ئەو وشانە حیساب دەکات کە دەکرێت دواتر بێن. گەر store ئەو وشەیە بێت کە لەو دۆخەدا زۆرترین جار دواتر دێت، یەکەم جار store پێشنیار دەکرێت.

Quick checkپشکنینی خێراWhy does the keyboard suggest The and Thanks after Th, rather than Thursday?بۆچی دوای Th وشەکانی The و Thanks پێشنیار دەکات، نەک Thursday؟

Predictive text: guessing your next wordپێشبینیی دەق: مەزەندەکردنی وشەی داهاتووت

Counting what comes nextژماردنی ئەوەی دواتر دێت

The probability that store comes next is a conditional probability: the probability of a word, given the words already typed. A simple way to estimate it is to count. Suppose that in a large collection of messages the words I am going to the appear 200 times, and 70 of those times the next word is store:

ئەوەی store دواتر بێت ئەگەرێکی مەرجدارە: وشەیەک، بە مەرجی ئەو وشانەی پێشتر نووسراون. ڕێگایەکی سادە بۆ خەمڵاندنی ژماردنە. وا دابنێ لە کۆمەڵێکی گەورەی نامەدا وشەکانی ⁦I am going to the⁩ دووسەد جار هاتوون و لە حەفتا جاریاندا وشەی دواتر store بووە:

P(store∣I am going to the)≈70200=0.35P(\text{store} \mid \text{I am going to the}) \approx \frac{70}{200} = 0.35

Count how often the words come together, divide by how often the beginning appears: a relative frequency used as an estimate.

بژمێرە وشەکان چەند جار پێکەوە دێن و دابەشی بکە بەسەر ژمارەی هاتنی سەرەتاکەدا: دووبارەبوونەوەی ڕێژەیی وەک خەمڵاندن.

Bar chart under a text box that says "I am going to the ___". Bars: store 0.35 (the longest, highlighted), market 0.25, university 0.15, and a dashed bar for other words 0.25. A note says the probabilities were estimated by counting a large collection of texts.هێڵکاریی ستوونی لە ژێر خانەیەکی دەقدا کە دەڵێت «I am going to the ___». ستوونەکان: store 0.35 (درێژترین، دیارکراو)، market 0.25، university 0.15 و ستوونێکی پچڕپچڕ بۆ وشەکانی تر 0.25. تێبینییەک دەڵێت ئەگەرەکان بە ژماردنی کۆمەڵێکی گەورەی دەق خەمڵێنراون.
The three most probable next words become the keyboard's three suggestionsسێ وشەی گونجاوتر بۆ دواتر دەبنە سێ پێشنیارەکەی CêIT

The keyboard shows the three most probable words: store, market, university. All possible next words together have probability 1: the three shown cover 0.75 and the dashed bar holds the other 0.25.

سێ وشەی گونجاوتر پیشان دەدات: store، market، university. هەموو وشە گونجاوەکانی دواتر پێکەوە 1ـە: ئەو سێیەی پیشان دراون ⁦0.75⁩ دەگرنەوە و ستوونە پچڕپچڕەکە ⁦0.25⁩ـەکەی تر هەڵدەگرێت.

Quick checkپشکنینی خێراIn the same collection, I am going to the is followed by market 50 times out of 200. What is the estimated probability of market?لە هەمان کۆمەڵەدا، لە دووسەد جار پەنجا جار market دوای ⁦I am going to the⁩ هاتووە. خەمڵێنراوی market چەندە؟

Predictive text: guessing your next wordپێشبینیی دەق: مەزەندەکردنی وشەی داهاتووت

Each letter you type changes the listهەر پیتێک دەینووسیت لیستەکە دەگۆڕێت

While you type a word, the keyboard keeps only the words that start with your letters and shares the probability among them. Suppose these are the counts of first words that start with T in a collection of messages: The 120, Thanks 60, This 50, To 40, That 40, Today 35, They 30, Tomorrow 30, There 25, Thank 15, Thursday 5 (450 in all).

کاتێک وشەیەک دەنووسیت، تەنها ئەو وشانە دەهێڵێتەوە کە بە پیتەکانی تۆ دەست پێ دەکەن و لە نێوانیاندا دابەش دەکات. وا دابنێ ئەمانە ژمارەی ئەو یەکەم وشانەن کە بە T دەست پێ دەکەن لە کۆمەڵێک نامەدا: The ⁦120⁩، Thanks ⁦60⁩، This ⁦50⁩، To ⁦40⁩، That ⁦40⁩، Today ⁦35⁩، They ⁦30⁩، Tomorrow ⁦30⁩، There ⁦25⁩، Thank ⁦15⁩، Thursday 5 (کۆی گشتی ⁦450⁩).

Animation of a phone text box. With "T" typed, the suggestions are The, Thanks, This; the bars show The 0.27, Thanks 0.13, This 0.11, That 0.09; 11 words still fit. With "Th": The 0.35, Thanks 0.17, This 0.14, That 0.12; 8 words fit. With "Tha": Thanks 0.52, That 0.35, Thank 0.13; 3 words fit. With "Than": Thanks 0.80, Thank 0.20; 2 words fit. With "Thanks": Thanks 1.00; 1 word fits.
Animation of a phone text box. With "T" typed, the suggestions are The, Thanks, This; the bars show The 0.27, Thanks 0.13, This 0.11, That 0.09; 11 words still fit. With "Th": The 0.35, Thanks 0.17, This 0.14, That 0.12; 8 words fit. With "Tha": Thanks 0.52, That 0.35, Thank 0.13; 3 words fit. With "Than": Thanks 0.80, Thank 0.20; 2 words fit. With "Thanks": Thanks 1.00; 1 word fits.
Typing T, Th, Tha, Than, Thanks: the remaining words share the whole probabilityنووسینی T، Th، Tha، Than، Thanks: ئەو وشانەی دەمێننەوە هەموو لە نێوان خۆیاندا دابەش دەکەنCêIT

After Th, only 8 words remain, with 345 counts together, so P(The∣Th)=120/345≈0.35P(\text{The} \mid \text{Th}) = 120/345 \approx 0.35. After Than, only Thanks (60) and Thank (15) fit: P(Thanks∣Than)=60/75=0.80P(\text{Thanks} \mid \text{Than}) = 60/75 = 0.80. Every new letter makes the sample space smaller, exactly as in conditional probability. The owner's screenshot shows The and Thanks as the top suggestions after Th, the same two that lead here.

دوای Th تەنها هەشت وشە دەمێننەوە کە پێکەوە ⁦345⁩ جار هاتوون، بۆیە P(The∣Th)=120/345≈0.35P(\text{The} \mid \text{Th}) = 120/345 \approx 0.35. دوای Than تەنها Thanks ⁦(60)⁩ و Thank ⁦(15)⁩ دەگونجێن: P(Thanks∣Than)=60/75=0.80P(\text{Thanks} \mid \text{Than}) = 60/75 = 0.80. هەر پیتێکی نوێ بۆشایی نموونەکە بچووکتر دەکاتەوە، ڕێک وەک لە . خاوەنی سایتەکە دوای Th وشەکانی The و Thanks وەک باشترین پێشنیار پیشان دەدات، هەمان ئەو دوانەی لێرەدا لە پێشن.

Quick checkپشکنینی خێراAfter Tha, the remaining words are Thanks (60), That (40) and Thank (15). What is the probability of That?دوای Tha، ئەو وشانەی دەمێننەوە ئەمانەن: Thanks ⁦(60)⁩، That ⁦(40)⁩ و Thank ⁦(15)⁩. That چەندە؟

Predictive text: guessing your next wordپێشبینیی دەق: مەزەندەکردنی وشەی داهاتووت

Language models, small and largeمۆدێلەکانی زمان، بچووک و گەورە

Definitionپێناسە

A model that gives the probability of the next word (or of a whole sentence) from the words before it. Large ones are .

مۆدێلێکە کە ئەگەری وشەی دواتر (یان هەموو ڕستەیەک) لە وشەکانی پێشووەوە دەدات. گەورەکانیان .

The course note adds that a language model is a kind of AI made to work with natural language and to write text that sounds human. The table of next-word probabilities above is a very small language model.

تێبینییەکەی خولەکە ئەوەش دەڵێت کە جۆرێکە لە بۆ کارکردن لەگەڵ زمانی سروشتی و نووسینی دەقێک کە وەک هی مرۆڤ دەچێت. خشتەی وشەی دواتر لە سەرەوە زۆر بچووکە.

The probability of a whole sentence is built word by word: each word's probability, given the words before it, multiplied together. This is the multiplication rule written with product notation:

ڕستەیەکی تەواو وشە بە وشە دروست دەکرێت: هەر وشەیەک، بە مەرجی وشەکانی پێشووی، هەموویان لێکدەدرێن. ئەمە هەمان یاسای لێکدانی ئەگەرە کە بە نیشانەی پی نووسراوە:

P(w1w2…wn)=∏k=1nP(wk∣w1…wk−1)P(w_1 w_2 \dots w_n) = \prod_{k=1}^{n} P(w_k \mid w_1 \dots w_{k-1})
A tiny language model: count what follows "the"مۆدێلێکی زمانی بچووک: ئەوە بژمێرە کە دوای «the» دێتPYTHON
from collections import Counter

text = """i am going to the store . we are going to the market .
i am going to the store . they are going to the university .
i am going to the store now . you are going to the market ."""
words = text.split()

# count the words that come straight after "the"
after_the = Counter(words[i + 1] for i in range(len(words) - 1) if words[i] == "the")
total = sum(after_the.values())
for word, count in after_the.most_common():
    print(f"P({word} | the) = {count}/{total} = {count / total:.2f}")
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-5

Here the text is typed into the program. A real model reads millions of words from files: reading a file word by word is taught in Words, numbers and CSV tables.

لێرەدا دەقەکە لە ناو نووسراوە. ڕاستەقینە ملیۆنان وشە لە دەخوێنێتەوە: خوێندنەوەی وشە بە وشە لە وشە، ژمارە و خشتەی CSV فێر دەکرێت.

Lineدێڕی 9

Counter counts each word that comes straight after "the".

Counter هەر وشەیەک دەژمێرێت کە ڕاستەوخۆ دوای «the» دێت.

Lineدێڕی 11-12

Each count divided by the total is an estimated conditional probability.

هەر ژمارەیەک دابەش بە کۆکە خەمڵێنراوە.

Real keyboards learn from far more text, and newer ones use neural networks: Apple's 2023 keyboard update, for example, uses a transformer language model for word prediction. Large language models, the engines of chatbots, are trained on huge amounts of text for one job: predict the next word (or piece of a word). They give probabilities, not certain facts, which is why a chatbot can sound sure and still be wrong. More in Neural networks, deep learning and generative AI and Natural language processing in your pocket.

ڕاستەقینە لە دەقێکی زۆر زیاتر فێر دەبن و نوێترەکانیان بەکار دەهێنن: بۆ نموونە نوێکردنەوەی Apple لە ⁦2023⁩ـدا بۆ پێشبینیی وشە بەکار دەهێنێت. ، کە بزوێنەری ، لەسەر بڕێکی زۆر زۆری دەق بۆ یەک کار ڕاهێنراون: پێشبینیی وشەی دواتر (یان پارچەیەکی وشە). ئەوان دەدەن، نەک ڕاستیی دڵنیا؛ بۆیە دەکرێت دڵنیا دیار بێت و هێشتا هەڵە بێت. زیاتر لە تۆڕە دەمارییەکان، فێربوونی قووڵ و ژیریی دەستکردی بەرهەمهێنەر و چارەسەرکردنی زمانی سروشتی لە گیرفانتدا.

Quick checkپشکنینی خێراWhat does a large language model learn to do during training? لە کاتی ڕاهێناندا فێری چی دەبێت؟

Large Language Models explained briefly3Blue1Brown · Englishئینگلیزی · 8.1M viewsبینین · 202K likesلایک

See how a modern AI chatbot writes its answer by predicting the next word again and again.

ببینە نوێی چۆن وەڵامەکەی دەنووسێت: جار لە دوای جار پێشبینیی وشەی داهاتوو دەکات.

Whole video (8 minutes): next-word probabilities, training, and transformers, made for the Computer History Museum.

هەموو ڤیدیۆکە (⁦8⁩ خولەک): وشەی داهاتوو، ڕاهێنان و ؛ بۆ ⁦Computer History Museum⁩ دروست کراوە.

Probability across computer scienceبەکارهێنانی ئەگەر لە سەرانسەری زانستی کۆمپیوتەردا

The course notes list six fields of computer science where probability is a working tool. The tables keep each field's job and add one example you already know or will meet soon. Here are the first three; the other three come after a closer look at cryptography.

تێبینییەکانی خولەکە شەش بواری زانستی دەژمێرن کە تێیاندا ئامرازێکی کارە. خشتەکان کاری هەر بوارێک دەهێڵنەوە و نموونەیەک زیاد دەکەن کە پێشتر دەیناسیت یان بەم زووانە دەیبینیت. ئەمە سێ بواری یەکەمن؛ سێیەکەی تر دوای سەیرکردنێکی وردتری دێن.

FieldبوارWhat probability does thereڕۆڵی لەو بوارەداExampleنموونە
Machine learningبواری Models uncertainty and learns from incomplete or noisy data (how a model learns from examples), for example with Bayesian networks and hidden Markov models.نادڵنیایی مۆدێل دەکات و لە ناتەواو یان ژاوەژاویدار فێر دەبێت (فێربوونی ئامێر چۆن لە نموونەکانەوە فێر دەبێت)، بۆ نموونە بە و .A spam filter weighs the words of an email.فلتەری سپام وشەکانی ئیمەیڵێک دەکێشێت.
Artificial intelligenceبواری Reasons and decides under uncertainty, in language processing and in computer vision. The notes call probability "the heart of AI".لە بارودۆخی نادڵنیادا بیر دەکاتەوە و بڕیار دەدات، لە و ناسینەوەی وێنەدا. تێبینییەکان بە «دڵی » ناو دەبەن.Speech recognition and predictive text, earlier in this lesson. و ، لە پێشتری ئەم وانەیەدا.
Cryptographyبواری Measures how likely an attacker is to guess or break a secret, to analyse protocols and design new ones that resist attacks.دەپێوێت هێرشبەر چەندە هەیە نهێنییەک مەزەندە بکات یان بیشکێنێت، بۆ شیکردنەوەی پرۆتۆکۆلەکان و دیزاینی پرۆتۆکۆلی نوێی بەرگەگر.Guessing a random 128-bit key: 1/21281/2^{128} per try.مەزەندەکردنی هەڕەمەکیی ⁦128⁩ : 1/21281/2^{128} بۆ هەر هەوڵێک.
Quick checkپشکنینی خێراWhy does cryptography need probability?بۆچی پێویستی بە هەیە؟

Probability across computer scienceبەکارهێنانی ئەگەر لە سەرانسەری زانستی کۆمپیوتەردا

Cryptography: making a guess hopelessکریپتۆگرافی: بێهیواکردنی مەزەندە

Encryption is only as strong as its key. A 128-bit key is one of 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38} possible keys: two choices for each of the 128 bits, by the multiplication principle. If it is chosen at random, with every key equally likely, one guess is right with probability 1/2128≈2.9×10−391/2^{128} \approx 2.9 \times 10^{-39}.

تەنها هێندەی بەهێزە. ⁦128⁩ یەکێکە لە 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38} گونجاو: بۆ هەر یەکێک لە ⁦128⁩ دوو هەڵبژاردن، بەپێی یاسای بنەڕەتی ژماردن. گەر بە هەڕەمەکی هەڵبژێردرێت و هەموو یەکسان لە ئەگەردا بن، ڕاستبوونی یەک مەزەندە 1/2128≈2.9×10−391/2^{128} \approx 2.9 \times 10^{-39}ـە.

An attacker who tries keys one by one finds the right key, on average, halfway through: after about 21272^{127} tries (an expected value). Even at a million million (101210^{12}) tries per second:

هێرشبەرێک کە یەک بە یەک تاقی دەکاتەوە، بە تێکڕا لە نیوەی ڕێگادا کلیلە ڕاستەکە دەدۆزێتەوە: دوای نزیکەی 21272^{127} هەوڵ (نرخی پێشبینیکراو). تەنانەت بە ملیۆن ملیۆن (101210^{12}) هەوڵ لە چرکەیەکدا:

21271012 s≈1.7×1026 s≈5.4×1018 years\frac{2^{127}}{10^{12}} \text{ s} \approx 1.7 \times 10^{26} \text{ s} \approx 5.4 \times 10^{18} \text{ years}

That is hundreds of millions of times the age of the universe (about 1.4×10101.4 \times 10^{10} years).

ئەمە سەدان ملیۆن هێندەی تەمەنی گەردوونە (نزیکەی 1.4×10101.4 \times 10^{10} ساڵ).

There is one condition: the key must really be random. A key made by a predictable generator can be guessed in a few thousand tries, as the last part of this lesson shows. Keys, ciphers and encryption are taught in Symmetric encryption: one shared key.

یەک مەرج هەیە: دەبێت بەڕاستی هەڕەمەکی بێت. کە بەرهەمهێنەرێکی پێشبینیکراو دروستی کردبێت، بە چەند هەزار هەوڵێک مەزەندە دەکرێت، وەک بەشی کۆتایی ئەم وانەیە نیشانی دەدات. ، و لە شفرەکردنی هاوچەشن: یەک کلیلی شفرەکردنی هاوبەش فێر دەکرێن.

Quick checkپشکنینی خێراA 4-digit PIN (0000–9999) is chosen at random. What is the probability that a thief's single guess is right?کۆدێکی نهێنیی PIN بە چوار ژمارە ⁦(0000–9999)⁩ بە هەڕەمەکی هەڵدەبژێردرێت. ئەوە چەندە کە یەک مەزەندەی دزێک ڕاست بێت؟

Probability across computer scienceبەکارهێنانی ئەگەر لە سەرانسەری زانستی کۆمپیوتەردا

Three more fields: algorithms, queues and gamesسێ بواری تر: ئەلگۆریزمەکان، ڕیزی چاوەڕوانی و یاری

The other three fields use chance on purpose, or because customers and players are unpredictable.

سێ بوارەکەی تر یان ڕێکەوت بە مەبەست بەکار دەهێنن، یان پێویستیان پێیەتی چونکە ڕەفتاری کڕیار و یاریزان پێشبینی ناکرێت.

FieldبوارWhat probability does thereڕۆڵی لەو بوارەداExampleنموونە
Randomized algorithmsبواری Algorithms that make random choices, to be faster on average or to solve problems that are hard to solve without chance; probability measures how well they do. کە هەڵبژاردنی هەڕەمەکی دەکەن، بۆ ئەوەی بە تێکڕا خێراتر بن یان کێشەیەک چارەسەر بکەن کە بێ ڕێکەوت قورسە؛ بە دەپێورێت چەندە باش کار دەکەن.Quicksort with a random pivot avoids its slowest case (compare slow and fast sorting); a hash table spreads keys over its slots almost like random throws; the Monte Carlo method below. quicksort بە تەوەرێکی هەڕەمەکی لە خاوترین بارەکەی دوور دەکەوێتەوە (ڕیزکردنی خاو و خێرا بەراورد بکە)؛ خشتەیەکی هاش بە شێوەیەکی نزیک لە هەڕەمەکی بەسەر شوێنەکانیدا بڵاو دەکاتەوە؛ لە خوارەوە.
Queueing theoryبواری Models waiting lines where customers or requests arrive at random times, such as computer networks and call centres.ڕیزی چاوەڕوانی مۆدێل دەکات کە کڕیار یان داواکاری لە کاتی هەڕەمەکیدا دێن، وەک تۆڕی و ناوەندی پەیوەندی.How many servers a website needs so that users rarely wait; the field began with telephone calls in Copenhagen in 1909.ماڵپەڕێک چەند پێویستە بۆ ئەوەی بەکارهێنەران کەم چاوەڕێ بکەن؛ ئەم بوارە لە ⁦1909⁩ـدا بە پەیوەندیی تەلەفۆن لە کۆپنهاگن دەستی پێکرد.
Game theoryبواری Studies situations where the result depends on several players' choices and on chance.ئەو بارودۆخانە دەخوێنێت کە ئەنجامەکەیان پشت بە هەڵبژاردنی چەند یاریزانێک و بە ڕێکەوت دەبەستێت.A penalty kick: a kicker who always shoots to the same side is easy to stop, so the best plan is to choose sides at random with fixed probabilities.لێدانی پەنالتی: یاریزانێک کە هەمیشە بۆ هەمان لا لێدەدات ئاسان دەگیرێت، بۆیە باشترین پلان هەڵبژاردنی لایە بە هەڕەمەکی بە جێگیر.

In short, probability is how computer science designs and analyses algorithms, reasons under uncertainty and predicts from data.

بە کورتی، زانستی بە دیزاین و شی دەکاتەوە، لە نادڵنیاییدا بیر دەکاتەوە و لە پێشبینی دەکات.

Quick checkپشکنینی خێراA company wants to know how many support staff it needs so that callers rarely wait more than two minutes. Which field helps most?کۆمپانیایەک دەیەوێت بزانێت چەند کارمەندی پشتگیریی پێویستە بۆ ئەوەی پەیوەندیکەران کەم جار زیاتر لە دوو خولەک چاوەڕێ بکەن. کام بوار زیاتر یارمەتی دەدات؟

Earthquakes: probabilities of shaking, not datesبوومەلەرزە: ئەگەری لەرزین، نەک بەروار

The Kurdistan Region lies in the Zagros mountains, one of the world's active earthquake belts. On 12 November 2017 a magnitude 7.3 earthquake struck 29 km south of Halabja, near the Iran–Iraq border, and was felt across the region. Nobody can stop earthquakes, but engineers can design buildings to survive them, and for that they need probability.

هەرێمی کوردستان دەکەوێتە ناو چیاکانی زاگرۆسەوە، کە یەکێکە لە پشتێنە چالاکەکانی بوومەلەرزە لە جیهاندا. لە ⁦12⁩ی تشرینی دووەمی ⁦2017⁩ بوومەلەرزەیەک بە گەورەیی ⁦7.3⁩ لە ⁦29⁩ کیلۆمەتری باشووری هەڵەبجە، نزیک سنووری ئێران و عێراق، ڕوویدا و لە سەرانسەری ناوچەکەدا هەستی پێکرا. کەس ناتوانێت بوومەلەرزە ڕابگرێت، بەڵام ئەندازیاران دەتوانن بینا بە شێوەیەک دیزاین بکەن کە بەرگەی بگرێت. بۆ ئەمەش پێویستە.

Probabilistic seismic hazard analysis (PSHA) is the method they use. It combines the region's past earthquakes (its seismicity), geological information about faults (their shape and how active they are), the seismicity of nearby regions and other factors into one mathematical model. The model estimates the probability of different levels of ground shaking at a site, caused by earthquakes of different sizes at different distances.

⁦(PSHA)⁩ ئەو ڕێگایەیە کە بەکاری دەهێنن. بوومەلەرزەکانی ڕابردووی ناوچەکە، زانیاریی جیۆلۆجی دەربارەی شکاوییەکانی زەوی (شێوەیان و چەند چالاکن)، بوومەلەرزەکانی ناوچە نزیکەکان و هۆکاری تر لە یەک مۆدێلی بیرکاریدا کۆ دەکاتەوە. مۆدێلەکە ئاستە جیاوازەکانی لەرزینی زەوی لە شوێنێکدا دەخەمڵێنێت، کە بوومەلەرزەی قەبارە جیاواز لە دووریی جیاوازەوە دروستی دەکەن.

Quick checkپشکنینی خێراWhat does probabilistic seismic hazard analysis (PSHA) estimate for a site? بۆ شوێنێک چی دەخەمڵێنێت؟

Earthquakes: probabilities of shaking, not datesبوومەلەرزە: ئەگەری لەرزین، نەک بەروار

The hazard curve, and what it cannot doچەماوەی مەترسیی بوومەلەرزە و ئەوەی ناتوانێت بیکات

Graph for an imaginary town. Horizontal axis: ground shaking from 0 to 1.0 g. Vertical axis on a scale 0.1%, 1%, 10%, 100%: the chance of that shaking being exceeded in 50 years. The curve falls from near 100% for weak shaking to about 0.2% for very strong shaking. Two points are marked: 10% in 50 years at about 0.2 g, and 2% in 50 years, the level used for design, at about 0.38 g.هێڵکاری بۆ شارۆچکەیەکی خەیاڵی. تەوەرەی ئاسۆیی: لەرزینی زەوی لە 0 تا 1.0 g. تەوەرەی ستوونی لەسەر پێوەری 0.1%، 1%، 10%، 100%: ئەگەری تێپەڕاندنی ئەو لەرزینە لە پەنجا ساڵدا. چەماوەکە لە نزیکەی 100% بۆ لەرزینی لاواز دادەبەزێت بۆ نزیکەی 0.2% بۆ لەرزینی زۆر بەهێز. دوو خاڵ دیاری کراون: دە لە سەد لە پەنجا ساڵدا لە نزیکەی 0.2 g، هەروەها دوو لە سەد لە پەنجا ساڵدا، کە ئاستی دیزاینە، لە نزیکەی 0.38 g.
A seismic hazard curve: the stronger the shaking, the smaller its probability: لەرزین هەتا بەهێزتر بێت، بچووکترەCêIT

The result is a seismic hazard curve: for each level of shaking, the probability that it is exceeded at that place within a time period, such as 50 years. Engineers use it to design buildings, bridges and other structures that can withstand earthquakes. Building codes often design for the shaking that has a 2% probability of being exceeded in 50 years; the hazard maps of the United States Geological Survey (USGS) show exactly this.

ئەنجامەکە : بۆ هەر ئاستێکی لەرزین، ئەوەی لەو شوێنەدا لە ماوەیەکی دیاریکراودا، وەک پەنجا ساڵ، تێپەڕێت. ئەندازیاران بۆ دیزاینی بینا، پرد و پێکهاتەی تر بەکاری دەهێنن کە بەرگەی بوومەلەرزە بگرن. یاساکانی بیناسازی زۆرجار بۆ ئەو لەرزینە دیزاین دەکەن کە تێپەڕاندنی لە پەنجا ساڵدا دوو لە سەدە؛ نەخشەکانی مەترسیی ڕێکخراوی ڕووپێوی جیۆلۆجیی ئەمریکا ⁦(USGS)⁩ ڕێک ئەمە نیشان دەدەن.

Quick checkپشکنینی خێراA hazard map says a city has a 2% probability of strong shaking in the next 50 years. What does this tell you?نەخشەیەکی مەترسی دەڵێت شارێک دوو لە سەدی لەرزینی بەهێزی لە پەنجا ساڵی داهاتوودا هەیە. ئەمە چیت پێ دەڵێت؟

Earthquakes: probabilities of shaking, not datesبوومەلەرزە: ئەگەری لەرزین، نەک بەروار

What does "2% in 50 years" mean?«دوو لە سەد لە پەنجا ساڵدا» واتای چییە؟

Suppose each year has the same small probability pp that the shaking goes above the design level, and years are independent. "At least once in 50 years" is the complement of "not in any of the 50 years":

وا دابنێ هەر ساڵێک هەمان بچووکی ppی هەیە کە لەرزین لە ئاستی دیزاین تێپەڕێت و ساڵەکان سەربەخۆن. «لانیکەم جارێک لە پەنجا ساڵدا» ڕووداوی تەواوکەری «لە هیچ یەکێک لە پەنجا ساڵەکەدا نا»یە:

1−(1−p)50=0.02(1−p)50=0.981−p=0.981/50≈0.999596p≈0.000404≈12475\begin{aligned} 1 - (1 - p)^{50} &= 0.02 \\ (1 - p)^{50} &= 0.98 \\ 1 - p &= 0.98^{1/50} \approx 0.999596 \\ p &\approx 0.000404 \approx \tfrac{1}{2475} \end{aligned}

So "2% in 50 years" means about 1 chance in 2,475 in any one year. Engineers call 2,475 years the return period. In the same way, "10% in 50 years" means about 1 in 475 per year.

کەواتە «دوو لە سەد لە پەنجا ساڵدا» واتە نزیکەی یەک لە 24752475 لە هەر ساڵێکدا. ئەندازیاران 24752475 ساڵ ناو دەنێن . بە هەمان شێوە «دە لە سەد لە پەنجا ساڵدا» واتە نزیکەی یەک لە 475475 لە ساڵێکدا.

Quick checkپشکنینی خێراA building is designed for shaking with a 10% probability of being exceeded in 50 years. If the two 50-year periods are independent, what is the probability of exceeding it at least once in 100 years?بینایەک بۆ لەرزینێک دیزاین کراوە کە تێپەڕاندنی لە پەنجا ساڵدا دە لە سەدە. گەر هەردوو ماوە پەنجا ساڵییەکە سەربەخۆ بن، لانیکەم جارێک تێپەڕاندنی لە سەد ساڵدا چەندە؟

Random numbers from a machine that follows rulesژمارە هەڕەمەکییەکان لە ئامێرێکەوە کە یاسا جێبەجێ دەکات

A computer follows its instructions exactly: the same steps always give the same result. So where do Python's random numbers come from? From a formula. The random module uses a pseudo-random number generator called the Mersenne Twister. Starting from a number called the seed, it produces a long sequence that looks random and passes statistical tests, and only repeats after 219937−12^{19937} - 1 numbers. random.random() returns a number from 0 up to (not including) 1, in the interval [0,1)[0, 1), with every part of that interval equally likely (a uniform distribution).

ڕێنماییەکانی بە وردی جێبەجێ دەکات: هەمان هەنگاو هەمیشە هەمان ئەنجام دەدات. کەواتە Python لە کوێوە دێن؟ لە هاوکێشەیەکەوە. random بەرهەمهێنەری بەکار دەهێنێت کە ناوی ⁦Mersenne Twister⁩ـە. لە ژمارەیەکەوە دەست پێ دەکات کە پێی دەگوترێت ، زنجیرەیەکی درێژ بەرهەم دەهێنێت کە هەڕەمەکی دیارە و لە تاقیکردنەوە ئامارییەکان دەردەچێت و تەنها دوای 219937−12^{19937} - 1 ژمارە دووبارە دەبێتەوە. random.random() ژمارەیەک لە [0,1)[0, 1)ـدا دەگەڕێنێتەوە، واتە لە 0 تا 1 بەبێ خودی 1. هەموو بەشێکی ئەو هەمان هەیە (دابەشبوونی یەکنەواخت).

A very long book of random digitsکتێبێکی زۆر درێژی ژمارە

Think of a book with millions of pages of random-looking digits, sold in every bazaar. The seed tells you which page to start on. Two people who start on the same page read the same "random" digits: perfect for repeating an experiment or finding a bug. But anyone who learns your page can read ahead of you.

کتێبێک بهێنە پێش چاوت کە ملیۆنان پەڕە ژمارەی تێدایە کە هەڕەمەکی دیارن و لە هەموو بازاڕێک دەفرۆشرێت. پێت دەڵێت لە کام پەڕەوە دەست پێ بکەیت. دوو کەس کە لە هەمان پەڕەوە دەست پێ دەکەن هەمان ژمارە «هەڕەمەکی»ـیەکان دەخوێننەوە: نایابە بۆ دووبارەکردنەوەی تاقیکردنەوەیەک یان دۆزینەوەی هەڵەیەک. بەڵام هەر کەسێک پەڕەکەت بزانێت دەتوانێت پێش تۆ بخوێنێتەوە.

Where the analogy stops workingسنووری ئەم نموونەیە

The generator does not store a book; it computes each number from the previous state, and its "book" is far too long to read to the end.

بەرهەمهێنەرەکە کتێب هەڵناگرێت؛ هەر ژمارەیەک لە دۆخی پێشووەوە حیساب دەکات. ئەو «کتێبە»ش هێندە درێژە کە هەرگیز ناگەیتە کۆتاییەکەی.

Quick checkپشکنینی خێراWhat does random.seed(7) at the start of a program do?random.seed(7) لە سەرەتای چی دەکات؟

how does “random” work?Low Level · Englishئینگلیزی · 83K viewsبینین · 4.2K likesلایک

A random number generator is a formula started from a seed: the same seed gives the same numbers, so security needs a secure generator.

دروستکەری کە لە دەست پێدەکات: هەمان هەمان ژمارەکان دەدات، بۆیە پێویستی بە دروستکەرێکی پارێزراو هەیە.

Whole video (5 minutes): what an RNG is, seeding (1:49), why rand() is predictable, and a secure generator (OpenSSL, 3:53).

هەموو ڤیدیۆکە (⁦5⁩ خولەک): دروستکەری چییە، دانانی ⁦(1:49)⁩، بۆچی rand() پێشبینی دەکرێت، هەروەها دروستکەرێکی پارێزراو (OpenSSL، ⁦3:53⁩).

Random numbers from a machine that follows rulesژمارە هەڕەمەکییەکان لە ئامێرێکەوە کە یاسا جێبەجێ دەکات

Monte Carlo: estimating π with random pointsڕێگای مۆنتی کارلۆ: خەمڵاندنی π بە خاڵی هەڕەمەکی

You already used random to toss a coin 1,000 times; its everyday tools are in The random module.

پێشتر randomـت بۆ هەڵدانی دراوێک هەزار جار بەکار هێنا؛ ئامرازە ڕۆژانەکانی لە مۆدیوڵی random دەناسیت.

Here is a surprising use of chance: computing a number that has nothing random about it. Pick a point at random in a 1×11 \times 1 square, with both coordinates from random.random(). The quarter circle of radius 1 covers π/4\pi/4 of the square's area, so the probability that the point lands inside it is π/4\pi/4. By the law of large numbers, the share of points inside settles near π/4\pi/4, and four times that share settles near π.

ئەمە بەکارهێنانێکی سەرسوڕهێنەری ڕێکەوتە: حیسابکردنی ژمارەیەک کە هیچ شتێکی هەڕەمەکیی تێدا نییە. خاڵێک بە هەڕەمەکی لە چوارگۆشەیەکی 1×11 \times 1ـدا هەڵبژێرە، هەردوو ڕێکخەرەکەی لە random.random()ـەوە. چارەکە بازنەی نیوەتیرە 1 π/4\pi/4ی ڕووبەری چوارگۆشەکە دادەپۆشێت، بۆیە کەوتنی خاڵەکە لە ناویدا π/4\pi/4ـە. بەپێی یاسای ژمارە گەورەکان، بەشی ئەو خاڵانەی دەکەونە ناوەوە لە نزیک π/4\pi/4 دەگیرسێتەوە و چوار هێندەی ئەو بەشە لە نزیک π.

P(x2+y2≤1)=π/41=π4⟹π≈4×points insideall pointsP(x^2 + y^2 \le 1) = \frac{\pi/4}{1} = \frac{\pi}{4} \quad\Longrightarrow\quad \pi \approx 4 \times \frac{\text{points inside}}{\text{all points}}
Animation: random points fill a square that contains a shaded quarter circle. Points inside the quarter circle are green, points outside are orange. A panel shows the count and the estimate: 10 points, 9 inside, 4 × 9 / 10 = 3.600; 100 points, 79 inside, 3.160; 500 points, 396 inside, 3.168; 1,000 points, 788 inside, 3.152; 2,000 points, 1,571 inside, 3.142. Under it: π = 3.14159…
Animation: random points fill a square that contains a shaded quarter circle. Points inside the quarter circle are green, points outside are orange. A panel shows the count and the estimate: 10 points, 9 inside, 4 × 9 / 10 = 3.600; 100 points, 79 inside, 3.160; 500 points, 396 inside, 3.168; 1,000 points, 788 inside, 3.152; 2,000 points, 1,571 inside, 3.142. Under it: π = 3.14159…
A seeded run of 2,000 random points: the estimate wobbles, then settles near πجێبەجێکردنێکی ⁦2,000⁩ خاڵی هەڕەمەکی بە جێگیر: خەمڵاندنەکە دەلەرێتەوە، پاشان لە نزیک π دەگیرسێتەوەCêIT

This is the Monte Carlo method: answer a question by repeating a random experiment many times and counting. It was named in the 1940s by scientists at Los Alamos (Stanisław Ulam, John von Neumann and Nicholas Metropolis), after the famous casino in Monaco, and today it is used for risk in engineering and finance, for physics and for game-playing AI.

ئەمە ـە: وەڵامدانەوەی پرسیارێک بە دووبارەکردنەوەی بۆ زۆر جار و ژماردن. لە ساڵانی چلەکاندا زانایانی لۆس ئەلامۆس (ستانیسواڤ ئولام، جۆن ڤۆن نۆیمان و نیکۆلاس مێترۆپۆلیس) ئەم ناوەیان لێنا، بە ناوی یانە بەناوبانگەکەی قوماری مۆناکۆ. ئەمڕۆ بۆ لە ئەندازیاری و دارایی، بۆ فیزیا و بۆ یاریکردن بەکار دێت.

Quick checkپشکنینی خێراIn a run, 1,571 of 2,000 random points land inside the quarter circle. What is the estimate of π?لە جێبەجێکردنێکدا، ⁦1,571⁩ لە ⁦2,000⁩ خاڵی هەڕەمەکی دەکەونە ناو چارەکە بازنەکەوە. خەمڵاندنی π چەندە؟

Random numbers from a machine that follows rulesژمارە هەڕەمەکییەکان لە ئامێرێکەوە کە یاسا جێبەجێ دەکات

The π experiment in Pythonتاقیکردنەوەی π لە Pythonـدا

Estimate π with 100,000 random pointsπ بە 100 000100\,000 خاڵی هەڕەمەکی بخەمڵێنەPYTHON
import random

random.seed(7)                      # fixed seed: the same points on every run
inside = 0
for n in range(1, 100_001):
    x = random.random()             # a number from 0 up to (not including) 1
    y = random.random()
    if x * x + y * y <= 1:          # inside the quarter circle of radius 1
        inside += 1
    if n in (100, 1_000, 10_000, 100_000):
        print(f"{n:>7} points: {inside:>6} inside, pi is about {4 * inside / n:.4f}")
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

The fixed seed makes your run print exactly these numbers. Remove the line to get a new experiment each time.

جێگیر وا دەکات جێبەجێکردنەکەت ڕێک ئەم ژمارانە چاپ بکات. ئەم دێڕە لاببە بۆ ئەوەی هەر جارە تاقیکردنەوەیەکی نوێ بکەیت.

Lineدێڕی 7

A point is inside the quarter circle when its distance from the corner is at most 1, that is x2+y2≤1x^2 + y^2 \le 1.

خاڵێک لە ناو چارەکە بازنەکەدایە کاتێک دووریی لە گۆشەکەوە لە 1 زیاتر نەبێت، واتە x2+y2≤1x^2 + y^2 \le 1.

Lineدێڕی 10

The estimate after 100, 1,000, 10,000 and 100,000 points.

خەمڵاندنەکە دوای ⁦100⁩، ⁦1,000⁩، ⁦10,000⁩ و ⁦100,000⁩ خاڵ.

With 100 points the estimate is off by about 0.02; with 100,000 points it is off by less than 0.001. The error of a Monte Carlo estimate shrinks roughly like 1/n1/\sqrt{n}: to make it 10 times smaller you need about 100 times as many points. Your own run without a seed gives different numbers, but the same pattern.

بە ⁦100⁩ خاڵ خەمڵاندنەکە نزیکەی ⁦0.02⁩ هەڵەیە؛ بە 100 000100\,000 خاڵ کەمتر لە ⁦0.001⁩ هەڵەیە. هەڵەی خەمڵاندنی بە نزیکەیی وەک 1/n1/\sqrt{n} بچووک دەبێتەوە: بۆ ئەوەی دە جار بچووکتر بێت، نزیکەی سەد هێندە خاڵت پێویستە. جێبەجێکردنی خۆت بێ ژمارەی جیاواز دەدات، بەڵام هەمان شێوە.

Quick checkپشکنینی خێراA Monte Carlo estimate with 10,000 points is typically off by about 0.016. About how many points do you need to make the typical error 10 times smaller?خەمڵاندنێکی بە ⁦10,000⁩ خاڵ بە شێوەیەکی ئاسایی نزیکەی ⁦0.016⁩ هەڵەیە. نزیکەی چەند خاڵت پێویستە بۆ ئەوەی هەڵە ئاساییەکە دە جار بچووکتر بێت؟

Random numbers from a machine that follows rulesژمارە هەڕەمەکییەکان لە ئامێرێکەوە کە یاسا جێبەجێ دەکات

When chance must stay secretکاتێک ڕێکەوت دەبێت نهێنی بمێنێتەوە

For a simulation, a repeatable "random" sequence is a gift. For security it is a disaster. Imagine a server that makes 6-digit login codes with random, seeded with the clock: the number of the current second. An attacker who knows the code was made in the last hour only has to try 3,601 seeds:

بۆ ، زنجیرەیەکی «هەڕەمەکی»ی دووبارەکراو دیارییە. بۆ کارەساتە. بهێنە پێش چاوت کە کۆدی چوونەژوورەوەی شەش ژمارەیی بە random دروست دەکات و کاتژمێرەکەیە: ژمارەی چرکەی ئێستا. هێرشبەرێک کە دەزانێت کۆدەکە لە دوایین کاتژمێردا دروست کراوە، تەنها پێویستە ⁦3,601⁩ تاقی بکاتەوە:

Why a clock seed is dangerousبۆچی تۆوی هەڕەمەکیی کاتژمێر مەترسیدارەPYTHON
import random

made_at = 1_761_300_000          # the second (Unix time) when the server made the code
random.seed(made_at)             # BAD: the seed is just the clock
code = random.randint(100000, 999999)

# An attacker knows the code was made during the last hour: only 3,601 possible seeds.
tries = 0
for guess in range(made_at - 3600, made_at + 1):
    tries += 1
    random.seed(guess)
    if random.randint(100000, 999999) == code:
        print("seed found after", tries, "tries; the code is", code)
        break
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

BAD: the seed is just the time, so it can be guessed.

خراپ: تەنها کاتەکەیە، بۆیە مەزەندە دەکرێت.

Lineدێڕی 8-14

The attacker repeats the server's steps for every possible second until the same code comes out.

هێرشبەر هەنگاوەکانی بۆ هەموو چرکەیەکی گونجاو دووبارە دەکاتەوە تا هەمان کۆد دەردەچێت.

A random guess at a 6-digit code (100000 to 999999) is right with probability 1/900 0001/900\,000. Knowing the seed rule turns that into certainty after at most 3,601 tries. Python's documentation says it plainly: the generators in random should not be used for security; use the secrets module, which draws on the most secure randomness the operating system provides. There is no seed to guess:

مەزەندەیەکی هەڕەمەکی بۆ کۆدێکی شەش ژمارەیی (⁦100000⁩ تا ⁦999999⁩) بە 1/900 0001/900\,000 ڕاستە. زانینی یاسای ئەمە دوای لانیزۆر ⁦3,601⁩ هەوڵ دەکات بە دڵنیایی. بەڵگەنامەکانی Python بە ڕوونی دەیڵێن: نابێت بەرهەمهێنەرەکانی random بۆ بەکار بهێنرێن؛ secrets بەکار بهێنە، کە لە پارێزراوترین سەرچاوەی ڕێکەوتی وەردەگرێت. هیچ نییە بۆ مەزەندەکردن:

A login code from secretsکۆدی چوونەژوورەوە لە secretsـەوەPYTHON
import secrets

code = secrets.randbelow(900000) + 100000   # 100000 ... 999999, from the operating system
print("login code:", code)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

randbelow(900000) gives 0 to 899999; adding 100000 gives a 6-digit code. Your output is different on every run.

randbelow(900000) ژمارەیەک لە 0 تا ⁦899999⁩ دەدات؛ زیادکردنی ⁦100000⁩ کۆدێکی شەش ژمارەیی دەدات. لە هەر جێبەجێکردنێکدا جیاوازە.

The same rule protects every password, reset link and token: an attacker's chance must stay as small as the counting says. Why a password must be random, not only long, is taught in Long is not enough: it must be random; the full random and secrets toolbox is in the Python track, random is not for passwords: secrets.

هەمان یاسا هەموو ، گۆڕینەوە و نیشانەیەکی ئاسایش دەپارێزێت: هێرشبەر دەبێت هێندە بچووک بمێنێتەوە کە ژماردنەکە دەڵێت. بۆچی دەبێت هەڕەمەکی بێت، نەک تەنها درێژ، لە درێژی بەس نییە: دەبێت هەڕەمەکی بێت فێر دەکرێت؛ هەموو ئامرازەکانی random و secrets لە بەشی Pythonـدان، random بۆ تێپەڕەوشە نییە: secrets.

Quick checkپشکنینی خێراA website needs a random link for resetting forgotten passwords. Which choice is safe?ماڵپەڕێک هەڕەمەکیی پێویستە بۆ گۆڕینی لەبیرچوو. کام هەڵبژاردن پارێزراوە؟

Common mistakesهەڵە باوەکان

  • "The phone knows what I said." It only computes the most probable text. When two texts sound alike, it can choose the wrong one.
  • Confusing P(word)P(\text{word}) with P(word∣context)P(\text{word} \mid \text{context}). store is not a common word overall, but after I am going to the it is the most probable one.
  • Thinking a hazard map gives the date of the next earthquake. It gives probabilities of shaking over a period; nobody can predict the day.
  • Reading "once in 2,475 years" as "safe for a long time". The probability is the same every year.
  • Adding probabilities of "at least once". For two independent 50-year periods at 10%, the answer is 1−0.92=0.191 - 0.9^2 = 0.19, not 0.20.
  • Thinking a seed makes numbers "more random". A seed makes them repeatable.
  • Using random for passwords, codes or keys. Use secrets.
  • «مۆبایلەکە دەزانێت چیم گوت.» تەنها گونجاوترین دەق حیساب دەکات. کاتێک دوو دەق دەنگیان لە یەک دەچێت، دەکرێت هەڵەکەیان هەڵبژێرێت.
  • تێکەڵکردنی P(word)P(\text{word}) لەگەڵ P(word∣context)P(\text{word} \mid \text{context}). store بە گشتی وشەیەکی زۆر باو نییە، بەڵام دوای ⁦I am going to the⁩ گونجاوترینە.
  • وابزانیت نەخشەی مەترسی بەرواری بوومەلەرزەی داهاتوو دەدات. لەرزین بۆ ماوەیەک دەدات؛ کەس ناتوانێت ڕۆژەکە پێشبینی بکات.
  • خوێندنەوەی «جارێک لە 24752475 ساڵدا» وەک «بۆ ماوەیەکی درێژ سەلامەت». هەموو ساڵێک وەک یەکە.
  • کۆکردنەوەی «لانیکەم جارێک». بۆ دوو ماوەی پەنجا ساڵیی سەربەخۆ بە دە لە سەد، وەڵامەکە 1−0.92=0.191 - 0.9^2 = 0.19ـە، نەک ⁦0.20⁩.
  • وابزانیت ژمارەکان «هەڕەمەکیتر» دەکات. دووبارەکراویان دەکات.
  • بەکارهێنانی random بۆ ، کۆد یان . secrets بەکار بهێنە.
Quick checkپشکنینی خێراA student says: "The keyboard suggested store, so store is the most common word in English." What is wrong?قوتابییەک دەڵێت: « storeی پێشنیار کرد، کەواتە store باوترین وشەی ئینگلیزییە.» چی هەڵەیە؟

Exercisesڕاهێنانەکان

Exerciseڕاهێنان1. Suggestions after "see you"1. پێشنیارەکان دوای «⁦see you⁩»

In 100 messages, see you was followed by tomorrow 40 times, soon 25, later 15, there 10, Saturday 6 and Sunday 4. (a) Give the probability of each word. (b) Which three words does the keyboard suggest? (c) The user types the letter s. Which words still fit, and what are their new probabilities?

لە ⁦100⁩ نامەدا، دوای ⁦see you⁩ وشەی tomorrow ⁦40⁩ جار هات، soon ⁦25⁩، later ⁦15⁩، there ⁦10⁩، Saturday 6 و Sunday 4. (أ) هەر وشەیەک بدۆزەرەوە. (ب) کام سێ وشە پێشنیار دەکات؟ (ج) بەکارهێنەر پیتی s دەنووسێت. کام وشانە هێشتا دەگونجێن و نوێیەکانیان چەندن؟

Show answerوەڵامەکە پیشان بدە
  • (a) 0.40, 0.25, 0.15, 0.10, 0.06, 0.04 (they add up to 1).
  • (b) tomorrow, soon, later.
  • (c) soon, Saturday and Sunday fit, 35 messages in all: 25/35≈0.7125/35 \approx 0.71, 6/35≈0.176/35 \approx 0.17, 4/35≈0.114/35 \approx 0.11.
  • (أ) ⁦0.40⁩، ⁦0.25⁩، ⁦0.15⁩، ⁦0.10⁩، ⁦0.06⁩، ⁦0.04⁩ (کۆکەیان 1ـە).
  • (ب) tomorrow، soon، later.
  • (ج) soon، Saturday و Sunday دەگونجێن، کۆی گشتی ⁦35⁩ نامە: 25/35≈0.7125/35 \approx 0.71، 6/35≈0.176/35 \approx 0.17، 4/35≈0.114/35 \approx 0.11.
Exerciseڕاهێنان2. Which text wins?2. کام دەق دەباتەوە؟

A recogniser hears one short phrase. For recognise speech: P(sound∣W)=0.20P(\text{sound} \mid W) = 0.20, P(W)=0.0005P(W) = 0.0005. For wreck a nice beach: P(sound∣W)=0.25P(\text{sound} \mid W) = 0.25, P(W)=0.00002P(W) = 0.00002. Which text does it output, and how many times more probable is it?

سیستەمێکی ناسینەوە دەستەواژەیەکی کورت دەبیستێت. بۆ ⁦recognise speech⁩: P(sound∣W)=0.20P(\text{sound} \mid W) = 0.20، P(W)=0.0005P(W) = 0.0005. بۆ ⁦wreck a nice beach⁩: P(sound∣W)=0.25P(\text{sound} \mid W) = 0.25، P(W)=0.00002P(W) = 0.00002. کام دەق دەکاتە و چەند جار زیاترە؟

Hintئاماژە

Multiply the two probabilities for each text, then compare.

بۆ هەر دەقێک دوو لێکبدە، پاشان بەراوردیان بکە.

Show answerوەڵامەکە پیشان بدە
0.20×0.0005=0.00010.25×0.00002=0.0000050.0001/0.000005=20\begin{aligned} 0.20 \times 0.0005 &= 0.0001 \\ 0.25 \times 0.00002 &= 0.000005 \\ 0.0001 / 0.000005 &= 20 \end{aligned}

recognise speech wins: it is 20 times more probable, although wreck a nice beach matches the sound a little better.

⁦recognise speech⁩ دەباتەوە: بیست جار زیاترە، هەرچەندە ⁦wreck a nice beach⁩ کەمێک باشتر لەگەڵ دەنگەکە دەگونجێت.

Exerciseڕاهێنان3. 10% in 50 years3. دە لە سەد لە پەنجا ساڵدا

A bridge is designed for shaking with a 10% probability of being exceeded in 50 years. Assume independent years. (a) Find the probability pp for one year and the return period. (b) Find the probability that the shaking is exceeded at least once in 100 years.

پردێک بۆ لەرزینێک دیزاین کراوە کە تێپەڕاندنی لە پەنجا ساڵدا دە لە سەدە. ساڵەکان بە سەربەخۆ دابنێ. (أ) pp بۆ یەک ساڵ و بدۆزەرەوە. (ب) ئەوە بدۆزەرەوە کە لەرزینەکە لانیکەم جارێک لە سەد ساڵدا تێپەڕێت.

Show answerوەڵامەکە پیشان بدە
(1−p)50=0.90  ⇒  p=1−0.901/50≈0.0021≈1475P(at least once in 100 years)=1−0.902=0.19\begin{aligned} (1-p)^{50} &= 0.90 \;\Rightarrow\; p = 1 - 0.90^{1/50} \approx 0.0021 \approx \tfrac{1}{475} \\ P(\text{at least once in 100 years}) &= 1 - 0.90^2 = 0.19 \end{aligned}

Return period: about 475 years.

: نزیکەی 475475 ساڵ.

Exerciseڕاهێنان4. Monte Carlo by hand4. ڕێگای مۆنتی کارلۆ بە دەست

(a) 7,862 of 10,000 random points fall inside the quarter circle. Estimate π. (b) Your estimate with 10,000 points is off by about 0.003. Roughly how many points would make a typical error 10 times smaller?

(أ) ⁦7,862⁩ لە ⁦10,000⁩ خاڵی هەڕەمەکی دەکەونە ناو چارەکە بازنەکەوە. π بخەمڵێنە. (ب) خەمڵاندنەکەت بە ⁦10,000⁩ خاڵ نزیکەی ⁦0.003⁩ هەڵەیە. نزیکەی چەند خاڵ هەڵەیەکی ئاسایی دە جار بچووکتر دەکات؟

Show answerوەڵامەکە پیشان بدە
  • (a) 4×7862/10000=3.14484 \times 7862 / 10000 = 3.1448.
  • (b) About 100 times as many: 1 000 0001\,000\,000 points, because the error shrinks like 1/n1/\sqrt{n}. (One run can be luckier or unluckier than typical.)
  • (أ) خەمڵاندن: 4×7862/10000=3.14484 \times 7862 / 10000 = 3.1448.
  • (ب) نزیکەی سەد هێندە: 1 000 0001\,000\,000 خاڵ، چونکە هەڵەکە وەک 1/n1/\sqrt{n} بچووک دەبێتەوە. (یەک جێبەجێکردن دەکرێت بەختی لە ئاسایی باشتر یان خراپتر بێت.)
Exerciseڕاهێنان5. random or secrets?5. random یان secrets؟

Choose the module for each job and give the reason: (a) shuffling the questions of a practice quiz so that a teacher can reproduce the order; (b) a one-time login code sent by SMS; (c) a dice game for children; (d) a link for resetting a password. (e) What is the probability that one random guess of a 6-digit code (100000 to 999999) is right?

بۆ هەر کارێک هەڵبژێرە و هۆکارەکەی بڵێ: (أ) تێکەڵکردنی پرسیارەکانی تاقیکردنەوەیەکی ڕاهێنان بە شێوەیەک مامۆستا بتوانێت ڕیزبەندییەکە دووبارە بکاتەوە؛ (ب) کە بە SMS دەنێردرێت؛ (ج) یاریی بەردەزار بۆ منداڵان؛ (د) بۆ گۆڕینی . (هـ) ئەوە چەندە کە یەک مەزەندەی هەڕەمەکی بۆ کۆدێکی شەش ژمارەیی (⁦100000⁩ تا ⁦999999⁩) ڕاست بێت؟

Show answerوەڵامەکە پیشان بدە
  • (a) random with a fixed seed: the order must repeat.
  • (b) secrets: an attacker must not be able to predict it.
  • (c) random: nothing secret is at stake.
  • (d) secrets, for example secrets.token_urlsafe().
  • (e) 1/900 000≈0.00000111/900\,000 \approx 0.0000011.
  • (أ) random بە جێگیر: ڕیزبەندییەکە دەبێت دووبارە ببێتەوە.
  • (ب) secrets: نابێت هێرشبەر بتوانێت پێشبینیی بکات.
  • (ج) random: هیچ نهێنییەک لە مەترسیدا نییە.
  • (د) secrets، بۆ نموونە secrets.token_urlsafe().
  • (هـ) دەکاتە 1/900 000≈0.00000111/900\,000 \approx 0.0000011.
Exerciseڕاهێنان6. Which field?6. کام بوار؟

Name the field from the two tables of computer science fields: (a) a model learns to recognise handwritten digits from thousands of noisy examples; (b) an online shop works out how many checkout servers it needs on a busy day; (c) a goalkeeper and a penalty taker each choose a side; (d) a sorting program picks its pivot at random.

بوارەکە لە هەردوو خشتەی بوارەکانی زانستی ناو بنێ: (أ) لە هەزاران نموونەی ژاوەژاویدار فێری ناسینەوەی ژمارەی دەستنووس دەبێت؛ (ب) فرۆشگایەکی ئۆنلاین حیساب دەکات لە ڕۆژێکی قەرەباڵغدا چەند پارەدانی پێویستە؛ (ج) گۆڵپارێزێک و لێدەری پەنالتییەک هەر یەکەیان لایەک هەڵدەبژێرن؛ (د) تەوەرەکەی بە هەڕەمەکی هەڵدەبژێرێت.

Show answerوەڵامەکە پیشان بدە
  • (a) Machine learning.
  • (b) Queueing theory.
  • (c) Game theory.
  • (d) Randomized algorithms.
  • (أ) بواری .
  • (ب) بواری .
  • (ج) بواری .
  • (د) بواری .

Summaryپوختە

  • Speech recognition outputs the most probable text for the sound: Bayes multiplies how well a text matches the sound by how common the text is. HMMs did this from the 1980s; neural networks do it today.
  • Predictive text ranks words by the conditional probability of the next word given what you typed; each letter shrinks the list. A language model gives probabilities of word sequences.
  • Machine learning, AI, cryptography, randomized algorithms, queueing theory and game theory all depend on probability.
  • PSHA gives the probability that shaking at a place is exceeded within a period (a hazard curve); "2% in 50 years" is about 1 in 2,475 per year. It does not predict earthquakes.
  • random is pseudo-random and repeatable with a seed: good for simulations such as the Monte Carlo estimate of π. For passwords, codes and keys use secrets.
  • گونجاوترین دەق بۆ دەنگەکە دەکاتە : گونجانی دەقێک لەگەڵ دەنگەکە لە باوبوونی دەقەکە دەدات. لە هەشتاکانەوە ئەمەی دەکرد؛ ئەمڕۆ دەیکەن.
  • وشەکان بە پێی ی وشەی دواتر ڕیز دەکات، بە مەرجی ئەوەی نووسیوتە؛ هەر پیتێک لیستەکە بچووک دەکاتەوە. زنجیرەی وشە دەدات.
  • ، ، ، ، و هەموویان پشت بە دەبەستن.
  • تێپەڕاندنی لەرزین لە شوێنێکدا لە ماوەیەکدا دەدات ()؛ «دوو لە سەد لە پەنجا ساڵدا» نزیکەی یەک لە 24752475ـە لە ساڵێکدا. پێشبینیی بوومەلەرزە ناکات.
  • random نیمچەهەڕەمەکییە و بە دووبارە دەبێتەوە: باشە بۆ وەک خەمڵاندنی π بە . بۆ ، کۆد و secrets بەکار بهێنە.
Review questionsپرسیارەکانی پێداچوونەوە
Why does a keyboard's top suggestion change when you type one more letter?بۆچی باشترین پێشنیاری کیبۆرد دەگۆڕێت کاتێک پیتێکی تر دەنووسیت؟

Words that do not start with the new letters drop out, so the probability is shared among fewer words: a smaller sample space.

ئەو وشانەی بە پیتە نوێیەکان دەست پێ ناکەن دەردەچن، بۆیە لە نێوان وشەی کەمتردا دابەش دەبێت: بچووکتر.

Can PSHA tell us the year of the next big earthquake in the Zagros?دەتوانێت شیکاریی ئەگەریی مەترسیی بوومەلەرزە ساڵی بوومەلەرزە گەورەکەی داهاتووی زاگرۆسمان پێ بڵێت؟

No. It gives probabilities of shaking over a period; nobody can predict the time, place and size of a single earthquake.

نەخێر. لەرزین بۆ ماوەیەک دەدات؛ کەس ناتوانێت کات، شوێن و قەبارەی یەک بوومەلەرزە پێشبینی بکات.

Why is a fixed seed useful in the π program but dangerous in a login system?بۆچی تۆوێکی هەڕەمەکیی جێگیر بۆ بەرنامەی خەمڵاندنی π بەسوودە بەڵام لە سیستەمی چوونەژوورەوەدا مەترسیدارە؟

It makes the numbers repeat. Repeating helps you check a simulation, but it lets an attacker reproduce a secret code.

ژمارەکان دووبارە دەکاتەوە. دووبارەبوونەوە یارمەتیت دەدات بپشکنیت، بەڵام ڕێگە بە هێرشبەر دەدات کۆدێکی نهێنی دووبارە دروست بکاتەوە.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Project: Predicting a Football Match with Probabilityپرۆژە: پێشبینیکردنی یارییەکی تۆپی پێ بە ئەگەر

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.