Majid Al-RaimiGenerating candidates with edit distanceتوليد المرشحين بمسافة التحرير

ICS 582Lecture 05المحاضرة 05Part 03الجزء 03

Generating candidates with edit distanceتوليد المرشحين بمسافة التحرير

Turning a misspelling like acress into a short list of real words: Damerau-Levenshtein edits of distance one, the four edit types, and why distance one or two is enough.تحويل خطأ مثل acress إلى قائمة قصيرة من الكلمات الحقيقية: تعديلات Damerau-Levenshtein بمسافة واحد، وأنواع التعديل الأربعة، ولماذا تكفي المسافة واحد أو اثنان.

Conceptsالمفاهيم
3
Slidesالشرائح
13-16
Readingمدة القراءة
18 min18 دقيقة
Understoodما فهمته
0/3 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

The noisy channel model from the previous part says: pick the word that maximizes channel probability times prior. That rule has a hidden precondition. Before you can take an argmax, you need a set of words to take it over, and scoring every word in a dictionary of hundreds of thousands of entries for every typo would be wasteful and mostly pointless. This part builds that set.

The idea is short to state: the intended word is almost always a few keystrokes away from what was typed, so generate every string a small number of edits away and keep the ones that are real words. The details are where exam marks live: which edits count, how each one is named, how many strings the generator produces, and why a radius of one or two edits is enough. One running example carries the whole part, the misspelling acress.

يقول نموذج القناة المشوشة من الجزء السابق: اختر الكلمة التي تعظّم حاصل ضرب احتمال القناة في الاحتمال المسبق (prior). لهذه القاعدة شرط مسبق خفي. قبل أن تأخذ argmax تحتاج إلى مجموعة من الكلمات تأخذه عليها، وحساب درجة كل كلمة في قاموس يضم مئات الآلاف من المدخلات مع كل خطأ إملائي سيكون هدرًا وبلا فائدة في معظمه. هذا الجزء يبني تلك المجموعة.

الفكرة قصيرة في صياغتها: الكلمة المقصودة تبعد دائمًا تقريبًا بضع ضغطات مفاتيح عمّا كُتب، لذلك نولّد كل سلسلة تبعد عددًا صغيرًا من التعديلات ونحتفظ بما هو كلمات حقيقية منها. أما التفاصيل فهي حيث تكمن درجات الامتحان: أي التعديلات تُحتسب، وكيف يُسمّى كل منها، وكم سلسلة يولّدها المولّد، ولماذا يكفي نصف قطر من تعديل واحد أو تعديلين. مثال واحد مستمر يحمل الجزء كله، وهو الخطأ الإملائي acress.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Explain why the noisy channel needs a short candidate list before it can score anything.تشرح لماذا يحتاج نموذج القناة المشوشة (<bdi>noisy channel</bdi>) إلى قائمة قصيرة من المرشحين قبل أن يستطيع حساب أي درجة.
  2. Name the two sources of candidates: words spelled similarly and words pronounced similarly.تسمّي مصدرَي المرشحين: كلمات متشابهة في التهجئة، وكلمات متشابهة في النطق.
  3. Classify any one-edit error as deletion, insertion, substitution or transposition, from the typist's point of view.تصنّف أي خطأ بتعديل واحد إلى حذف (deletion) أو إدراج (insertion) أو استبدال (substitution) أو تبديل مواضع (transposition)، من وجهة نظر الكاتب.
  4. Rebuild the seven-row acress table, including why acres appears twice.تعيد بناء جدول acress ذي الصفوف السبعة، بما في ذلك سبب ظهور acres مرتين.
  5. Count the edit-1 strings of a word with 54n + 25 and explain why the dictionary filter is the decisive step.تحسب عدد السلاسل على بُعد تعديل واحد من كلمة باستخدام 54n + 25، وتشرح لماذا يكون فلتر القاموس هو الخطوة الحاسمة.
  6. Justify the edit-distance radius of 1 or 2 and the extra space and hyphen edits.تبرّر نصف قطر مسافة التعديل البالغ 1 أو 2، وتعديلَي إدراج المسافة والشرطة الإضافيين.

