Lecture 02 · Words and Tokens
المحاضرة 02 · الكلمات والرموز (Tokens)
Corpora and Unicode
المدونات النصية (Corpora) وUnicode
P2 SHOULDWhere text data comes from and why it has to be documented, then the three layers every piece of digital text sits on: code point, glyph, byte.
من أين تأتي بيانات النص ولماذا يجب توثيقها، ثم الطبقات الثلاث التي يقوم عليها كل نص رقمي: code point وglyph وbyte.
Two separate topics share this page. The corpus half is conceptual and gets asked as "why document a dataset". The Unicode half is mechanical and gets asked as "how many bytes does this character take" or "what is the difference between a code point and a glyph". The byte material here is the setup for byte-level BPE on the next page, so do not skip it.
موضوعان منفصلان يتشاركان هذه الصفحة. نصف الـ corpus مفاهيمي ويأتي في الامتحان بصيغة "لماذا نوثّق مجموعة بيانات". ونصف Unicode آلي ويأتي بصيغة "كم بايتاً يأخذ هذا الحرف" أو "ما الفرق بين code point وglyph". ومادة البايتات هنا هي التمهيد لـ byte-level BPE في الصفحة التالية، فلا تتخطّها.
Part one · Corpora
الجزء الأول · المدونات النصية (Corpora)
What a corpus is, slide 28
ما الـ corpus، الشريحة 28
A corpus is a structured collection of texts, and very often it comes with annotations layered on top (part-of-speech tags, named entities, sentiment labels, parse trees).
الـ corpus مجموعة منظمة من النصوص، وكثيراً ما تأتي معها تعليقات توضيحية (annotations) فوقها (وسوم أقسام الكلام، والكيانات المسماة، وتصنيفات المشاعر، وأشجار الإعراب).
The word "structured" is doing real work. A pile of files is not a corpus. A corpus has been collected deliberately, organized, and usually described.
كلمة "منظمة" تؤدي عملاً حقيقياً. كومة من الملفات ليست corpus. الـ corpus جُمع عن قصد ونُظّم ووُصف في العادة.
The slide lists where the text comes from:
تسرد الشريحة مصادر النص:
- books
الكتب
- news
الأخبار
- web crawl
الزحف على الويب (web crawl)
- social media
وسائل التواصل الاجتماعي
- speech transcripts
تفريغات الكلام
And it names the dimensions along which corpora differ from each other. These are the key variation dimensions:
وتسمّي الأبعاد التي تختلف فيها الـ corpora عن بعضها. هذه هي أبعاد التباين الرئيسية:
| Dimensionالبُعد | What it variesما الذي يتغير فيه | Example of a difference it causesمثال على فرق يسببه |
|---|---|---|
| Domainالمجال (Domain) | subject areaالموضوع | medical text uses vocabulary a news model has never seenالنص الطبي يستخدم مفردات لم يرها نموذج الأخبار قط |
| Genreالنوع (Genre) | type of writingنوع الكتابة | legal contracts have very long sentences, tweets have very short onesالعقود القانونية جملها طويلة جداً، والتغريدات جملها قصيرة جداً |
| Timeالزمن (Time) | period of productionفترة الإنتاج | a 1990s corpus has no word for most of today's technologycorpus من التسعينيات لا يحوي كلمة لمعظم تقنيات اليوم |
| Demographicsالخصائص الديموغرافية (Demographics) | who wrote or spoke itمن كتبه أو قاله | age, region and education shape word choice and spellingالعمر والمنطقة والتعليم تشكّل اختيار الكلمات والتهجئة |
| Language varietyالتنوع اللغوي (Language variety) | which dialect or registerأي لهجة أو سجل لغوي | Modern Standard Arabic and Gulf dialect differ enough to break a model trained on only oneالعربية الفصحى المعاصرة واللهجة الخليجية تختلفان بما يكفي لإفشال نموذج دُرّب على إحداهما فقط |
الجدول خمسة أبعاد. المجال (Domain) يغيّر الموضوع: النص الطبي يستخدم مفردات لم يرها نموذج الأخبار قط. والنوع (Genre) يغيّر نوع الكتابة: العقود القانونية جملها طويلة جداً والتغريدات جملها قصيرة جداً. والزمن (Time) يغيّر فترة الإنتاج: corpus من تسعينيات القرن الماضي لا كلمة فيه لمعظم تقنيات اليوم. والديموغرافيا (Demographics) تغيّر من كتب أو تكلم: العمر والمنطقة والتعليم تشكّل اختيار الكلمات والتهجئة. وتنوع اللغة (Language variety) يغيّر اللهجة أو المستوى: الفصحى المعاصرة واللهجة الخليجية تختلفان بما يكفي لكسر نموذج دُرّب على واحدة منهما فقط.
Why documentation matters, slide 29
لماذا يهم التوثيق، الشريحة 29
This slide makes one claim, and it is the quotable one:
هذه الشريحة تطرح دعوى واحدة، وهي القابلة للاقتباس:
أي: النماذج ترث التحيزات والقيود من الـ corpora التي دُرّبت عليها.
Think about what that means practically. A model has no independent access to the world. Everything it believes about language came from the text it was shown. If that text over-represents one group, one era, or one dialect, the model over-represents them too, and nothing in the training procedure will flag it.
فكّر فيما يعنيه ذلك عملياً. النموذج ليس له وصول مستقل إلى العالم. كل ما يعتقده عن اللغة جاء من النص الذي عُرض عليه. فإذا كان ذلك النص يُفرط في تمثيل فئة واحدة أو حقبة واحدة أو لهجة واحدة، أفرط النموذج في تمثيلها أيضاً، ولن يُنبّه أي شيء في إجراء التدريب إلى ذلك.
So to interpret a result (not just produce one) you need metadata about the corpus. The slide lists exactly five things:
لذلك لكي تفسّر نتيجة (لا أن تنتجها فقط) تحتاج إلى بيانات وصفية (metadata) عن الـ corpus. وتسرد الشريحة خمسة أشياء بالضبط:
- collection procedure
إجراء الجمع
- time period
الفترة الزمنية
- languages and varieties
اللغات وتنوعاتها
- speaker or author demographics
ديموغرافيا المتحدثين أو الكتّاب
- licensing and privacy
الترخيص والخصوصية
Notice that the last one is not about accuracy at all. It is about whether you are legally and ethically allowed to use the data. That is part of the same documentation requirement.
لاحظ أن الأخير لا علاقة له بالدقة إطلاقاً. إنه يتعلق بما إذا كان مسموحاً لك قانونياً وأخلاقياً أن تستخدم البيانات. وهذا جزء من متطلب التوثيق نفسه.
Data statements and datasheets, slide 30
بيانات الوصف (Data statements) وصحائف البيانات (datasheets)، الشريحة 30
The practice that follows from slide 29: ship structured documentation alongside the dataset, not as an afterthought. Two names for the same idea are in circulation, "data statements" and "datasheets", and the slide treats them together.
الممارسة التي تترتب على الشريحة 29: أرفق توثيقاً منظماً مع مجموعة البيانات، لا كفكرة لاحقة. هناك اسمان متداولان للفكرة نفسها، "data statements" و"datasheets"، والشريحة تعاملهما معاً.
Six things go in it:
ستة أشياء تدخل فيه:
| Sectionالقسم | The question it answersالسؤال الذي يجيب عنه |
|---|---|
| Motivation and intended useالدافع والاستخدام المقصود | Why was this built, and what was it built for?لماذا بُني، ولأي غرض بُني؟ |
| Compositionالتكوين (Composition) | What is actually in it? How much, of what kinds?ما الذي فيه فعلاً؟ كم، ومن أي أنواع؟ |
| Collection processعملية الجمع | How was it gathered? Who produced the text? Was there consent?كيف جُمع؟ من أنتج النص؟ هل كانت هناك موافقة؟ |
| Preprocessing and annotationالمعالجة المسبقة والتوسيم | What was cleaned, filtered, tokenized or labelled, and by whom?ما الذي نُظّف أو صُفّي أو قُطّع أو وُسم، ومن قام بذلك؟ |
| Ethical considerationsالاعتبارات الأخلاقية | Who could be harmed by it, and what is in it that should not be?من قد يتضرر منه، وما الذي فيه ولا ينبغي أن يكون؟ |
| Distribution constraintsقيود التوزيع | Who may use it, under what license, with what restrictions?من يحق له استخدامه، وبأي ترخيص، وبأي قيود؟ |
أقسام الجدول وأسئلتها: الدافع والاستخدام المقصود: لماذا بُني هذا، ولأي غرض بُني؟ والتكوين: ما الموجود فيه فعلاً؟ وكم منه، ومن أي أنواع؟ وعملية الجمع: كيف جُمع؟ ومن أنتج النص؟ وهل كانت هناك موافقة؟ والمعالجة المسبقة والتوسيم: ما الذي نُظّف أو صُفّي أو قُطّع أو وُسم، ومن قام بذلك؟ والاعتبارات الأخلاقية: من قد يتضرر منه، وما الموجود فيه مما لا ينبغي أن يكون؟ وقيود التوزيع: من يحق له استخدامه، وبأي ترخيص، وبأي قيود؟
The slide names three benefits: transparency, reproducibility, and responsible use. If you are asked to justify the practice in one line, those three words are the answer.
تسمّي الشريحة ثلاث فوائد: الشفافية (transparency)، وقابلية إعادة الإنتاج (reproducibility)، والاستخدام المسؤول (responsible use). وإذا طُلب منك تبرير هذه الممارسة في سطر واحد، فهذه الكلمات الثلاث هي الجواب.
The corpus is the model's entire world. If it is not in the corpus, the model never learned it. If it is over-represented in the corpus, the model over-believes it.
الـ corpus هو عالم النموذج كله. إن لم يكن الشيء في الـ corpus فالنموذج لم يتعلمه قط. وإن كان ممثَّلاً أكثر من اللازم في الـ corpus فالنموذج يصدّقه أكثر من اللازم.
And for the five metadata items: how, when, what language, who, and may-I. That last one, licensing and privacy, is the one students forget because it is not technical.
وللعناصر الوصفية الخمسة: كيف، ومتى، وأي لغة، ومن، وهل يحق لي. والأخير، الترخيص والخصوصية، هو الذي ينساه الطلاب لأنه ليس تقنياً.
Part two · Unicode
الجزء الثاني · Unicode
Why Unicode matters, slide 31
لماذا يهم Unicode، الشريحة 31
An NLP system has to represent text from every writing system it might meet: Latin, Cyrillic, Arabic, Han, emoji, and more. You cannot do that with a per-language character set, because then the same number means different things in different files.
نظام NLP يجب أن يمثّل نصاً من كل نظام كتابة قد يصادفه: اللاتيني والسيريلي والعربي والصيني (Han) والإيموجي وغيرها. ولا يمكنك فعل ذلك بمجموعة حروف خاصة بكل لغة، لأن الرقم نفسه سيعني عندئذ أشياء مختلفة في ملفات مختلفة.
Unicode's answer is a single global registry. Every character in every script gets its own number, and that number is called a code point. It is written in the form U+XXXX with hexadecimal digits.
جواب Unicode سجل عالمي واحد. كل حرف في كل نظام كتابة يحصل على رقم خاص به، وهذا الرقم يسمى code point. ويُكتب بالصيغة U+XXXX بأرقام ست عشرية.
أي أن U+0061 هو الـ code point للحرف 'a'.
Then the slide drops the sentence that generates most of the confusion in this area:
ثم تُسقط الشريحة الجملة التي تولّد معظم الالتباس في هذا الموضوع:
أي: الشكل المرئي نفسه (glyph) قد يقابل code points مختلفة، والعكس صحيح.
So the number and the picture are not locked together. One shape, several possible numbers. One number, several possible shapes depending on the font and the position in the word. Hold that thought for slide 33.
إذن الرقم والصورة غير مقفلين معاً. شكل واحد، وعدة أرقام ممكنة. ورقم واحد، وعدة أشكال ممكنة بحسب الخط وموضع الحرف في الكلمة. احتفظ بهذه الفكرة للشريحة 33.
ASCII, slide 32
ASCII، الشريحة 32
Before Unicode there was ASCII, which covers only the basic Latin letters, digits and punctuation, and which needs just 7 bits per character. Slide 32 is a figure of selected ASCII codes. Here is the figure transcribed, with the binary column computed from the hex so you can see the pattern:
قبل Unicode كان هناك ASCII، الذي يغطي فقط الحروف اللاتينية الأساسية والأرقام وعلامات الترقيم، ويحتاج 7 بتات فقط لكل حرف. الشريحة 32 شكل لرموز ASCII مختارة. وهذا هو الشكل منقولاً، مع عمود ثنائي محسوب من الست عشري لترى النمط:
| Chالحرف | Hexست عشري | Decعشري | Binaryثنائي | Chالحرف | Hexست عشري | Decعشري | Binaryثنائي |
|---|---|---|---|---|---|---|---|
| < | 3C | 60 | 00111100 | \ | 5C | 92 | 01011100 |
| = | 3D | 61 | 00111101 | [ | 5D | 93 | 01011101 |
| > | 3E | 62 | 00111110 | ^ | 5E | 94 | 01011110 |
| ? | 3F | 63 | 00111111 | _ | 5F | 95 | 01011111 |
| @ | 40 | 64 | 01000000 | ` | 60 | 96 | 01100000 |
| A | 41 | 65 | 01000001 | a | 61 | 97 | 01100001 |
| B | 42 | 66 | 01000010 | b | 62 | 98 | 01100010 |
| C | 43 | 67 | 01000011 | c | 63 | 99 | 01100011 |
كل صف في الجدول حرف مع قيمته الست عشرية والعشرية والثنائية. مثلاً < هو 3C أي 60 أي 00111100، وA هو 41 أي 65 أي 01000001، وa هو 61 أي 97 أي 01100001. والجدول يمتد من < (60) إلى C (67) في العمود الأيسر، ومن \ (92) إلى c (99) في العمود الأيمن.
Two patterns worth noticing, because they come back later:
نمطان يستحقان الملاحظة، لأنهما يعودان لاحقاً:
- Every binary value starts with a 0. ASCII only uses 7 of the 8 bits. That spare leading 0 is the hook UTF-8 hangs its whole design on.
كل قيمة ثنائية تبدأ بـ 0. ASCII يستخدم 7 فقط من البتات الثمانية. وهذا الصفر البادئ الفائض هو المشجب الذي يعلّق عليه UTF-8 تصميمه كله.
- Uppercase and lowercase differ by exactly 32 (0x20). A is 65, a is 97. B is 66, b is 98. That is one bit flipped, which is why lowercasing used to be a single bitwise operation. It stops being that simple the moment you leave ASCII.
الحرف الكبير والصغير يختلفان بـ 32 بالضبط (0x20). A هو 65 وa هو 97. B هو 66 وb هو 98. هذا بت واحد مقلوب، ولهذا كان التحويل إلى حروف صغيرة عملية bitwise واحدة. ويتوقف عن أن يكون بهذه البساطة لحظة خروجك من ASCII.
Code points, glyphs, and normalization, slide 33
نقاط الترميز (Code points) والأشكال المرسومة (glyphs) والتطبيع، الشريحة 33
The slide separates two things that look like one thing:
تفصل الشريحة بين شيئين يبدوان شيئاً واحداً:
- A code point is an abstract identifier. It is a number. It has no shape.
الـ code point معرّف مجرد. إنه رقم. وليس له شكل.
- A glyph is a rendered shape. It is what the font draws on the screen.
الـ glyph شكل مرسوم. إنه ما يرسمه الخط على الشاشة.
Then: some characters can be composed in multiple ways. The slide's example is accented characters. The letter é can be stored as one code point that means "e with acute accent", or as two code points that mean "plain e" followed by "add an acute accent to the previous character". Both draw the identical glyph. Neither is wrong.
ثم: بعض الحروف يمكن تركيبها بأكثر من طريقة. ومثال الشريحة الحروف ذات العلامات. الحرف é يمكن تخزينه code point واحداً يعني "e مع علامة حادة"، أو code points اثنين يعنيان "e عادية" يتبعها "أضف علامة حادة للحرف السابق". وكلاهما يرسم الـ glyph نفسه تماماً. ولا أحد منهما خاطئ.
Here is what that actually looks like:
وهكذا يبدو ذلك فعلياً:
composed form (NFC) U+00E9 1 code point 2 UTF-8 bytes decomposed form (NFD) U+0065 + U+0301 2 code points 3 UTF-8 bytes both render as: e with an acute accent a naive string equality test says they are DIFFERENT
الصيغة المركّبة (NFC) هي U+00E9: code point واحد وبايتان في UTF-8. والصيغة المفكّكة (NFD) هي U+0065 + U+0301: code points اثنان وثلاثة بايتات في UTF-8. كلاهما يُعرض e بعلامة حادة، لكن اختبار مساواة السلاسل الساذج يقول إنهما مختلفان.
That last line is the whole problem. A search for one form silently fails to find the other. Two "identical" words end up as two separate entries in your vocabulary. Your token counts are split in half for no linguistic reason.
هذا السطر الأخير هو المشكلة كلها. البحث عن صيغة يفشل بصمت في إيجاد الأخرى. وكلمتان "متطابقتان" تنتهيان مدخلين منفصلين في مفرداتك. وتنقسم عدّات الـ tokens إلى نصفين بلا أي سبب لغوي.
Normalization is the fix: a defined procedure that rewrites text into one canonical choice of form, so that visually identical text compares equal. The slide's sentence is that normalization can affect matching and tokenization, which is a warning as much as a recommendation. If you normalize, your token boundaries change. If you do not, your matching breaks.
الـ Normalization هو الحل: إجراء محدد يعيد كتابة النص إلى اختيار قانوني (canonical) واحد للصيغة، فيتساوى النص المتطابق بصرياً عند المقارنة. وجملة الشريحة أن الـ normalization قد يؤثر في المطابقة والتقطيع، وهذا تحذير بقدر ما هو توصية. إذا طبّقت normalization تغيرت حدود الـ tokens. وإن لم تطبّقه انكسرت المطابقة.
يُظهر الرسم تسلسلين من الـ code points يؤديان إلى حرف مرئي واحد: المركّب U+00E9 والمفكّك U+0065 + U+0301، وكلاهما يشير إلى الـ glyph نفسه é، وسهم normalize (NFC) يحوّل المفكّك إلى المركّب. ثم يُرمَّز كل منهما بـ UTF-8: الأول بايتان C3 A9، والثاني ثلاثة بايتات 65 CC 81. متطابقان على الشاشة، مختلفان في الذاكرة، وغير متساويين في مقارنة السلاسل. الـ glyph هو ما تراه، والـ code points هي ما يُخزَّن، ولهذا وُجد الـ normalization.
UTF-8, slide 34
UTF-8، الشريحة 34
Unicode assigns numbers. It does not say how to write those numbers into a file. That job belongs to an encoding, and the one that won is UTF-8.
Unicode يعيّن الأرقام. لكنه لا يقول كيف تُكتب هذه الأرقام في ملف. هذه مهمة الترميز (encoding)، والترميز الذي انتصر هو UTF-8.
Slide 34 gives three properties:
تعطي الشريحة 34 ثلاث خصائص:
- UTF-8 is a variable-length encoding of Unicode code points into bytes.
UTF-8 ترميز متغير الطول (variable-length) لـ code points الخاصة بـ Unicode إلى بايتات.
- ASCII characters use 1 byte; many others use 2 to 4 bytes.
حروف ASCII تستخدم بايتاً واحداً، وكثير من غيرها يستخدم من 2 إلى 4 بايتات.
- It is backward compatible with ASCII, and it is the common choice in web and NLP pipelines.
إنه متوافق مع ASCII رجعياً (backward compatible)، وهو الخيار الشائع في الويب ومسارات NLP.
"Variable-length" is the key word. The number of bytes depends on which character it is. Small code points are cheap, large code points are expensive.
"متغير الطول" هي الكلمة المفتاح. عدد البايتات يعتمد على أي حرف هو. الـ code points الصغيرة رخيصة، والكبيرة مكلفة.
Backward compatibility follows directly from the ASCII pattern you saw above. Every ASCII byte has a leading 0, so UTF-8 reserves "leading bit is 0" to mean "this is a one-byte ASCII character" and builds everything else out of bytes whose leading bit is 1. An old ASCII file is therefore already a valid UTF-8 file, unchanged.
التوافق الرجعي ينتج مباشرة من نمط ASCII الذي رأيته أعلاه. كل بايت ASCII يبدأ بـ 0، فيحجز UTF-8 "البت الأول يساوي 0" ليعني "هذا حرف ASCII من بايت واحد"، ويبني كل ما عداه من بايتات بتها الأول 1. لذلك فأي ملف ASCII قديم هو أصلاً ملف UTF-8 صالح، دون أي تغيير.
Unicode to UTF-8 mapping, slide 35
التحويل من Unicode إلى UTF-8، الشريحة 35
Slide 35 is the table that tells you exactly how to lay the bits out. Here it is transcribed:
الشريحة 35 هي الجدول الذي يخبرك بالضبط كيف ترتب البتات. وهذا هو منقولاً:
| Code points (from – to)نقاط الترميز (من – إلى) | Bit valueقيمة البتات | Byte 1البايت 1 | Byte 2البايت 2 | Byte 3البايت 3 | Byte 4البايت 4 |
|---|---|---|---|---|---|
| U+0000 – U+007F | 0xxxxxxx | 0xxxxxxx | – | – | – |
| U+0080 – U+07FF | 00000yyy yyxxxxxx | 110yyyyy | 10xxxxxx | – | – |
| U+0800 – U+FFFF | zzzzyyyy yyxxxxxx | 1110zzzz | 10yyyyyy | 10xxxxxx | – |
| U+010000 – U+10FFFF | 000uuuuu zzzzyyyy yyxxxxxx | 11110uuu | 10uuzzzz | 10yyyyyy | 10xxxxxx |
صفوف الجدول: من U+0000 إلى U+007F بايت واحد 0xxxxxxx. ومن U+0080 إلى U+07FF بايتان 110yyyyy 10xxxxxx. ومن U+0800 إلى U+FFFF ثلاثة بايتات 1110zzzz 10yyyyyy 10xxxxxx. ومن U+010000 إلى U+10FFFF أربعة بايتات 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx. وعمود Bit value يبيّن بتات الـ code point التي تُصبّ في الخانات.
Read the byte patterns, not the ranges. The structure is completely regular:
اقرأ أنماط البايتات لا المدى. البنية منتظمة تماماً:
- A one-byte character starts with
0.الحرف ذو البايت الواحد يبدأ بـ 0.
- A lead byte of a multi-byte character starts with as many
1s as there are bytes in total, then a0. Two bytes gives110, three gives1110, four gives11110.البايت القائد (lead byte) لحرف متعدد البايتات يبدأ بعدد من الآحاد يساوي عدد البايتات الكلي، ثم 0. بايتان يعطيان 110، وثلاثة تعطي 1110، وأربعة تعطي 11110.
- Every continuation byte starts with
10. Always. No exceptions.كل بايت تكميلي (continuation byte) يبدأ بـ 10. دائماً. بلا استثناءات.
That design means you can land anywhere in a UTF-8 stream and immediately tell whether you are at the start of a character or in the middle of one. The x, y, z, u letters are just the bits of the code point poured into the remaining slots, most significant first.
هذا التصميم يعني أنك تستطيع أن تهبط في أي مكان من تيار UTF-8 وتعرف فوراً هل أنت في بداية حرف أم في وسطه. والحروف x وy وz وu هي مجرد بتات الـ code point مصبوبة في الخانات المتبقية، الأعلى قيمة أولاً.
Encode the Arabic letter م (meem), code point U+0645, into UTF-8 by hand using the table above.
رمّز الحرف العربي م (ميم)، والـ code point له U+0645، إلى UTF-8 يدوياً باستخدام الجدول أعلاه.
STEP 1 which row of the table?
U+0645 is between U+0080 and U+07FF -> the 2-byte row
pattern: 110yyyyy 10xxxxxx
STEP 2 write the code point in binary
0x0645 = 1605 decimal
1605 = 1024 + 512 + 64 + 4 + 1
1605 = 1 1 0 0 1 0 0 0 1 0 1 (11 bits)
STEP 3 the 2-byte row needs 11 payload bits, 5 then 6. split it.
top 5 bits (yyyyy) = 11001
low 6 bits (xxxxxx) = 000101
STEP 4 pour the bits into the template
byte 1 = 110 + 11001 = 11011001 = 0xD9 = 217
byte 2 = 10 + 000101 = 10000101 = 0x85 = 133
ANSWER
م is D9 85 in UTF-8. 2 bytes for 1 character.
CHECK byte 1 starts with 110, so "two bytes follow this pattern".
byte 2 starts with 10, so "I am a continuation". consistent.
خطوات المقطع: (1) U+0645 بين U+0080 وU+07FF، فهو في صف البايتين بالنمط 110yyyyy 10xxxxxx. (2) 0x0645 = 1605 عشرياً، و1605 = 1024 + 512 + 64 + 4 + 1، فبالثنائي 11001000101 (11 بتاً). (3) صف البايتين يحتاج 11 بت حمولة، 5 ثم 6: الخمسة العليا 11001 والستة الدنيا 000101. (4) صبّها في القالب: البايت الأول 110 + 11001 = 11011001 = 0xD9 = 217، والثاني 10 + 000101 = 10000101 = 0x85 = 133. الجواب: م هي D9 85 في UTF-8، أي بايتان لحرف واحد. والتحقق: البايت الأول يبدأ بـ 110 أي "حرف من بايتين"، والثاني يبدأ بـ 10 أي "أنا بايت تكميلي"، والنتيجة متسقة.
Run the same recipe on the letter A, code point U+0041. It falls in the first row, so it is one byte, 0 followed by the 7 bits 1000001, which is 0x41 = 65. That is precisely the ASCII value from slide 32, which is backward compatibility in action.
طبّق الوصفة نفسها على الحرف A، والـ code point له U+0041. يقع في الصف الأول، فهو بايت واحد: 0 تتبعه البتات السبعة 1000001، وهذا 0x41 أي 65. وهذه بالضبط قيمة ASCII من الشريحة 32، أي التوافق الرجعي وهو يعمل.
يعرض الرسم أربعة حروف مع الـ code point وبايتات UTF-8 لكل منها: A (U+0041) بايت واحد 41. وم (U+0645) بايتان D9 85. و世 (U+4E16) ثلاثة بايتات E4 B8 96. والإيموجي (U+1F600) أربعة بايتات F0 9F 98 80. الحرف الواحد ليس بايتاً واحداً. المربع الملوّن باللون الأساسي هو البايت القائد، والمربعات الرمادية بايتات تكميلية. اقرأ البتات الأولى: 0 يعني بايت ASCII منفرداً، و110 و1110 و11110 تعلن عن حرف من 2 و3 و4 بايتات، وكل بايت تكميلي يبدأ بـ 10.
Why bytes are useful, slide 36
لماذا الـ bytes مفيدة، الشريحة 36
Now the payoff, and the bridge to the tokenization page:
والآن الثمرة، والجسر إلى صفحة الـ tokenization:
- Any text can be represented as bytes, so there is no "unknown character" issue.
أي نص يمكن تمثيله بايتات، فلا توجد مشكلة "حرف مجهول".
- Byte-level tokenization handles arbitrary scripts, emojis, and typos.
الـ tokenization على مستوى البايت يتعامل مع أي نظام كتابة، والإيموجي، والأخطاء المطبعية.
- But bytes may lose linguistic structure, so they are often combined with learned merges.
لكن البايتات قد تفقد البنية اللغوية، لذلك تُدمج غالباً مع دمجات متعلَّمة (learned merges).
Work through why the first point is airtight. There are exactly 256 possible byte values. If your base vocabulary is all 256, then every possible file, in every script, including ones invented after your model was trained, is already fully covered. There is no input you can be handed that contains a symbol you have never seen. Out-of-vocabulary stops being a thing that can happen.
تتبّع لماذا النقطة الأولى محكمة تماماً. هناك 256 قيمة ممكنة بالضبط للبايت. فإذا كانت مفرداتك الأساسية هي الـ 256 كلها، فكل ملف ممكن، بأي نظام كتابة، بما في ذلك ما اختُرع بعد تدريب نموذجك، مغطى بالكامل أصلاً. لا يوجد دخل يمكن أن يُعطى لك فيه رمز لم تره من قبل. ويتوقف الـ out-of-vocabulary عن أن يكون شيئاً ممكن الحدوث.
The cost is in the third bullet. A byte is not a linguistic unit. In the Arabic letter م the bytes D9 and 85 mean nothing on their own, and the model has to learn that they always travel together. That is exactly the job "combined with learned merges" is pointing at, and the method that does it is on the next page.
الثمن في البند الثالث. البايت ليس وحدة لغوية. في الحرف العربي م البايتان D9 و85 لا يعنيان شيئاً منفردين، وعلى النموذج أن يتعلم أنهما يسيران معاً دائماً. وهذه بالضبط المهمة التي تشير إليها عبارة "تُدمج مع دمجات متعلَّمة"، والطريقة التي تؤديها في الصفحة التالية.
Code point versus glyph versus byte
نقطة الترميز مقابل الـ glyph مقابل البايت
Three layers, and exam questions live on the boundaries between them.
ثلاث طبقات، وأسئلة الامتحان تعيش على الحدود بينها.
| Code pointنقطة الترميز (Code point) | Glyphالـ Glyph | Byteالبايت (Byte) | |
|---|---|---|---|
| What it isما هو | an abstract number identifying a characterرقم مجرد يعرّف حرفاً | a rendered shape drawn by a fontشكل يرسمه الخط (font) | 8 bits of storage, a value from 0 to 2558 بتات من التخزين، قيمة من 0 إلى 255 |
| Written asكيف يُكتب | U+0645 | the visible mark on screenالعلامة المرئية على الشاشة | D9 or 217 or 11011001D9 أو 217 أو 11011001 |
| Who decides itمن يحدده | the Unicode standardمعيار Unicode | the font designerمصمم الخط | the encoding, here UTF-8الترميز، وهنا UTF-8 |
| How many per characterكم لكل حرف | usually 1, sometimes a sequenceعادة 1، وأحياناً تسلسل | 1 drawn shape, but it varies by font and positionشكل مرسوم واحد، لكنه يختلف حسب الخط والموضع | 1 to 4 in UTF-8, not fixedمن 1 إلى 4 في UTF-8، وليس ثابتاً |
| Can two differ and still look the same?هل يمكن أن يختلف اثنان ويبدوان متطابقين؟ | yes, U+00E9 vs U+0065 U+0301نعم، U+00E9 مقابل U+0065 U+0301 | that is the point, they look identicalهذا هو المقصود، فهما يبدوان متطابقين | yes, C3 A9 vs 65 CC 81نعم، C3 A9 مقابل 65 CC 81 |
| Size of the alphabetحجم الأبجدية | over 1.1 million possibleأكثر من 1.1 مليون ممكن | unbounded, font dependentغير محدود، ويعتمد على الخط | exactly 256256 بالضبط |
| Can it ever be unknown?هل يمكن أن يكون مجهولاً؟ | yes, a new character can appearنعم، قد يظهر حرف جديد | yes, you get a missing-glyph boxنعم، فيظهر لك مربع الـ glyph المفقود | no, all 256 values always existلا، القيم الـ 256 كلها موجودة دائماً |
الجدول يقارن الطبقات الثلاث. ما هو: الـ code point رقم مجرد يعرّف حرفاً، والـ glyph شكل يرسمه خط، والـ byte ثمانية بتات تخزين بقيمة من 0 إلى 255. يُكتب: U+0645، مقابل العلامة المرئية على الشاشة، مقابل D9 أو 217 أو 11011001. من يحدده: معيار Unicode، ومصمم الخط، والترميز وهو هنا UTF-8. كم لكل حرف: عادة 1 وأحياناً تسلسل، وشكل واحد مرسوم يختلف بحسب الخط والموضع، ومن 1 إلى 4 في UTF-8 غير ثابت. هل يختلف اثنان ويبدوان متطابقين: نعم، U+00E9 مقابل U+0065 U+0301، وهذا هو المقصود في الـ glyph فهما يبدوان متطابقين، ونعم في البايتات C3 A9 مقابل 65 CC 81. حجم الأبجدية: أكثر من 1.1 مليون ممكن، وغير محدود ويعتمد على الخط، و256 بالضبط. هل يمكن أن يكون مجهولاً: نعم قد يظهر حرف جديد، ونعم تحصل على مربع الحرف المفقود، ولا في البايتات لأن القيم الـ 256 كلها موجودة دائماً.
The bottom row is the whole argument for byte-level models in one cell.
الصف الأخير هو حجة النماذج على مستوى البايت كلها في خلية واحدة.
Number, picture, storage. Code point is the number, glyph is the picture, byte is the storage. Three different layers, and a question that mixes them up is testing exactly this.
رقم، وصورة، وتخزين. الـ code point هو الرقم، والـ glyph هو الصورة، والـ byte هو التخزين. ثلاث طبقات مختلفة، والسؤال الذي يخلط بينها يختبر هذا بالضبط.
For UTF-8 lengths: count the leading ones. Leading 0 means one byte. Leading 110 means two. Leading 1110 means three. Leading 11110 means four. Continuation bytes always start 10.
ولأطوال UTF-8: عُدّ الآحاد البادئة. 0 في البداية يعني بايتاً واحداً. و110 يعني اثنين. و1110 يعني ثلاثة. و11110 يعني أربعة. والبايتات التكميلية تبدأ دائماً بـ 10.
For the ranges: 7F, 7FF, FFFF. Those are the last code point of the 1, 2 and 3 byte zones. Everything past FFFF takes four.
وللمدى: 7F و7FF وFFFF. هذه آخر code point في مناطق البايت الواحد والاثنين والثلاثة. وكل ما بعد FFFF يأخذ أربعة.
"One character equals one byte." True only for ASCII. In UTF-8 the length varies from 1 to 4 bytes. Your name in Arabic is a string whose byte count is roughly double its character count, because every Arabic letter sits in the 2-byte range. مرحبا is 5 characters and 10 bytes.
"الحرف الواحد يساوي بايتاً واحداً." صحيح فقط لـ ASCII. في UTF-8 يتراوح الطول من 1 إلى 4 بايتات. واسمك بالعربية سلسلة عدد بايتاتها نحو ضعف عدد حروفها، لأن كل حرف عربي يقع في منطقة البايتين. فـ مرحبا 5 حروف و10 بايتات.
"UTF-8 is a fixed-width encoding." It is explicitly a variable-length encoding, in the slide's own words. If it were fixed-width it could not be backward compatible with ASCII and still reach a million code points.
"UTF-8 ترميز ثابت العرض." هو صراحة ترميز متغير الطول بعبارة الشريحة نفسها. ولو كان ثابت العرض لما أمكن أن يكون متوافقاً رجعياً مع ASCII ويصل مع ذلك إلى مليون code point.
Confusing Unicode with UTF-8. Unicode is the catalogue of characters and their numbers. UTF-8 is one way of writing those numbers as bytes. "Convert to Unicode" is not a meaningful instruction; "encode as UTF-8" is.
الخلط بين Unicode وUTF-8. Unicode هو فهرس الحروف وأرقامها. وUTF-8 طريقة واحدة لكتابة تلك الأرقام بايتات. عبارة "Convert to Unicode" ليست تعليمة ذات معنى، أما "encode as UTF-8" فهي كذلك.
Assuming the same-looking string is the same string. The composed and decomposed forms of é are not equal to a byte comparison, which is the entire reason normalization is on the slide.
افتراض أن السلسلة التي تبدو نفسها هي السلسلة نفسها. الصيغتان المركّبة والمفكّكة لـ é غير متساويتين في مقارنة البايتات، وهذا هو السبب الكامل لوجود الـ normalization على الشريحة.
Thinking normalization is free. Slide 33 says it can affect matching and tokenization. Stripping accents makes more things match, and also destroys a distinction some languages need.
الظن بأن الـ normalization مجاني. الشريحة 33 تقول إنه قد يؤثر في المطابقة والتقطيع. إزالة العلامات تجعل أشياء أكثر تتطابق، وتمحو في الوقت نفسه تمييزاً تحتاجه بعض اللغات.
Thirty-second recap
خلاصة في ثلاثين ثانية
ملخص: الـ corpus مجموعة منظمة من النصوص وغالباً موسومة، ويختلف بالمجال والنوع والزمن والديموغرافيا والتنوع اللغوي، والنماذج ترث التحيزات من corpora التدريب. والـ data statement يضم الدافع والتكوين والجمع والمعالجة المسبقة والأخلاقيات والتوزيع، وفوائده الشفافية وقابلية إعادة الإنتاج والاستخدام المسؤول. الـ code point هو الرقم، وU+0061 هو 'a'، والـ glyph هو الشكل المرسوم، والـ glyph نفسه قد يكون له code points مختلفة. UTF-8 متغير الطول من 1 إلى 4 بايتات، وASCII بايت واحد فـ UTF-8 متوافق رجعياً، والبايتات التكميلية تبدأ دائماً بـ 10. و256 قيمة للبايت، فلا يوجد حرف مجهول.
Check yourself
اختبر نفسك
Slide 34 describes UTF-8 as a variable-length encoding. What does that mean in practice?
تصف الشريحة 34 UTF-8 بأنه ترميز متغير الطول. ماذا يعني ذلك عملياً؟
The length is determined by which code point range the character falls in: U+0000 to U+007F takes 1 byte, up to U+07FF takes 2, up to U+FFFF takes 3, and beyond that 4. B describes UTF-32, which is fixed-width and wastes space on ASCII. A is the tempting wrong answer because "variable" sounds context-dependent; it is not, the mapping is deterministic and depends only on the character itself.
الجواب C. الطول يتحدد بالمدى الذي يقع فيه الـ code point للحرف: من U+0000 إلى U+007F بايت واحد، وحتى U+07FF بايتان، وحتى U+FFFF ثلاثة، وما بعد ذلك أربعة. والجواب B يصف UTF-32، وهو ثابت العرض ويهدر المساحة على ASCII. والجواب A هو الخطأ المُغري لأن "متغير" توحي بالاعتماد على السياق، وليس كذلك، فالتحويل حتمي ويعتمد فقط على الحرف نفسه.
You see the byte 10110001 in the middle of a UTF-8 stream. What do you immediately know?
ترى البايت 10110001 في وسط تيار UTF-8. ماذا تعرف فوراً؟
Every continuation byte starts with the bits 10, and this one does. A is wrong because a one-byte ASCII character starts with 0; that leading 1 rules it out. C is the most tempting error: the lead byte of a two-byte character starts 110, not 10. This self-synchronizing property is why you can jump into the middle of a UTF-8 file and find a character boundary.
الجواب B. كل بايت تكميلي يبدأ بالبتين 10، وهذا البايت كذلك. والجواب A خاطئ لأن حرف ASCII ذا البايت الواحد يبدأ بـ 0، والـ 1 البادئ يستبعده. والجواب C هو الخطأ الأكثر إغراءً: البايت القائد لحرف من بايتين يبدأ بـ 110 لا بـ 10. وخاصية التزامن الذاتي (self-synchronizing) هذه هي سبب قدرتك على القفز إلى وسط ملف UTF-8 وإيجاد حد حرف.
The letter é appears twice in a file, once as U+00E9 and once as U+0065 followed by U+0301. They render identically. What is the consequence for an NLP pipeline, and what addresses it?
الحرف é يظهر مرتين في ملف، مرة بـ U+00E9 ومرة بـ U+0065 يتبعه U+0301. ويُعرضان بشكل متطابق. ما العاقبة على مسار NLP، وما الذي يعالجها؟
This is exactly slide 33. Both forms are valid, both look the same, and neither a string equality test nor a byte comparison can tell they are the same word, so your token counts get split. A is the tempting answer because the glyphs genuinely are identical, but the slide's point is that identical appearance and identical storage are different things. Normalization is the stated fix, with the caveat that it can itself change tokenization.
الجواب D. هذه هي الشريحة 33 بالضبط. الصيغتان صالحتان، وتبدوان متطابقتين، ولا يستطيع اختبار مساواة السلاسل ولا مقارنة البايتات أن يعرف أنهما الكلمة نفسها، فتنقسم عدّات الـ tokens. والجواب A مُغرٍ لأن الـ glyphs متطابقة فعلاً، لكن مقصد الشريحة أن تطابق المظهر وتطابق التخزين شيئان مختلفان. والـ normalization هو الحل المذكور، مع التحفظ بأنه قد يغيّر الـ tokenization نفسه.
Slide 36 says any text can be represented as bytes so there is no unknown-character issue. Why is that guarantee airtight?
تقول الشريحة 36 إن أي نص يمكن تمثيله بايتات فلا توجد مشكلة الحرف المجهول. لماذا هذا الضمان محكم؟
The argument is pure counting: the byte alphabet is finite and tiny, so you can enumerate all of it in advance and nothing new can ever arrive. B is the most common wrong reason given for byte-level methods; speed is not the point, coverage is. C reverses the relationship: bytes carry Unicode via UTF-8, they are not themselves characters, and a lone continuation byte is not any character at all.
الجواب A. الحجة عدّ خالص: أبجدية البايتات محدودة وصغيرة جداً، فيمكنك حصرها كلها مسبقاً ولا يمكن أن يصل شيء جديد أبداً. والجواب B هو السبب الخاطئ الأكثر شيوعاً لطرق مستوى البايت، فالسرعة ليست المقصد، بل التغطية. والجواب C يعكس العلاقة: البايتات تحمل Unicode عبر UTF-8، وليست هي نفسها حروفاً، والبايت التكميلي المنفرد ليس أي حرف إطلاقاً.
Slide 29 lists metadata a corpus should carry so results can be interpreted. Which of these does the slide include that is not about model accuracy at all?
تسرد الشريحة 29 البيانات الوصفية التي يجب أن يحملها الـ corpus لكي تُفسَّر النتائج. أي منها تذكره الشريحة ولا علاقة له بدقة النموذج إطلاقاً؟
Licensing and privacy govern whether you are permitted to use the data, which is a legal and ethical question rather than a performance one, and it is on the slide alongside the four technical items. B is tempting because demographics also sounds like an ethics item, but it is listed for an interpretive reason: knowing who produced the text tells you which populations the model will serve well and which it will not.
الجواب C. الترخيص والخصوصية يحكمان ما إذا كان مسموحاً لك استخدام البيانات، وهذا سؤال قانوني وأخلاقي لا سؤال أداء، وهو على الشريحة بجانب البنود التقنية الأربعة. والجواب B مُغرٍ لأن الديموغرافيا تبدو أيضاً بنداً أخلاقياً، لكنها مذكورة لسبب تفسيري: معرفة من أنتج النص تخبرك بأي الفئات سيخدمها النموذج جيداً وأيها لا.
Which statement correctly separates a code point from a glyph?
أي عبارة تفصل بشكل صحيح بين الـ code point والـ glyph؟
Slide 31 and slide 33 state the split and add that the same visual shape can correspond to different code points and the reverse. C is the misconception the slides are written to prevent, and it is tempting because in plain ASCII text the two really do line up one to one. D confuses code points with bytes; code points go past a million and are not limited to a byte's range.
الجواب B. الشريحتان 31 و33 تذكران هذا الفصل وتضيفان أن الشكل المرئي نفسه قد يقابل code points مختلفة والعكس. والجواب C هو التصور الخاطئ الذي كُتبت الشرائح لمنعه، وهو مُغرٍ لأن الاثنين في نص ASCII العادي يتطابقان فعلاً واحداً لواحد. والجواب D يخلط بين الـ code points والبايتات، فالـ code points تتجاوز المليون ولا تقتصر على مدى البايت.