Introduction to googleLanguageR

Mark Edmondson

2017-11-16

googleLanguageR contains functions for analysing language through the Google Cloud Machine Learning APIs

Note all are paid services, you will need to provide your credit card details for your own Google Project to use them.

The package can be used by any user who is looking to take advantage of Google’s massive dataset to train these machine learning models. Some applications include:

The applications of the API results could be relevant to business or researchers looking to scale text analysis.

Google Natural Language API

Google Natural Language API reveals the structure and meaning of text by offering powerful machine learning models in an easy to use REST API. You can use it to extract information about people, places, events and much more, mentioned in text documents, news articles or blog posts. You can also use it to understand sentiment about your product on social media or parse intent from customer conversations happening in a call center or a messaging app.

Read more on the Google Natural Language API

Google Cloud Translation API

Google Cloud Translation API provides a simple programmatic interface for translating an arbitrary string into any supported language. Translation API is highly responsive, so websites and applications can integrate with Translation API for fast, dynamic translation of source text from the source language to a target language (e.g. French to English).

Read more on the Google Cloud Translation Website

Google Cloud Speech API

Google Cloud Speech API enables you to convert audio to text by applying neural network models in an easy to use API. The API recognizes over 80 languages and variants, to support your global user base. You can transcribe the text of users dictating to an application’s microphone or enable command-and-control through voice among many other use cases.

Read more on the Google Cloud Speech Website

Installation

  1. Create a Google API Console Project
  2. Within your project, add a payment method to the project
  3. Within your project, check the relevant APIs are activated
  1. Generate a service account credential as a JSON file
  2. Return to R, and install this library via devtools::install_github("MarkEdmondson1234/googleLanguageR")

Usage

Authentication

The best way to authenticate is to use an environment file. See ?Startup. I usually place this in my home directory. (e.g. if using RStudio, click on Home in the file explorer, create a new TEXT file and call it .Renviron)

Set the file location of your download Google Project JSON file in a GL_AUTH argument:

#.Renviron
GL_AUTH=location_of_json_file.json

Then, when you load the library you should auto-authenticate:

library(googleLanguageR)
# Setting scopes to https://www.googleapis.com/auth/cloud-platform
# Set any additional scopes via options(googleAuthR.scopes.selected = c('scope1', 'scope2')) before loading library.
# Successfully authenticated via location_of_json_file.json

You can also authenticate directly using the gl_auth function pointing at your JSON auth file:

library(googleLanguageR)
gl_auth("location_of_json_file.json")

You can then call the APIs via the functions: