Chapterبەش 8 · Lectureوانە 8.1
Machine Learning Basics (Supplementary)بنەماکانی فێربوونی ئامێر (زیادە)
A supplementary first look at machine learning: models learned from data, supervised, unsupervised and reinforcement learning, training, validation and test data, overfitting, and a tiny nearest-neighbour program in plain Python.
یەکەم سەیرکردنێکی زیادە بۆ : کە لە فێر دەبێت، ، و ، ، و ، و بەرنامەیەکی بچووکی بە سادە.
What you will learnچی فێر دەبیت
- Explain what machine learning is and how it differs from programs with hand-written rules.
- Tell supervised, unsupervised and reinforcement learning apart, and classification from regression.
- Explain why data is split into training, validation and test data, and what overfitting is.
- Read and run a nearest-neighbour classifier written without libraries, and measure its accuracy.
- ڕوونی بکەیتەوە چییە و چۆن لە بەرنامەی خاوەن یاسای دەستنووس جیاوازە.
- ، و لە یەکتر جیا بکەیتەوە و لە .
- ڕوونی بکەیتەوە بۆچی دابەش دەکرێت بۆ ، و و چییە.
- پۆلێنکەرێکی کە بەبێ نووسراوە بخوێنیتەوە و جێبەجێی بکەیت و وردییەکەی بپێویت.
What is machine learning?فێربوونی ئامێر چییە؟
All the AI programs in this course so far follow rules that a person wrote: search in a maze, minimax for a game, logic for a knowledge base. Machine learning works the other way round. We give the computer many examples, and it finds the rule itself. The result is called a model: a program with learned settings that makes predictions about new cases.
هەموو بەرنامەکانی لەم کۆرسەدا تا ئێستا پەیڕەوی ئەو یاسایانە دەکەن کە مرۆڤێک نووسیونی: گەڕان لە ، بۆ یاری، لۆجیک بۆ . بە پێچەوانەوە کار دەکات. نموونەی زۆر دەدەین بە کۆمپیوتەر و خۆی یاساکە دەدۆزێتەوە. ئەنجامەکە پێی دەوترێت : بەرنامەیەک بە ڕێکخستنی فێربووەوە کە پێشبینی دەربارەی حاڵەتی نوێ دەکات.
A part of in which a computer learns patterns from many examples instead of following rules that a programmer wrote. The more good it gets, the better it usually becomes.
بەشێکە لە کە تێیدا کۆمپیوتەر لە ڕێگەی نموونەی زۆرەوە شێوازەکان فێر دەبێت، لە جیاتی ئەوەی پەیڕەوی ئەو یاسایانە بکات کە نووسیونی. هەتا باشتری پێ بدرێت، زۆرجار باشتر دەبێت.
An example. In the logic lesson we wrote a rule by hand: if I study hard and get enough sleep, I will pass. A machine-learning program would not get this rule. It would get a table of past students (hours of study, hours of sleep, passed or not) and learn from it how to predict the result of a new student. This lesson ends with exactly such a program.
نموونەیەک. لە وانەی لۆجیکدا، یاسایەکمان بە دەست نووسی: ئەگەر زۆر بخوێنم و بەس بخەوم، دەردەچم. بەرنامەیەکی ئەم یاسایە وەرناگرێت. خشتەیەکی خوێندکارانی پێشوو وەردەگرێت (کاتژمێرەکانی خوێندن، کاتژمێرەکانی خەوتن، دەرچوو یان نا) و لێیەوە فێر دەبێت چۆن ئەنجامی خوێندکارێکی نوێ پێشبینی بکات. ئەم وانەیە ڕێک بە بەرنامەیەکی لەو جۆرە کۆتایی دێت.
What a machine-learning system produces from its training data: a function with learned settings that turns each new input into a prediction.
ئەوەیە کە سیستەمێکی لە بەرهەمی دەهێنێت: بە ڕێکخستنی فێربوو کە هەر نوێ دەکات بە پێشبینییەک.
The English words for this topic (data, algorithm, train, predict, chatbot…) are practised in Technical English, How machine learning learns from examples.
وشە ئینگلیزییەکانی ئەم بابەتە (data، algorithm، train، predict، chatbot…) لە ئینگلیزیی تەکنیکیدا ڕاهێنانیان لەسەر کراوە، فێربوونی ئامێر چۆن لە نموونەکانەوە فێر دەبێت.
Three kinds of machine learningسێ جۆری فێربوونی ئامێر
Machine-learning systems are usually put into three groups, by the kind of data they learn from:
سیستەمەکانی زۆرجار بەپێی جۆری ئەو لێیەوە فێر دەبن، دەخرێنە سێ گرووپەوە:
Three kinds of machine learningسێ جۆری فێربوونی ئامێر
Supervised learningفێربوونی چاودێریکراو
Machine learning from labelled examples: each training example comes with the right answer, and the model learns to predict the answer for new inputs.
لە ڕێگەی نموونەی نیشانەکراوەوە: هەر نموونەیەکی ڕاهێنان وەڵامە دروستەکەی لەگەڵدایە و فێر دەبێت وەڵام بۆ نێوخستەی نوێ پێشبینی بکات.
In supervised learning every training example comes with the answer, called the label. Think of a student who practises with last year's exam questions and checks every answer against the teacher's answer sheet: after enough practice, she can answer new questions too. There are two main tasks:
لە هەموو نموونەیەکی ڕاهێنان وەڵامەکەی لەگەڵدایە، کە پێی دەوترێت . خوێندکارێک بهێنە بەرچاوت کە بە پرسیارەکانی تاقیکردنەوەی پاری ڕاهێنان دەکات و هەموو وەڵامێکی خۆی لەگەڵ وەڵامنامەی مامۆستاکە بەراورد دەکات: دوای ڕاهێنانی پێویست، دەتوانێت وەڵامی پرسیاری نوێش بداتەوە. دوو ئەرکی سەرەکی هەیە:
- Classification: predict a category. Spam or not spam? Pass or fail? Which letter is in this picture? Many classifiers give each category a probability (What Is Probability?); a classic spam filter, naive Bayes, combines the probabilities of the words in a message.
- Regression: predict a number. The price of a flat in Sulaymaniyah from its size, or tomorrow's temperature.
- : پێشبینیی پۆلێک. یان نا؟ دەردەچێت یان نا؟ ئەم وێنەیە کام پیتە؟ زۆرێک لە پۆلێنکەرەکان دەدەن بە هەر پۆلێک (ئەگەرێتی چییە؟)؛ فلتەرێکی کلاسیکیی ، پۆلێنکەری بەیزی ساکار، وشەکانی نامەیەک پێکەوە لێک دەدات.
- : پێشبینیی ژمارەیەک. نرخی شوقەیەک لە سلێمانی بەپێی ڕووبەرەکەی، یان پلەی گەرمای سبەینێ.
Training examples that come with the correct answer (the label), such as photos tagged "cat" or "dog".
نموونەی ڕاهێنانن کە وەڵامە دروستەکەیان (نیشانەکە) لەگەڵدایە، وەک ئەو وێنانەی «پشیلە» یان «سەگ»یان لەسەر نووسراوە.
Three kinds of machine learningسێ جۆری فێربوونی ئامێر
Unsupervised learningفێربوونی چاودێرینەکراو
Machine learning from examples without answers: the model looks for structure on its own, for example groups of similar customers.
لە نموونەی بێ وەڵامەوە: بە خۆی بەدوای ڕێکخستندا دەگەڕێت، بۆ نموونە گرووپی کڕیاری لێکچوو.
Here the data has no labels. Nobody says what the right answer is; the program looks for patterns by itself. The most common task is clustering: putting similar items into groups. A shop in Erbil could cluster its customers by what they buy, and only afterwards give the groups names ("students", "families"…). Unlike classification, the groups are not decided in advance.
لێرەدا هیچ نییە. کەس ناڵێت وەڵامە دروستەکە چییە؛ بەرنامەکە خۆی بەدوای شێوازەکاندا دەگەڕێت. باوترین ئەرک ـە: خستنی شتە لێکچووەکان لە گرووپدا. دوکانێک لە هەولێر دەتوانێت کڕیارەکانی بەپێی ئەوەی دەیکڕن گرووپ بکات و تەنیا دواتر ناو لە گرووپەکان بنێت («خوێندکاران»، «خێزانەکان»…). بە پێچەوانەی ، گرووپەکان پێشتر دیاری ناکرێن.
A machine-learning task in which the model groups similar things together without being told the groups in advance.
ئەرکێکی کە تێیدا شتە لێکچووەکان پێکەوە گرووپ دەکات بەبێ ئەوەی پێشتر گرووپەکانی پێ بوترێت.
Three kinds of machine learningسێ جۆری فێربوونی ئامێر
Reinforcement learningفێربوونی بەهێزکردنەوە
Machine learning by trial and error: an agent acts, receives rewards or penalties and learns which actions bring the most reward over time.
بە تاقیکردنەوە و هەڵە: کار دەکات، یان سزا وەردەگرێت و فێر دەبێت کام کارانە بەدرێژایی کات زۆرترین پاداشت دەهێنن.
An agent acts in an environment and, after its actions, receives rewards (good result) or penalties (bad result). Nobody tells it the right action; it learns by trying. Over time it builds a policy: a strategy that says which action to take in each situation so that the total reward is as high as possible. Games and robots are typical uses: a program can learn to play tic-tac-toe well just by playing many games and getting +1 for a win and −1 for a loss.
ئەیجێنتێک لە کار دەکات و دوای (ئەنجامی باش) یان سزا (ئەنجامی خراپ) وەردەگرێت. کەس پێی ناڵێت دروست چییە؛ بە تاقیکردنەوە فێر دەبێت. بە تێپەڕبوونی کات دروست دەکات: ستراتیژێک کە دەڵێت لە هەر دۆخێکدا چ بکات بۆ ئەوەی کۆی تا بتوانێت بەرز بێت. یاری و نموونەی باون: بەرنامەیەک دەتوانێت تەنیا بە یاریکردنی زۆر و وەرگرتنی +1 بۆ بردنەوە و −1 بۆ دۆڕان، فێری یاریکردنی باشی ببێت.
In reinforcement learning, a number that the environment gives the agent after an action: positive for good results, negative for bad ones.
لە ، ژمارەیەکە کە دوای کارێک دەیداتە : موجەب بۆ ئەنجامی باش و سالب بۆ ئەنجامی خراپ.
In , the strategy that an learns: for each situation, which action to take so that the total is as high as possible.
لە ، ئەو ستراتیژەیە کە فێری دەبێت: لە هەر دۆخێکدا چ کارێک بکات بۆ ئەوەی کۆی تا بتوانێت بەرز بێت.
Training data and test dataدراوەی ڕاهێنان و دراوەی تاقیکردنەوە
How do we know that a model has really learned? We split the examples we have into separate parts:
چۆن بزانین بەڕاستی فێر بووە؟ ئەو نموونانەی هەمانە دابەش دەکەین بۆ چەند بەشێکی جیا:
- Training data: the model learns from these examples.
- Validation data: used while building the model, to compare settings or methods and choose the best one.
- Test data: kept hidden until the end; used once, to measure how well the model works on examples it has never seen.
- : لەم نموونانەوە فێر دەبێت.
- : لە کاتی دروستکردنی بەکار دێت، بۆ بەراوردکردنی ڕێکخستن یان ڕێگەکان و هەڵبژاردنی باشترینیان.
- : تا کۆتایی شاراوە دەمێنێتەوە؛ یەکجار بەکار دێت بۆ پێوانی ئەوەی چەند باش لەسەر ئەو نموونانە کار دەکات کە هەرگیز نەیبینیون.
The examples that a system learns from, for example thousands of emails that people have already marked as spam or not spam. If the training data is poor or unfair, the system's answers will be poor or unfair too.
ئەو نموونانەن کە سیستەمێکی لێیانەوە فێر دەبێت، بۆ نموونە هەزاران ئیمەیڵ کە خەڵک پێشتر نیشانەیان کردوون وەک یان نا. ئەگەر ئەو نموونانە خراپ یان نادادپەروەر بن، وەڵامەکانی سیستەمەکەش خراپ یان نادادپەروەر دەبن.
Data used only to check that something works. In machine learning, examples kept apart from training measure how well a works on cases it has never seen; in software and database testing, sample records (often invented) let you try a program, a form or a table without touching real data.
کە تەنها بۆ پشکنینی ئەوە بەکار دێت کە شتێک کار دەکات. لە فێربوونی ئامێردا، ئەو نموونانەی جیا لە ڕاهێنان ڕادەگیرێن دەپێون چەند باش لەسەر ئەو حاڵەتانە کار دەکات کە هەرگیز نەیبینیون؛ لە تاقیکردنەوەی و ، تۆماری نموونەیی (زۆرجار دەستکرد) ڕێگەت پێ دەدەن ، فۆرمێک یان خشتەیەک تاقی بکەیتەوە بێ ئەوەی دەست لە دراوەی ڕاستەقینە بدەیت.
A teacher gives homework questions to practise (training), a mid-term to see who needs help (validation), and a final exam with new questions (test). If the final exam used exactly the homework questions, a student who memorised the answers would get full marks without understanding anything.
مامۆستایەک پرسیاری ئەرکی ماڵەوە دەدات بۆ ڕاهێنان (training)، تاقیکردنەوەیەکی نیوەی ساڵ بۆ ئەوەی بزانێت کێ پێویستی بە یارمەتییە (validation) و تاقیکردنەوەیەکی کۆتایی بە پرسیاری نوێ (test). ئەگەر تاقیکردنەوەی کۆتایی ڕێک پرسیارەکانی ئەرکی ماڵەوە بوایە، خوێندکارێک کە وەڵامەکانی لەبەر کردبوو نمرەی تەواوی وەردەگرت بەبێ ئەوەی لە هیچ تێگەیشتبێت.
Where the analogy stops workingسنووری ئەم نموونەیە
A model does not "understand" like a student. It only finds patterns in numbers, and it can find wrong patterns if the training data is poor or unfair.
وەک خوێندکار «تێناگات». تەنیا شێواز لە ژمارەکاندا دەدۆزێتەوە و ئەگەر خراپ یان نادادپەروەر بێت، دەتوانێت شێوازی هەڵە بدۆزێتەوە.
Training data and test dataدراوەی ڕاهێنان و دراوەی تاقیکردنەوە
Overfittingزیادەگونجاندن
When a learns its too closely, including accidents and noise, so it does very well on those examples but badly on new data.
کاتێکە کە زۆر لە نزیکەوە فێر دەبێت، تەنانەت ڕێکەوت و ژاوەژاوەکانیشی، بۆیە لەسەر ئەو نموونانە زۆر باشە بەڵام لەسەر نوێ خراپ.
A model overfits when it learns the training data too closely, including its accidents and noise, so it does very well on the training data but badly on new data. What we really want is generalisation: good predictions for cases the model has not seen. A typical sign of overfitting: the score on the training data keeps rising while the score on the validation data falls.
کاتێک دەکات کە زۆر لە نزیکەوە فێر دەبێت، تەنانەت ڕێکەوت و ژاوەژاوەکانیشی، بۆیە لەسەر زۆر باشە بەڵام لەسەر نوێ خراپ. ئەوەی بەڕاستی دەمانەوێت گشتاندنـە: پێشبینیی باش بۆ ئەو حاڵەتانەی نەیبینیون. نیشانەیەکی باوی : نمرە لەسەر بەردەوام بەرز دەبێتەوە لە کاتێکدا نمرە لەسەر دادەبەزێت.
Training and testing data, and overfitting: a wiggly line fits the training points perfectly but predicts new points badly.
و ، هەروەها : هێڵێکی پێچاوپێچ بە تەواوی لەگەڵ خاڵەکانی ڕاهێنان دەگونجێت، بەڵام بۆ خاڵە نوێیەکان پێشبینیی خراپ دەکات.
Starts at 0:29, after the short song, to the end: split into training and test data, two models, and the definition of overfitting (5:10).
لە 0:29 دەست پێدەکات، دوای گۆرانییە کورتەکە، تا کۆتایی: دابەشکردنی بۆ و ، دوو ، هەروەها پێناسەی (5:10).
A tiny example: the nearest neighbourنموونەیەکی بچووک: نزیکترین دراوسێ
Now a complete supervised-learning program, with no libraries. Each example is a student described by two features: hours of study and hours of sleep before a quiz. The label is the result: "pass" or "fail". The numbers are invented for this lesson.
ئێستا بەرنامەیەکی تەواوی ، بەبێ هیچ . هەر نموونەیەک خوێندکارێکە کە بە دوو وەسف کراوە: کاتژمێرەکانی خوێندن و کاتژمێرەکانی خەوتن پێش کویزێک. ئەنجامەکەیە: "pass" یان "fail". ژمارەکان بۆ ئەم وانەیە دروست کراون.
One measurable input that describes an example for a , such as the hours of study of a student or the size of a flat.
یەک نێوخستەی پێوانەکراوە کە نموونەیەک بۆ وەسف دەکات، وەک کاتژمێرەکانی خوێندنی خوێندکارێک یان ڕووبەری شوقەیەک.
The method is the simplest one there is, the nearest neighbour: to predict the result of a new student, find the training example that is closest to it (the straight-line distance between the two points) and copy its label.
ڕێگەکە سادەترین ڕێگەیە کە هەیە، : بۆ پێشبینیکردنی ئەنجامی خوێندکارێکی نوێ، ئەو نموونەی ڕاهێنانە بدۆزەرەوە کە لێیەوە نزیکترە (دووریی هێڵی ڕاست لە نێوان دوو خاڵەکەدا) و وەربگرە.
A simple method: to predict the answer for a new example, find the closest known example (or the k closest, which then vote) and use its label.
ڕێگەیەکی سادەی : بۆ پێشبینیکردنی وەڵامی نموونەیەکی نوێ، نزیکترین نموونەی زانراو بدۆزەرەوە (یان k نزیکترین، کە پاشان دەنگ دەدەن) و نیشانەکەی بەکاربهێنە.
# A tiny machine-learning program: 1-nearest-neighbour, no libraries.
# Each example: (hours of study, hours of sleep) -> result of a quiz.
# The numbers are invented for this lesson.
import math
training = [
((1, 8), "fail"), ((2, 5), "fail"), ((3, 7), "fail"), ((5, 4), "fail"),
((9, 3), "fail"), ((2, 9), "fail"), ((3, 3), "fail"), ((6, 7), "pass"),
((8, 6), "pass"), ((7, 8), "pass"), ((4, 8), "pass"), ((8, 8), "pass"),
((7, 5), "pass"), ((5, 9), "pass"),
]
testing = [
((6, 8), "pass"), ((2, 6), "fail"), ((8, 4), "fail"),
((5, 7), "pass"), ((9, 6), "pass"), ((5, 5), "pass"),
]
def distance(a, b):
return math.dist(a, b) # straight-line distance
def predict(point):
nearest = min(training, key=lambda example: distance(example[0], point))
return nearest[1] # copy the label of the closest example
def accuracy(examples):
right = sum(predict(x) == label for x, label in examples)
return f"{right}/{len(examples)}"
if __name__ == "__main__":
for x, label in testing:
print(x, "-> predicted:", predict(x), "| real:", label)
print("accuracy on the training data:", accuracy(training))
print("accuracy on the test data: ", accuracy(testing))(6, 8) -> predicted: pass | real: pass (2, 6) -> predicted: fail | real: fail (8, 4) -> predicted: fail | real: fail (5, 7) -> predicted: pass | real: pass (9, 6) -> predicted: pass | real: pass (5, 5) -> predicted: fail | real: pass accuracy on the training data: 14/14 accuracy on the test data: 5/6
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 6-11
The training data: 14 labelled examples.
: 14 نموونەی نیشانەکراو.
- Lineدێڕی 12-15
The test data: 6 other examples, kept apart.
: 6 نموونەی دیکە کە جیا ڕاگیراون.
- Lineدێڕی 18-19
math.distgives the straight-line distance between two points (Python 3.8 or newer).math.distدووریی هێڵی ڕاست لە نێوان دوو خاڵدا دەدات ( 3.8 یان نوێتر).- Lineدێڕی 22-24
Learning and predicting in one step: find the closest training example and copy its label.
فێربوون و پێشبینیکردن لە یەک هەنگاودا: نزیکترین نموونەی ڕاهێنان بدۆزەرەوە و وەربگرە.
- Lineدێڕی 27-29
Accuracy: how many predictions were right.
Truecounts as 1.وردی: چەند پێشبینی ڕاست بوون.
Trueوەک 1 دەژمێردرێت.
Look at the two accuracy lines. On the training data the program is always right (14/14), but that proves nothing: each training example is its own nearest neighbour, so the program has simply memorised them. The honest measure is the test data: 5 of 6. The student who studied 5 hours and slept 5 hours passed, but the nearest known student (5, 4) failed, so the model got it wrong.
سەیری دوو دێڕەکەی وردی بکە. لەسەر بەرنامەکە هەمیشە ڕاستە (14/14)، بەڵام ئەمە هیچ ناسەلمێنێت: هەر نموونەیەکی ڕاهێنان خۆیەتی، بۆیە بەرنامەکە بە سادەیی لەبەری کردوون. پێوانە ڕاستەقینەکە : 5 لە 6. ئەو خوێندکارەی 5 کاتژمێر خوێندی و 5 کاتژمێر خەوت دەرچوو، بەڵام نزیکترین خوێندکاری زانراو (5, 4) دەرنەچووبوو، بۆیە هەڵەی کرد.
Harvard's CS50 AI lecturer explains each idea with clear pictures and Python code; each placement plays only the chapter that matches its screen.
مامۆستای کۆرسی CS50 AIـی زانکۆی Harvard هەر بیرۆکەیەک بە وێنەی ئاشکرا و کۆدی ڕوون دەکاتەوە؛ لە هەر شوێنێک تەنها ئەو بەشەی لێدەدرێت کە لەگەڵ ئەو شاشەیە دەگونجێت.
Plays 7:25:22–7:31:47: rainy and dry days on a graph (humidity, pressure), nearest-neighbour classification, then k-nearest-neighbours with a vote, and why it can be slow.
لە 7:25:22 تا 7:31:47 لێدەدرێت: ڕۆژانی بارانی و وشک لەسەر (شێ و پەستان)، بە ، پاشان k بە دەنگدان، هەروەها بۆچی دەکرێت هێواش بێت.
A tiny example: the nearest neighbourنموونەیەکی بچووک: نزیکترین دراوسێ
Asking more neighboursپرسیارکردن لە دراوسێی زیاتر
One neighbour can be unlucky. k-nearest-neighbours asks the k closest examples and takes a vote. Try it with k = 3:
یەک دراوسێ لەوانەیە بەدبەخت بێت. k-nearest-neighbours پرسیار لە k نزیکترین نموونە دەکات و دەنگ دەدرێت. بە k = 3 تاقی بکەرەوە:
Write predict_k(point, k=3): sort the training examples by distance, take the labels of the first 3, and return the most common label. What is the accuracy on the test data now?
predict_k(point, k=3) بنووسە: نموونەکانی ڕاهێنان بەپێی دووری ڕیز بکە، 3ی یەکەم وەربگرە و باوترین بگەڕێنەرەوە. وردی لەسەر ئێستا چەندە؟
Hintئاماژە
sorted(training, key=lambda example: math.dist(example[0], point))
sorted(training, key=lambda example: math.dist(example[0], point))
Show answerوەڵامەکە پیشان بدە
# Exercise answer: k-nearest-neighbours with k = 3 (a vote).
import math
from nearest_neighbour import training, testing
def predict_k(point, k=3):
by_distance = sorted(training, key=lambda example: math.dist(example[0], point))
votes = [label for _, label in by_distance[:k]]
return max(set(votes), key=votes.count) # the most common label
right = 0
for x, label in testing:
guess = predict_k(x)
right += guess == label
print(x, "-> predicted:", guess, "| real:", label)
print("accuracy on the test data:", f"{right}/{len(testing)}")(6, 8) -> predicted: pass | real: pass (2, 6) -> predicted: fail | real: fail (8, 4) -> predicted: pass | real: fail (5, 7) -> predicted: pass | real: pass (9, 6) -> predicted: pass | real: pass (5, 5) -> predicted: pass | real: pass accuracy on the test data: 5/6
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7
sorted(..., key=...)orders the examples from the closest to the farthest.sorted(..., key=...)نموونەکان لە نزیکترینەوە بۆ دوورترین ڕیز دەکات.- Lineدێڕی 9
The label that appears most often among the 3 votes.
ئەو لە نێو 3 دەنگەکەدا زیاتر دووبارە بووەتەوە.
Still 5/6, but the mistakes changed: (5, 5) is now right (two of its three neighbours passed), and (8, 4) is now wrong. With so little data, no method is perfect. Real systems learn from thousands or millions of examples, and choose k with the validation data.
هێشتا 5/6، بەڵام هەڵەکان گۆڕان: (5, 5) ئێستا ڕاستە (دوو لە سێ دراوسێکەی دەرچوون) و (8, 4) ئێستا هەڵەیە. بە ئەوەندە کەم، هیچ ڕێگەیەک تەواو نییە. سیستەمە ڕاستەقینەکان لە هەزاران یان ملیۆنان نموونەوە فێر دەبن و k بە هەڵدەبژێرن.
Neural networks, deep learning and generative AIتۆڕە دەمارییەکان، فێربوونی قووڵ و ژیریی دەستکردی بەرهەمهێنەر
The nearest-neighbour program keeps every example and compares. Most modern systems instead train a neural network: many small connected units whose connection strengths are adjusted, example after example, to reduce the errors. Learning with networks of many layers is called deep learning; such networks are behind today's speech recognition, image recognition and chatbots. (Their history is in What is AI?.)
بەرنامەی هەموو نموونەیەک دەهێڵێتەوە و بەراورد دەکات. لە جیاتی ئەوە، زۆربەی سیستەمە نوێیەکان ڕادەهێنن: چەندین یەکەی بچووکی بەیەکەوە بەستراو کە هێزی پەیوەندییەکانیان نموونە لە دوای نموونە ڕێک دەخرێت بۆ ئەوەی هەڵەکان کەم ببنەوە. فێربوون بە تۆڕێک کە چەندین چینی هەیە پێی دەوترێت ؛ ئەم جۆرە تۆڕانە لە پشت ، ناسینەوەی وێنە و ئەمڕۆوەن. (مێژووەکەیان لە ژیریی دەستکرد چییە؟دایە.)
Generative AI goes one step further: the model learns the patterns of huge amounts of text, images or sound and creates new content of the same kind. Chatbots are built on large language models, trained on huge amounts of text to predict the next word. Predicting the next word is a probability question: see Language models, small and large.
هەنگاوێک زیاتر دەڕوات: شێوازەکانی بڕێکی زۆر زۆری دەق، وێنە یان دەنگ فێر دەبێت و ناوەڕۆکی نوێی هەمان جۆر دروست دەکات. لەسەر دروست کراون، کە لەسەر بڕێکی زۆر زۆری دەق ڕاهێنراون بۆ پێشبینیکردنی وشەی داهاتوو. پێشبینیکردنی وشەی داهاتوو پرسیارێکی : بڕوانە مۆدێلەکانی زمان، بچووک و گەورە.
AI that creates new content, such as text, images or sound, after learning the patterns of a very large amount of existing examples. Chatbots built on are generative AI.
جۆرێک لە کە ناوەڕۆکی نوێ دروست دەکات، وەک دەق، وێنە یان دەنگ، دوای فێربوونی شێوازەکانی بڕێکی زۆر زۆری نموونەی هەبوو. ئەو لەسەر دروست کراون .
- Learning agents. A learning agent improves its own behaviour from experience; machine learning is the tool it uses (agent types).
- Optimisation. Training changes the model's settings step by step so that the error goes down, much like hill climbing going up (here: down) a landscape.
- Search and logic still matter. Game programs, route planners and checkers of rules still use the methods of this course, often together with learning.
- . لە ڕێگەی ئەزموونەوە ڕەفتاری خۆی باشتر دەکات؛ ئەو ئامرازەیە کە بەکاری دەهێنێت (جۆرەکانی ئەیجێنت).
- باشترینکردن. ڕاهێنان ڕێکخستنەکانی هەنگاو بە هەنگاو دەگۆڕێت بۆ ئەوەی هەڵە کەم ببێتەوە، زۆر لە چیاهەڵەگڕی دەچێت کە بە دیمەنێکدا بەرەو سەرەوە (لێرەدا: بەرەو خوارەوە) دەڕوات.
- گەڕان و لۆجیک هێشتا گرنگن. بەرنامەکانی یاری، پلاندانەری ڕێگە و پشکنەرانی یاسا هێشتا ڕێگەکانی ئەم کۆرسە بەکار دەهێنن، زۆرجار لەگەڵ فێربووندا.
How AI, machine learning, deep learning and generative AI fit inside each other, and how each one grew in time.
چۆن ، ، و یەک لەناو یەکدان و هەر یەکەیان بە درێژایی کات چۆن گەشەی کردووە.
Plays 4:48–9:08: deep learning (neural networks), foundation models, large language models as a kind of autocomplete, generative AI for text, audio and video, and deepfakes.
لە 4:48 تا 9:08 لێدەدرێت: ()، ، وەک جۆرێک لە تەواوکەری خۆکار، بۆ دەق و دەنگ و ڤیدیۆ، هەروەها ڤیدیۆ و دەنگی ساختە (deepfakes).
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Why it is a problemبۆچی کێشەیە | Betterباشتر |
|---|---|---|
| Testing the model on its training dataتاقیکردنەوەی لەسەر | It can score 100% just by remembering.دەتوانێت تەنیا بە لەبەرکردن 100٪ وەربگرێت. | Keep separate test data. جیا ڕابگرە. |
| Too little or one-sided data کەم یان یەکلایەنە | The model learns wrong or unfair patterns. شێوازی هەڵە یان نادادپەروەر فێر دەبێت. | Collect enough data that represents everyone it will be used for. پێویست کۆ بکەرەوە کە نوێنەرایەتیی هەموو ئەو کەسانە بکات کە بۆیان بەکار دەهێنرێت. |
| Mixing up classification and regressionتێکەڵکردنی و | You choose the wrong kind of model and score.جۆری هەڵەی و نمرە هەڵدەبژێریت. | Category → classification; number → regression.پۆل ← ؛ ژمارە ← . |
| Features on very different scales (grams and kilometres) بە پێوەری زۆر جیاواز (گرام و کیلۆمەتر) | In nearest-neighbour, the biggest numbers decide the distance alone.لە ، گەورەترین ژمارەکان بە تەنیا دووری دیاری دەکەن. | Bring features to similar ranges first (our hours are all 0–10).یەکەمجار بهێنە بۆ مەودای وەک یەک (کاتژمێرەکانی ئێمە هەموویان 0–10ن). |
| Thinking machine learning replaces rules everywhereوا بزانیت لە هەموو شوێنێک جێگەی یاسا دەگرێتەوە | When the rules are known and must be exact (a game, a law), written rules or search are clearer and safer.کاتێک یاساکان زانراون و دەبێت ورد بن (یارییەک، یاسایەک)، یاسای نووسراو یان گەڕان ڕوونتر و پارێزراوترن. | Use learning where examples are easy to get and rules are hard to write.فێربوون لەو شوێنانە بەکاربهێنە کە نموونە ئاسان دەست دەکەوێت و نووسینی یاسا قورسە. |
Exercisesڕاهێنانەکان
Name the kind of learning (supervised: classification or regression; unsupervised; reinforcement): (a) predicting tomorrow's electricity use of a city in kilowatt-hours; (b) grouping news articles by topic without any topics given; (c) a robot vacuum that gets a reward for every clean square; (d) recognising handwritten Kurdish letters from labelled samples.
جۆری فێربوونەکە دیاری بکە (: یان ؛ ؛ ): (أ) پێشبینیکردنی بەکارهێنانی کارەبای سبەینێی شارێک بە کیلۆوات-کاتژمێر؛ (ب) گرووپکردنی هەواڵەکان بەپێی بابەت بەبێ ئەوەی هیچ بابەتێک پێشتر دیاری کرابێت؛ (ج) گسک کە بۆ هەر چوارگۆشەیەکی پاک وەردەگرێت؛ (د) ناسینەوەی پیتی کوردیی دەستنووس لە نموونەی نیشانەکراوەوە.
Show answerوەڵامەکە پیشان بدە
- (a) supervised, regression (a number);
- (b) unsupervised, clustering;
- (c) reinforcement learning;
- (d) supervised, classification (a category: which letter).
- (أ) ، (ژمارەیەک)؛
- (ب) ، ؛
- (ج) ؛
- (د) ، (پۆلێک: کام پیت).
Use the training data of nearest_neighbour.py. What does the 1-nearest-neighbour program predict for the students (2, 7), (8, 7) and (6, 3)? Find the nearest example yourself, then check with Python.
nearest_neighbour.py بەکاربهێنە. بەرنامەی بۆ خوێندکارانی (2, 7)، (8, 7) و (6, 3) چی پێشبینی دەکات؟ خۆت نزیکترین نموونە بدۆزەرەوە، پاشان بە بیپشکنە.
Show answerوەڵامەکە پیشان بدە
(2, 7): the nearest example is (3, 7), distance 1, fail. (8, 7): (8, 6) and (8, 8) are both at distance 1 and both passed, so pass. (6, 3): the nearest is (5, 4), distance √2 ≈ 1.41, fail.
(2, 7): نزیکترین نموونە (3, 7)ـە، دووری 1، fail. (8, 7): (8, 6) و (8, 8) هەردووکیان لە دووریی 1دان و هەردووکیان دەرچوون، بۆیە pass. (6, 3): نزیکترینیان (5, 4)ـە، دووری √2 ≈ 1.41، fail.
from nearest_neighbour import predict
for student in [(2, 7), (8, 7), (6, 3)]:
print(student, "->", predict(student))(2, 7) -> fail (8, 7) -> pass (6, 3) -> fail
Summary and reviewپوختە و پێداچوونەوە
- Machine learning builds a model from examples instead of rules written by hand.
- Supervised learning uses labelled data (classification: categories; regression: numbers). Unsupervised learning finds structure in unlabelled data (clustering). Reinforcement learning learns a policy from rewards.
- Train on training data, choose settings with validation data, and measure once on unseen test data.
- Overfitting: great on training data, poor on new data. The goal is generalisation.
- Nearest neighbour: copy the label of the closest known example.
- لە نموونەکانەوە دروست دەکات لە جیاتی یاسای دەستنووس.
- بەکار دەهێنێت (: پۆل؛ : ژمارە). پێکهاتە لە بێ دەدۆزێتەوە (). لە فێر دەبێت.
- لەسەر ڕابهێنە، ڕێکخستنەکان بە هەڵبژێرە و یەکجار لەسەر نەبینراو بپێوە.
- : لەسەر زۆر باش، لەسەر نوێ لاواز. ئامانج گشتاندنە.
- : نزیکترین نموونەی زانراو وەربگرە.
What is a feature, and what is a label, in the quiz example?لە نموونەی کویزەکەدا، تایبەتمەندی چییە و نیشانە چییە؟
The features are the inputs (hours of study, hours of sleep). The label is the answer we want to predict (pass or fail).
نێوخستەکانن (کاتژمێرەکانی خوێندن، کاتژمێرەکانی خەوتن). ئەو وەڵامەیە کە دەمانەوێت پێشبینی بکەین (pass یان fail).
Why is a model tested on data it has never seen?بۆچی مۆدێل لەسەر ئەو دراوەیەی تاقی دەکرێتەوە کە هەرگیز نەیبینیوە؟
Because the real use is new cases. A score on seen data can come from memorising and hides overfitting.
چونکە بەکارهێنانی ڕاستەقینە بۆ حاڵەتی نوێیە. نمرە لەسەر بینراو دەکرێت لە لەبەرکردنەوە بێت و دەشارێتەوە.
How is reinforcement learning different from supervised learning?فێربوونی بەهێزکردنەوە چۆن لە فێربوونی چاودێریکراو جیاوازە؟
Nobody gives the right action. The agent tries actions, receives rewards or penalties and learns a policy that brings the most reward.
کەس دروست نادات. تاقی دەکاتەوە، یان سزا وەردەگرێت و فێر دەبێت کە زۆرترین دەهێنێت.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
How machine learning relates to AI and deep learning, and the three kinds: supervised, unsupervised and reinforcement learning, with simple examples.
پەیوەندیی بە و ، هەروەها سێ جۆرەکەی: ، و ، لەگەڵ نموونەی سادە.
Whole video (8:23): ML vs AI vs deep learning, then supervised (1:32), unsupervised (4:26) and reinforcement learning (6:38).
هەموو ڤیدیۆکە (8:23): بەرامبەر و ، پاشان (1:32)، (4:26) و (6:38).
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Google for Developers — Introduction to Machine Learning: What is ML?
- Google Machine Learning Crash Course — Overfitting
- CS50's Introduction to AI with Python — Notes 4: Learning
- UC Berkeley CS188 textbook — 9.1 Machine Learning
- CS50's Introduction to AI with Python — Notes 5: Neural Networks
- Google Machine Learning Crash Course — Introduction to Large Language Models
- Russell & Norvig, Artificial Intelligence: A Modern Approach, 4th ed., ch. 19 Learning from Examples (§19.7.1 Nearest-neighbor models) and ch. 22 Reinforcement Learning
- Python documentation — math.dist
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.