Someone types acress. No English dictionary contains it, so this is a Non-word error: detection is a simple lookup. Correction is the hard half. What did they mean? Your mind probably offers actress or across within a second, and maybe acres. You did not search a dictionary alphabetically. You searched the neighbourhood of the typo, words that look like it.

يكتب شخص ما acress. لا يحتوي أي قاموس إنجليزي على هذه الكلمة، لذا فهذا non-word error (خطأ ينتج كلمة غير موجودة): اكتشافه مجرد بحث بسيط في القاموس. التصحيح هو النصف الصعب. ماذا كان يقصد؟ غالبًا يقترح عليك ذهنك actress أو across خلال ثانية، وربما acres. لم تبحث في القاموس أبجديًا. بل بحثت في جوار الخطأ، أي الكلمات التي تشبهه.

From a typo to a list of suspectsمن الخطأ الإملائي إلى قائمة من المشتبه بهم

Candidate generation is that neighbourhood search made explicit. It turns one observed string x into a short list of real words w, and only those words go on to the Noisy channel model, where each is scored by P(x|w)P(w). The argmax in that formula ranges over the candidate list, not over the whole vocabulary. That is the first thing to understand about this step: it decides which answers are even possible. If the right word is not generated, no amount of good scoring can recover it.

Candidate generation (توليد المرشحين) هو هذا البحث في الجوار وقد صار صريحًا. فهو يحوّل سلسلة واحدة مرصودة x إلى قائمة قصيرة من الكلمات الحقيقية w، وهذه الكلمات وحدها تنتقل إلى noisy channel model، حيث تُعطى كل منها درجة بالقيمة P(x|w)P(w). الـ argmax في هذه الصيغة يمتد على قائمة المرشحين، لا على المفردات كلها. هذا أول ما يجب فهمه عن هذه الخطوة: إنها تحدد أي الإجابات ممكنة أصلًا. إذا لم تُولَّد الكلمة الصحيحة، فلن يستطيع أي قدر من حساب الدرجات الجيد استعادتها.

w^=argmax⁡w∈C(x)  P(x∣w) P(w)\hat{w} = \underset{w \in C(x)}{\operatorname{argmax}}\; P(x \mid w)\,P(w)
The noisy channel decision, restricted to the candidate set C(x) built in this partقرار القناة المشوشة، مقيدًا بمجموعة المرشحين C(x) المبنية في هذا الجزء

The lecture names two ways a real word can be near a typo.

تذكر المحاضرة طريقتين يمكن أن تكون بهما كلمة حقيقية قريبة من خطأ إملائي.

  • Similar spelling. The word has a small Edit distance to the error: a few letters inserted, deleted, replaced or swapped turn one into the other. This catches typographical errors, slips of the fingers such as actress typed as acress.تهجئة متشابهة. للكلمة edit distance (مسافة تعديل) صغيرة إلى الخطأ: بضعة أحرف تُدرج أو تُحذف أو تُستبدل أو تُبدَّل مواضعها فتحوّل إحداهما إلى الأخرى. هذا يلتقط typographical errors (أخطاء الطباعة)، وهي زلّات الأصابع مثل كتابة actress على شكل acress.
  • Similar pronunciation. The word sounds like the error. Each string is first mapped to an approximate pronunciation, and candidates are words whose pronunciation is a small edit distance from the pronunciation of the typo. This catches cognitive errors, where the writer spells by sound, which letter edits alone can miss when the spelling is far off but the sound is close.نطق متشابه. الكلمة تبدو في صوتها مثل الخطأ. تُحوَّل كل سلسلة أولًا إلى نطق تقريبي، والمرشحون هم الكلمات التي يبعد نطقها مسافة تعديل صغيرة عن نطق الخطأ. هذا يلتقط cognitive errors (الأخطاء الإدراكية)، حين يتهجّى الكاتب الكلمة بحسب صوتها، وهي أخطاء قد تفوت تعديلات الأحرف وحدها عندما تكون التهجئة بعيدة لكن الصوت قريب.
