<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Spelling Correction as a Foreign Language</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Yingbo Zho∗u</string-name>
          <email>yingbzhou@ebay.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Utkarsh Porwal</string-name>
          <email>uporwal@ebay.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Roberto Konow</string-name>
          <email>rkonow@ebay.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>eBay Inc</institution>
          ,
          <addr-line>San Jose, California</addr-line>
          ,
          <country country="US">USA</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2019</year>
      </pub-date>
      <abstract>
        <p>sources for spelling mistakes, e.g. typing too fast, unintentional key In this paper, we reformulated the spelling correction problem asstroke, phonetic ambiguity among others. Lastly, in certain context a machine translation task under the encoder-decoder framework. (e.g. in a search engine) it is not easy to obtain clean training data This reformulation enabled us to use a single model for solvifnogr language model as the input does not follow what is typical in this problem that is traditionally formulated as learning a langnuaatgueral language. model and an error model. This model employs multi-layer recur- Since the goal is to get text that maximP (ixz|xe˜), can we directly rent neural networks as an encoder and a decoder. We demonstrate model this conditional distribution instead? In this work, we exthe efectiveness of this model using an internal dataset, where theplore this route, which by passes the need to have multiple models training data is automatically obtained from user logs. The moadneld avoid getting errors from multiple sources. We achieve this ofers competitive performance as compared to the state of the art by applying the sequence to sequence learning framework using methods but does not require any feature engineering nor hand recurrent neural networks [16] and reformulate the spelling cortuning between models. rection problem as a neural machine translation problem, where the misspelled input is treated as a foreign language.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        forward neural network for modeling sequential data. More
formally, le(tx1, x2, . . . , xT ), xt ∈ Rd be the input, an RNN update its
ct = ft ⊙ ct −1 + (1 − ft ) ⊙ tanh(Wc xt + Ucht −1 + bc )
internal recurrent hidden states by doing the following computwa-here the input is the misspelled text and the output is the
cortion: responding correct spellings. One challenge for this formulation
ht = ψ (ht −1, xt ) (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) is that unlike in machine translation problem, the vocabulary is
large but still li m2.iHtoewdever, in spelling correction, the input
where ψ is a nonlinear function. Traditionally, in a standard RNN
the ψ is implemented as an aine transformation followed by avocabulary is potentially unbounded, which rules out the possibility
pointwise nonlinearity, such as of applying word based encoding for this problem. In addition, the
large output vocabulary is a general challenge in neural network
ht = ψ (ht −1, xt ) = tanh(W xt + U ht −1 + bh ) based machine translation models because of the large Softmax
IRnoatdhdaitctainobne, cthaelcRuNlNatemdabyyaulssionhgavaenootuhtepru(ynts1o,nyl2i,.n. e.a,yrTf)u,nyctϕti∈on outTphuet imantpruit/xo.utput vocabulary problem can be solved by using a
character based encoding scheme. Although it seems appropriate
yt = ϕ(ht , xt ) for encoding the input, this scheme puts unnecessary burden on
From this recursion, the recurrent neural network naturally models the decoder, since for a correction the decoder need to learn the
the conditional probabiPl(yitt|yx1, . . . , xt ). correct spelling of the word, word boundaries, and etc. We choose
the byte pair encoding (BPE) schem1e5[] that strikes the balance
      </p>
      <p>One problem with standard RNN is that it is diicult for them to
learn long term dependencie2s,[9], and therefore in practice more between too large output vocabulary and too much learning burden
sophisticated funct iψoanre often used to alleviate this problem. for decoders. In this scheme, the vocabulary is built by recursively
For example the long short term memory (LSTM)1[0] is one widely merging most frequent pairs of strings starting from character,
and the vocabulary size is controlled by the number of merging
used recursive unit that is designed to learn long term dependencies.</p>
      <p>
        A layer LSTM consists of three gates and one memory cell, the iterations.
