<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexander Veysov on Medium]]></title>
        <description><![CDATA[Stories by Alexander Veysov on Medium]]></description>
        <link>https://medium.com/@aveysov?source=rss-f29885e9bef3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*X1TbUks60dG6pA2iizx8lA.jpeg</url>
            <title>Stories by Alexander Veysov on Medium</title>
            <link>https://medium.com/@aveysov?source=rss-f29885e9bef3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:46:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aveysov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Pre-trained Model to Restore Punctuation and Capital Letters in 4 Languages]]></title>
            <link>https://aveysov.medium.com/a-pre-trained-model-to-restore-punctuation-and-capital-letters-in-4-languages-d07bccf96f66?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d07bccf96f66</guid>
            <category><![CDATA[capitalization]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[punctuation]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 14:20:35 GMT</pubDate>
            <atom:updated>2021-10-06T16:06:52.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*WT6FE423_DP6LjiJG1b_sQ.png" /></figure><p><em>Originally published at </em><a href="https://habr.com/ru/post/581960/"><em>https://habr.com</em></a><em> on October 6, 2021.</em></p><p>Working with <a href="https://habr.com/ru/post/559640/">speech recognition models</a> we often encounter misconceptions among potential customers and users (mostly related to the fact that people have a hard time distinguishing substance over form). People also tend to believe that punctuation marks and spaces are somehow obviously present in spoken speech, when in fact real spoken speech and written speech are entirely different beasts.</p><p>Of course you can just start each sentence with a capital letter and put a full stop at the end. But it is preferable to have some relatively simple and universal solution for “restoring” punctuation marks and capital letters in sentences that our speech recognition system generates. And it would be really nice if such a system worked with any texts in general.</p><p><strong>For this reason, we would like to share a system that:</strong></p><ul><li>Inserts capital letters and basic punctuation marks (dot, comma, hyphen, question mark, exclamation mark, dash for Russian);</li><li>Works for 4 languages (Russian, English, German, Spanish) and can be extended;</li><li>By design is domain agnostic and is not based on any hard-coded rules;</li><li>Has non-trivial metrics and succeeds in the task of improving text readability;</li></ul><p>To reiterate — the purpose of such a system is only to improve the readability of the text. It does not add information to the text that did not originally exist.</p><h3>The Problem and The Solution</h3><p>Let’s assume that the input is a sentence in lowercase letters without any punctuation, i.e. similar to the outputs of any <a href="https://github.com/snakers4/silero-models#speech-to-text">speech recognition systems</a>. We ideally need a model that makes texts proper, i.e. restores capital letters and punctuation marks. A set of punctuation marks .,-!?- was chosen based on characters most used on average.</p><p>Also we embraced the assumption that the model should insert only one symbol after each token (a punctuation mark or a space). This automatically rules out complex punctuation cases (i.e. direct speech). This is an intentional simplification, because the main task is to improve readability as opposed to achieving grammatically ideal text.</p><p>The solution had to be universal enough to support several key languages. By design we can easily extend our system to an arbitrary number of languages should need arise.</p><p>Initially we envisaged the solution to be small BERT-like model with some classifiers on top. We used internal text corpora for training.</p><p>We acquainted ourselves with a solution of a similar problem from <a href="https://habr.com/ru/company/barsgroup/blog/563854/">here</a>. However, for our purposes we needed:</p><ul><li>A lighter model with a more general specialization;</li><li>An implementation that does not directly use extrnal APIs and a lot of third-party libraries;</li></ul><p>As a result, our solution mostly depends only on PyTorch.</p><h3>Model Compression</h3><p>After extensive experiments we eventually settled on the simplest possible architecture, and the final weight of the model was still 520 megabytes.</p><p>So we tried <a href="https://habr.com/ru/post/563778/">to compress</a> the model. The simplest option is of course quantization (particularly a combination of static and dynamic as described <a href="https://github.com/pytorch/pytorch/issues/65185#issue-998785028">here</a>).</p><p>As a result, the model was compressed to around 130 megabytes without significant loss of quality. Also we reduced the redundant vocabulary by throwing out tokens for non-used languages. This allowed us to compress the embedding from 120,000 tokens to 75,000 tokens.</p><p>Provided that at that moment the model was smaller than 100 megabytes, we decided against investing time in more sophisticated compression techniques (i.e. dropping less used tokens or model factorization). All of the metrics below are calculated with this small quantized model.</p><h3>Metrics</h3><p>Contrary to the popular trends we aim to provide as detailed, informative and honest metrics as possible. In this particular case, we used the following datasets for validation:</p><ul><li>Validation subsets of our private text corpora (5,000 sentences per language);</li><li>Audiobooks, we use the <a href="http://www.caito.de/2019/01/the-m-ailabs-speech-dataset/">caito</a> dataset, which has texts in all the languages the model was trained on (20,000 random sentences for each language);</li></ul><p>We use the following metrics:</p><ul><li>WER (word error rate) as a percentage: separately calculated for repunctuation WER_p (both sentences are transformed to lowercase) and for recapitalization WER_c (here we throw out all punctuation marks);</li><li>Precision / recall / F1 to check the quality of classification (i) between the space and the punctuation marks mentioned above .,-!?-, and (ii) for the restoration of capital letters - between classes <em>a token of lowercase letters</em> / <em>a token starts with a capital</em> / <em>a token of all caps</em>. Also we provide confusion matrices for visualization;</li></ul><h3>Results</h3><p>For the correct and informative metrics calculation, the following transformations were applied to the texts beforehand:</p><ul><li>Punctuation characters other than .,-!?- were removed;</li><li>Punctuation at the beginning of a sentence was removed;</li><li>In case of multiple consecutive punctuation marks we keep only the first one;</li><li>For Spanish ¿¡ were discarded from the model predictions, because they aren&#39;t in the texts of the books, but in general the model places them as well;</li></ul><h3>WER</h3><p>WER_p / WER_c are specified in the cells below. The baseline metrics are calculated for a naive algorithm that starts the sentence with a capital letter and ends it with a full stop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*JZKKcp5feaB-rNbFEbRrdQ.png" /></figure><h3>Examples</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57b527e1ba207442769b5eceab1ae2cd/href">https://medium.com/media/57b527e1ba207442769b5eceab1ae2cd/href</a></iframe><h3>Try it Yourself</h3><p>The model is published in the repository <a href="https://github.com/snakers4/silero-models"><strong>silero-models</strong></a>. And here is a simple snippet for model usage (more detailed examples can be found in <a href="https://colab.research.google.com/github/snakers4/silero-models/blob/master/examples_te.ipynb"><strong>colab</strong></a>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ec55ebbf5ff688aa6102c1933c22339/href">https://medium.com/media/0ec55ebbf5ff688aa6102c1933c22339/href</a></iframe><h3>Limitations and Future Work</h3><p>We had to put a full stop somewhere (pun intended), so the following ideas were left for future work:</p><ul><li>Support inputs consisting of several sentences;</li><li>Try model factorization and pruning (i.e. attention head pruning);</li><li>Add some relevant meta-data from the spoken utterances, i.e. pauses or intonations (or any other embedding);</li></ul><p><em>Originally published at </em><a href="https://habr.com/ru/post/581960/"><em>https://habr.com</em></a><em> on October 6, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d07bccf96f66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Portable Voice Activity Detector Released]]></title>
            <link>https://medium.com/data-science/modern-portable-voice-activity-detector-released-417e516aadde?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/417e516aadde</guid>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[speech]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Thu, 14 Jan 2021 07:15:54 GMT</pubDate>
            <atom:updated>2021-10-02T09:08:08.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HzmAdh_K93WiSOjC.png" /><figcaption>Image by Author</figcaption></figure><p>Currently, there are hardly any high quality / modern / free / public voice activity detectors except for WebRTC Voice Activity Detector ( <a href="https://github.com/wiseman/py-webrtcvad">link</a>). WebRTC though starts to show its age and it suffers from many false positives.</p><p>Also in some cases it is crucial to be able to anonymize large-scale spoken corpora (i.e. remove personal data). Typically personal data is considered to be private / sensitive if it contains (i) a name (ii) some private ID. Name recognition is a highly subjective matter and it depends on locale and business case, but Voice Activity and Number Detection are quite general tasks.</p><p><strong>Key features:</strong></p><ul><li>Modern, portable;</li><li>Low memory footprint;</li><li>Superior metrics to WebRTC;</li><li>Trained on huge spoken corpora and noise / sound libraries;</li><li>Slower than WebRTC, but fast enough for IOT / edge / mobile applications;</li><li>Unlike WebRTC (which mostly tells silence from voice), our VAD can tell voice from noise / music / silence;</li><li>PyTorch (JIT) and ONNX checkpoints;</li></ul><p><strong>Typical use cases:</strong></p><ul><li>Spoken corpora anonymization;</li><li>Can be used together with WebRTC;</li><li>Voice activity detection for IOT / edge / mobile use cases;</li><li>Data cleaning and preparation, number and voice detection in general;</li><li>PyTorch and ONNX can be used with a wide variety of deployment options and backends in mind;</li></ul><h3>Getting Started</h3><p>For each algorithm you can see the examples in the provided <a href="https://colab.research.google.com/github/snakers4/silero-vad/blob/master/silero-vad.ipynb"><strong>colab</strong></a><strong> </strong>or in the <a href="https://github.com/snakers4/silero-vad"><strong>repo</strong></a><strong> </strong>itself. For VAD we also provide streaming examples for a single stream and multiple streams.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ddd2391f2a9f1394480bd87d859d53d/href">https://medium.com/media/4ddd2391f2a9f1394480bd87d859d53d/href</a></iframe><h3>Latency</h3><p>All speed test were run on AMD Ryzen Threadripper 3960X using only 1 thread:</p><pre>torch.set_num_threads(1) # pytorch <br>ort_session.intra_op_num_threads = 1 # onnx ort_session.inter_op_num_threads = 1 # onnx</pre><p>Streaming latency depends on 2 factors:</p><ul><li><strong>num_steps</strong> — number of windows to split each audio chunk into. Our post-processing class keeps previous chunk in memory (250 ms), so new chunk (also 250 ms) is appended to it. The resulting big chunk (500 ms) is split into <strong>num_steps</strong> overlapping windows, each 250 ms long;</li><li><strong>number of audio streams</strong>;</li></ul><p>So <strong>batch size</strong> for streaming is <strong>num_steps <em>* </em>number of audio streams</strong>. Time between receiving new audio chunks and getting results is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TG93e64U1OLK-DZNDJQVog.png" /><figcaption>VAD latency</figcaption></figure><h3>Throughput</h3><p><strong>RTS</strong> (seconds of audio processed per second, real time speed, or 1 / RTF) for full audio processing depends on <strong>num_steps</strong> (see previous paragraph) and <strong>batch size</strong> (bigger is better).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STMTr-m07xHkCoTwazSPYA.png" /><figcaption>VAD throughput measured in seconds of audio processed per second</figcaption></figure><h3>VAD Quality Benchmarks</h3><p>We use random 250 ms audio chunks for validation. Speech to non-speech ratio among chunks is about ~50/50 (i.e. balanced). Speech chunks are sampled from real audios in four different languages (English, Russian, Spanish, German), then random background noise is added to some of them (~40%).</p><p>Since our VAD (only VAD, other networks are more flexible) was trained on chunks of the same length, model’s output is just one float from 0 to 1 — <strong>speech probability</strong>. We use speech probabilities as thresholds for precision-recall curve. This can be extended to 100–150 ms. Less than 100–150 ms cannot be distinguished as speech with confidence.</p><p><a href="https://github.com/wiseman/py-webrtcvad">Webrtc</a> splits audio into frames, each frame has corresponding number (0 <strong>or</strong> 1). We use 30ms frames for webrtc, so each 250 ms chunk is split into 8 frames, their <strong>mean</strong> value is used as a treshold for plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GVFee6UiCVkyun1y.png" /><figcaption>Image by Author</figcaption></figure><p><em>Originally published at </em><a href="https://habr.com/ru/post/537276/"><em>https://habr.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=417e516aadde" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/modern-portable-voice-activity-detector-released-417e516aadde">Modern Portable Voice Activity Detector Released</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing with Nvidia’s New Ampere GPUs and Trying MIG]]></title>
            <link>https://medium.com/data-science/playing-with-nvidias-new-ampere-gpus-and-trying-mig-d7196b48a64?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7196b48a64</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Sat, 05 Dec 2020 17:29:38 GMT</pubDate>
            <atom:updated>2020-12-05T17:29:38.220Z</atom:updated>
            <content:encoded><![CDATA[<h4>Is upgrading to Ampere worth it?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KZlYhA-OrVRos97f.jpg" /><figcaption>Image by Author</figcaption></figure><p>Every time when the essential question arises, whether to upgrade the cards in the server room or not, I look through <a href="https://timdettmers.com/2020/09/07/which-gpu-for-deep-learning/">similar</a> articles and watch such <a href="https://www.youtube.com/watch?v=deqljDr618c&amp;t=1100s">videos</a>.</p><p>Channel with the aforementioned video is very underestimated, but the author does not deal with ML. In general, when analyzing comparisons of accelerators for ML, several things usually catch your eye:</p><ul><li>The authors usually take into account only the “adequacy” for the market of new cards in the United States;</li><li>The ratings are far from the people and are made on very standard networks (which is probably good overall) without details;</li><li>The popular mantra to train more and more gigantic models makes its own adjustments to the comparison;</li></ul><p>The answer to the question “which card is better?” is not rocket science: Cards of the 20* series didn’t get much popularity, while the 1080 Ti from Avito (Russian craigslist) still are very attractive (and, oddly enough, don’t get cheaper, probably for this reason).</p><p>All this is fine and dandy and the standard benchmarks are unlikely to lie too much, but recently I learned about the existence of Multi-Instance-GPU technology for A100 video cards and native support for <a href="https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices">TF32</a> for Ampere devices and I got the idea to share my experience of the real testing cards on the Ampere architecture (3090 and A100). In this short note, I will try to answer the questions:</p><ul><li>Is the upgrade to Ampere worth it? (spoiler for the impatient — yes);</li><li>Are the A100 worth the money (spoiler — in general — no);</li><li>Are there any cases when the A100 is still interesting (spoiler — yes);</li><li>Is MIG technology useful (spoiler — yes, but for inference and for very specific cases for training);</li></ul><h3>Simple Things</h3><p>Let’s immediately address the elephant in the room. At the time of this writing:</p><ul><li>3090 is quite difficult to buy and they are sold with about a 30–40% premium (in the CIS). Moreover, there is a shortage of new cards not only in the CIS;</li><li>The A100 is almost impossible to buy. Nvidia partners said that there is 1 piece in the Russian Federation, then a few more units will arrive;</li><li>I haven’t searched a lot, but I didn’t find information on whether PCIE version of A100 is compatible with conventional ATX platforms (Nvidia partners didn’t answer this question, but I assume that the cards do not have their own cooler and they are supposed to be installed in a server chassis with “loud” fan) — <strong>update</strong> — they are indeed passive;</li><li>3080 and lower models (although they are very interesting for the price, and especially for games) were not tested, because we do not have them, and we did not consider buying them due to the size of their memory (I naively assumed that it would be possible to run several networks on 1 card, but everything works a little differently there);</li></ul><p>For obvious reasons, the holy war — to bow to the AWS religion — is omitted here.</p><h3>Superior Cooling</h3><p>According to the utilities from Nvidia, the 3090 and A100 are 15–20 degrees cooler than Maxwell and Pascal. I did not take accurate measurements, but on average the situation is like this:</p><ul><li>4 * 1080 Ti (Pascal) with minimal cooling hacks operate <strong>in the range of 75–80C</strong> under 100% load;</li><li>3 * Titan X (Maxwell) worked <strong>around 85C</strong> under 100% load;</li><li>3 * 3090 (Ampere) operate <strong>in the range of 60–70C</strong> under 100% load;</li><li>No overclocking, no restrictions on the power supply of cards or cooler speeds were applied anywhere, everything is out of the box;</li><li>All cards have a blower fan, that is, they push heat out of the case;</li></ul><p>There are 3 hypotheses why this is the case:</p><ul><li>New technical process;</li><li>The 3090 has a slightly different shape of the card itself, the size of the fan is noticeably larger, the size of the hole on the rear panel is much larger;</li><li>3090 seems heavier (maybe someone knows where to find the exact numbers, there are no cards at hand now) which probably implies heavier heatsink;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IHcg9ivVVwGypSHm.png" /><figcaption>Image by Author</figcaption></figure><blockquote><em>A clear illustration of the differences between the cards, could someone from the comments tell the diameter of the fan?</em></blockquote><h3>Naïve Metrics</h3><p>First, to make sure the drivers work correctly (and when they did not work correctly, the numbers were completely different), let’s test all the available cards with gpu-burn. The result is on the picture and correlates very strongly with what is reported in the reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*mjWFGd4hAMwYczYYuUJ-mQ.png" /><figcaption>Image by Author</figcaption></figure><p>MIG wasn’t tested here, you will see why further in the article.</p><h3>Pricing</h3><p>It is important to note here that we bought the 1080 Tis and Titan Xs from the second hand market almost “new” (less than a year of use). We will not dwell once again on the holy wars about miners and Nvidia’s pricing policy, but if you use even secondhand gaming cards carefully, their service life is about 3–4 years. Prices and characteristics are approximate. According to the information from Nvidia partners in Russia, only one A100 is on sale until the new year. When new 1080 Tiы were available, prices ranged from about 50k to 100k rubles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*AHvmy1zzt5XsPdbeP4CU6Q.png" /><figcaption>Image by Author</figcaption></figure><blockquote><em>Make the obvious conclusions.</em></blockquote><h3>Trying 3090 and A100 with MIG</h3><h3>Trying 3090</h3><p>And now let’s move on to the most interesting thing — to real down-to-earth tests. <strong>In theory, it seems that if the memory and computing capabilities of the 3090 or A100 are 2–3 times higher than the 1080 Ti, then 1 such card can replace 2–3 1080 Ti and a standard server with 4 proper PCIE ports can replace a server with 12 cards?</strong> Or is it possible to take, let’s say, 3–4 PCIE versions of A100 and get a very powerful server, dividing each of them into several compute instances using MIG?</p><p>The short answer is no, the longer answer is also no, but with many caveats.</p><p>Why, would you ask? Well, server rack platforms that fully support 8–16 video cards even in the smallest reasonable configuration cost 4–5 times more expensive than standard ATX professional solutions. And DGX Workstation or DGX are sold with about a 50% premium to similar configurations assembled on Mikrotik or Gigabyte platforms.</p><p>Card manufacturers are in no hurry to release fully-fledged single-slot GPUs (except for PNY with the Quadro series, but this is a separate story and is more likely for design or inference). Of course, you can assemble a custom water circuit for 7 cards (there were several motherboard models with 7 proper PCIE ports), but it’s “difficult” and it’s not clear where to host it (and the game is not worth the trouble). With the advent of PCIE 4.0, the attractiveness of such solutions, in theory, should grow, but I haven’t seen anything interesting on the market yet.</p><p>A couple of remarks about the task on which we tested:</p><ul><li>Task — training Spech-to-Text network on the Ukrainian <a href="https://github.com/egorsmkv/speech-recognition-uk">dataset</a>;</li><li>Due to the problem itself, the experimentally optimal batch size for one process — 50 — cannot be increased significantly without losses in the convergence rate;</li><li>It is on this task that AMP does not work for us (although it works for others, all other things being equal, we have not yet understood why), but this is more of an optimization. That is, it’s not about the hardware, but about the task. It works on other tasks, so let’s keep things simple;</li><li>An important caveat — since the fact this task is a sequence-to-sequence, in the general case batching here is not entirely trivial. Files of different lengths only get into the batch with files of about the same length (to reduce wasted padding processing resources), but the size of the batch is static for easier comparisons and faster convergence;</li><li>The dynamic and increased batch size were tested, but this does not particularly affect the speed and convergence rate (or worsens);</li></ul><p>Contrary to the trend of making more and more gigantic networks, we are miniaturizing our algorithms and are trying to make our networks more and more efficient. Therefore, it is more interesting to increase the worker count, not the networks size or batch size.</p><p>And here we come across the first pitfall ( <a href="https://t.me/snakers4/2590">https://t.me/snakers4/2590</a>) — Distributed Data Parallel from PyTorch (DDP, the optimal way of scaling networks to “many” video cards) out of the box is essentially configured only for 1 process on 1 card. That is, 1 process can use 1+ card. 2 processes cannot use 1 card, even if there is more than enough IO / compute / RAM. In older driver versions, there is no explicit limitation, and on 1080 Ti 2 processes per 1 card could be launched (but the speed increase is only 5–10% instead of 40–50%). With the new cards, an exception has already been cut in there.</p><pre>RuntimeError: NCCL error in: /opt/conda/conda-bld/pytorch_1603729096996/work/torch/lib/c10d/ProcessGroupNCCL.cpp:784, invalid usage, NCCL version 2.7.8</pre><p>But not everything is so sad and bad. Maybe because of some low-level magic in the drivers, maybe because of TF32 (I hope experts will prompt here), maybe because of the developments in <a href="https://docs.nvidia.com/deploy/pdf/CUDA_Multi_Process_Service_Overview.pdf">MPS</a> 3090s behave a little differently in our benchmark:</p><ul><li>Ceteris paribus they use more memory than Titan X and 1080 Ti (~16 GB instead of 7–8 GB);</li><li>The speed is about 3 times higher than with the Titan X (Maxwell);</li><li>[We still need to accurately measure the speed on 1080 Ti];</li><li>Utilization of cards at a high level — over 90%;</li></ul><p>When we try to run 2 DDP workers on 1 card, we just get an error, when we try to train 2 networks “at the same time” we get a proportional slowdown, when the batch increases, the speed gain is insignificant. The timings for 2 * 3090 are like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*F9SVdxHKgn-XVmgdDkNcdA.png" /><figcaption>Image by Author</figcaption></figure><p>For the sake of completeness, it is also important to note that Nvidia has an MPS which supposedly allows you to spin 2 processes on the cards without switching the context, and PyTorch has a built-in RPC framework. But I simply could not adequately use the former without getting incomprehensible low-level errors, and the latter requires a radical rewriting of the code and drastically complicates the code for training models (although it is very interesting in the long term).</p><p>So, with 3090 everything is clear. It will not replace two cards, of course, but by itself, even with “extra” memory (I remind, we train small networks), it works 2–3 times faster. Whether this is equivalent to having 2–3 cards depends on the task.</p><p><strong>TLDR:</strong></p><ul><li>You can simply replace the cards with a blower fan in your rig with 3090s (the only thing is that there are 2 8-pin power connectors in 3090, but there are 2000-Watt power supplies on the market that can definitely power 4–5 such cards, or just use 2 synced power supplies);</li><li>Most likely, the temperature of the cards will drop by 10–20 degrees Celsius;</li><li>These cards are now expensive and are in short supply (and probably are unlikely to become widely adopted), but if your most expensive resource is time, then this is an interesting option;</li><li>If a large memory size is critical for you, you essentially have no choice;</li></ul><h3>Trying the A100 with MIG</h3><p>Having looked at the metrics, availability, and price of cards, the A100 at first glance does not seem to be an interesting option at all, except for perhaps to train for 3 days 1 large network on 16 A100s on a small, not very private dataset in the cloud. Also, if AMP / FP16 helps your algorithms a lot, then A100 can significantly add speed.</p><p>But the A100 has an interesting <a href="https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html#lgi">MIG technology</a> (Multi-Instance GPU). In fact, it allows you to break one “large and powerful” card into a set of small “subcards” and then create virtual Compute Instances, which can be accessed as separate cards.</p><p>There are quite a lot of details, check the documentation for them, but the following presets are available there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*Tn30GF9M3ehAC-6ovirowA.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*69nxNYmf6j3gF_vD.png" /><figcaption>Source: Nvidia — <a href="https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html#concepts">https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html</a></figcaption></figure><blockquote><em>Available configurations</em></blockquote><p>The question arises, what if our network is small, and A100 in theory (at least on FP16) should be 2 times more powerful than 3090? Is it possible to take 4 A100 and make 12 GPUs similar to 1080 Ti? Is it possible to train neural networks on these numerous “micro-cards” in the same way as on several conventional ones?</p><p>We will answer the questions one by one. Here are both the <a href="https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html#concepts">documentation</a> itself and a very recent blog <a href="https://developer.nvidia.com/blog/getting-the-most-out-of-the-a100-gpu-with-multi-instance-gpu/">post</a> from Nvidia.</p><p>There is a paragraph in the documentation:</p><pre>MIG supports running CUDA applications by specifying the CUDA device on which the application should be run. With CUDA 11, only enumeration of a single MIG instance is supported. CUDA applications treat a CI and its parent GI as a single CUDA device. </pre><pre>CUDA is limited to use a single CI and will pick the first one available if several of them are visible. To summarize, there are two constraints: </pre><pre>- CUDA can only enumerate a single compute instance <br>- CUDA will not enumerate non-MIG GPU if any compute instance is enumerated on any other GPU Note that these constraints may be relaxed in future NVIDIA driver releases for MIG.</pre><p>At first, when I read it, it seemed to me that it just meant that you cannot divide 2 cards at the same time. After I tried to play around with a real card, it turned out that the framework inside the container sees only 1 “card” (and apparently it only selects the “first” one). Moreover, if we carefully read the examples that Nvidia gives in its blog, they essentially all refer to the scenario “1 container — 1 piece of the card” or “tuning 7 small models in parallel”.</p><p>There is also a passage like this:</p><pre>There is no GPU-to-GPU P2P (both PCIe and NVLINK) support in MIG mode, so MIG mode does not support multi-GPU or multi-node training.<br> <br>For large models or models trained with a large batch size, the models may fully utilize a single GPU or even be scaled to multi-GPUs or multi-nodes.</pre><pre>In these cases, we still recommend using a full GPU or multi-GPUs, even multi-nodes, to minimize total training time.</pre><p>If you use MIG for its intended purpose, that is, divide the card into physical pieces (slices), assign them Compute Instances, and drop them into isolated containers — then everything works as it should. It just works. Otherwise — it does not.</p><h3>Final Measurements</h3><p>Here are not really ideal comparisons (on Titan I had DP and not DDP), and on the A100, in the end, I did not run experiments for 10, 20, 30 hours (why pollute the atmosphere), but I measured the time for 1 epoch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*Nqi9btyO58l5NPgmmmVxVw.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nuih-AjdESZAwgYt.png" /><figcaption>Image by Author</figcaption></figure><blockquote><em>When you launch 1 network on the A100, the utilization does not even reach half — well, that is, if it could be cut into 2–3 cards, everything would be fine</em></blockquote><p>On 1080 Ti, resources were only to run 1 epoch.</p><h3>Conclusions</h3><p><strong>Conclusions about 3090:</strong></p><ul><li>If we forget about stock shortages, then the upgrade is worth it. You will get x2 speed up minimum. If AMP works for you, then maybe even all x3-x4;</li><li>Given the increased productivity, the price seems a bit high, but not exorbitant. A price reduction of about 30–40%, it seems to me, would be adequate;</li><li>When a new generation of cards came out, everyone was worried about cooling. But the cards are surprisingly cold;</li><li>The only problem is that the card demands 2 8-pin connectors for power supply;</li></ul><p><strong>Conclusions about the A100:</strong></p><ul><li>Judging by the price divided by the performance, the card is not very interesting (the markup is 2–3 times against 3090);</li><li>The fact that Nvidia made the technology for efficient inference is cool, otherwise the cards have become too big and poweful;</li><li>If you can use ordinary gaming cards (the same 1080 Ti or PNY Quadro) for inference, then they represent much more value for money;</li><li>There is a great untapped potential in the development of MIG technology;</li><li>If you really need 40 GB of memory and a lot of computing, then there are really no alternatives;</li><li>It is unclear whether the PCIE version could be installed in a regular ATX case without custom, hacking, or water cooling;</li></ul><p><em>Originally published at </em><a href="https://habr.com/ru/post/531436/"><em>https://habr.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7196b48a64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/playing-with-nvidias-new-ampere-gpus-and-trying-mig-d7196b48a64">Playing with Nvidia’s New Ampere GPUs and Trying MIG</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Google-level STT Models Released]]></title>
            <link>https://aveysov.medium.com/modern-google-level-stt-models-released-c6491019e30c?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6491019e30c</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[speech]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 15:21:23 GMT</pubDate>
            <atom:updated>2020-09-22T12:29:27.941Z</atom:updated>
            <content:encoded><![CDATA[<p>Our models are on par with <strong>premium Google models </strong>and also really simple to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EdxNQOw9zJnZJJbC.png" /></figure><p>We are proud to announce that we have built from ground up and released our high-quality (i.e. on par with <strong>premium Google models</strong>) speech-to-text Models for the following languages:</p><ul><li>English;</li><li>German;</li><li>Spanish;</li></ul><p><strong>You can find all of our models in our </strong><a href="https://github.com/snakers4/silero-models#getting-started"><strong>repository</strong></a><strong> together with examples, quality and performance benchmarks</strong>. Also we invested some time into making our models as accessible as possible — you can try our examples as well as PyTorch, ONNX, TensorFlow checkpoints. You can also load our model via TorchHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2Z0rqIEo4BHZQHgljqmHw.png" /><figcaption>Medium does not support tables, please go here to see the original table <a href="https://github.com/snakers4/silero-models#getting-started">https://github.com/snakers4/silero-models#getting-started</a></figcaption></figure><h3>Why This is a Big Deal</h3><p>Speech-to-text has traditionally had high barriers of entry due to a number or reasons:</p><ul><li>Hard-to-collect data;</li><li>Costly annotation and high data requirements;</li><li>High compute requirements and adoption of obsolete hard to use technologies;</li></ul><p>Here are some of the typical problems that existing ASR solutions and approaches had before our release:</p><ul><li>STT Research typically focused on huge compute budgets;</li><li>Pre-trained models and recipes did not generalize well, were difficult to use even as-is, relied on obsolete tech;</li><li>Until now STT community lacked easy to use high quality production grade STT models;</li></ul><p>First we tried to alleviate some of these problems for the community by publishing the largest Russian spoken corpus in the world (see our Habr post <a href="https://habr.com/ru/post/474462/">here</a>). Now we try to solve these problems as follows:</p><ul><li>We publish a set of pre-trained high-quality models for popular languages;</li><li>Our models are designed to be as robust to different domains as you can see in our benchmarks;</li><li>Our models are pre-trained on vast and diverse datasets;</li><li>Our models are fast and can be run on commodity hardware;</li><li>Our models are easy to use;</li></ul><h3>Embarrassing Simplicity</h3><p>We believe that modern technology should be embarrassingly simple to use. In our work we follow these design principles:</p><ul><li>Models should be compact and fast;</li><li>Models should generalize across domains, there should be one general solution tailored superficially to particular domains, not vice-versa;</li><li>Models should be easy to use;</li></ul><h3>Further plans</h3><p>Now the smallest we could compress our models is around 50 Megabytes.<br> We still have plans to compress our Enterprise Edition models up to ~20 Megabytes without loss of fidelity. We also are planning to release Community Edition model for other popular languages.</p><h3>Links</h3><ul><li><a href="https://github.com/snakers4/silero-models">Silero models on Github</a></li><li><a href="https://github.com/snakers4/silero-models/wiki">Project Wiki</a></li><li><a href="https://github.com/snakers4/silero-models/wiki/Performance-Benchmarks">Performance benchmarks</a></li><li><a href="https://github.com/snakers4/silero-models/wiki/Quality-Benchmarks">Quality benchmarks</a></li><li><a href="https://colab.research.google.com/github/snakers4/silero-models/blob/master/examples.ipynb">Examples on Colab</a></li></ul><p><em>Originally published at </em><a href="https://habr.com/ru/post/519562/"><em>https://habr.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6491019e30c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Towards an ImageNet Moment for Speech-to-Text]]></title>
            <link>https://medium.com/data-science/towards-an-imagenet-moment-for-speech-to-text-dabeaa962438?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/dabeaa962438</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 18:23:44 GMT</pubDate>
            <atom:updated>2020-07-15T14:54:26.602Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Making progress towards useful and practical STT using a combination of existing ideas and techniques</em></h4><p><em>Originally published at </em><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/"><em>https://thegradient.pub</em></a><em> on March 28, 2020. All citations and references preserved as they were in the original article. Medium also does not have any handy table-of-contents features, so I will leave the original links as well. Where appropriate, I will provide a link to the original part of the article. I also provide links to more up-to-date benchmarks.</em></p><ol><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#introduction"><strong>Introduction</strong></a></li><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#related-work-and-inspiration">Related Work and Inspiration</a></li><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#open-speech-to-text-russian-">Open Speech To Text (Russian)</a></li><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#making-a-great-speech-to-text-model">Making a Great Speech To Text Model</a></li><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#model-benchmarks-and-generalization-gap">Model Benchmarks and Generalization Gap</a></li><li><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#further-work">Further Work</a></li></ol><p>Speech-to-text (STT), also known as automated-speech-recognition (ASR), has a long history and has made amazing progress over the past decade. Currently, it is often believed that only large corporations like Google, Facebook, or Baidu (or local state-backed monopolies for the Russian language) can provide deployable “in-the-wild” solutions. This is due to several reasons:</p><ol><li>High compute requirements that are usually used in papers erect artificially high entry barriers;</li><li>Speech requiring significant data due to the diverse vocabulary, speakers, and compression artifacts;</li><li>A mentality where practical solutions are abandoned in favor of impractical, yet state of the art (SOTA) solutions.</li></ol><p>In this piece we describe our effort to alleviate these concerns, both globally and for the Russian language, by:</p><ol><li>Introducing the diverse 20,000 hour <a href="https://github.com/snakers4/open_stt">Open STT dataset</a> published under CC-NC-BY license;</li><li>Demonstrating that it is possible to achieve competitive results using only TWO consumer-grade and widely available GPUs;</li><li>Offering a plethora of design patterns that democratize entry to the speech domain for a wide range of researchers and practitioners.</li></ol><h3>Introduction</h3><p>Following the success and the democratization (the so-called <a href="https://thegradient.pub/nlp-imagenet/">“ImageNet moment”</a>, i.e. the reduction of hardware requirements, time-to-market and minimal dataset sizes to produce deployable products) of computer vision, it is logical to hope that other branches of Machine Learning (ML) will follow suit. The only questions are, when will it happen and what are the necessary conditions for it to happen?</p><p>In our opinion, the ImageNet moment in a given ML sub-field arrives when:</p><ul><li>The architectures and model building blocks required to solve 95% of standard “useful” tasks are widely available as standard and tested open-source framework modules;</li><li>Most popular models are available with pre-trained weights;</li><li>Knowledge transfer from standard tasks using pre-trained models to different everyday tasks is solved;</li><li>The compute required to train models for everyday tasks is minimal (e.g. 1–10 GPU days in STT) compared to the compute requirements previously reported in papers (100–1000 GPU days in STT);</li><li>The compute for pre-training large models is available to small independent companies and research groups;</li></ul><p>If the above conditions are satisfied, one can develop new useful applications with reasonable costs. Also democratization occurs — one no longer has to rely on giant companies such as Google as the only source of truth in the industry.</p><blockquote>I will be mentioning “usefulness” throughout this article. In a broad sense our firm belief is that something is useful when it produces non-zero sum outcomes for the whole society and there are no outright losers. It means that the majority of people more or less benefit from this something, not only a privileged minority. Also, to consider something useful there should be at least no negative discrimination against a certain racial or income group. For example, should “perfect” self-driving cars be deployed at scale some jobs will have to evolve, but overall this technology will be “useful”. Should “perfect” face detection be deployed at scale, it will probably exacerbate more problems than it will solve. This is highly subjective, so take this with a grain of salt.</blockquote><blockquote>This piece will describe our pursuit of an ImageNet moment for STT, which has so far not been found, and particularly in the context of Russian language. Our main goal is to build and deploy useful models as fast as possible on a limited compute budget, and to share our results of how to do this so others can build on our findings, so we can collectively achieve an ImageNet moment for STT.</blockquote><blockquote>This is not a traditional peer-reviewed research paper, but rather a summary of our pragmatic attempts to make progress towards useful and practical STT using a combination of existing ideas and techniques.</blockquote><blockquote>We decided to share it in this format as opposed to as a paper at a conference or arxiv so that our findings are as accessible to as many as possible. While peer review to ensure technical correctness can of course be useful, we are confident in our claims here due to use of largely existing ideas and the empirical results we present. We will dedicate a separate piece on why we believe that the current peer reviewed and corporation-backed research is not the fastest way for the society to progress as a whole; the short version is that while these flawed systems work in the long run, in the short run there are much faster ways to make progress.</blockquote><blockquote>In a nutshell — ideas presented here really work in production and have been proven by out-of-domain validation. What is more important — most of them are down-to-earth and do not require extravagant hardware or a lot of code. We welcome feedback and criticism here — <a href="/service/mailto:aveysov@gmail.com">aveysov@gmail.com</a></blockquote><h3>Related Work and Inspiration</h3><p>For our experiments we have chosen the following stack of technologies:</p><ul><li>Feed-forward neural networks for acoustic modelling (mostly grouped 1D convolutions with <a href="https://arxiv.org/pdf/1808.08127.pdf">squeeze and excitation</a> and transformer blocks);</li><li><a href="https://distill.pub/2017/ctc/">Connectionist temporal classification</a> loss (CTC loss);</li><li>Composite tokens consisting of graphemes (i.e. alphabet letters) as modelling units (opposed to phonemes);</li><li>Beam search with a pre-trained language model (LM) as a decoder.</li></ul><p>There are many ways to approach STT. Discussing their drawbacks and advantages is out of scope here. Everything in this article is said about an end-to-end approach using mostly graphemes (i.e. alphabet letters) and neural networks.</p><p>In a nutshell — to train an end-to-end grapheme model you just need a lot of small audio files with corresponding transcriptions, i.e. file.wav and transcription.txt. You can also use CTC loss, which alleviates the requirement to have time-aligned annotation (otherwise you will need either to provide an alignment table by yourself or learn alignment within your network). A common alternative to CTC loss is the standard categorical cross-entropy loss with attention, but it trains slowly by itself and it is usually used together with CTC loss anyway.</p><p><strong>This “stack” was chosen for a number of reasons:</strong></p><ul><li>Scalability. You can scale your compute by adding GPUs;</li><li>Future proofing. Should a new neural network block become mainstream, it can be integrated and tested within days. Migrating to another framework is also easy;</li><li>Simplicity. Namely using Python and PyTorch you can focus on experimentation and not solving legacy constraints;</li><li>Flexibility. Building proper code in Python you can test new features (i.e. speaker diarization) in days;</li><li>By not using attention in the decoder nor phonemes or recurrent neural networks we achieve faster convergence and need less maintenance for our models;</li></ul><h3>Open Speech To Text (Russian)</h3><p>All publicly available supervised English datasets that we know of are smaller than 1,000 hours and have very limited variability. <a href="http://arxiv.org/abs/1512.02595">DeepSpeech 2</a>, a seminal STT paper, suggests that you need at least 10,000 hours of annotation to build a proper STT system. 1,000 hours is also a good start, but given the generalization gap (discussed below) you need around 10,000 hours of data in different domains.</p><p>Typical academic datasets have the following drawbacks:</p><ul><li>Too ideal. Recorded in studio or too clean compared to real world applications;</li><li>Too narrow of a domain. Difficulty in STT follows this simple formula: noise level * vocabulary size * number of speakers;</li><li>Mostly only English. Though projects like <a href="https://voice.mozilla.org/en/datasets">Common Voice</a> alleviate this constraint to some extent, you cannot reliably find a lot of data in languages other than German and English. Also Common Voice is probably more suitable for speaker identification task more than speech-to-text because their texts are not very diverse;</li><li>Different compression. Wav files have little to no compression artifacts and therefore don’t represent real world sound bytes that are compressed in different ways;</li></ul><p>Because of these drawbacks, about 6 months ago we decided to collect and share an unprecedented spoken corpus in Russian. We targeted 10,000 hours at first. To our knowledge this is unprecedented even for the English language. We have seen an <a href="http://ceur-ws.org/Vol-2267/475-479-paper-91.pdf">attempt</a> to do work similar to ours, but despite the government funding, their datasets are not publicly available.</p><p>Recently we released a <a href="https://github.com/snakers4/open_stt/releases">1.0-beta version</a> of the dataset. It includes the following domains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oo95xiR-sH6iBSRj8c1iOQ.png" /></figure><p>Our data-collection process was the following:</p><ul><li>Collect some data then clean it using heuristics;</li><li>Train some models and use those models to further clean the data;</li><li>Collect more data and use alignment to align transcripts with audio;</li><li>Train better models and use those models to further clean the data;</li><li>Collect more data and manually annotate some data;</li><li>Repeat all the steps.</li></ul><p>You can find <a href="https://github.com/snakers4/open_stt">our corpus here</a> and you can <a href="https://opencollective.com/open_stt">support our dataset here</a>.</p><p>Though this is already substantial, we are not yet done. Our short term plan is:</p><ul><li>Do some housekeeping, clean the data more, and clean-up some legacy code;</li><li>Migrate to .ogg in order to minimize data storage space while maintaining quality;</li><li>Add several new domains (courtroom dialogues, medical lectures and seminars, poetry).</li></ul><blockquote>PS.<strong> </strong>We did all of this, our dataset was even featured on azure datasets, now we are planning in releasing pre-trained models for 3 new languages: English / German / Spanish.</blockquote><h3>Making a Great Speech To Text Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OcmnlHzwz9IgKh32.jpg" /></figure><p>To build a great STT model, it needs the following characteristics:</p><ul><li>Quick inference;</li><li>Parameter-efficient;</li><li>Easy to maintain and improve;</li><li>Does not require a lot of compute to train, a 2 x 1080Ti machine or less should suffice;</li></ul><p>We take these as our goals, and describe how we fulfilled them below.</p><p>Traditionally models are selected by benchmarking them on a couple of<br> fixed “ideal” unseen validation datasets. In the previous sections we<br> explained why this is sub-optimal if you have real world usage in mind<br> and the only datasets available are academic datasets. Given limited<br> resources to properly compare models you need a radically different<br> approach, which we present in this section. Also keep in mind that there<br> is no “ideal” validation dataset when you are dealing with real<br> in-the-wild data — you need to <strong>validate on each domain separately</strong>.</p><p>Usually when reporting some results on some public dataset (e.g.<br> ImageNet), researchers allegedly run full experiments with different<br> hyper-parameters from scratch until convergence. Also, a good practice<br> is to run the so-called ablation tests, i.e. experiments that test<br> whether or not additional features of a model were actually useful by<br> comparing the performance of the model with and without those features.</p><p>In real life, practitioners cannot afford themselves the luxury of<br> running hundreds or thousands of experiments from scratch till<br> convergence or building some fancy reinforcement learning code to<br> control experiments. Also, the dominance of over-parameterized methods<br> in the literature and the availability of enterprise oriented toolkits<br> discourages researchers from deeply optimizing their pipelines. When you<br> explore the hardware options, in the professional or cloud segment there<br> is a bias towards expensive and impractical solutions.</p><p>Read <a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#making-a-great-speech-to-text-model"><strong>here</strong></a> more to learn about our model selection methodology.</p><h4>Overall Progress Made</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*95_WMhv06NyBpJWC.png" /></figure><p>Initially we started with a fork of <a href="https://github.com/SeanNaren/deepspeech.pytorch">Deep Speech 2 in PyTorch</a>. The original Deep Speech 2 model is based on a deep LSTM or GRU recurrent network, which are slow. The above image illustrates the optimizations we were able to add to the original pipeline. More specifically, we were able to do the following without hurting model performance:</p><ul><li>Reduce the model size around 5x;</li><li>Speed up its convergence 5–10x;</li><li>The small (25M-35M params) final model can be trained on 2x1080 Ti GPUs instead of 4;</li><li>The large model still requires 4x1080 Ti but has a bit lower final CER (1–1.5 percentage point lower) compared to the small model.</li></ul><p>The above chart only has convolutional models, which we found to be much faster than their recurrent counterparts. We started on the process to getting these results as follows:</p><ol><li>Used an existing implementation of Deep Speech 2;</li><li>Run a few experiments on LibriSpeech, where we noticed that RNN models are typically very slow compared to their convolutional counterparts;</li><li>Added a plain Wav2Letter inspired model, which was actually underparameterized for Russian, so we increased the model size;</li><li>Noticed that the model was okay, but very slow to train, so we tried to optimize the training time.</li></ol><p><strong>So, we then explored the following ideas to improve things:</strong></p><ul><li>Idea 1 — Model Stride</li><li>Idea 2 — Compact Regularized Networks</li><li>Idea 3 — Using Byte-Pair Encoding</li><li>Idea 4 — Better Encoder</li><li>Idea 5 — Balance Capacity — Never Use 4 GPUs Again</li><li>Idea 6 — Stabilize the Training in Different Domains, Balance Generalization</li><li>Idea 7 — Make A Very Fast Decoder</li></ul><p>Please follow this <a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#overall-progress-made"><strong>link</strong></a><strong> </strong>to learn about each of these ideas in detail.</p><h3>Model Benchmarks and Generalization Gap</h3><p>In real life it is expected that if the model is trained on one domain, there will be a significant generalization gap on another. But is there a generalization gap in the first place? If there is, then what are the main differences between domains? Can you train one model to work fine on many reasonable domains with decent signal-to-noise ratio?</p><p>There is a generalization gap, and you can even deduce which ASR systems were trained on which domains. Also, with the ideas above, you can train a model that will perform decently even on unseen domains.</p><p>According to our observations, these are the main differences that cause the generalization gap between domains:</p><ul><li>Overall noise level;</li><li>Vocabulary and pronunciation;</li><li>The codecs or hardware used to compress audio;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3PKXN3hx1qQsESZVdoWXw.png" /><figcaption>Obviously now this chart is already very old, you can find more up-to-date metrics for Russian on silero.ai</figcaption></figure><blockquote>This benchmark includes both an acoustic model and a language model. The acoustic model is run on GPU, the results are accumulated, and then language model post-processing is run on multiple CPUs;</blockquote><p>For more detailed benchmarks, some thoughts on production usage and benchmark analysis please go <a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/#model-benchmarks-and-generalization-gap"><strong>here</strong></a>. For up-to-date and updated benchmarks please go <a href="https://www.silero.ai/tag/our-speech-to-text/"><strong>here</strong></a><strong> </strong>(Russian)<strong>.</strong></p><h3><strong>Further Work</strong></h3><p>Here is a list of ideas, that we tested (some of which even worked), but we decided in the end that their complexity does not justify the benefits they provide:</p><ul><li>Getting rid of gradient clipping. Gradient clipping takes from 25% to 40% of batch time. We tried various hacks to get rid of it, but could not do it without suffering a severe drop in convergence speed;</li><li>ADAM, Novograd and other new and promising optimizers. In our experience, they worked only with simpler non speech related domains or toy datasets;</li><li>Sequence-to-sequence decoder, double supervision. These ideas work. Attention-based decoders with categorical cross-entropy loss instead of CTC are notoriously slow starters (you add speech decoding to the already burdensome task of alignment). Hybrid networks did not perform much better to justify their complexity. This probably just means that hybrid networks require a lot of parameter fine-tuning;</li><li>Phoneme-based and phoneme-augmented methods. Though these helped us regularize a few over-parametrized models (100–150M params), they proved not very useful for smaller models. Surprisingly an extensive tokenization study by Google <a href="http://arxiv.org/abs/1902.01955">arrived at the similar result</a>;</li><li>Networks that increase in width gradually. A common design pattern in computer vision, so far such networks converged worse that their counterparts with the same network width;</li><li>Usage of <a href="https://arxiv.org/abs/1911.08609">IdleBlocks</a>. At first glance, this did not work, but maybe more time was needed to make it work;</li><li>Try any sort of tunable filters instead of STFT. We tried various implementations of tunable STFT filters and SincNet filters, but in most cases we could not even stabilize the training of the models with such filters;</li><li>Train a pyramid-shaped model with different strides. We failed to achieve any improvement here;</li><li>Use model distillation and quantization to speed up inference. At the moment when we tried native quantization in PyTorch it was still in beta and <a href="https://t.me/snakers4/2405">did not support our modules yet</a>;</li><li>Add complementary objectives like speaker diarization or noise cancelling. Noise cancelling works, but it proved to be more of an aesthetic use;</li></ul><p><strong>Author Bio</strong></p><p><em>Alexander Veysov is a Data Scientist in Silero, a small company building NLP / Speech / CV enabled products, and author of Open STT — probably the largest public Russian spoken corpus. Silero has recently shipped its own Russian STT engine. Previously he worked in a then Moscow-based VC firm and Ponominalu.ru, a ticketing startup acquired by MTS (major Russian TelCo). He received his BA and MA in Economics in Moscow State University for International Relations (MGIMO). You can follow his channel in </em><a href="https://t.me/snakers41"><em>telegram</em></a><em> (@snakers41).</em></p><p><strong>Acknowledgments</strong></p><p><em>Thanks to Andrey Kurenkov and Jacob Anderson from The Gradient for their contributions to this piece.</em></p><p><strong>Citation</strong><br><em>For attribution in academic contexts or books, please cite this work as</em></p><blockquote><em>Alexander Veysov, “Toward’s an ImageNet Moment for Speech-to-Text”, The Gradient, 2020.</em></blockquote><p><strong>BibTeX citation</strong></p><blockquote><em>@article{veysov2020towardimagenetstt,<br>author = {Veysov, Alexander},<br>title = {Toward’s an ImageNet Moment for Speech-to-Text},<br>journal = {The Gradient},<br>year = {2020},<br>howpublished = {\url{ </em><a href="https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/"><em>https://thegradient.pub/towards-an-imagenet-moment-for-speech-to-text/</em></a><em> } },<br>}</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dabeaa962438" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/towards-an-imagenet-moment-for-speech-to-text-dabeaa962438">Towards an ImageNet Moment for Speech-to-Text</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open STT 1.0 release]]></title>
            <link>https://medium.com/data-science/open-stt-v10-release-1c28da67f2e6?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c28da67f2e6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Mon, 04 Nov 2019 13:45:24 GMT</pubDate>
            <atom:updated>2019-11-05T17:56:01.474Z</atom:updated>
            <content:encoded><![CDATA[<p>Finally we made it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*XXIXi91Q108xSk7P.jpg" /><figcaption><em>I wanted to give him an ushanka, but my paint editing skills are too poor</em></figcaption></figure><h3>TLDR</h3><p>This is a very brief accompanying post for the <a href="https://github.com/snakers4/open_stt/releases">release</a> of <strong>Open STT / TTS v1.0</strong>.</p><p><strong>In a nutshell:</strong></p><ul><li><strong>Open STT</strong> is published <a href="https://github.com/snakers4/open_stt">here</a>, <strong>Open TTS</strong> is published <a href="https://github.com/snakers4/open_tts">here</a>, noise dataset is published <a href="https://github.com/snakers4/asr-noises">here</a>;</li><li>We added 2 new datasets in 2 new large and diverse domains with around <strong>15,000 hours of annotation</strong>;</li><li>New datasets have <strong>real speaker labels</strong> (which will soon be released);</li><li>Overall annotation quality is improved, most numerous annotation edge cases were fixed;</li><li>Dataset normalization greatly improved;</li></ul><h3>Open STT recap</h3><p>Some time ago we were disappointed by the <a href="https://spark-in.me/post/stt-dark-forest">state</a> (a more refined article coming soon) of STT in general (compared to Computer Vision for example), especially in Russian.</p><p>In general it suffers from many problems: (i) small / not very useful / not always public academic datasets (ii) huge impractical solutions (iii) bulky / outdated / impractical toolkits (iv) an industry with a lot of history and already bitten by the SOTA bug (v) lack of working solutions without too many strings attached.</p><p>So we <a href="https://spark-in.me/post/russian-open-stt-part1">decided</a> to build from the ground up a dataset for Russian and then build a set of pre-trained deployable models based on the dataset. And then maybe cover a couple more languages.</p><p>Open STT is arguably the largest / best open STT / TTS dataset that exists now. Please follow the above links to learn more.</p><h3>Major features in latest releases</h3><p><strong>Major latest </strong><a href="https://github.com/snakers4/open_stt/releases"><strong>release</strong></a><strong> highlights:</strong></p><ul><li>See the above TLDR bullets;</li><li>Speaker labels for the new datasets;</li><li>The dataset is now available as .wav files via torrent (I am seeding with a 1 gbit/s channel) and as .mp3 files via direct download link (also fast download speeds);</li><li>Small manually annotated validation dataset (18 hours) covering 3 main domains;</li><li>Overall upstream model quality improvement;</li><li>No more “dangling” letters;</li><li>Improved voice activity detection;</li><li>Vastly improved dataset normalization;</li><li>Obviously annotation is not perfect, but from time to time we add exclude <a href="https://github.com/snakers4/open_stt/issues/5">lists</a> when we add new data to filter the most obnoxious cases;</li></ul><p><strong>Potential usage:</strong></p><ul><li>Speech-to-text (obviously);</li><li>Denoising (also consider our asr-noises <a href="https://github.com/snakers4/asr-noises">dataset</a> for this);</li><li>Large scale text-to-speech (<strong>new</strong>);</li><li>Speaker diarization (<strong>new</strong>);</li><li>Speaker identification (<strong>new</strong>);</li></ul><h3>Licensing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*ZFTQ8bs2HQcEIyTN91Yb3g.jpeg" /></figure><p>The dataset is mostly published under cc-nc-by <a href="https://github.com/snakers4/open_stt/#license">license</a>.</p><p>If you would like to use it commercially, submit a <a href="https://forms.gle/nosMaNgj8MWKm99d9">form</a> and then contact us <a href="https://spark-in.me/cdn-cgi/l/email-protection#6906190c07361a1d1d290e06060e050c0e1b061c191a470a0604">here</a>.</p><p>If you need a fast (i.e. not requiring GPUs to run) / dependable / offline STT / TTS system please contact <a href="https://spark-in.me/cdn-cgi/l/email-protection#a1c0d7c4d8d2ced7e1c6ccc0c8cd8fc2cecc">me</a>.</p><h3>What is next?</h3><ul><li>Improve / re-upload some of the existing datasets, refine the labels;</li><li>Attempt to annotate previous data with speaker labels;</li><li>Publish pre-trained models and post-processing;</li><li>Refine and publish the speaker labels;</li><li>Probably add new languages;</li><li>Refine the STT labels;</li></ul><p><em>Originally published at </em><a href="https://spark-in.me/post/open-stt-release-v10"><em>https://spark-in.me</em></a><em> on November 4, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c28da67f2e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/open-stt-v10-release-1c28da67f2e6">Open STT 1.0 release</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating the Speech to Text Dark Forest]]></title>
            <link>https://aveysov.medium.com/navigating-the-speech-to-text-dark-forest-b511e6e7aa88?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b511e6e7aa88</guid>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[text-to-speech]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 11:31:38 GMT</pubDate>
            <atom:updated>2019-08-19T14:02:02.110Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Do not fall prey to fallacies</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/0*yjMbIroaZ5WPGkJf.jpg" /></figure><h3>Boring introduction</h3><p>Recently I read this trilogy of <a href="https://en.wikipedia.org/wiki/The_Dark_Forest">books</a> (which is awesome, down-to-earth, gritty and instant classic by the way). There is a very nice analogy that permeates the whole trilogy in one way or another (I just could not help sharing it):</p><blockquote><em>Like hunters in a “dark forest”, a civilization can never be certain of an alien civilization’s true intentions. The extreme distance between stars creates an insurmountable “chain of suspicion” where any two civilizations cannot communicate well enough to relieve mistrust, making conflict inevitable. Leaving a primitive civilization alone is not an option due to the exponential progress of technological change, and a civilization you have detected might easily surpass your own technological level in a few centuries and become a threat. If you have detected a civilization, than you have also confirmed that said civilization will eventually be able to detect you. Therefore, it is in every civilization’s best interest to preemptively strike and destroy any developing civilization before it can become a threat, but without revealing their own location to the wider universe, thus explaining the Fermi paradox.</em></blockquote><p>To put it more plain words — imagine that it is dark and you are alone in the forest. You can see the marks on the trees / snow and you have some idea that there are other creatures there. You want to study the forest and communicate with them, but you do not know yet that the forest is populated by solitary hunters for whom the optimal strategy is to attack / plunder and flee. Even though sticking together in large groups may be more optimal in the long run (what omnivorous humans did by the way compared to many solitary apex predators), the current state heavily punishes all newcomers for revealing themselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*S2qQx018bIo2yWr3.jpg" /><figcaption><strong>If the proverbial Dark Forest existed, probably creatures inhabiting it would look something like this</strong></figcaption></figure><p>It really amazed me that <strong>this kind of analogy transfers really well to real life and kind of explains the status quo in many fields</strong>. You can say that ML in general is becoming a Dark Forest now. Long ago social networks became Dark Forests where everyone is virtue signalling (or just using it as a messenger, lol) and everybody has a very cool artificial version of themselves (I do not use social networks, btw). Unlike social networks, that heavily punish all people who dare honestly express their real selves on them, ML / tech is less punitive (yet, but if your carefully read you NDA / indemnity / IP part of your English law agreement — you may think otherwise).</p><p>If you came here for a hardcore article or post (you may find something recent on my <a href="https://t.me/snakers4">channel</a>), I am sorry to disappoint, this will be more of a rant. And yeah, if you have ever been taken out of polite Western society of fake smiles for a contrast — western society is also a Dark Forest. This news <a href="https://www.vice.com/en_us/article/d3ag37/us-cities-are-helping-people-buy-amazon-surveillance-cameras-using-taxpayer-money?xyz">article</a> just takes the cake — when the Chinese government just builds surveillance — but <strong>the Americans ask the public to build the cages themselves</strong>. So cool.</p><p>I have not posted for a while in this blog. I was preoccupied with many things, building an easy to use / approachable speech-to-text model / dataset being one of them. I also had a first decent vacation since 2015, but that would not be the topic of this post. Also there was a series of down-to-earth “challenges” in my life connected with relocations / renting an office / solving some basic questions. It does not sound like much, but it takes time and attention.</p><blockquote><em>Initially I wanted to postpone any STT related blog posts until we have released pre-trained models / have released version </em><em>0.6 or </em><em>0.7 of our </em><a href="https://github.com/snakers4/open_stt/releases"><em>dataset</em></a><em> (now it&#39;s </em><em>0.5) / have done a very cool thing we are planning to do in future (I will not reveal it yet, but you are welcome to guess). But I realize that this is probably taking too much time, so let&#39;s have a bit of fun! We are very close to finishing off our models and the dataset, and this cool thing, but one thing at a time.</em></blockquote><p>Anyway now I just would like to tell you about my overall experience of working on this thing — a working Russian STT model and huge STT dataset — and how this and ML in general resembles a Dark Forest:</p><h3>TLDR;</h3><ul><li><strong>Technology is a Dark Forest</strong>. Until it isn’t. But then it is again. It is cyclic;</li><li><strong>Academic world is a kind of a Dark Forest</strong></li><li>Everyone is virtue signalling. The signal in papers is very diluted, unless this is a once a year breakthrough paper. Finally I came to a conclusion that 95% of current ML academic papers are nothing but career building. Just read between the lines, hunt for ideas. <em>People who read just code and / or just abstracts and / or look for hyper-params in papers — are cynical, but in the end they are right</em>. I had some glimmer of hope previously, but now I am more cynical about it. Of course sometimes there are truly awesome ideas in papers — but 95% of crap on top is necessary evil?;</li><li><strong>Machine Learning is trending towards being a Dark Forest</strong></li><li>More precisely — it is following a technology cycle and now it is entering this Dark Forest phase. Remember when everyone was amazed at how open everything was (open architectures, reproducible experiments, pre-trained networks). Now the trend has shifted to industrialization, huge networks, AutoML, self-supervised learning (which btw is a good thing) and building walled-off gardens. This is a good thing that <strong>ML is actually useful and deployable</strong> (unlike the crypto bubbles, financial derivative bubble, etc) in real life, but it feels like people are becoming more separated into practitioners / 0.01% benchmark SOTA pushers / hardcore C++ engineers. The awesome melting pot of ideas seems to be less pronounced at least for now;</li><li><strong>And finally — STT is also kind of a mild Dark Forest</strong></li><li>Being that it is data intensive (there are some cool ideas like joint STT / TTS training, but I believe that something resembling weakly supervised training, i.e. automatic pseudo-labelling, or mix-match will work in “in-the-wild” scenario. It already works btw in offline fashion) it is no wonder that it is mostly done by large corporations. With all of their perks — fitting to idealized “unlimited” data, building walled-off ecosystems, using 10x more resources than necessary. There is no motivation in the system to build simple / dependable / reproducible systems, especially for languages other than English. This is reflected in papers on the topic. Of course you may say that wav2letter++ / kaldi / esp-net exist and they are open-source an I just suck at ML / coding. Yeah, right, please use them, go on. But can you really depend on them? <strong>Can you really tell what is wrong with your non-standard wav2letter++ model, unless you can internalize the whole C++ codebase?</strong> If you need this yesterday and do not have 6 months to dig into a project that took 10 people a year to write? Of course in case you are a “rockstar 10x ninja guru” developer that may not apply to you xD;</li></ul><p>So, people may say “if it works do not fix it”. But if no-one voices such concerns, then the systems may evolve beyond recognition. And we may find yet another walled-off corporate bullshit ecosystem instead of a thriving community that benefits real people. “First they came” <a href="https://en.wikipedia.org/wiki/First_they_came_...">argument</a>.</p><p>A system should serve people, not itself. For now, such system makes our life better asymptotically, i.e. if perfect wav2letter++ would not mean free ASR for all of us, but it may trickle down in the form of ideas / free annotation / datasets — you name it. But it is easy just to project these walling-off trend and see that awesome sprawling communities of ideas may perish should some trends continue.</p><h3>Technology cycles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fRzJPt_8PqkaghEa.jpg" /><figcaption><strong><em>Do not get me started on cargo cult! I know that this is just an aerodynamic model, please preserve your bile for now</em></strong></figcaption></figure><p>Technology is a Dark Forest. Until it is not. Let me explain what I mean. If you are from the CIS, have you ever tried posting anything original to <a href="http://habr.com/">habr.com</a> (just read Russian comments <a href="https://habr.com/ru/post/450760/">here</a> or <a href="https://habr.com/ru/post/428674/">here</a>)? Anything where you can proudly say — “I created this and I think it is useful! I want to share this cool stuff!”. If you are not from the CIS, probably same can be said about Reddit, I do not know, please PM me if you have experience.</p><p>Best case scenario — everyone will ignore it. More down-to-earth scenario — everyone will be appalled because whatever you did does not stick to some idealistic pre-conceived notion (ofc everyone will disregard your time / resource limitations, goals etc etc). <strong>The best way to seek the help of online community is to half-ass something, post it, and then see all of these self-righteous angry trolls coming from under their bridges to show you the true and the only way</strong>. Because people care more about boosting their (virtual) ego at your expense instead of actually helping do something helpful for greater good (i.e. non zero sum game).</p><p>If you collect such feedback, you can even find good bits in it! Because you may ask why anyone would care if something wrong is said in the Internet? Because they are idealistic knights in shining armor? No — because of virtue signalling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*EQfabK4GnHL92aMl.png" /><figcaption><strong><em>You built some complicated thing. If you ask people politely to review / help — they will ignore. But if you deliberately make a couple mistakes — everyone will seem to care at once</em></strong></figcaption></figure><p>Ok, but what does it have to do with technology and Dark Forests? Well, you see, if 95% of what you see is this, then how does actual progress happen? Of course if 1000 engineers work on a new generation of CPUs for 2 years something will happen regardless of how efficient they are. But my bet is that you do not have 1000 engineers and 2 years. You need your result yesterday.</p><p>And here it gets interesting. Imagine a new technology born or reaching some form of maturity (i.e. modern machine learning, web, mobile apps, etc). Each new technology first attracts people <strong>who want to see the results of their actions</strong>. Because they need people who get the shit done without rambling for 2 hour about self-righteousness. Then public and marketing catches up, marketing BS starts flooding the information channels. Then someone builds a killer app and / or applies this technology to a real problem / creates a 10x faster neural network / solves some challenge — you name it. Then this gets purchased / copied / stolen / lawfully expropriated / replicated by a large company (the end result is the same just the amount of time required differs) … and the technology enters a Dark Forest state. No one has an incentive to take risks, no one is wants to build something new, status quo is the new motto, everyone is happy and content.</p><p>This is why it is important to stay hungry / foolish, keep eggs in separate baskets and in general try to keep everything as simple as fuck.</p><h3>Bitten by the SOTA Bug</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*7bZ1BhijXx6VynyA.jpg" /><figcaption><strong><em>A medieval cat achieving state of the art speed record disregarding some practical issues like blowing up afterwards</em></strong></figcaption></figure><p>It is not news that academic world or to put it in more plain terms — <strong>people writing papers</strong> (scholars, corporate employees, ML competition participants, whatever) are not immune to Goodhart’s law. Found this <a href="https://thegradient.pub/over-optimization-of-academic-publishing-metrics">gem</a> and this <a href="https://medium.com/ai2-blog/5-steps-to-reconciling-pre-prints-and-blind-review-92a2d80d8735">gem</a> recently on this topic. Seriously just read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*1VzWQ7XejOSV7vVR.png" /><figcaption><strong><em>Wait, we should this also be a part of the Dark Forest?</em></strong></figcaption></figure><p>When reading ML papers they feel more and more like publish or perish / chasing 0.01% on some vague outdated academic leaderboard. Filling the tickmarks instead of doing something useful.</p><p>Probably you are already fed up with me ranting, let me be more concrete. Dear people writing papers! I have a bone to pick with you. <strong>To be more precise several bones:</strong></p><ul><li><strong>What is with the fact that no papers are publishing convergence curves?</strong></li><li>Why? Who cares about achieving +0.05% (being that ML is kind of random) on some outdated not-in-the-wild benchmark by using 10x more compute and / or using 10x more GPU hours on your computing cluster? I understand that ML progresses in cycles, first someone achieves +0.05% at the sake of 10x more compute, then someone optimizes it, but why not be more open about it? Also sometimes it is worth running all of your experiments till the end, but usually you can see on first epochs that something does not fly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/0*pcsRxmeDHgewA0Iq.png" /><figcaption><strong><em>All other things being equal, feels like baseline_scale2 is the best, right?</em></strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*xyoDTw7IVZ4XUXhh.png" /><figcaption><strong>Hell no! If only papers posted charts like this!</strong></figcaption></figure><ul><li><strong>Why do you copy-paste and drag the obscure mathematical formulas from paper to paper even if your contribution has nothing to do with these formulas?</strong></li><li>Do not give me the BS that “each paper would be self-sufficient and any newcomer would understand everything from just one paper”. It does not work like this. Why not just write like “we use this loss, invented by this guy here, implemented by this guy here, and yeah, we just use this implementation for everything, and here is our Dockerfile!”. This is productive. But probably then the majority of papers will sound like “ahem, I came to work, just did used from utils import *; the monolithic behemoth of our internal wrappers and just changed some settings - sent it to our 1000 GPUs - and viola, new SOTA result!&quot;. Sounds not very sexy, right?</li><li><strong>Being vague on what you really built and where you started</strong></li><li>Being vague on which elements are crucial to your system and which can be trimmed. If you started with some black box framework and just slapped something on top of that — just say this. Or do proper ablation tests. Or just show your path. Just be frank. Do not hide behind big words.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*7m9H5FIhaQeSmv0F.png" /><figcaption><strong><em>I understand that an illustration from a NAS paper is probably a bit misleading here, but it obviously shows which exploration steps have been taken</em></strong></figcaption></figure><ul><li><strong>Being vague about the generalization of your approach</strong></li><li>Doing something on your laptop on MNIST is kind of cringe nowadays (yeah you can fit any sufficiently large shitty network to anything given enough time and money), but at least it feels honest. But I would never believe that people who have 4–5 people working on a paper do not have OOD (out-of-dataset) / private / additional data to test their model on. DeepSpeech <a href="http://arxiv.org/abs/1512.02595">paper</a> probably is the best paper to illustrate this. They just showed how much performance depends on adding more data. Even if they cannot share this data. <strong>If what you do works only on ideal small dataset and requires 10x more compute and time — it is useless</strong>. No, you are not pushing state-of-the-art unless there is a fundamentally cool new characteristic about what you did. Ah, maybe you care about and reproducibility? But ahem, making your contribution reproducible and approachable by the public may be 10x more work. So it’s better just to omit anything that would point your fellow practitioners in the right direction. Because otherwise you are vulnerable and the Dark Forest will strike. Also do not get me started on <strong>stack and blend 100 similar things approach</strong>. If you genuinely mix several different things, i.e. a RNN + regular expressions + some linear regressions each solving a small sub-task its very cool. But just stacking 100 similar networks is not.</li><li><strong>Another flavour of the same thing — hyper-param stability.</strong></li><li>Hyper-params usually deserve a small section in the middle of paper. But sometimes it actually takes a lot of time to tune them just right (and it even may be more important that your brand-new SOTA improvement). So why not be more open about how you found them? How much compute it takes?Does it scale to other datasets? Are they stable?</li></ul><p>Please do something useful! <strong>Also in particular, the problems I had with STT papers were the following:</strong></p><ul><li><strong>All the cool new unsupervised learning approaches (wav2vec, cyclic training, etc)</strong></li><li>Looks very cool, but why show “progress” on some random small datasets? Why not just scale with speakers in LibriSpeech? Run a test — does it scale to X% speakers from LibriSpeech and that’s it! Why not extrapolate how compute efficient is your method, even by means of back of the envelope computation? Of course, unsupervised / self-supervised / semi-supervised methods may be an order of magnitude slower, but what also about annotation cost trade-off? There are not complicated matters, but just commons sense. But you see, saying that “we achieved almost unsupervised something, but in real life is even less practical than supervised” does not sound sexy at all;</li><li><strong>Some remarks on Wav2letter</strong></li><li>Wav2letter <a href="http://arxiv.org/abs/1609.03193">paper</a> is cool. So deceivingly simple and nice … like a fresh breath of air. I was one of the reasons I decided to try build an STT system. But wait, on real data it just does not fit as promised! Maybe you need to fit it for 30 days on 8 V100 GPUs? I fully understand that actually you can just <a href="https://t.me/snakers4/2334">train longer</a> to miniaturize the model, but papers like <a href="http://arxiv.org/abs/1904.03288">this</a> (they use ~150M params instead of ~30M to achieve similar results) kind of shows that everything is a bit more complicated;</li><li><strong>Huge highly regularized networks</strong></li><li>All papers featuring large networks, GLU activations and 0.6 dropout. You can fit any network on anything. Really. They are this flexible. But you know, the time and compute taken may differ 10x. And will it work on real life / dirty data;</li><li><strong>All papers boasting learning custom pre-processing instead of STFT / MFCC or something similar</strong></li><li>May be I am just an idiot, but we tried such things, and they worked, but even on toy data converged much slower. Given that actually one “comma” in such a fragile thing as pre-processing may be deal-breaker, lack of published code from paper authors is strange (come-on, if you spent a lot of time tuning your pre-processing, and probably it is just 50 lines of code, then why just not share it? The community will benefit and you will get the PR boost). There is a cool paper — <a href="http://arxiv.org/abs/1808.00158">SincNet</a> — where the author had a cool idea and even published down-to-earth code you can test with your data — we are yet to try it. Also — as some papers have shown ( <a href="https://arxiv.org/abs/1904.00760">1</a>) <a href="https://eng.uber.com/deconstructing-lottery-tickets/">2</a> <a href="http://arxiv.org/abs/1903.01611">3</a> <a href="http://arxiv.org/abs/1905.01067">4</a>) — sometimes you do not even need a complicated structure and per se training for the model to work;</li><li><strong>Doing everything end-to-end mantra</strong></li><li>It is so cool when you can just put everything in one network on one framework (and it can be even agnostic to framework) and just hit .forward()! Then you will enjoy all sorts of cool things - like porting to TensorRT, using ONNX, etc etc But when you do something supposedly end-to-end, i.e. train a conv-LM instead of using an arbitrary one ... you nevertheless require a separate post-processing step using a different language / stack / etc. It is not useful. It is just a novelty item. Maybe adding an additional LM-loss will help instead?</li></ul><h3>Dog Eat Dog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*Ai4FDN4mzd4xFxKT.jpg" /><figcaption><strong><em>Medieval cats are so cool</em></strong></figcaption></figure><p>Probably Dark Forest is a bit of exaggeration, but some behaviors were observed were kind of similar in spirit.</p><p>Usually I am not the one to brag about how many “job offers per second I have” or “how many jobs I have at the moment” or “how much money per second I make” (all of this is vain and undignified) or any obnoxious shit like this, but stick with me for a couple of anecdotes now.</p><p>This may get a bit funny / ridiculous. All of this happened after we published one of first more or less mature versions of our <a href="https://github.com/snakers4/open_stt/releases">dataset</a>.</p><ul><li>When we published our dataset on <a href="https://habr.com/ru/post/450760/">habr.com</a>, 33% of comments were constructive (i.e. data encoding, becoming a co-author, etc) and <strong>66% were about what assholes we were</strong>:</li><li>We have committed a crime against book / video / recording right holders and we should drop dead and be punished immediately! Yeah right, Imagenet was compiled in a similar fashion, but no one has any problems using it. Because progress and fair use. I agree that this is a grey area, but for more details just read the comments;</li><li>We should have published data under Public Domain licence because of reasons. Because a private company should reach an agreement with authors to use the data commercially to continue virtue signalling. You cannot just tell authors to go take a walk. cc-bc-by actually allows any people working for social good to use the data and we have helped researchers do so on several occasions already;</li><li>Ofc on numerous occasions people told me that what we do should not be done, because Google or because Yandex. Because Dark Forest. Yeah right, we will see when comparing benchmarks xD;</li><li>We were approached on 3 different occasions with some vague offers to join some teams, and in <strong>one case we even could collaborate on making our dataset better</strong>, which is very cool! The Dark Forest thing about this is how one of these guys was advertising their company. After some inquiries we kind of realized that 5,000 hours of annotation he was bragging about did existed only in theory and the sole purpose of our communication was to eliminate a potential competitor in its infancy. Yeah like this <a href="https://en.wikipedia.org/wiki/Peter_Minuit">guy</a>. We may fail and we may suck at what we do, our dataset may be full of rubbish but (i) we are not idiots (ii) we actually believe that life is not a zero sum game for a change;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Ma-N1sitgtFUuK_Q.jpg" /><figcaption><strong><em>The picture says “Prohibit! Tighten! Do not allow!</em></strong></figcaption></figure><h3>Make your network 4–5x faster. But first make it 4–5x slower</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*mZhUMR9xSWD-KoZt.png" /><figcaption><strong><em>Actually the pix2pix Doomguy on the right does not look creepy at all!!</em></strong></figcaption></figure><p>So, you may ask, wtf is this article? If you are ranting, then offer something. The idea of this article is that a lot of resources is being spent on resume building and protecting against Dark Forest strikes — not on really useful things. True, some of my tests leave much to be desired in terms of their rigorousness, but at least I am not full of bs.</p><p>Let’s return to this chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*sAZERDnzt9QSE9J0.png" /><figcaption><strong><em>Applying MobileNet-style optimizations make any CNN better — and any network is over-parametrized</em></strong></figcaption></figure><p>We learned the following useful things about STT so far. Some of these may be fairly obvious in hindsight (now you can officially start spewing your venom right now how all of this was obvious from the very beginning for you 7 years ago):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wFpg6r9mRqRuaOvO.png" /><figcaption><strong><em>Your path to a working STT model may look something like this</em></strong></figcaption></figure><ul><li><strong>The Russian language:</strong></li><li>Your CER will easily be 2x of the English model with similarly clean data;</li><li>Your WER may be 2–3x depending on your post processing and how clean your data is;</li><li><strong>Generalization:</strong></li><li>You should cross validate your network across different domains. Then you will see real performance of your model in the wild;</li><li>Your domain difficulty essentially is noise x voice diversity x vocabulary diversity;</li><li>This will be mitigated when you have more data, but as a rule of thumb you may think that if you have one noisy domain, on another noisy domain you will have +10pp CER;</li><li>Your model will get better if you have more annotation. Refer to DeepSpeech paper 2 for exact figures — but probably x5 — x10 annotation may give you minus 7–10pp of CER;</li><li>Annotation quality matters and domain noise matters. If on perfect clear data a non over-fitted network may have 3–4% CER, then probably you can extrapolate that 5–10% CER on more noisy in-the-wild data is achievable, and very noisy data will be even worse;</li><li><strong>Your network:</strong></li><li>CNNs are a bit worse than similarly sized GRUs / LSTMs, but are 2–3x faster (at least);</li><li>Separable convolutions + bottlenecks can make your model 4–5x lighter and 3–4x faster (an idea very similar to this <a href="http://arxiv.org/abs/1904.02619">paper</a>, their particular model did not really work for us, but a model with similar ideas did). Such network takes 3x longer to train and overfits less, though;</li><li>Using 4x or 8x sequence down-scaling (probably with BPE, we are yet to achieve similar performance with 10k BPE) does not really hurt performance, but speeds up your training 2x-3x;</li><li>Dilated convolutions make your network ~2x slower, but CNNs stop skipping words (unlike RNNs);</li><li>If you are using a CNN, using skip-connections / residual networks is an obvious design choice;</li><li>Your CNN capacity probably will have to be 2–4x larger than wav2letter;</li><li>Try using <a href="http://arxiv.org/abs/1709.02755">SRU</a> instead of LSTM / GRU (we are yet to try it);</li><li>You may use any pre-processing and network. The only difference will be — how long you will have to train it given enough data;</li><li><strong>Training your network:</strong></li><li>Batch similarly sized audio chunks together. This can speed up your training up to 2x;</li><li>Make your pre-processing pipeline as simple as possible — why not just read binary int16 data from disk instead of converting data on-the-fly?;</li><li>Make your augmentation pipeline as efficient and cheap as possible;</li><li>Streamline your hardware. SSD storage is very cheap nowadays;</li><li>Having several sources of annotation (i.e. graphemes + phonemes) may help avoid plateaus. But this has to be investigated in more detail;</li><li><strong>Augmentations</strong></li><li>Are crucial for larger networks. Helped avoid plateaus for larger networks. Not so crucial for smaller networks;</li><li>Reduce the generalization gap;</li></ul><h3>PS — you do not need beam search?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Oi61I4o0-ioWx8PB.png" /><figcaption><strong>Turns out a network with BPE300 is ~30% faster, WER is 5–7pp better, CER is almost the same. Cool stuff!</strong></figcaption></figure><p><em>Originally published at </em><a href="https://spark-in.me/post/stt-dark-forest"><em>https://spark-in.me</em></a><em> on August 12, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b511e6e7aa88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Russian Open Speech To Text (STT/ASR) Dataset]]></title>
            <link>https://medium.com/data-science/russian-open-speech-to-text-stt-asr-dataset-4c4e5d6a292c?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c4e5d6a292c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[open-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Thu, 02 May 2019 07:15:28 GMT</pubDate>
            <atom:updated>2019-05-02T07:15:28.285Z</atom:updated>
            <content:encoded><![CDATA[<h4>4000 hours of STT data in Russian</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LW0PjW_EPvFYkCLN.png" /></figure><p><strong><em>If you do not pay the iron price, you know someone paid it for you. It works like this in every aspect of life</em></strong></p><p><em>Originally posted on </em><a href="https://spark-in.me/post/russian-open-stt-part1"><em>spark-in.me</em></a><em> on May 1, 2019</em></p><h3>TLDR</h3><p>This is an accompanying post for our <a href="https://github.com/snakers4/open_stt/">release</a> of <strong>Russian Open Speech To Text (STT/ASR) Dataset</strong>. This is meant to be a bit light-hearted and tongue in cheek. All opinions are my own, and probably opinions of my <a href="https://github.com/snakers4/open_stt/#contacts">colleagues</a> differ. This is a non-technical summary. Do not take this too seriously, probably 50% of this text is some kind of subtle joke (<strong>ping me if you find all the Easter eggs</strong>!).</p><p><strong>Anyway, here is the dataset:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*cyzRjawfLaLP2WohhvER_Q.png" /><figcaption>Dataset composition</figcaption></figure><p><strong>TLDR:</strong></p><ul><li>We have collected and published a dataset with <strong>4,000+ hours</strong> to train speech-to-text models in Russian;</li><li>The data is very diverse, cross domain, the quality of annotation ranges from good enough to almost perfect. Our intention was to collect a dataset that would somehow <strong>relate</strong> to real-life / business applications. Collecting only pure / clean data in academic fashion is of little interest. Ideally this dataset is a first step on a path to a repo with pre-trained STT models;</li><li>We intend to grow this amount to around <strong>10,000 hours</strong> or even maybe to 20,000 hours, if the stars align properly (we know how to get to 6–7k, we will improvise something);</li><li>We have <strong>NOT invested any real money</strong> in creation of this dataset (except of course for our time and effort), so we are releasing it under <a href="https://creativecommons.org/licenses/by-nc/4.0/">cc-by-nc</a> license. If you want to use the dataset for commercial purposes please go <a href="https://github.com/snakers4/open_stt/#contacts">here</a>;</li><li>You can see releases history <a href="https://github.com/snakers4/open_stt/releases">here</a>;</li></ul><h3>Speeding up the Imagenet moment</h3><p>Ideally it goes like this:</p><ul><li>Pull existing public models and datasets;</li><li>Collect some MVP dataset in your domain;</li><li>Build an MVP model;</li><li>Add more difficult cases;</li><li>Validate, test, rinse and repeat;</li></ul><p>In domains like Computer Vision (CV) and Natural Language Processing (NLP) there is something to build on, these are only things that work in 95% of cases:</p><ul><li>Widely shared Imagenet pre-trained models. Each framework has a repo like <a href="https://github.com/Cadene/pretrained-models.pytorch">this</a> — where you can get any sort of CV model with weights. Just add water;</li><li>In NLP, in my experience tools like FastText work best. Modern huge networks like BERT also work, but in real life we did not find them <a href="https://towardsdatascience.com/complexity-generalization-computational-cost-in-nlp-modeling-of-morphologically-rich-languages-7fa2c0b45909">practical</a>;</li></ul><p><strong>But in STT in Russian there is nothing really to build on:</strong></p><ul><li>Of course there are paid APIs / commercial last-gen products / products from government-related entities — but they have their <a href="https://drive.google.com/open?id=1XOOgcHJziA2-IuPYAnOm4b4E6g4ue1GamwAaFzL7QuQ">drawbacks</a> (besides being private or being built of less transparent technologies);</li><li>Public datasets are scarce at best (&lt;100 hours) and non-diverse / too clean at worst;</li><li>Even English public datasets … are academic and detached from real life usage;</li><li>STT has a long history, and it has a bias towards being developed by large tech companies;</li><li>Unlike Google / Facebook / Baidu which are known to publish stellar research (FAIR’s papers are awesome and accessible, Google less so), Yandex is not really known to add anything to the community;</li></ul><p><strong>In STT also there are several less discussed “gotcha” perks:</strong></p><ul><li>There is a speculation on how much data you need for proper generalization — estimates range from 5,000 hours to 20,000 hours. For example Librispeech (<strong>LS</strong>, one of the most popular datasets) is 1,000 hours and very “clean”. Google and Baidu report training on 10,000–100,000 hours of data in various papers for various settings;</li><li>If in CV your “domain” for which you learn features is for example <strong>“cats”</strong> (in certain positions that is, see explanations of Hinton’s CapsNets on this) in STT it is a bit more complicated. Your data can be <strong>clean / noisy</strong>. Also <strong>each voice is its own domain</strong>, models are amazing in adapting to voices. Also <strong>vocabulary is also an issue</strong>. So, basically when someone reports a 3 percentage point improvement on LS (i.e. 10% WER reduced to 7% WER) — you should take this with a grain of salt. My initial pipeline built in 1–2 days was able to work on LS quite well;</li><li>Cross domain transfer (i.e. when you train on books and validate on phone calls) works, but quite poorly. You can easily get +20pp WER. Also minor things like intonation / talking differently in noisy conditions matter;</li></ul><p>So — you can think of our venture as a first step towards providing a set of public models for the community in our language (Russian, the majority of our methods scale to other languages) and bringing the Imagenet moment closer / making reasonably good STT models for the public.</p><p>You can say that now we are knee-deep in the data. To succeed we will need to go deeper! Please stop me from producing these horrible puns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o5u6bs_3P9UjNL_x.png" /></figure><h3>Seeking contributors</h3><p>If you are willing to make a sensible contribution to our dataset / venture — you are welcome! We will make sure to publish as much as possible as friendly as possible.</p><p>Please contact us <a href="https://github.com/snakers4/open_stt/#contacts">here.</a></p><p>You can frame it like this. If 4 people (not working 100% of time on this project only) can make a difference, probably your addition will tip the balance of scales towards building a truly flexible deployable model?</p><h3>How not to share datasets</h3><p>First of all, here is the list of things <strong>I dislike that people do all the time when sharing datasets</strong>:</p><ul><li>Obviously paywalls with no way to inspect what you will get in advance;</li><li>Academic ivory tower attitude — “our dataset is cool and large, but useless in real life”;</li><li>Registration walls. Yes, “our dataset is public, but we will share it only for the chosen”. This thing. And yeah, if we decide not to share it with you, you will not be notified. Or most probably — nobody pays the moderator;</li><li>Sharing via Google Drive (btw, you can use wget with Google Drive, you need to download a cookie and use their link structure) or something that relies on temporary / dynamic links. Ideally you should just be able to use wget or better aria2c to get the data;</li><li>Poor hosting, poor CDN, poor speeds. It is laughable when people share a dataset, that probably would cost upwards of US$100k — US$1m to annotate from scratch manually, but spare US$100 per month on actually properly hosting the dataset;</li><li>Sharing via torrent … w/o having active seeders with at least 100 Mbit/s uplink speed. Academic torrents is great, but no seeders at any time;</li><li>Poor folder organization, no meta-data files, illogical structure;</li><li>Bloated, outdated tools and file formats used to load the dataset (hello xml and object detection datasets);</li><li>Convoluted and obscure code to read such data. You can pull off miracles with one liners in pandas. No, really;</li><li>No way to check your data;</li><li>Generally not caring about users;</li><li>Sharing data in proprietary formats / pushing some form of agenda;</li></ul><p><strong>We made a reasonable effort not to make any of these mistakes:</strong></p><ul><li>First of all, <strong>all links are public</strong>. We sourced the majority of our data from the Internet, so we s<strong>hare back whatever we can</strong>;</li><li>We did not do this yet (<a href="https://github.com/snakers4/open_stt/issues/2">help</a> us, why not), but you can just write a script that would download everything, unpack everything, check md5 sums and files in one go;</li><li>Dataset is hosted on <strong>AWS compatible bucket</strong> with CDN — download speeds will be good. You can use aria2c with -x flag to load files faster;</li><li>Data is mostly checked and written in the same format;</li><li>Data is collected in a disk DB optimized (see the repo for details) to work <strong>even on hard drives</strong> (we did not test it). I believe that a RAID array or NVME cache for your hard drive array will solve the IO problem entirely (we ourselves use SSD NVME drives);</li><li>Meta data file;</li><li>Some rudimentary hackable code snippets for easier start;</li></ul><h3>Finding a motivation, making a difference, ethics and motivation</h3><p><strong>Finally a set of points I would like to make:</strong></p><ul><li>After I made some baseline prototype and dataset, I was really disappointed in the result. If not for <a href="https://buriy.com/">Yuri’s</a> sound advice, experience and collaboration — I probably would have abandoned the project. Yuri, I am eternally grateful for your help. Yeah, I saw that STT in Russian was ripe for “ImageNet moment” plucking, but we would not stay motivated if not for you;</li><li>Obviously, even if we fail to provide usable / robust models for the public, our data / models will serve as a first step in this direction;</li><li>“Oh, such dataset should cost a fortune”. Yes, building something like this from scratch probably would cost millions. But we are not alone, and life is not a zero sum game — so it’s easier;</li><li>Life is not a zero sum game — therefore we saw an opportunity to make the dataset public — and we did it;</li><li>No, it is not unethical to use the data the way we use it. First of all, for 100% of data we use —<strong> we did not put it there</strong>. Someone did. And we do not use the data for the same purpose it was uploaded;</li><li>And finally, the elephant in the room. By publishing such a dataset, <strong>we bring the impending doom described in Orwell’s 1984 closer</strong>. Yes and no. You see, I do not believe that it is feasible to achieve such accuracy that actually <strong>jailing people based on STT results would make economic sense</strong>. If you have a real life WER of 10% — for most business applications, you have built amazing product! But to put people in prison it is too much — you will just end up processing false positives. I understand that in more civilized countries a court decision is required to take such actions. I believe that some other technologies that are<strong> INHERENTLY more toxic </strong>(like face recognition) than STT. After all — if you want to say something in private — say something in private (use encryption or just talk in person). You cannot go outside in private. I understand that we are talking about mass applications of such technologies, but even if you are up to something sketchy — it is your choice to call someone to talk about it. Going to a mall and being apprehended because of looking like some ethnic minority (i) first of all is already an issue already in many countries (ii) is not your choice. Concealing your appearance may also pose questions;</li><li>“Your dataset sucks because X”! Yeah, please give feedback, but make it logical, ideally drop us an email or a Github issue. Mostly we just collected all the data we could grab. But if you care so much, you are welcome to contribute!;</li><li>I also love <strong>ad hominem</strong> (such people always surface eventually) criticisms like this “you pretend to take a high moral stance by doing something (i.e. sharing the dataset), the why you did Y”. I mostly addressed this a two points above;</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c4e5d6a292c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/russian-open-speech-to-text-stt-asr-dataset-4c4e5d6a292c">Russian Open Speech To Text (STT/ASR) Dataset</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complexity / generalization /computational cost in NLP modeling of morphologically rich languages]]></title>
            <link>https://medium.com/data-science/complexity-generalization-computational-cost-in-nlp-modeling-of-morphologically-rich-languages-7fa2c0b45909?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa2c0b45909</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 15:17:54 GMT</pubDate>
            <atom:updated>2019-03-12T13:34:46.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*wejCVK-9Rocp43BnZ8aQhw.png" /><figcaption><strong>Deep FastText. You can also use this trick with transformers</strong></figcaption></figure><h3><strong>Comparing complex NLP models for complex languages on a set of real tasks</strong></h3><h4>Does it make sense to pre-train transformer-based models? Can you do better than BPE? Which architecture is better for which task?</h4><p>This will be one of those articles, where we do not publish “plug and play” code, but we ramble endlessly about what we tried and failed (or maybe not?) and most importantly <strong>how this fits onto a broader image</strong>.</p><p>Over the course of last 3–6 months we have tried various models for basic NLP tasks (like classification, sequence-to-sequence modeling, machine comprehension) for one morphologically rich language — <strong>Russian</strong>. This is kind of cool, because we can inherit the vast modern literature and codebase of modern NLP methods (RNNs, LSTMs, embeddings, PyTorch, FastText, LASER to name a few).</p><p><strong>But there are usually 3 pains:</strong></p><ul><li>Russian is much more complex than English and <strong>morphologically rich</strong>;</li><li>There are very scarce public benchmarks / datasets / corpuses;</li><li>NLP research in Russian is mostly non-existent (this primarily means applied benchmarks by real people). Afaik, state-of-the-art in Russian-English NMT is held by <a href="https://arxiv.org/abs/1801.03615">Chinese</a> guys;</li></ul><p><strong>These are our conclusions so far:</strong></p><ul><li><strong>Easy tasks</strong> — Despite the widely advertised improvements made by Transformers on a plethora of NLP tasks (I would consider 10 class classification on a academic dataset with 5–10k rows and several classes an “easy task”), we <strong>failed to reap REAL benefits</strong> of using transformers on such “easy tasks” given the <strong>computation cost and added complexity and inference time</strong>. Proper RNN / <a href="http://arxiv.org/abs/1803.01271">CNN</a> based models with attention quickly become capped by the bias in the data — not by task complexity;</li><li>There was one case when on a dialogue intent 30 class classification task the “baseline” model gave 51% top1 accuracy, whereas the transformer gave around <strong>57%</strong>. But on further investigation and cleaning — after we removed bias from data and reduced the number of categories to ~15–20, this boost evaporated, i.e. <strong>transformer was better in fitting to biased data</strong>.</li><li>Also what is remarkable — generative pre-training (BERT) in our setting behaves <strong>actually worse than just initializing an embedding bag layer with FastText n-gram vectors</strong> (given time, effort and computational resources required — it is a no-brainer you should not pre-train such models yourself).</li><li>Btw, such “easy” tasks include in my opinion mostly: classification, tagging, intent classification, search classification, POS, NER (provided of course you have a proper dataset).</li><li><strong>Sequence-to-sequence tasks</strong> — I guess you should put NMT here, but it is a thing in itself, we did not even tackle. On a semi-difficult (if a fat LSTM converges for a couple of days — it’s something, right?) <a href="https://spark-in.me/post/cft-spelling-2018">task</a> of typo correction in human names in the CIS states (do not dismiss it, read the post, it is not that easy as it sounds) — we just <strong>did not have enough patience to wait until transformers would converge</strong>. I would estimate they converged ~5x slower. We did not any sort of pre-training there, because the domain is very different;</li><li><strong>Really difficult tasks</strong>. Here for Russian I could only dig out the so-called <a href="http://docs.deeppavlov.ai/en/master/components/squad.html#sdsj-task-b">SberSQUAD</a>. Note that on the SQUAD itself the transformers now have the best EM (exact match) and exceed human performance with scores floating around 90% EM. The state-of-the-art model custom built for this particular task gives around 60% EM according to <a href="http://docs.deeppavlov.ai/en/master/components/squad.html#sdsj-task-b">DeepPavlov</a> (of course we do not know - it is train or val and whether validation was handled correctly). But here it becomes interesting:</li><li>A baseline back of the envelope model built it one day could achieve around 15% EM;</li><li>I could fit a transformer with embedding bag (initialized by FastText) up to 37-40% EM with a high learning rate of 1e-3 (45 hours to train on a single 1080 Ti);</li><li>When we added the generative pre-training, the model <strong>started converging several times faster</strong>, but no matter how we tried — we could not beat 30% EM - the model just overfitted eventually - so pre-training with our Embedding bag approach works, but just plain FastText init is better in the end;</li><li>Inference benchmarks — just benchmarking decently-sized transformers (300–400 hidden-size, 12 attention heads) on CPU inferences — gives around a 10x inference time as a rule of thumb on the same data compared to LSTMs w/o speed optimizations (just padding).</li></ul><p>Naturally take these with a grain of salt. And yes, probably all of this just means one of the following things:</p><ul><li>We made some bugs in code — though we took our time and checked everything thoroughly;</li><li>Since we mostly used 1m of 150 dimensional embeddings (to fit into memory) with a transformer with hidden size of 400, probably size matters;</li><li>Most likely — pre-training with the equivalent of 99 days * 1080Ti also matters;</li><li>Also probably due to imbalanced model (1m ngrams, shallow transformer) and lack of attention layer in our embedding bag — our model is essentially bottlenecked and / or overfits somehow on pre-train;</li></ul><h3>Latest tendencies in NLP models</h3><p>You may not know that there are 2 large groups of “complicated” languages — <strong>agglutinative and fusional languages</strong>, English itself being mostly analytic language (in English most sense in conveyed by way of helper words (particles, prepositions, etc)).</p><p>I am no linguistic expert, but Russian has a lot of agglutinative and fusional features. We have inflection, conjugation, morphemes and a lot of ways to mix all of this stuff!</p><p>So, on a very basic level every word in Russian can be split like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*rvbOqIxZ7wz5By0r" /><figcaption><strong>Subword units in Russian</strong></figcaption></figure><p>And yes, especially in verbs — for popular roots there exist verbs with almost all popular prefixes and they … surprise-surprise have very different meanings. If you know German — you will instantly understand me.</p><p>And of course to add to word formation — we have inflection and conjugation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/0*AvW8NCB8mCGRJPre.png" /><figcaption><strong>Inflection in Russian</strong></figcaption></figure><h3>Word representations in modern NLP</h3><p>Word <a href="http://arxiv.org/abs/1607.04606">vectors</a> revolutionized the NLP scene back when the original Word2Vec paper came out. But they actually became usable for languages with morphology only when <a href="http://arxiv.org/abs/1804.10959">FastText</a> and its awesome implementation were introduced.</p><p>If you are not familiar with Word2Vec — it essentially just learns say N (usually 300) dimensional word vectors from raw text, namely from words that surround the word in question. FastText takes this idea a bit further and learns subword vectors instead of word vectors and a word is just a weighted average of its subwords. If you are more into a technical aspect of this — nowadays you do not even need custom engineering to implement a basic w2v model — it can easily be <a href="https://towardsdatascience.com/implementing-word2vec-in-pytorch-skip-gram-model-e6bae040d2fb?gi=af2766789cd5">done</a> with embedding layers in modern deep learning frameworks.</p><p>But all of this is fine and dandy in theory. In reality the closest word to cat is … dog. Coffee is related to cup as coffee is a beverage often drunk in a cup, but coffee is not similar to cup in that coffee is a beverage and cup is a container. Because these vectors DO NOT CAPTURE MEANING. They capture CONTEXT. If course you can use approaches like this <a href="https://research.fb.com/publications/auto-encoding-dictionary-definitions-into-consistent-word-embeddings/">one</a>, where you essentially train something similar to a auto-encoder or a GAN to encode the dictionary word definition into a vectors. But this seems a bit high maintenance for most cases.</p><p>Also prior to FastText doing anything <strong>practical</strong> and <strong>deployable</strong> with Word2Vec was a pain for languages like Russian because:</p><ul><li>For a simple task you may have a vocabulary of 50-100k;</li><li>For a real production tasks — you vocabulary most likely will be within a 1m-10m range;</li><li>Whole Russian internet contains ~100m unique words;</li></ul><p>I did not do any benchmarks for English, but I would guess that the same figures would be around 5x-10x lower, which nevertheless does not make certain tasks tractable. This particular vocabulary problem is kind of alleviated in the mainstream NLP literature by using the so-called byte pair encoding (<a href="http://arxiv.org/abs/1508.07909">BPE</a>), which essentially learns how to split words efficiently into chunks.</p><p>Theoretically, BPE should be able to work nicely with agglutinative languages because morphemes do not change. The only problem is that Russian has a lot of fusional features as well. It makes sense that with NMT BPE would not work well, but with more down-to-earth tasks?</p><p>I tried testing BPE on a variety of tasks (I usually tried several vocabulary sizes like 30k / 100k / 500k) — and the best I had was a small decrease in accuracy, like 1–3pp, compared to char-level approaches and embedding bag approaches. I asked around in the community — and surprise-surprise I am not alone in observation <strong>that BPE kind of not works for Russian</strong>. Of course, maybe one should also balance the model weight in this case, but in my case the only 2 criteria were: (i) model should be fast during runtime (ii) model should converge fast during training. With modern GPUs and RAM there is little difference between having 50k and 250k vocabulary, unless you are doing NMT or language modelling, of course.</p><p>What is also puzzling — I have rarely seen mainstream papers apart from FastText of course that try to build word embedding solutions that would somehow <strong>take rich morphology into consideration</strong>. This Russian-Chinese NMT paper is an <a href="http://arxiv.org/abs/1801.03615">exception</a> — but they predict only endings separately.</p><h3>Attention, transformers, generative pre-training</h3><p>All of these are very important concepts.</p><p>But I will not bother copy pasting the same text and illustrations and will just redirect you to the best pages I know of explaining these concepts:</p><ul><li>How transformers work — <a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">annotated</a> transformer and <a href="http://jalammar.github.io/illustrated-transformer/">illustrated</a> transformer;</li><li>How attention <a href="https://lilianweng.github.io/lil-log/2018/06/24/attention-attention.html">works</a> and different types of attention;</li><li>How sequence to sequence model work — the <a href="https://bastings.github.io/annotated_encoder_decoder/">annotated</a> encoder decoder;</li><li>You <a href="https://bair.berkeley.edu/blog/2018/08/06/recurrent/">do not need</a> RNNs;</li></ul><p>In essence now to solve the applied NLP tasks, you have the following options to choose from:</p><ul><li><strong>Embedding layer</strong> to represent words or chars is a must have;</li><li><strong>Vocabulary</strong>: char-level / Fixed / BPE-based approaches / Embedding bag / FastText-based approaches;</li><li><strong>Embedding initialization</strong>: Word2Vec or Glove / FastText /a mixture of the above;</li><li><strong>The model itself:</strong></li><li>(1) <a href="https://t.me/snakers4/2253">TCN / RNN</a> + simple self-<a href="https://t.me/snakers4/2239">attention</a>;</li><li>(2) Encoder-decoder based sequence to sequence model;</li><li>(3) Transformer;</li></ul><p>Just select the correct combination and you are good to go!<br>Our task was mainly to understand how transformers (3) fit into this ecosystem — BPE or not, how to initialize the embeddings, how benchmark tasks are solved etc etc</p><h3>Our solution to word representation problem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*qmE0wwwkiSEFOj1v.png" /><figcaption><strong>Our approach to word representations for Russian in a nutshell</strong></figcaption></figure><p>So, now you see that working with a morphologically rich language is a chore. By working I mean producing models that you are sure <strong>will generalize well to modestly unknown situations</strong>.</p><p>But can’t we combine two of the best instruments we have? FastText + deep learning models? Turns out we can and this can be easily done using an EmbeddingBag <a href="https://pytorch.org/docs/stable/nn.html#embeddingbag">layer</a> in PyTorch for example. You can build a small model with attention and a mixture or words / ngrams / chars — but it most likely will work slower than low-level C++ implementation.</p><p>This approach works fantastically with plain models like TCNs / RNNs / CNNs and provides generalization and totally eliminates OOV cases, no more UNK tokens or any similar clunky solutions!</p><p>But can we generalize this to a transformer model pre-trained on large corpus of text?</p><p>There are only 3 fundamental problems with this approach:</p><ul><li>Adding <a href="https://discuss.pytorch.org/t/attention-on-nn-embeddingbag/10521">attention</a> to an embedding bag layer is a problem not likely to be solved;</li><li>To guarantee generalization you need at least around 500k-1000k ngrams;</li><li>You face technical issues — language modeling labels are not usable anymore for LM task (you have to use the model’s embeddings as ground truth) + using standard DataParallel wrappers becomes slow in PyTorch because of large embedding layer, to achieve true parallelism probably you have to use DistributedDataParallel;</li><li>You can get away with just using Embedding Bags on one GPU and then dividing the resulting bagged tensors into the right shape, but when you have a multi-GPU setup it becomes much more difficult, because instead of tokens each token becomes a padded sequence;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*7fvPwdafZ2BTeauQ.png" /><figcaption><strong><em>Typical vocabulary coverage (% of ngrams covered in a word) in case your ngram set is properly chosen. With 1m 2–6 grams you can cover even 100m dictionaries.</em></strong></figcaption></figure><h3>Is Transformer / BERT / GPT better for you?</h3><p>TLDR — unless you can use a pre-trained one — then most likely not, unless this is the only architecture powerful enough to handle your task.</p><h3>Seq2seq benchmark</h3><p>Please refer to this <a href="https://spark-in.me/post/cft-spelling-2018">post</a>.<br>TLDR — on a complicated sequence to sequence benchmark the transformer based models seems to have converged much slower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*OIr42qyBwMkKO_Yp.jpg" /><figcaption><strong><em>Shall we wait one more week?</em></strong></figcaption></figure><h3>Generative pre-training done 10–100x faster?</h3><p>We will not release our whole pre-training code (and what is more important — data scraping, pre-processing and our Dataset for obvious reasons), but you can just stick these classes <a href="https://github.com/huggingface/pytorch-pretrained-BERT/blob/master/pytorch_pretrained_bert/modeling.py">here</a> into a huggingface model, to:</p><ul><li>Start with pre-trained BPE vectors;</li><li>Start with old version of Embedding bag (which works better, lol);</li><li>Start with padded version of Embedding bag (to easily use multi-GPU wrappers);</li></ul><p>In a nutshell, what they say about US$50–100k computational resource required to pre-train a transformer seems totally unfeasible. Can we make it faster somehow for common folk like us?</p><p>(<em>Me from future: </em><strong><em>Yeah, do not pre-train, just train with Embedding bag initilized with FastText!</em></strong>)</p><p>In a purely American / Silicon Valley elitism fashion, papers like BERT do not do any poor man’s ablation tests like what would happen to convergence if you initialized your model with FastText?</p><p>But anyway, how can we speed up convergence? Let’s assume that pre-training takes 400 days on one 1080Ti and let’s work from there:</p><ul><li>Starting from pre-trained vectors / n-grams — <strong>maybe x10 faster?</strong> ;</li><li>Not using a large softmax layer (even if it is linked to your embedding layer) but using cosine loss or something inspired by <a href="http://arxiv.org/abs/1812.04616">this</a>. By the way these guys <strong>also start from FastText</strong> — <strong>x2 faster?</strong>;</li><li>A lighter model — <strong>x4 faster?</strong>;</li><li>Using an embedding bag layer that works well for Russian language;</li></ul><p>All in all with all of these “optimizations” it seems feasible to be able to <strong>pre-train / tune a transformer in a week or so</strong>) And it is real, the only problem is that the actual pre-trained model did not really seem to beat a model just initilized with FastText.</p><h3>Pre-traininig experiments</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/0*FvoNccBMvADAGZlq.png" /></figure><p>* We used 2 GPU setup for each model, but in the end we found out that the newer version of the embedding bag was roughly 25% slower + due to large embedding bag size;<br>** Classification task from BERT paper;</p><p><strong>Other “failed” approached we tested:</strong></p><ul><li>All models trained from scratch converged much slower and plateaued quickly;</li><li>All BPE based models initialized with FastText converged much slower and plateaued quickly around 65% sequential task accuracy;</li><li>FastText + embedding freeze — minus 5pp sequential task accuracy;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*di4hroyEDf6E6Axn.png" /><figcaption><strong><em>L2 embedding loss</em></strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I8XOPkAn5cnfAAp-.png" /><figcaption><strong>Cosine embedding loss</strong></figcaption></figure><h3>Actually trying out the pre-trained model</h3><p>This was by far the most disappointing part of this whole exercise.</p><p>As mentioned in the intro — any sort of transformer (from scratch, pre-trained, from FastText) did not help in our “easy” classification task on a complex domain (but FastText was the best).</p><p><strong>On a challenging SberSQUAD task, we has the following results:</strong></p><ul><li>A FastText initialized model trained with a high lr of 1e-3 to about 37%-40% EM. Probably more can be achieved with LR decay. Remarkably model diverged frequently and seemed to “jump” on each restart;</li><li>When we tried the pre-trained model with high lr of 1e-3 it trained much faster than FastText, but <strong>overfitted heavily</strong>;</li><li>If we started with lower lr somewhere around 5e-4 - then the pre-trained model traned also<strong> much faster</strong> than FastText, but overfitted around 30% EM;</li></ul><p>I suppose if we invested x10 resources into actually tuning the hyper-parameters, then we would achieve a higher result. But you see — generative pre-training IS NOT A SILVER BULLET. especially for non generative tasks.</p><p>On any SANE task — conventional RNNs / CNNs / TCNs — blow transformers out of the water.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6MK3TiZNBugJc2MT.png" /><figcaption><strong>Top performance of FastText initialized transformer</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/0*aVJAhyJDyVK_krMk.jpg" /><figcaption><strong>Some comparisons</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*pmJev6cJlKsiTdka.png" /><figcaption><strong>Low learning rate, pre-train vs. fast-text</strong></figcaption></figure><h3>Embedding bag code</h3><p>Just use our <a href="https://gist.github.com/snakers4/f2188adf217baabad2ff6733d48cfaef">code</a>, stick it <a href="https://github.com/huggingface/pytorch-pretrained-BERT/blob/master/pytorch_pretrained_bert/modeling.py">here</a> and add water. No, we are not stupid, and we use version control.</p><h3>Improvements or how to make our idea mainstream</h3><p>People from OpenAI, Google and FAIR, if you are reading this, you can do the following:</p><ul><li>Solve attention problem within the Embedding bag layer;</li><li>Add more compute to train a larger transformer with larger embedding bags;</li><li>Test such generative pre-training on other benchmarks for morphologically rich languages if you have them;</li><li>Invest time and effort into proper sub-word splitting techniques and pass bags corresponding to different kinds of sub-words separately;</li></ul><h3>References</h3><p><strong>Popular tools</strong></p><ul><li>Temporal convolutional <a href="http://arxiv.org/abs/1803.01271">network</a>;</li><li>Popular BPE <a href="https://github.com/google/sentencepiece">implementation</a>;</li><li>Auto-Encoding <a href="https://research.fb.com/publications/auto-encoding-dictionary-definitions-into-consistent-word-embeddings/">Dictionary Definitions</a> into Consistent Word Embeddings;</li><li>PyTorch BERT by <a href="https://github.com/huggingface/pytorch-pretrained-BERT">Huggingface</a>;</li><li>Improved English to Russian Translation by Neural Suffix <a href="https://arxiv.org/abs/1801.03615">Prediction</a>;</li><li>BERT <a href="https://nlp.stanford.edu/seminar/details/jdevlin.pdf">pre-training</a>;</li></ul><p><strong>Corpuses / datasets / benchmarks in Russian:</strong></p><ul><li>Russian SQUAD and sentiment analysis <a href="https://t.me/snakers4/2213">datasets</a>;</li><li>Mining for a large <a href="https://t.me/snakers4/2131">web corpus</a> in Russian;</li><li>My posts on parsing <a href="https://spark-in.me/post/parsing-wikipedia-in-four-commands-for-nlp">Wikipedia</a>, and parsing <a href="https://spark-in.me/post/parsing-common-crawl-in-four-simple-commands">Common Crawl</a>;</li><li>Prepared and deduplicated Common Crawl <a href="https://t.me/snakers4/2147">texts</a>;</li><li>Downsides of using common crawl to train <a href="https://t.me/snakers4/2230">sentence encoders</a>;</li><li>DeepPavlov Russian <a href="http://docs.deeppavlov.ai/en/master/components/squad.html#sdsj-task-b">SQUAD</a>;</li><li>FastText <a href="https://t.me/snakers4/2175">pre-trained</a> on the largest corpus in Russian;</li></ul><p><strong>Simple sentence embedding baselines:</strong></p><ul><li><a href="http://nlp.town/blog/sentence-similarity/index.html">http://nlp.town/blog/sentence-similarity/index.html</a>;</li><li><a href="https://openreview.net/pdf?id=SyK00v5xx">https://openreview.net/pdf?id=SyK00v5xx</a>;</li></ul><p><strong>Word embeddings explained:</strong></p><ul><li><a href="http://www.offconvex.org/2015/12/12/word-embeddings-1/">http://www.offconvex.org/2015/12/12/word-embeddings-1/</a>;</li><li><a href="http://www.offconvex.org/2016/02/14/word-embeddings-2/">http://www.offconvex.org/2016/02/14/word-embeddings-2/</a>;</li></ul><p><strong>Original word embedding papers:</strong></p><ul><li><a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf">Word2Vec</a> — Distributed Representations of Words and Phrasesand their Compositionality;</li><li><a href="http://arxiv.org/abs/1804.10959">FastText</a> Enriching Word Vectors with Subword Information</li></ul><p><strong>Illustrated state-of-the-art NLP models and approaches:</strong></p><ul><li><a href="https://lilianweng.github.io/lil-log/2018/06/24/attention-attention.html">Attention</a>;</li><li><a href="http://jalammar.github.io/illustrated-transformer/">Illustrated</a> transformer;</li><li><a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">Annotated</a> transformer;</li><li><a href="https://bastings.github.io/annotated_encoder_decoder/">Annotated</a> encoder decoder;</li><li>Plain <a href="https://t.me/snakers4/2239">self-attention</a> in PyTorch;</li><li>A couple of notes on <a href="https://t.me/snakers4/2253">TCNs</a> and <a href="https://t.me/snakers4/223">self-attention</a>;</li><li>Training NMT models <a href="http://arxiv.org/abs/1812.04616">several times faster</a> w/o a large softmax layer?;</li></ul><p><strong>Other links</strong></p><ul><li>Russian word <a href="http://inrussian.russkiepravila.ru/russian-word-parts/">parts</a>;</li><li>CFT 2018 <a href="https://spark-in.me/post/cft-spelling-2018">competition</a>;</li></ul><p><em>Originally published at </em><a href="https://spark-in.me/post/bert-pretrain-ru"><em>spark-in.me</em></a><em> on March 1, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa2c0b45909" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/complexity-generalization-computational-cost-in-nlp-modeling-of-morphologically-rich-languages-7fa2c0b45909">Complexity / generalization /computational cost in NLP modeling of morphologically rich languages</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Winning a CFT 2018 spelling correction competition]]></title>
            <link>https://medium.com/data-science/winning-a-cft-2018-spelling-correction-competition-b771d0c1b9f6?source=rss-f29885e9bef3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b771d0c1b9f6</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Alexander Veysov]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 11:21:54 GMT</pubDate>
            <atom:updated>2018-11-22T14:20:17.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>Or building a task-agnostic seq2seq pipeline on a challenging domain</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GI5PoxlPkN4N4W9p.jpg" /></figure><p><em>This is the first time we managed to win (i.e. 1st place) an ML competition together</em></p><p>A small philosophic preamble.</p><p>We participated as <a href="https://profi.ru/">Profi.ru</a> team (yours truly + Dmitry Voronin helped a bit) and Sava Kalbachou (<a href="https://lucidworks.com/">Lucidworks</a>), my old time pal from many competitions, also a specialist in NLP.<br> It was a long, difficult, nervous and surprisingly rewarding journey for our team.</p><p>To sum all the experience in one line — <strong>the journey is more important than the destination</strong>. This competition taught us a lot about being persistent, trying new things, falling down and standing up again.</p><p>I personally compiled / optimized 3 or 4 pipelines for this task, until I could build the best one. Also, as usual, we found a crucial error one day before the finish line xD</p><h3>TLDR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*1i2byZmCDK4OMSiz.jpg" /></figure><p>We managed to apply some of the current state-of-the-art sequence-to-sequence models to a real in the wild <a href="https://datasouls.com/c/cft-contest/description#">problem</a> in a challenging domain in a mixed multi-task / auto-encoder setting.</p><p>The core of the task was — text input classification (<strong>correct / needs to be corrected / random non-relevant trash</strong>) and input correction (essentially spell check).</p><p><strong>The domain was — names of individuals from the countries of the CIS:</strong></p><ul><li>Mostly Russia, Moldova, Uzbekistan, Georgia, Tadzhikistan, Kazakhstan, Ukraine, etc;</li><li>Names usually consist of 3 parts (name, surname, patronym) — Иванов Иван Иванович. Sometimes in certain republics patronyms have additional suffixes added as a fourth word (ОГЛЫ, same as вич suffix in Russian, but a separate word);</li><li>There were 2+ alphabets with a total around 70+ characters + a lot of noise in the data;</li></ul><p><strong>Models that worked best</strong></p><ul><li>Sequence-to-sequence:</li><li>Tuned sequence-to-sequence bidirectional GRU (see details below) — 92.5% wo heuristics, 93% with heuristics, 93%+ in ensemble;</li><li>Proper sequence-to-sequence inference loop;</li><li>Also a simpler model in Keras without bottleneck and with Conv1D output layer worked well — with a top score of 88-89%;</li><li>Strongest naïve heuristic — if the output of seq2seq inference loop is the same as input — then the input is correct;</li></ul><p><strong>Key takeaways:</strong></p><ul><li>Seq2seq transformer took <strong>much more time to train</strong> and we failed to make it work the same as traditional models. Obviously we lack experience with it, but this is the fourth time I notice <strong>real people</strong> mention that transformer is not for “real” people (i.e. non-practical);</li><li>Our main competitor (with ~200 submissions) did not use Deep Learning at all — he <strong>essentially reverse engineered the augmentation pipeline of the hosts</strong> — which is tough work, but does not scale to other domains;</li><li>Batch seq2seq predictions are key to fast inference;</li><li>Beam search, though being a tough gem to implement, <strong>boosted the score insignificantly</strong> (obvious culprit — small dictionary);</li></ul><h3>Domain / dataset description</h3><p>One illustration is better than a thousand words. Please also note — in train + test there were ~2000 countries, i.e. country input was also very noisy.</p><p>We ended up not using countries at all — as adding country embeddings did not boost our metrics</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*v9xsmYubSuxio78q297jew.png" /></figure><p>The hosts of the competition also shared a strong and simple <a href="https://github.com/datasouls/cft2018-fiotypos/blob/master/baseline/baseline.ipynb">baseline</a>:</p><ul><li>A linear regression classifier on ~1m n-grams;</li><li>Plain usage of 3rd party library to correct misprints;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*n8T81ebZb5EQuGCl.jpg" /><figcaption><em>The distribution of the number of errors per query</em></figcaption></figure><h3>Code release</h3><p>We will not bother replicating the whole training process (and due to our agreement with competition hosts), since there were a lot of fine-tuning steps, but overall <strong>these bits will be reusable for you</strong>:</p><ul><li><a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/preprocessing_av.ipynb">Preparing</a> the competition dataset (see the first chapter of the notebook);</li><li><a href="https://github.com/snakers4/cft-contest-2018/blob/master/Dockerfile">Dockerfile</a> in case you run into problems in your environment (when the image was build PyTorch 4.0 or 4.1 was a major version, target it, or you will have to make code compatible);</li><li>Keras model:</li></ul><pre>python preprocessing.py python spell_simple_seq2seq_train_predict.py</pre><ul><li>PyTorch BiLSTM seq2seq:</li><li>Best model training: <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder_utils.py">utils</a>;</li><li>Best model <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder.py">classes</a>;</li><li>Best model train <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/train_encoder_decoder_predict.py">pipeline</a>;</li><li>Typical launch command (flag names are self-explanatory):</li></ul><pre>CUDA_VISIBLE_DEVICES=0 python3 train_encoder_decoder_predict.py \ --resume weights/some_checkpoint.pth.tar \<br> --heavy_decoder True --lr_factor 0.5 \<br> --trn_df_path ../data/pseudo_aug2_proc_trn.csv \<br> --tb_name test_name \<br> --lr 1e-6 --epochs 100 \<br> --batch_size 128 \<br> --hidden_size 512 --dropout 0.2 \<br> --num_layers 4 --num_classes 3 --emb_size 512 \<br> --cn_emb_size 0 --num_cn 0 \<br> --tensorboard True \</pre><h3>Key milestones in achieving our result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*LlCtYsHL8TE-f_BvH_u0rg.png" /><figcaption>This is how our scores improved</figcaption></figure><ul><li>(*) Most likely we just did not invest enough time into this, but the target of the base pipeline was different, so we abandoned the idea;</li><li>(**) Whereas the biggest reasonable BiGRU model trained for 15-20 hours, this would train for at least a week on one GPU to achieve similar result;</li><li>(***) LR decay mostly, MOAR layers!;</li><li>(****) Two time we made errors when generating augmented data. At first I mixed 2 columns (source and target) in 50% of cases - and the model trained a bit better at first. Then I forgot to change target labels when augmenting the data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KoF-2el-sl2XRUfV.jpg" /></figure><p>Please refer to these <strong>amazing articles</strong> for more nuts and bolts of the models we used:</p><p><strong>What worked:</strong></p><ul><li>Sequence to sequence modelling with biLSTMs (91%+);</li><li>Validation matched LB precisely — we did not try K-Fold validation, but splitting the dataset in advance was accurate enough;</li><li>Using a simple pipeline to clean extra characters and obvious errors;</li><li>Pseudo-labelling and text augmentations (91% + 1.5% on a single model);</li><li>Using the “whole” train dataset, i.e. using all of the correct names as “correct” and using all of the incorrect names. Paired with additional augmentations (1x size of the train dataset) — turned out to be our single best pre-processing pipeline (91% + 1.5% on a single model);</li><li>Post-processing heuristics (see below);</li><li>Running batch-based inference loops (in the annotated encoder decoder and transformer predictions are handled with batch-size of 1);</li></ul><h3>Ideas / solutions / models that did not work or we did not try</h3><ul><li><a href="https://github.com/google/sentencepiece">BPE / Sentencepiece</a> — we tried using several vocabularies (500, 1500, 5000 tokens size etc.) obtained in unsupervised fasion via Sentencepiece. But it didn’t really help model to converge faster and results were worse than we expected;</li><li><a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder_utils.py#L353">Beam search</a> — most likely because of model confidence and small vocabulary. It boosted the score a bit, but did not provide a lot of value. It was a tough nut to crack, but I was dissapointed it did not work as much as we expected;</li><li>Transformer model — when I adopted and optimized the annotated transformer <a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">pipeline</a> it worked, but failed to converge within meaningful time;</li><li>LM assisted classifier from Open AI transformer experiments — it failed to converge at all, most likely because it lacked a proper seq2seq inference loop, it was a low hanging fruit for me (I just had the this pipeline ready, while Sava boasted his initial 88% pipeline);</li><li>Multi-GPU / cluster / distributed training — didn’t try it;</li><li>Running augmentations on the fly — I believe you can extend this <a href="https://github.com/pytorch/text/blob/master/torchtext/data/iterator.py#L257">line</a> in torchtext to do so, but I postponed it a bit, and then just had no time to do that. But that may speed up the convergence 3–10x from my experience;</li></ul><h3>Text data augmentation</h3><p>After some reverse engineering process (by the way based on the word ngrams), it turned out, that organizers use pretty simple typos generation methods. There are 5 main types:</p><ul><li><strong>Insert</strong>, the most dominant type (<em>~50%</em> of all cases). Just takes a random letter in a word and inserts a new letter before or after it. A new letter is a random closest (on a keybord) letter to the chosen one, for example — letters <strong>W</strong>, <strong>S</strong> or <strong>A</strong> if <strong>Q</strong> is chosen. <strong>IVAN</strong> — <strong>ICVAN</strong>;</li><li><strong>Change</strong>, <em>~30%</em>, just changes a random letter in a word into random closest to it on a keybord (like in <strong>insert</strong> case). <strong>IVAN</strong> — <strong>IVQN</strong>;</li><li><strong>Wwap</strong> positions of two nearest random letters, <em>~5%</em>. <strong>IVAN</strong> — <strong>IAVN</strong>;</li><li><strong>Delete space</strong> between two words, <em>~7.5%</em>;</li><li><strong>Delete letter</strong> (completely random <em>~7.5%</em>), <strong>IVAN</strong> — <strong>VAN</strong>;</li></ul><p>Each query with typos contains a combination of one (<em>93%</em> of all cases), two (<em>6%</em>) or three (<em>~1%</em>) mistakes listed above.</p><p>So we managed to write our own funcion for generating an additional dataset and use it alongside the original one for training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/0*2eFaAI3wr8yLf-Gj.jpg" /></figure><h3>Post-processing heuristics</h3><p>After building the first seq2seq model we noticed that sometimes model predicts class 0 (phrase doesn’t contains error), but predicted phrase is different from original one. We used this as a heuristic to change predicted class from 0 to 1 (phrase contains error), that gave us 0.5–1.5% boost, depending on the quality of the model (less for strong models).</p><p>Another heuristic was in changing predicted class/phrase to predictions from quite different model (like Keras one) in cases when we are sure that there is a mistake in predictions (model predicts class 1, but predicted phrase is equal to original phrase).</p><h3>Heuristics that did not work, or that we did not explore</h3><p>At some moment of time we noticed, that the network is several times more likely to make errors with the words it “knows” compared to “new” words (names / surnames / patronyms). It meant that the network generalized well, but nevertheless we tried applying an obvious heuristic to test, in essence similar to pseudo-labelling.</p><p>Obviously we tried using dictionary heuristic, i.e. checking whether the predicted words are present in the vocabulary of names. It gave a significant boost on validation, but failed to provide reasonable boost on test (most likely because there are rare names that are predicted wrong and / or are not present in train). Obviously we tried adding predicted “correct” test names, but that did not help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*V2tUTQlhN7QXEcCq.jpg" /></figure><p>Train vs. test word dictionary overlap</p><h3>Ensembling models</h3><p>As it often happens during competitions, at some point close to the end you just have to do some stacking/ensembling to continue conpeting and stay at the top of LB. This contest wasn’t an exception.</p><p>We used hold-out validation data to find optimal way of ensembling and its parameters. For the first task of classification we used kind of geometrical mean of predicted probabilities from variety diverse models. For the second taks of name correction we implemented simple majority voting mechanism that was applied for each of the token of predicted names. After each step heuristics described above were used as well.</p><p>This quite simple yet efficient ensemble gave us final ~0.003% boost and 1st place. We selected it and best single model as our two final submissions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e9QHXLoa4UVtlGKV.png" /></figure><h3>Improving the annotated encoder-decoder and the annotated transformer</h3><p>As you may know, biLSTMs / biGRUs and transformers are the best models on the market when it comes to the challenging tasks like the following:</p><ul><li>Neural Machine Translation;</li><li>Text abstraction;</li><li>Sequence to sequence modelling;</li><li>Text inference tasks;</li></ul><p>And we were standing on the shoulders of the giants when re-using the stellar pipelines from these tutorials <a href="https://bastings.github.io/annotated_encoder_decoder/">encoder decoder</a> and <a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">annotated transformer</a>.</p><p>But as everything in our life, they are not perfect.</p><p><strong>Key shortcomings:</strong></p><ul><li>Predictions in both of them are handled with batch-size of one. This is not ideal when you run a lot of end-to-end experiments;</li><li>Annotated encoder decoder boasts loss weighting, but it is not explained that when pairing this with secondary objectives (like in our case) — you have to be extra careful with weighting both components of the loss to avoid over / underfitting on one task;</li><li>While torchtext is awesome for the purpose it was build (to accelerate NMT experiments) — for applied competition NLP pipelines — it is a bit slow and bulky and seed parameters are non intuitive. Probably I should have solved caching a bit better, but I opted for the simplest solution with CSV files I explain below;</li><li>I fully understand that distributed / data parallel routines in PyTorch is a bit experimental and in high maintenance, but ofc annotated transformers multi GPU loss compute function broke in PyToch 0.4+. I decided not to fix this, but probably I should have, expecially for transformer;</li></ul><h3>Batch predictions and beam search</h3><p>Much attention in both turotials was paid to running models efficiently when training and validating the model. But for some reason the inference greedy search loops presented in the tutorials are written for batches with size 1.</p><p>As you may be aware, this slows down end-to-end validation 10x. So, I have written essentially 3 functions:</p><h3>All of these abstractions from torchtext … how to cook them well</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bwlyro6s6U-rPKE1.jpg" /></figure><p>Obviously these were built for NMT. They also load all the data in the form of tensors into RAM for faster iteration (and it is a good idea to use iterators in python when working with these to avoid more RAM usage) unlike the standard PyTorch Dataset / Dataloader classes, which a bit more flexible.</p><p><strong>Advantages of these abstractions:</strong></p><ul><li>Code reuse and simplicity;</li><li>They are … high level and abstract;</li><li>The steps of creating, describing and pre-processing the dataset are easy and streamlined;</li><li>Tedious steps like adding start tokens, end tokens, unique tokens, pad tokens are just done for you;</li><li>Once you get hold of the splits and dictionary building — it becomes really easy to substitute your text preprocessing functions to try different tokenization schemes (for example check this <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder_utils.py#L111">one</a> and this <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder_utils.py#L108">one</a>);</li></ul><p><strong>Downsides</strong>:</p><ul><li>You have to be very careful with leaks when building dictionaries to make re-runs of the same model compatible (this actually held me a bit in the beginning);</li><li>Obviusly this works out of the box only for numerical and text data. Any other forms of data — you will have to improvise / extend classes;</li><li>I did not like how splits were implemented there — so we ended up creating a hould out dataset via splitting a separate .csv file;</li><li>In case you have a lot of data (e.g. 10M input target pairs) — RAM consumption is very high — so you essentially have to monkey patch / extend these classes if you want to have more data / use augmentations;</li><li>Though in theory it is easy to extend these classes to read .feather instead of .csv, I did not do it due to lack of time and lack of focus;</li><li>Pickling issues — since reading .csv files is slow, I tried to pickle some obvious objects - but failed - iterators / generators are not picklable in python3. I guess I should have done it with the dataset class (not the BucketIterator class);</li></ul><h3>Model flavours</h3><p>At some point in time I noticed that there are essentially 2 bottle-necks in our best model:</p><ul><li>The flow between encoder and decoder is bottle-necked by the fact that encoder is bidirectional, and decoder is not. So simply speaking I solved this by making my decoder <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder.py#L22">2 times bigger</a> (and it helped my model to converge);</li><li>I also experimented with adding <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder.py#L64">country embeddings</a> and adding a <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder.py#L36">skip connection</a> and one more attention layer in essense similar to copy attention from abstraction models — these ideas did not work for me;</li><li>I also played with essentially <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder.py#L53">dropping</a> embeddings at all (char level model), with poor results; On the other hand, Keras models worked reasonably better at char level than using embeddings.</li></ul><p>Notably, best models were quite heavy, heavy decoder also adding quite a lot of time to epoch.</p><h3>Loss weighting is crucial!</h3><p>I did not run ablation tests for this (I had a lot of experience failing in object detection with 2–3 losses, though) — but I assumed that since loss is essentially applied n_token times for language modelling target and then normalized by the number or tokens, to achieve best results the classification loss should be similary <a href="https://github.com/snakers4/cft-contest-2018/blob/master/src/pytorch/encoder_decoder_utils.py#L89">sized</a>. I achieved this simply by using the most convenient loss layer in PyTorch (yeah, I forgot to divide this loss by batch-size, but this turned out to be not so cricial, I guess).</p><h3>KLD loss?</h3><p>A neat idea from annotated transformer that I did not explore — replace the classification loss with KLD-like loss (usually used in variational auto-encoders) to add more variance to predictions. But I guess it is not important for a small vocabulary.</p><h3>References</h3><ul><li>Mechanics of seq2seq models with <a href="https://jalammar.github.io/visualizing-neural-machine-translation-mechanics-of-seq2seq-models-with-attention/">attention</a>;</li><li>The amazing illustrated <a href="http://jalammar.github.io/illustrated-transformer/">transformer</a>;</li><li>Annotated <a href="https://bastings.github.io/annotated_encoder_decoder/">encoder decoder</a> and <a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">annotated transformer</a> (older PyTorch);</li><li>OpenAI transformer <a href="https://github.com/huggingface/pytorch-openai-transformer-lm">implementation</a> in PyTorch;</li><li>Torch text data pipeline <a href="http://mlexplained.com/2018/02/08/a-comprehensive-tutorial-to-torchtext/">explained</a>;</li><li>A <a href="https://medium.com/analytics-vidhya/https-medium-com-tomkenter-why-care-about-byte-level-seq2seq-models-in-nlp-26bcf05dd7d3">case</a> for byte level NMT models;</li></ul><p><em>Originally published at </em><a href="https://spark-in.me/post/cft-spelling-2018"><em>spark-in.me</em></a><em> on November 22, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b771d0c1b9f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/winning-a-cft-2018-spelling-correction-competition-b771d0c1b9f6">Winning a CFT 2018 spelling correction competition</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>