Two neighbourhoods around acress: words one letter edit away, and words whose pronunciation is closeجواران حول acress: كلمات تبعد تعديلًا واحدًا في الأحرف، وكلمات نطقها قريب

Both routes use the same tool, edit distance, applied to different strings: letters in one case, pronunciation symbols in the other. GNU aspell, for example, generates candidates by comparing Metaphone keys, and later systems fold this into a Phonetic error model. Part 8 returns to those. For the rest of this part we work with spelling, which is what the acress example and the Kernighan, Church and Gale data use.

يستخدم الطريقان الأداة نفسها، مسافة التعديل، مطبّقة على سلاسل مختلفة: الأحرف في حالة، ورموز النطق في الأخرى. فبرنامج GNU aspell مثلًا يولّد المرشحين بمقارنة مفاتيح Metaphone، والأنظمة اللاحقة تدمج ذلك في phonetic error model (نموذج أخطاء صوتي). يعود الجزء 8 إلى هذه الأنظمة. في بقية هذا الجزء نعمل على التهجئة، وهي ما يستخدمه مثال acress وبيانات Kernighan وChurch وGale.

Recall

Why does the noisy channel need a candidate generator at all, and what happens if the generator misses the intended word?لماذا تحتاج القناة المشوشة إلى مولّد مرشحين أصلًا، وماذا يحدث إذا فاتت المولّدَ الكلمةُ المقصودة؟

The argmax has to range over some finite, small set; scoring the whole vocabulary for every typo is wasteful, and most words are absurd corrections anyway. The generator defines that set. If the intended word is not in it, the decoder cannot choose it, however good the channel model and language model are, so generation sets an upper limit on accuracy.

يجب أن يمتد الـ argmax على مجموعة ما محدودة وصغيرة؛ فحساب درجات المفردات كلها مع كل خطأ إملائي هدر، ومعظم الكلمات تصحيحات سخيفة على أي حال. المولّد هو من يحدد تلك المجموعة. إذا لم تكن الكلمة المقصودة فيها، فلا يستطيع المفكّك (decoder) اختيارها مهما كانت جودة نموذج القناة ونموذج اللغة، لذلك يضع التوليد حدًا أعلى للدقة.

Take the intended word actress and imagine the typist hurrying. Their finger skips the t, and acress comes out. Now take caress: the typist hits a before c, and acress comes out again. Six different real words can turn into the same typo with a single slip each. The table on slide 15 lists every one of them and names the slip.

خذ الكلمة المقصودة actress وتخيّل الكاتب مستعجلًا. يتخطى إصبعه الحرف t، فتخرج acress. والآن خذ caress: يضغط الكاتب a قبل c، فتخرج acress مرة أخرى. ست كلمات حقيقية مختلفة يمكن أن تتحول إلى الخطأ نفسه بزلّة واحدة لكل منها. الجدول في الشريحة 15 يسرد كل واحدة منها ويسمّي الزلّة.

Four kinds of single slipأربعة أنواع من الزلّة الواحدة

Spelling correction uses Damerau-Levenshtein distance, which counts four operations, each at cost 1:

يستخدم تصحيح التهجئة Damerau-Levenshtein distance، التي تحتسب أربع عمليات، تكلفة كل منها 1:

  • Deletion: a letter of the intended word is left out (actress becomes acress).Deletion (حذف): يُترك حرف من الكلمة المقصودة دون كتابة (actress تصبح acress).
  • Insertion: an extra letter is typed (cress becomes acress).Insertion (إدراج): يُكتب حرف زائد (cress تصبح acress).
  • Substitution: one letter is typed in place of another (across becomes acress).Substitution (استبدال): يُكتب حرف مكان حرف آخر (across تصبح acress).
  • Transposition: two adjacent letters are swapped (caress becomes acress).Transposition (تبديل مواضع): يتبادل حرفان متجاوران موضعيهما (caress تصبح acress).
Each row starts from an intended word and applies one slip to reach acress; the marked letters are the ones the slip touchedيبدأ كل صف من كلمة مقصودة ويطبّق زلّة واحدة للوصول إلى acress؛ الأحرف المعلَّمة هي التي مسّتها الزلّة