computation of LSTM is as follo1w: ing As shown in papers1[], encoding the whole input string to a
single ixed length vector is not optimal, since it may not reserve all
it = σ (Wi xt + Uiht −1 + bi ) (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) the information that is required for a successful decoding. Therefore,
ot = σ (Woxt + Uoht −1 + bo ) (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) we introduce the attention mechanism from Bahdanau e1t]ail.[nto
ft = σ (Wf xt + Uf ht −1 + bf ) (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) this model. Formally, the attention model calculates a context vector
ci from the encoding statehs1, . . . , hT and decoder state si−1by
ht = ot ⊙ tanh(ct )
(
        <xref ref-type="bibr" rid="ref5">5</xref>
        )
(
        <xref ref-type="bibr" rid="ref6">6</xref>
        )
      </p>
      <p>
        T
ci = Õ λi jhj
j=1
(
        <xref ref-type="bibr" rid="ref9">9</xref>
        )
(
        <xref ref-type="bibr" rid="ref14">14</xref>
        )
(
        <xref ref-type="bibr" rid="ref15">15</xref>
        )
(
        <xref ref-type="bibr" rid="ref16">16</xref>
        )
where W , U , and b represents the corresponding input-to-hidden,
hidden-to-hidden weights and biases respect iσ(v·e)ldye.notes the exp{ai j }
sigmoid function,⊙anids the elementwise product. λi j = ÍTk=1 exp{aik } (
        <xref ref-type="bibr" rid="ref10">10</xref>
        )
leaArnniotnhegrpprroobblleemmiwshtehnaut siitnig sRnNoNt ctolesaorlvwehsaetqsuterantceegtyotsoeqauppenlcyewhen ai j = tanh(Wssi−1 + Whhj + b) (
        <xref ref-type="bibr" rid="ref11">11</xref>
        )
the input and output sequence does not share the same length where Ws , Wh are the weight vector for alignment model,band
(i.e. for outputs we havTe′ time steps, which may not equalTt)o, denotes the bias.
which is the typical setting for this type of tasks. Sutskever et alN.ow we are ready to introduce the full model for spelling
cor[16] propose to use an auto-encoder type of strategy, where the rection. The model takes a sequence of input (characters or BPE
input sequence is encoded to a ixed length vector by using the encoded sub-words) x1, . . . , xT and outputs a sequence of BPE
enlast hidden state of the recurrent neural network, and then decode coded sub-words y1, . . . , yT ′. For each input token the encoder
the output sequence from the vector. In more detail, let input and learns a functiofne to map to its hidden representatihot n
output sequence have T and T ′ time steps, andfe , fd denote the
encoding and decoding functions respectively, then the model tries ht = fe (ht −1, xt ; θe ) (
        <xref ref-type="bibr" rid="ref12">12</xref>
        )
to learnP (y1, . . . , yT ′ |x1, . . . , xT ) by h0 = 0 (
        <xref ref-type="bibr" rid="ref13">13</xref>
        )
s ≜ fe (x1, . . . , xT ) = hT
yt ≜ fd (s, y1, . . . , yt −1)
(
        <xref ref-type="bibr" rid="ref7">7</xref>
        )
(
        <xref ref-type="bibr" rid="ref8">8</xref>
        )
      </p>
      <p>The attentional decoder irst obtain the context veccttorbased on
equation 10, and then learns a functifodnthat decodes yt from the
context vector ct
where fe and fd are implemented using multi-layer LSTMs.
4 SPELLING CORRECTION AS A FOREIGN</p>
      <p>LANGUAGE
p(yt |st ) = softmax(W st + bd )
s0 = U hT
st = fd (st −1, ct ; θd )
It is easy to see that spelling correction problem can be formulatedwhere W and bd are the output matrix and biaUs, is a matrix that
as a sequence to sequence learning problem as mentioned in sectionmake sure that the hidden states of encoder would be consistent
3. In this sense, it is very similar to a machine translation probwleimth, the decoder’s. In our implementation, bfoethand fd are
1Sometimes additional weight matrix and vector are added to generate output from2The vocabulary is limited in a sense that the number of words are upper bounded, in
ht for LSTM, we choose to stick with the original formulation for simplicity. general
h1
…
x1
h2
…
x2</p>
      <p>Encoder
…
…
…
…
hT
…
EOS</p>
    </sec>
    <sec id="sec-2">
      <title>Attn: Ci</title>
      <p>Y1
s1
…
EOS
Y2
s2
…
y1</p>
    </sec>
    <sec id="sec-3">
      <title>Decoder</title>
      <p>…
…
…
…</p>
      <p>EOS
sT’
…
yT’
notice that in equation 18 the context vecctioris a function of
the encoding functifoen, so we are not left the encoder isolated.
Since all components are smooth and diferentiable, the model
can be easily trained with gradient based method to maximize the
likelihood on the dataset.</p>
      <sec id="sec-3-1">
        <title>Method</title>
      </sec>
      <sec id="sec-3-2">
        <title>Hasan et al.[8] C-2-W RNN W-2-W RNN C-2-C RNN</title>
      </sec>
      <sec id="sec-3-3">
        <title>Accuracy</title>
        <p>62.0%
59.9 %
62.5 %
55.1%
5 EXPERIMENTS
We test our model in the setting of correcting e-commerce queries. We use beam search to obtain the inal result from the model. The
Unlike machine translation problem, there is no public datasreetssult is illustrated in table 1, it is clear that our albeit much simpler,
for e-commerce spelling correction, and therefore we collect bothour RNN based model ofers competitive performance as compare
training and evaluation data internally. For training data, wetuostehe previous methods. It is interesting to note that, the BPE based
the event logs that tracks user behavior on an e-commerce website. encoder and decoder performs the best. The better performance
may attribute to the shorter resultant sequence as compared to the
Our heuristic for inding potential spelling related queries is based
on consecutive user actions in one search session. The hypothesischaracter case, and possibly more semantic meaningful segments
from the sub-words as compared to the characters. Surprisingly,
is that users will try to modify the search query until the search
result is desirable with the search intent, and from this sequentchee character based decoder performs quite well considering the
complexity of the learning task. This demonstrated the beneit from
of action on queries we can potentially extract the misspelling
and correct spelled query pair. Obviously, this includes a lot moerned-to-end training and the robustness of the framework.
diversity on query activities besides spelling mistakes, and thus
additional iltering is required to obtain representative dat6a foCrONCLUSION
spelling correction. We use the same techniques as Hasan e8t].al.[ In this paper, we reformulated the spelling correction problem as
Filtering multiple months of data from our data warehouse, wea machine translation task under the encoder-decoder framework.
got about 70 million misspelling and spell correction pairs aTshoeurreformulation allowed us to use a single model for solving the
training data. For testing, we use the same dataset as in paper problem and can be trained from end-to-end. We demonstrate the
[8], where it contains 4602 queries and the samples are labeled by efectiveness of this model using an internal dataset, where the
human. training data is automatically obtained from user logs. Despite the
simplicity of the model, it performed competitively as compared to
the state of the art methods that require a lot of feature engineering
and human intervention.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Dzmitry</given-names>
            <surname>Bahdanau</surname>
          </string-name>
          , Kyunghyun Cho, and
          <string-name>
            <given-names>Yoshua</given-names>
            <surname>Bengio</surname>
          </string-name>
          .
          <year>2014</year>
          .
          <article-title>Neural machine translation by jointly learning to align and tranrXslivatpe</article-title>
          .
          <source>reprint arXiv:1409.0473</source>
          (
          <year>2014</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Yoshua</given-names>
            <surname>Bengio</surname>
          </string-name>
          , Patrice Simard, and
          <string-name>
            <given-names>Paolo</given-names>
            <surname>Frasconi</surname>
          </string-name>
          .
          <year>1994</year>
          .
          <article-title>Learning long-term dependencies with gradient descent is diiIEcuElEt</article-title>
          .
          <source>transactions on neural networks 5</source>
          ,
          <issue>2</issue>
          (
          <year>1994</year>
          ),
          <year>157ś166</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Eric</given-names>
            <surname>Brill and Robert C Moore</surname>
          </string-name>
          .
          <year>2000</year>
          .
          <article-title>An improved error model for noisy channel spelling correctionP.rIonceedings of the 38th Annual Meeting on Association for Computational Linguistics</article-title>
          .
          <article-title>Association for Computational Linguistics</article-title>
          ,
          <year>286ś293</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Silviu</given-names>
            <surname>Cucerzan</surname>
          </string-name>
          and
          <string-name>
            <given-names>Eric</given-names>
            <surname>Brill</surname>
          </string-name>
          .
          <year>2004</year>
          .
          <article-title>Spelling correction as an iterative process that exploits the collective knowledge of web usePrrso</article-title>
          .
          <source>cIenedings of the 2004 Conference on Empirical Methods in Natural Language Processing. 293ś300.</source>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Stefen</given-names>
            <surname>Eger</surname>
          </string-name>
          , Tim vor der Brück, and
          <string-name>
            <given-names>Alexander</given-names>
            <surname>Mehler</surname>
          </string-name>
          .
          <year>2016</year>
          .
          <article-title>A comparison of four character-level string-to-string translation models for (OCR) spelling error correction</article-title>
          .
          <source>The Prague Bulletin of Mathematical Linguistics</source>
          <volume>105</volume>
          ,
          <issue>1</issue>
          (
          <year>2016</year>
          ),
          <year>77ś99</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Jianfeng</given-names>
            <surname>Gao</surname>
          </string-name>
          , Xiaolong Li, Daniel Micol, Chris Quirk, and
          <string-name>
            <given-names>Xu</given-names>
            <surname>Sun</surname>
          </string-name>
          .
          <year>2010</year>
          .
          <article-title>A large scale ranker-based system for search query spelling correctioPnr</article-title>
          .
          <source>oIcneedings of the 23rd International Conference on Computational Linguistics. Association for Computational Linguistics</source>
          ,
          <year>358ś366</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Jai</given-names>
            <surname>Gupta</surname>
          </string-name>
          , Zhen Qin,
          <string-name>
            <given-names>Michael</given-names>
            <surname>Bendersky</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Donald</given-names>
            <surname>Metzler</surname>
          </string-name>
          .
          <year>2019</year>
          .
          <article-title>Personalized Online Spell Correction for Personal SearcThh</article-title>
          .
          <source>eInWorld Wide Web Conference (WWW '19)</source>
          . ACM, New York, NY, USA,
          <year>2785ś2791</year>
          . https://doi.org/10.1145/ 3308558.3313706
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>Sasa</given-names>
            <surname>Hasan</surname>
          </string-name>
          , Carmen Heger, and
          <string-name>
            <given-names>Saab</given-names>
            <surname>Mansour</surname>
          </string-name>
          .
          <year>2015</year>
          .
          <article-title>Spelling Correction of User Search Queries through Statistical Machine TranslatiEoMnN</article-title>
          ..
          <source>LIPn. 451ś460.</source>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Sepp</given-names>
            <surname>Hochreiter</surname>
          </string-name>
          , Yoshua Bengio, Paolo Frasconi, and
          <string-name>
            <given-names>Jürgen</given-names>
            <surname>Schmidhuber</surname>
          </string-name>
          .
          <year>2001</year>
          .
          <article-title>Gradient low in recurrent nets: the diiculty of learning long-term dependencies</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>Sepp</given-names>
            <surname>Hochreiter</surname>
          </string-name>
          and
          <string-name>
            <given-names>Jürgen</given-names>
            <surname>Schmidhuber</surname>
          </string-name>
          .
          <year>1997</year>
          .
          <article-title>Long short-term memorNy</article-title>
          .
          <source>eural computation 9</source>
          ,
          <issue>8</issue>
          (
          <year>1997</year>
          ),
          <year>1735ś1780</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Mark</surname>
            <given-names>D</given-names>
          </string-name>
          <string-name>
            <surname>Kernighan</surname>
          </string-name>
          , Kenneth W Church, and William A Gale.
          <year>1990</year>
          .
          <article-title>A spelling correction program based on a noisy channel modelP</article-title>
          .
          <source>rIonceedings of the 13th conference on Computational linguistics-Volume 2. Association for Computational Linguistics</source>
          ,
          <year>205ś210</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>Yanen</given-names>
            <surname>Li</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Huizhong</given-names>
            <surname>Duan</surname>
          </string-name>
          , and
          <string-name>
            <given-names>ChengXiang</given-names>
            <surname>Zhai</surname>
          </string-name>
          .
          <year>2012</year>
          .
          <article-title>CloudSpeller: query spelling correction by using a uniied hidden markov model with web-scale resources</article-title>
          .
          <source>In Proceedings of the 21st International Conference on World Wide Web. ACM</source>
          ,
          <year>561ś562</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Chris J Lu</surname>
          </string-name>
          , Alan R Aronson, Sonya E Shooshan, and Dina DemnerFushman.
          <year>2019</year>
          .
          <article-title>Spell checker for consumer language (CSpell)J</article-title>
          .
          <source>ournal of the American Medical Informatics Association</source>
          <volume>26</volume>
          ,
          <issue>3</issue>
          (
          <issue>01</issue>
          <year>2019</year>
          ),
          <year>211ś218</year>
          . https://doi.org/10.1093/jamia/ocy171 arXiv:http://oup.prod.sis.lan/jamia/articlepdf/26/3/211/27642469/ocy171.pdf
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>Stephan</given-names>
            <surname>Raaijmakers</surname>
          </string-name>
          .
          <year>2013</year>
          .
          <article-title>A deep graphical model for spelling correction</article-title>
          . (
          <year>2013</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Rico</surname>
            <given-names>Sennrich</given-names>
          </string-name>
          , Barry Haddow, and
          <string-name>
            <given-names>Alexandra</given-names>
            <surname>Birch</surname>
          </string-name>
          .
          <year>2015</year>
          .
          <article-title>Neural machine translation of rare words with subword unairXtsi</article-title>
          .v preprint arXiv:
          <volume>1508</volume>
          .07909 (
          <year>2015</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>Ilya</surname>
            <given-names>Sutskever</given-names>
          </string-name>
          , Oriol Vinyals, and
          <string-name>
            <surname>Quoc</surname>
            <given-names>V</given-names>
          </string-name>
          <string-name>
            <surname>Le</surname>
          </string-name>
          .
          <year>2014</year>
          .
          <article-title>Sequence to sequence learning with neural networks</article-title>
          .
          <source>IAndvances in neural information processing systems. 3104ś 3112.</source>
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Casey</surname>
            <given-names>Whitelaw</given-names>
          </string-name>
          , Ben Hutchinson, Grace Y Chung, and
          <string-name>
            <given-names>Gerard</given-names>
            <surname>Ellis</surname>
          </string-name>
          .
          <year>2009</year>
          .
          <article-title>Using the web for language independent spellchecking and autocorrectiPorno</article-title>
          .
          <source>cIenedings of the 2009 Conference on Empirical Methods in Natural Language Processing: Volume 2-</source>
          Volume 2. Association for Computational Linguistics,
          <year>890ś899</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>