vrijdag 21 april 2017

Building a Sentiment Analyser for Your Surveys.

High failure rates at Dutch universities are a serious problem, but no one seems to connect it to the lack of proper quality systems. My experience is that most schools only measure progress at the end of a term via some kind of assessment. I always compare that principle to a car manufacturer who assesses the quality of his products only at the end of the production line. This producer would inevitably end up with a lot of scrap.

Yesterday I talked with a colleague of mine about quality control for education. He just started as a coordinator of an undergraduate programme at our university and is now searching for ways to increase the standards and improve the outcomes. I advised him to treat a course or a study curriculum as a genuine process in which you have inputs (ignorant students) that are transformed into outputs (knowledgeable starting professionals). If Toyota would be asked to design such a process, it would start by putting in quality control checks at all the critical points.

For my courses I'm using Moodle as a kind of educational ERP system. It contains the whole structure of a course in the form of content and activities. Each interaction of a student with the content or activity is saved as a transaction. By aggregating the transactions continuously, quality deviations can be noticed almost immediately allowing for much earlier intervention and better understanding of study processes.

My colleague plans to use Moodle's feedback activity for regular student satisfaction surveys. One problem with surveys however is that if you use standard scales (e.g. Likert) you miss out on a lot of information compared to using open questions. The problem with the latter is that the processing of the outcomes consumes a lot of time.

Unless of course you could automate that!

With R you can. Using the syuzhet package you can read in the surveys and have them scored for emotions and sentiment. These scores can then be visualised making it easier to analyse the data.

I've build a concept Shiny app that implements this idea. The outcomes of the Moodle feedback activity can be downloaded as CSV. This CSV can be uploaded and processed into sentiment scores. The scores are visualised using plotly and presented as a data table.



The code for the app as well as a test CSV file can be found on github.com/minorsmart/FEB2017/tree/master/Witek/SurveySent.

maandag 25 juli 2016

Using Google Speech API in R

How to do it

I am not quite the wizzard when it comes to HTTP, so me having figured out how to apply the Google Speech API in R is either sheer luck or good work by Google. It took me half a day mainly fiddling around with API keys and quality specs of the audio file (all is described clearly in the online documentation - as I found out at the end) . But now that it works I can really appreciate the power and precision of this tool. And it handles Dutch too!




library(httr)
library(RJSONIO)
library(base64enc)

# The API currently only accepts base64encoded data
audio_enc <- base64encode("bomans1.flac")

# Use the browser key from the Google Speech API (in this case hidden in the .Renviron file)
key <- Sys.getenv("SPEECH_API")

url <- paste0("https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=", key)

r <-
  POST(url = url
    ,
    body = toJSON(list(
      config = c(
        encoding = "FLAC",
        sample_rate = 22050,
        languageCode = "nl-NL"
      ),
      audio = c(content = audio_enc)
    ))
  )

content(r)$results[[1]]$alternatives[[1]]$transcript
## [1] "Ik zit mij bij het vensterraam dadelijk te vervelen Ik wou dat ik twee hondjes was dan konden we samen spelen"

You have to wait for around 20 seconds to receive the return json file from the Speech Engine.