The convention that decides exam answersالاصطلاح الذي يحسم إجابات الامتحان

The type always names what the typist did to the correct word to produce the error. Read every row as intended word → typo, never the other way. That is why the columns are called correct letter and error letter: the correct letter is what should have been typed, the error letter is what was typed, and a dash means nothing. So actress has correct letter t and error letter dash: a t should have been there and nothing was typed, a deletion. cress has correct letter dash and error letter a: nothing should have been there and an a was typed, an insertion.

يسمّي النوعُ دائمًا ما فعله الكاتب بالكلمة الصحيحة لينتج الخطأ. اقرأ كل صف على أنه intended word → typo (من الكلمة المقصودة إلى الخطأ)، لا العكس أبدًا. لهذا سُمّي العمودان correct letter (الحرف الصحيح) وerror letter (الحرف الخاطئ): الحرف الصحيح هو ما كان يجب أن يُكتب، والحرف الخاطئ هو ما كُتب فعلًا، والشرطة تعني لا شيء. إذن لـ actress حرف صحيح t وحرف خاطئ شرطة: كان يجب أن يوجد t ولم يُكتب شيء، أي حذف. ولـ cress حرف صحيح شرطة وحرف خاطئ a: لم يكن يجب أن يوجد شيء وكُتب a، أي إدراج.

CandidateالمرشحCorrect letterالحرف الصحيحError letterالحرف الخاطئPositionالموضعType, from the typist's sideالنوع، من جهة الكاتب
actressactresstt--22deletion: the typist left out tحذف: أسقط الكاتب الحرف t
cresscress--aa00insertion: the typist added aإدراج: أضاف الكاتب الحرف a
caresscaresscacaacac00transposition: c and a swappedتبديل مواضع: تبادل c وa موضعيهما
accessaccessccrr22substitution: r typed for cاستبدال: كُتب r مكان c
acrossacrossooee33substitution: e typed for oاستبدال: كُتب e مكان o
acresacres--ss44insertion: extra s after e (es|e)إدراج: s زائد بعد e (es|e)
acresacres--ss55insertion: extra s after s (ss|s)إدراج: s زائد بعد s (ss|s)
Slide 15 with the reasoning spelled out. Position is the index in acress, counting from 0, as in Jurafsky and Martin, Fig. B.3الشريحة 15 مع شرح المنطق كاملًا. الموضع هو الفهرس في acress بدءًا من 0، كما في Jurafsky and Martin، الشكل B.3

Why transposition gets its own operationلماذا يحصل تبديل المواضع على عملية خاصة به

In lecture 2 you computed minimum edit distance with three operations only, insertion, deletion and substitution. That is Levenshtein distance. Under it, caress and acress are two edits apart: two substitutions, or a deletion plus an insertion. Damerau observed in 1964 that swapping two neighbouring keys is one of the commonest typing mistakes, so he counted it as a single edit. Adding that one operation is the only difference, and it is what makes caress a distance-1 candidate.

في المحاضرة 2 حسبت مسافة التعديل الدنيا (minimum edit distance) بثلاث عمليات فقط: الإدراج والحذف والاستبدال. هذه هي مسافة Levenshtein. وفقها، تبعد caress وacress تعديلين: استبدالين، أو حذفًا مع إدراج. لاحظ Damerau عام 1964 أن تبديل مفتاحين متجاورين من أكثر أخطاء الطباعة شيوعًا، فاحتسبه تعديلًا واحدًا. إضافة هذه العملية الواحدة هي الفرق الوحيد، وهي ما يجعل caress مرشحًا على مسافة 1.

