<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/amazon-alexa-and-accented-english/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://juliasilge.com/blog/amazon-alexa/"> Rstats on Julia Silge</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Earlier this spring, one of my data science friends here in SLC got in contact with me about some fun analysis. My friend <a rel="nofollow" href="https://www.linkedin.com/in/dylanzwick/" target="_blank">Dylan Zwick</a> is a founder at <a rel="nofollow" href="https://www.pulselabs.ai/#/" target="_blank">Pulse Labs</a>, a voice-testing startup, and they were chatting with the Washington Post about a piece on how devices like Amazon Alexa deal with accented English. The piece is <a rel="nofollow" href="https://www.washingtonpost.com/graphics/2018/business/alexa-does-not-understand-your-accent/" target="_blank">published today in the Washington Post</a> and turned out really interesting! Let’s walk through the analysis I did for Dylan and Pulse Labs.</p>
<div>
<h2>Understanding the data</h2>
<p>Dylan shared voice testing results data with me via Google Sheets. The dataset included the phrase that each speaker spoke aloud, the transcription of the phrase that the Alexa device understood, and a categorization for each speaker’s accent.</p>
<pre><code>library(tidyverse)
library(googlesheets)
library(stringdist)

alexa_raw &lt;- gs_title(&quot;Alexa Speech to Text by Accent Data&quot;) %>%
    gs_read(range = cell_cols(1:4),
            verbose = FALSE) %>%
    set_names(&quot;truth&quot;, &quot;measured&quot;, &quot;accent&quot;, &quot;example&quot;)</code></pre>
<p>What do a few examples look like?</p>
<pre><code>alexa_raw %>% 
    sample_n(3) %>% 
    select(truth, measured, accent) %>% 
    kable()</code></pre>
<table>
<thead>
<tr>
<th align="left">truth</th>
<th align="left">measured</th>
<th align="left">accent</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">China proposes removal of two term limit potentially paving way for Xi to remain President</td>
<td align="left">china proposes removal of to term limit potentially paving way for gh remain president</td>
<td align="left">1</td>
</tr>
<tr>
<td align="left">As winter games close team USA falls short of expectations</td>
<td align="left">ask winter games close team usa fall short of expectations</td>
<td align="left">1</td>
</tr>
<tr>
<td align="left">China proposes removal of two term limit potentially paving way for Xi to remain President</td>
<td align="left">china china proposes removal of to time limit potentially paving way to remain president</td>
<td align="left">1</td>
</tr>
</tbody>
</table>
<p>The <code>truth</code> column here contains the phrase that the speaker was instructed to read (there are three separate test phrases), while the <code>measured</code> column contains the text as it was transcribed by Alexa. The <code>accent</code> column is a numeric coding (1, 2, or 3) for the three categories of accented English in this text. The three categories are US flat (which would be typical broadcast English in the US, often encounted in the West and Midwest), a native speaker accent (these folks included Southern US accents and accents from Britain and Australia), and a non-native speaker accent (individuals for whom English is not their first language).</p>
<pre><code>alexa &lt;- alexa_raw %>%
    mutate(accent = case_when(accent == 1 ~ &quot;US flat&quot;,
                              accent == 2 ~ &quot;Native speaker accent&quot;,
                              accent == 3 ~ &quot;Non-native speaker accent&quot;),
           accent = factor(accent, levels = c(&quot;US flat&quot;,
                                              &quot;Native speaker accent&quot;,
                                              &quot;Non-native speaker accent&quot;)),
           example = case_when(example == &quot;X&quot; ~ TRUE,
                               TRUE ~ FALSE),
           truth = str_to_lower(truth),
           measured = str_to_lower(measured)) %>%
    filter(truth != &quot;phrase&quot;,
           truth != &quot;&quot;) %>%
    mutate(distance = stringdist(truth, measured, &quot;lv&quot;))</code></pre>
<p>How many recordings from an Alexa device do we have data for, for each accent?</p>
<pre><code>alexa %>%
    count(accent) %>%
    kable()</code></pre>
<table>
<thead>
<tr>
<th align="left">accent</th>
<th align="right">n</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">US flat</td>
<td align="right">46</td>
</tr>
<tr>
<td align="left">Native speaker accent</td>
<td align="right">33</td>
</tr>
<tr>
<td align="left">Non-native speaker accent</td>
<td align="right">20</td>
</tr>
</tbody>
</table>
<p>This is a pretty small sample; we would be able to make stronger conclusions with more recordings.</p>
</div>
<div>
<h2>Visualizations</h2>
<p>Let’s look at the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Levenshtein_distance" target="_blank">string distance</a> between each between each benchmark phrase (the phrase that the speaker intended to speak) and the speech-to-text output from Alexa. We can think about this metric as the difference between what the speaker said and what Alexa heard.</p>
<pre><code>alexa %>%
    ggplot(aes(accent, distance, fill = accent, color = accent)) +
    geom_boxplot(alpha = 0.2, size = 1.5) +
    labs(x = NULL, y = &quot;String distance (Levenshtein distance)&quot;,
         title = &quot;How well does Alexa understand different accents?&quot;,
         subtitle = &quot;Speech with non-native accents is converted to text with the lowest accuracy&quot;) +
    theme(legend.position=&quot;none&quot;)</code></pre>
