📜 ⬆️ ⬇️

Google Cloud: New Platform and Machine Learning Capabilities

Hello colleagues.

Recently, we are carrying out plans to publish a book on natural language processing. One of the most ambitious solutions that determine the prospects of this industry, of course, is the Google Cloud platform, which is the best adapted for machine learning. Please speak out about the relevance of this book.


')
and read under the cat about a small library designed to process natural language in R.


One of the most important benefits that we have is speech and language. It is thanks to the ability of speech that we can boast of almost all of our achievements. The ability to analyze communication helps us understand each other much better.

It is for this purpose that Google developed the googleLanguageR Language R package, which allows you to convert speech into text, providing translation using neural networks and processing natural language using the machine learning services offered in Google Cloud .

Below you can briefly familiarize yourself with this package, and more detailed information is available on googleLanguageR .

Google selection

According to Google forecasts, machine learning will become a fundamental component of any business, so Google strives to build an infrastructure in which all the conditions for machine learning are created. Figuratively speaking, if machine learning is electricity, then Google wants to become the company that will fix the entire country with power transmission towers.



Perhaps Google is not the only company with such ambitions, but Google has an important advantage: the amount of data available. Thanks to twenty years of experience in search indexing, Google has built an unprecedented body of data for training models. In addition, Google’s recent steps toward audio and video processing have enabled the company to collect the largest voice and sound data sets. Thus, Google is convenient to develop applications for machine learning and embed them in their products - for example, in the search engine and Gmail. Google is ready to further invest in this industry - at least we note that the company recently acquired the British start-up Deepmind , engaged in research in the field of artificial intelligence and trained its own bot game of go - recently it was reported in the news that this program beat the world champion of go. Google also seriously took up open source, creating the leading machine learning library Tensorflow and publishing its code.

Of course, you can create your own machine learning models, but for those who don’t have enough experience, data or time, Google also offers more and more diverse machine learning APIs that are already pre-trained for specific tasks — for example, pattern recognition and video or job search. googleLanguageR serves as a wrapper for a subgroup of such machine learning APIs that are exposed to natural language processing - Cloud Speech, Translation and Natural Language.

Since the output of all these APIs is mutually complementary, all three APIs are included in one package. For example, you can decipher someone's words spoken in Danish, translate this text into English and determine whether the author relates positively or negatively to the content (tonality analysis), and then isolate the most important concepts and objects in the text (entity analysis).

Why do you need it

Fake news

One of the reasons why we began to look closely at this topic is the “fake news” and the effect they have on the political discourse in social networks. I was interested in whether it is possible in some way to measure the extent to which the news story reinforces someone's personal bias towards the problem within an individual filter bubble. The Entity API allows you to perform a large-scale analysis of entities and tonality on the tweet material, whereby various users and news sources of interest are compared - and it determines how much they correlate with your preferences, views and your selection of “authoritative” sources.

Write your own Alexa

Another motive of an applied nature is connected with the fact that nowadays users are increasingly beginning to work with applications using voice commands - and gradually this interaction will become the main one. According to Google, today 20% of requests come through voice search . I wish I had the opportunity to formulate a request like this: “R, print this report for client X to me”. The Shiny app, recording your voice, uploads it to the API, then parses the returned text and converts it into actions. Thus, you can create your own Alexa-like infrastructure.



Amazon from Amazon. A voice activated microphone connected to the Internet. Image from www.amazon.co.uk

Translate all

Finally, I live and work in Denmark. A total of about 6 million people all over the world speak Danish, so applications that are available in English may not appear soon or not at all. The machine translation API, which appeared in 2016, was widely advertised in the news as “with a system that invented its own language ”. Indeed, the program provides a much better translation from English to Dutch than the free web version, which may soon be used in Denmark.

Work with the library

To use these APIs in the R language, you first need to perform a one-time initial setup and create a Google Project, add a credit card number and authenticate - the whole process is described in detail on the package page.

After that, enter into the system those objects R, which are going to manipulate. Thanks to rOpenSci review, it was possible to provide a convenient extension of this system - thus, large text vectors can be written to the program, which the library will then parse; if necessary, the speed can be limited. Functions also work with the tidyverse channel syntax .

Speech to text conversion

Speech Cloud Speech API is provided via the gl_speech function.

It supports many audio formats and languages, and you can either directly record an audio file that is no longer than 60 seconds in length, or you can make asynchronous requests to work with larger audio files.

Code example:

 library(googleLanguageR) my_audio <- "my_audio_file.wav" gl_speech(my_audio) # A tibble: 1 x 3 # transcript confidence words #* <chr> <dbl> <list> #1 Hello Mum 0.9227779 <data.frame [19 x 3]> 


Transfer

Translation Cloud Translation API allows you to translate text using the gl_translate function.

Since billing occurs character by character, here you can advise the following: if you work with multiple languages ​​at once, then it is advisable to check offline first if a certain language, for example, English, is already taken into account in your system. To do this, use another package rOpenSci, cld2. In this way, you can do without spending money on translating text written in the target language, in this example, in English.

 library(googleLanguageR) library(cld2) library(purrr) my_text <- c("Katten sidder pĂĄ mĂĄtten", "The cat sat on the mat") ## offline detect language via cld2 detected <- map_chr(my_text, detect_language) # [1] "DANISH" "ENGLISH" ## get non-English text translate_me <- my_text[detected != "ENGLISH"] ## translate gl_translate(translate_me) ## A tibble: 1 x 3 # translatedText detectedSourceLanguage text #* <chr> <chr> <chr> #1 The cat is sitting on the mat da Katten sidder pĂĄ mĂĄtten 


Natural language processing

The natural language processing API helps to understand the structure and meaning of text. This API is available through the gl_nlp function.

It provides several types of analysis:



All this information is useful to understand the meaning of the sentence, so this particular API of all those listed has the most extensive application possibilities. Entity analysis provides text categorization: the syntax is returned in such a way that you can program other actions based on verbs and nouns. Analysis of tonality helps to understand the emotional coloring of the text.

The following shows what output you could get:

 library(googleLanguageR) quote <- "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." nlp <- gl_nlp(quote) str(nlp) #List of 6 # $ sentences :List of 1 # ..$ :'data.frame': 1 obs. of 4 variables: # .. ..$ content : chr "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." # .. ..$ beginOffset: int 0 # .. ..$ magnitude : num 0.6 # .. ..$ score : num -0.6 # $ tokens :List of 1 # ..$ :'data.frame': 20 obs. of 17 variables: # .. ..$ content : chr [1:20] "Two" "things" "are" "infinite" ... # .. ..$ beginOffset : int [1:20] 0 4 11 15 23 25 29 38 42 48 ... # .. ..$ tag : chr [1:20] "NUM" "NOUN" "VERB" "ADJ" ... # .. ..$ aspect : chr [1:20] "ASPECT_UNKNOWN" "ASPECT_UNKNOWN" "ASPECT_UNKNOWN" "ASPECT_UNKNOWN" ... # .. ..$ case : chr [1:20] "CASE_UNKNOWN" "CASE_UNKNOWN" "CASE_UNKNOWN" "CASE_UNKNOWN" ... # .. ..$ form : chr [1:20] "FORM_UNKNOWN" "FORM_UNKNOWN" "FORM_UNKNOWN" "FORM_UNKNOWN" ... # .. ..$ gender : chr [1:20] "GENDER_UNKNOWN" "GENDER_UNKNOWN" "GENDER_UNKNOWN" "GENDER_UNKNOWN" ... # .. ..$ mood : chr [1:20] "MOOD_UNKNOWN" "MOOD_UNKNOWN" "INDICATIVE" "MOOD_UNKNOWN" ... # .. ..$ number : chr [1:20] "NUMBER_UNKNOWN" "PLURAL" "NUMBER_UNKNOWN" "NUMBER_UNKNOWN" ... # .. ..$ person : chr [1:20] "PERSON_UNKNOWN" "PERSON_UNKNOWN" "PERSON_UNKNOWN" "PERSON_UNKNOWN" ... # .. ..$ proper : chr [1:20] "PROPER_UNKNOWN" "PROPER_UNKNOWN" "PROPER_UNKNOWN" "PROPER_UNKNOWN" ... # .. ..$ reciprocity : chr [1:20] "RECIPROCITY_UNKNOWN" "RECIPROCITY_UNKNOWN" "RECIPROCITY_UNKNOWN" "RECIPROCITY_UNKNOWN" ... # .. ..$ tense : chr [1:20] "TENSE_UNKNOWN" "TENSE_UNKNOWN" "PRESENT" "TENSE_UNKNOWN" ... # .. ..$ voice : chr [1:20] "VOICE_UNKNOWN" "VOICE_UNKNOWN" "VOICE_UNKNOWN" "VOICE_UNKNOWN" ... # .. ..$ headTokenIndex: int [1:20] 1 2 2 2 2 6 2 6 9 6 ... # .. ..$ label : chr [1:20] "NUM" "NSUBJ" "ROOT" "ACOMP" ... # .. ..$ value : chr [1:20] "Two" "thing" "be" "infinite" ... # $ entities :List of 1 # ..$ :Classes 'tbl_df', 'tbl' and 'data.frame': 6 obs. of 9 variables: # .. ..$ name : chr [1:6] "human stupidity" "things" "universe" "universe" ... # .. ..$ type : chr [1:6] "OTHER" "OTHER" "OTHER" "OTHER" ... # .. ..$ salience : num [1:6] 0.1662 0.4771 0.2652 0.2652 0.0915 ... # .. ..$ mid : Factor w/ 0 levels: NA NA NA NA NA NA # .. ..$ wikipedia_url: Factor w/ 0 levels: NA NA NA NA NA NA # .. ..$ magnitude : num [1:6] NA NA NA NA NA NA # .. ..$ score : num [1:6] NA NA NA NA NA NA # .. ..$ beginOffset : int [1:6] 42 4 29 86 29 86 # .. ..$ mention_type : chr [1:6] "COMMON" "COMMON" "COMMON" "COMMON" ... # $ language : chr "en" # $ text : chr "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." # $ documentSentiment:Classes 'tbl_df', 'tbl' and 'data.frame': 1 obs. of 2 variables: # ..$ magnitude: num 0.6 # ..$ score : num -0.6 


Thanks

The package was significantly improved thanks to the help of reviewers, Neil Richardson and Julia Gustavsen , thanks to whom the documentation, output and test cases were brought into the form in which version 0.1.0 included. Thank you very much!

We hope that for the time being we are only at the beginning, and the package will help the users themselves to improve. You can therefore speak about the subject on Github - and we will try to implement your suggestions. It is very interesting to see what users can achieve, armed with such powerful tools.

Source: https://habr.com/ru/post/359312/


All Articles