LevenshteinLevenshteinDamerau-LevenshteinDamerau-Levenshtein
OperationsالعملياتInsertion, deletion, substitutionالإدراج والحذف والاستبدالThe same three plus transposition of adjacent lettersالعمليات الثلاث نفسها مع تبديل موضعَي حرفين متجاورين
Distance from acress to caressالمسافة من acress إلى caress2 (two substitutions, or a deletion plus an insertion)2 (استبدالان، أو حذف مع إدراج)11
Where you met itأين قابلتهاLecture 2, minimum edit distance with dynamic programmingالمحاضرة 2، مسافة التعديل الدنيا بالبرمجة الديناميكيةThis lecture, candidate generationهذه المحاضرة، توليد المرشحين
Why it fits hereلماذا تناسب هناGeneral string similarity and alignmentتشابه السلاسل ومحاذاتها بشكل عامSwapped neighbours are one of the commonest typing slipsتبادل حرفين متجاورين من أكثر زلّات الطباعة شيوعًا
Levenshtein (lecture 2) versus Damerau-Levenshtein (this lecture)مسافة Levenshtein (المحاضرة 2) مقابل مسافة Damerau-Levenshtein (هذه المحاضرة)

Quick checkاختبار سريع

acress was typed when the writer meant caress. Which error type is this?كُتبت acress بينما قصد الكاتب caress. ما نوع هذا الخطأ؟

Quick checkاختبار سريع

acress was typed when the writer meant actress. Which error type is this?كُتبت acress بينما قصد الكاتب actress. ما نوع هذا الخطأ؟

Recall

Why does acres appear twice in the acress table, and why should both rows be kept?لماذا تظهر acres مرتين في جدول acress، ولماذا يجب الإبقاء على الصفين؟

acress ends in two s letters, and the extra one could have been typed after e (position 4) or after the first s (position 5), written es|e and ss|s on slide 24. Those are two distinct derivations of the same candidate. They are kept because each has its own channel probability, conditioned on a different preceding letter, and the probability that acres produced acress is the sum over the ways it could have happened.

تنتهي acress بحرفَي s، والحرف الزائد قد يكون كُتب بعد e (الموضع 4) أو بعد أول s (الموضع 5)، ويُكتبان es|e وss|s في الشريحة 24. هذان اشتقاقان مختلفان للمرشح نفسه. يُبقى عليهما لأن لكل منهما احتمال قناة خاصًا به، مشروطًا بحرف سابق مختلف، واحتمال أن تكون acres قد أنتجت acress هو مجموع الاحتمالات على كل الطرق التي يمكن أن يحدث بها ذلك.

How does a program actually find those six words? It does not compare acress against every dictionary entry. It runs the four operations in reverse on the typo itself, every possible way, and then asks the dictionary which of the results exist. Peter Norvig's well-known corrector does exactly this in a few lines. The number of strings it produces is worth computing once, because it explains the whole design.

كيف يجد البرنامج هذه الكلمات الست فعلًا؟ إنه لا يقارن acress بكل مدخل في القاموس. بل يشغّل العمليات الأربع بالعكس على الخطأ نفسه، بكل طريقة ممكنة، ثم يسأل القاموس أي النتائج موجود. مصحح Peter Norvig المعروف يفعل هذا بالضبط في بضعة أسطر. عدد السلاسل التي ينتجها يستحق أن يُحسب مرة واحدة، لأنه يفسّر التصميم كله.

Worked exampleمثال محلول