<p><img src="https://i1.wp.com/juliasilge.com/blog/2018/2018-07-19-amazon-alexa_files/figure-html/boxplot-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>I used the Levenshtein distance, but the results are robust to other string distance measures.</p>
<pre><code>alexa %>%
    group_by(accent) %>%
    summarise(distance = median(distance)) %>%
    ggplot(aes(accent, distance, fill = accent)) +
    geom_col(alpha = 0.8) +
    geom_text(aes(x = accent, y = 0.5, label = accent), color=&quot;white&quot;,
            family=&quot;IBMPlexSans-Medium&quot;, size=7, hjust = 0) +
    labs(x = NULL, y = &quot;String distance between phrase and speech-to-text output (median Levenshtein distance)&quot;,
         title = &quot;How well does Alexa understand English speakers with different accents?&quot;,
         subtitle = &quot;Speech with non-native accents is converted to text with the lowest accuracy&quot;) +
    scale_y_continuous(expand = c(0,0)) +
    theme(axis.text.y=element_blank(),
          legend.position=&quot;none&quot;) +
    coord_flip()</code></pre>
<p><img src="https://i0.wp.com/juliasilge.com/blog/2018/2018-07-19-amazon-alexa_files/figure-html/barplot-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>We can see here that the median difference is higher, by over 30%, for speakers with non-native-speaking accents. There is no difference for speakers with accents like British or Southern accents. That result looks pretty convincing, and certainly lines up with what <a rel="nofollow" href="https://www.washingtonpost.com/graphics/2018/business/alexa-does-not-understand-your-accent/" target="_blank">other groups in the WashPo piece</a> found, but it’s based on quite a small sample. Let’s try a statistical test.</p>
</div>
<div>
<h2>Statistical tests</h2>
<p>Let’s compare first the native speaker accent to the US flat group, then the non-native speakers to the US flat group.</p>
<pre><code>t.test(distance ~ accent, data = alexa %>% filter(accent != &quot;Non-native speaker accent&quot;))</code></pre>
<pre><code>## 
##  Welch Two Sample t-test
## 
## data:  distance by accent
## t = -0.55056, df = 60.786, p-value = 0.584
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.875468  2.202214
## sample estimates:
##               mean in group US flat mean in group Native speaker accent 
##                            8.739130                            9.575758</code></pre>
<pre><code>t.test(distance ~ accent, data = alexa %>% filter(accent != &quot;Native speaker accent&quot;))</code></pre>
<pre><code>## 
##  Welch Two Sample t-test
## 
## data:  distance by accent
## t = -1.3801, df = 25.213, p-value = 0.1797
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.125065  1.603326
## sample estimates:
##                   mean in group US flat 
##                                 8.73913 
## mean in group Non-native speaker accent 
##                                12.00000</code></pre>
<p>Performing some t-tests indicates that the group of speakers with flat accents and those with native speaker accents (Southern, British, etc.) are not different from each other; notice how big the p-value is (almost 0.6).</p>
<p>The situation is not clear for the comparison of the speakers with flat accents and those with non-native speaker accents, either. The p-value is about 0.18, higher than normal statistical cutoffs. It would be better to have more data to draw clear conclusions. Let’s do a simple power calculation to estimate how many measurements we would need to measure a difference this big (~30%, or ~3 on the string distance scale).</p>
<pre><code>power.t.test(delta = 3, sd = sd(alexa$distance), 
             sig.level = 0.05, power = 0.8)</code></pre>
<pre><code>## 
##      Two-sample t test power calculation 
## 
##               n = 93.37079
##           delta = 3
##              sd = 7.278467
##       sig.level = 0.05
##           power = 0.8
##     alternative = two.sided
## 
## NOTE: n is number in *each* group</code></pre>
<p>This indicates we would need on the order of 90 examples per group (instead of the 20 to 40 that we have) to measure the ~30% difference we see with statistical significance. That may be a lot of voice testing to do for a single newspaper article but would be necessary to make strong statements. This dataset shows how complicated the landscape for these devices is. Check out the piece online (which includes quotes from Kaggle’s <a rel="nofollow" href="http://www.rctatman.com/" target="_blank">Rachael Tatman</a>) and let me know if you have any feedback or questions!</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://juliasilge.com/blog/amazon-alexa/"> Rstats on Julia Silge</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/gGL9n6D40CU" height="1"></a></div>