How many strings lie one edit from a word of length n?كم سلسلة تقع على بُعد تعديل واحد من كلمة طولها n؟

  1. Deletionsالحذف

    Remove any one of the n letters: n strings.
    احذف أيًّا من الأحرف الـ n: n سلسلة.
  2. Transpositionsتبديل المواضع

    Swap any of the n - 1 adjacent pairs: n - 1 strings.
    بدّل أيًّا من الأزواج المتجاورة الـ n - 1: n - 1 سلسلة.
  3. Substitutionsالاستبدال

    Replace any of the n letters with any of 26 letters: 26n strings.
    استبدل أيًّا من الأحرف الـ n بأي حرف من الأحرف الـ 26: 26n سلسلة.
  4. Insertionsالإدراج

    Insert any of 26 letters into any of the n + 1 gaps, including both ends: 26(n + 1) strings.
    أدرج أيًّا من الأحرف الـ 26 في أي فجوة من الفجوات الـ n + 1، بما فيها الطرفان: 26(n + 1) سلسلة.
  5. Add them upاجمعها

    n+(n−1)+26n+26(n+1)=54n+25n + (n-1) + 26n + 26(n+1) = 54n + 25
    n+(n−1)+26n+26(n+1)=54n+25n + (n-1) + 26n + 26(n+1) = 54n + 25
  6. Plug in acressعوّض بـ acress

    With n = 6: 6 + 5 + 156 + 182 = 349 strings. If substitutions skip the letter that is already there (25n instead of 26n), it is 343. Some strings repeat, so the distinct count is 336, and one of those is acress itself (swapping the two s letters, or replacing a letter by itself, gives it back).
    مع n = 6: 6 + 5 + 156 + 182 = 349 سلسلة. إذا تخطّى الاستبدال الحرف الموجود أصلًا (25n بدلًا من 26n)، يصبح العدد 343. بعض السلاسل يتكرر، فيكون العدد المميز 336، وإحداها هي acress نفسها (تبديل حرفَي s، أو استبدال حرف بنفسه، يعيدها كما هي).
  7. Resultالنتيجة

    About 335 new strings, of which exactly six are English words: actress, cress, caress, access, across, acres. Roughly 98% of the generator's output is junk such as zcress or acrss.
    نحو 335 سلسلة جديدة، ست منها بالضبط كلمات إنجليزية: actress وcress وcaress وaccess وacross وacres. قرابة 98% من مخرجات المولّد نفايات مثل zcress أو acrss.
349 edit-1 strings of acress; only six survive the dictionary lookup349 سلسلة على بُعد تعديل واحد من acress؛ ست منها فقط تنجو من البحث في القاموس

This is why the dictionary filter, not the edit operations, is the key step. Generating strings is trivial and cheap; almost all of them are nonsense. Intersecting them with the dictionary is what turns a few hundred strings into a handful of real candidates, each with its edit type and position recorded for the channel model. Because the count is linear in n, edit-1 generation is fast for any realistic word.

لهذا السبب فإن فلتر القاموس، لا عمليات التعديل، هو الخطوة الأساسية. توليد السلاسل أمر تافه ورخيص؛ وكلها تقريبًا بلا معنى. تقاطعها مع القاموس هو ما يحوّل بضع مئات من السلاسل إلى حفنة من المرشحين الحقيقيين، مع تسجيل نوع التعديل وموضعه لكل منها لصالح نموذج القناة. ولأن العدد خطي في n، فإن توليد السلاسل على بُعد تعديل واحد سريع لأي كلمة واقعية.

Why stop at one or two editsلماذا نتوقف عند تعديل واحد أو تعديلين

The radius is set by data on real errors. Damerau's 1964 study found that more than 80% of the misspellings he examined were a single insertion, deletion, substitution or transposition, and the slide's rule follows: about 80% of errors are within edit distance 1, almost all within 2. Norvig's experiment agrees on the second half: in his development set only 3 of 270 errors were further than two edits from the correction.

يُحدَّد نصف القطر ببيانات الأخطاء الحقيقية. وجدت دراسة Damerau عام 1964 أن أكثر من 80% من الأخطاء الإملائية التي فحصها كانت إدراجًا واحدًا أو حذفًا أو استبدالًا أو تبديل مواضع، ومنها تأتي قاعدة الشريحة: نحو 80% من الأخطاء ضمن مسافة تعديل 1، وكلها تقريبًا ضمن 2. وتجربة Norvig تتفق مع الشطر الثاني: في مجموعة التطوير لديه كان 3 فقط من 270 خطأ أبعد من تعديلين عن التصحيح.

Going further is expensive and rarely useful. Applying the generator twice squares the work: for acress the edit-2 set has on the order of 335 × 349 ≈ 117,000 raw strings, and the number of real words inside that wider ring grows too, so the channel model has more distractors to separate. Norvig's corrector therefore tries distance 1 first and widens to distance 2 only when distance 1 finds no known word.

الذهاب أبعد مكلف ونادرًا ما يفيد. تطبيق المولّد مرتين يربّع العمل: لكلمة acress تضم مجموعة التعديلين ما يقارب 335 × 349 ≈ 117,000 سلسلة خام، ويزداد أيضًا عدد الكلمات الحقيقية داخل هذه الحلقة الأوسع، فيكون أمام نموذج القناة مشتّتات أكثر عليه التمييز بينها. لذلك يجرّب مصحح Norvig المسافة 1 أولًا، ولا يتوسع إلى المسافة 2 إلا عندما لا تجد المسافة 1 أي كلمة معروفة.

Space and hyphen as extra editsالمسافة والشرطة كتعديلات إضافية

Some errors are not inside a word at all. A typist who misses the space bar produces thisidea for this idea; one who drops a hyphen produces inlaw for in-law. Neither is one letter edit from a single dictionary word, so the plain generator returns nothing. Allowing the generator to insert a space or a hyphen between two letters fixes this, as long as the lookup then checks each piece. It adds only 2(n - 1) strings.

بعض الأخطاء ليست داخل كلمة أصلًا. الكاتب الذي يخطئ مفتاح المسافة ينتج thisidea بدلًا من this idea؛ ومن يُسقط شرطة ينتج inlaw بدلًا من in-law. لا يبعد أي منهما تعديل حرف واحد عن كلمة واحدة في القاموس، لذا لا يعيد المولّد العادي شيئًا. السماح للمولّد بإدراج مسافة أو شرطة بين حرفين يحل المشكلة، بشرط أن يفحص البحث بعد ذلك كل جزء على حدة. وهذا لا يضيف إلا 2(n - 1) سلسلة.

Try the generator below. Start with acress and check that the counts match the worked example and that the survivors match slide 15, both acres rows included. Then try teh, graffe, and the two run-together presets. Notice that the survivor column names the typist's error even though the generator ran the opposite operation. The run-together presets switch the space and hyphen option on; switch it on for acress too and a cress appears as an eighth row, a small reminder that every extra kind of edit also admits extra distractors.

جرّب المولّد أدناه. ابدأ بـ acress وتحقق من أن الأعداد تطابق المثال المحلول وأن الناجين يطابقون الشريحة 15، بما في ذلك صفّا acres كلاهما. ثم جرّب teh وgraffe والإعدادين المسبقين للكلمات الملتصقة. لاحظ أن عمود الناجين يسمّي خطأ الكاتب رغم أن المولّد نفّذ العملية المعاكسة. الإعدادان المسبقان للكلمات الملتصقة يفعّلان خيار المسافة والشرطة؛ فعّله مع acress أيضًا وستظهر a cress صفًا ثامنًا، تذكيرًا صغيرًا بأن كل نوع إضافي من التعديل يُدخل أيضًا مشتّتات إضافية.

InteractiveتفاعليEdit-1 candidate generatorمولّد المرشحين على بعد تعديل واحد
Delete a letter6n
Swap neighbours5n - 1
Replace a letter15626n
Insert a letter18226(n + 1)
Generated349strings
Distinct336strings
In dictionary7derivations

349 strings generated, 336 distinct, 7 dictionary derivations

CandidateCorrectErrorPositionTypist made
cress-a0insertion
acres-s4insertion
acres-s5insertion
caresscaac0transposition
accesscr2substitution
acrossoe3substitution
actresst-2deletion

The generator edits the typed word, so its operations run backwards from the typist. Deleting a letter from the typo finds a word where the typist inserted one, and inserting a letter finds a word where the typist deleted one. Position counts letters of the typed word from 0. The dictionary is a tiny demo list, not a real lexicon.يعدّل المولّد الكلمة المكتوبة، لذلك تسير عملياته في الاتجاه المعاكس لما فعله الكاتب. حذف حرف من الخطأ الإملائي يجد كلمة أدرج فيها الكاتب حرفًا زائدًا، وإدراج حرف يجد كلمة حذف منها الكاتب حرفًا. يُعدّ الموضع حروف الكلمة المكتوبة بدءًا من 0. القاموس هنا قائمة تجريبية صغيرة، وليس معجمًا حقيقيًا.

Quick checkاختبار سريع

Using 54n + 25, how many edit-1 strings does a four-letter typo generate?باستخدام 54n + 25، كم سلسلة على بُعد تعديل واحد يولّدها خطأ إملائي من أربعة أحرف؟

Recall

Why does candidate generation also allow inserting a space or hyphen?لماذا يسمح توليد المرشحين أيضًا بإدراج مسافة أو شرطة؟

Because some errors join two words: thisidea for this idea, inlaw for in-law. The run-together string is not one letter edit from any single dictionary word, so letter edits alone return nothing. Inserting a space or hyphen between two letters, then checking each piece against the dictionary, recovers these cases at a cost of only 2(n - 1) extra strings.

لأن بعض الأخطاء تدمج كلمتين: thisidea بدلًا من this idea، وinlaw بدلًا من in-law. السلسلة الملتصقة لا تبعد تعديل حرف واحد عن أي كلمة واحدة في القاموس، لذا لا تعيد تعديلات الأحرف وحدها شيئًا. إدراج مسافة أو شرطة بين حرفين، ثم فحص كل جزء في القاموس، يستعيد هذه الحالات بتكلفة لا تتجاوز 2(n - 1) سلسلة إضافية.

Recall

Of the 349 edit-1 strings of acress, how many survive, and what does that say about where the work happens?من بين 349 سلسلة على بُعد تعديل واحد من acress، كم منها ينجو، وماذا يخبرنا ذلك عن موضع العمل الحقيقي؟

Six distinct words (seven derivations, because acres arises twice). Nearly everything the generator makes is not a word, so the dictionary lookup does the real filtering; generation itself is cheap and blind.

ست كلمات مميزة (سبعة اشتقاقات، لأن acres تنشأ مرتين). كل ما يصنعه المولّد تقريبًا ليس كلمة، لذا فالبحث في القاموس هو من يقوم بالتصفية الحقيقية؛ أما التوليد نفسه فرخيص وأعمى.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • The noisy channel scores candidates, it does not invent them. Candidate generation hands it a short list of real words near the typo.القناة المشوشة تعطي المرشحين درجات ولا تخترعهم. توليد المرشحين يسلّمها قائمة قصيرة من الكلمات الحقيقية القريبة من الخطأ.
  • Candidates come from small edit distance in spelling, and from small edit distance between pronunciations.يأتي المرشحون من مسافة تعديل صغيرة في التهجئة، ومن مسافة تعديل صغيرة بين طريقتَي النطق.
  • Spelling edits are Damerau-Levenshtein: insertion, deletion, substitution, and transposition of two adjacent letters, each costing 1.تعديلات التهجئة هي تعديلات Damerau-Levenshtein: الإدراج والحذف والاستبدال وتبديل موضعَي حرفين متجاورين، وتكلفة كل منها 1.
  • The type names what the typist did to the intended word: actress to acress is a deletion of t, cress to acress is an insertion of a.يسمّي النوعُ ما فعله الكاتب بالكلمة المقصودة: من actress إلى acress حذفٌ للحرف t، ومن cress إلى acress إدراجٌ للحرف a.
  • acress has six candidates in seven rows: acres arises twice, from an extra s typed at position 4 or at position 5.لكلمة acress ستة مرشحين في سبعة صفوف: تظهر acres مرتين، من حرف s زائد كُتب في الموضع 4 أو في الموضع 5.
  • A word of length n has n + (n - 1) + 26n + 26(n + 1) = 54n + 25 edit-1 strings: 349 for acress, of which only six are words.للكلمة ذات الطول n عدد n + (n - 1) + 26n + 26(n + 1) = 54n + 25 من السلاسل على بُعد تعديل واحد: 349 لكلمة acress، ستّ منها فقط كلمات حقيقية.
  • About 80 percent of errors are within one edit and almost all within two. Space and hyphen insertion handle run-together words like thisidea and inlaw.نحو 80 بالمئة من الأخطاء تقع ضمن تعديل واحد، وكلها تقريبًا ضمن تعديلين. إدراج المسافة والشرطة يعالج الكلمات الملتصقة مثل thisidea وinlaw.

Sourcesالمصادر