<?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 Eno Compton on Medium]]></title>
        <description><![CDATA[Stories by Eno Compton on Medium]]></description>
        <link>https://medium.com/@enocom?source=rss-ccacdc8049f1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LPwdaFCt2QPPsEQS.jpeg</url>
            <title>Stories by Eno Compton on Medium</title>
            <link>https://medium.com/@enocom?source=rss-ccacdc8049f1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:58:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@enocom/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[Analyzing Japanese with Natural Language Processing and Go]]></title>
            <link>https://medium.com/@enocom/analyzing-japanese-with-natural-language-processing-and-go-64b26cb2436?source=rss-ccacdc8049f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/64b26cb2436</guid>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[translation]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Eno Compton]]></dc:creator>
            <pubDate>Tue, 19 Jun 2018 20:30:01 GMT</pubDate>
            <atom:updated>2018-06-19T21:22:06.382Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most exciting things about learning a foreign language is developing a proficiency for reading it. At first, sentences in the foreign languages start off as intimidating blocks of text, totally opaque and meaningless. With lots of practice, single words start to make sense here and there. A basic understanding of the language’s syntax transforms the process.</p><p>Let’s use the <a href="https://cloud.google.com/natural-language/">Google Cloud Natural Language API</a> to parse a long and seemingly complicated Japanese sentence and see how an understanding of the syntax helps us assemble the sentence’s meaning.</p><p>To start, here is a sentence completely unedited from a recent article in the Japanese newspaper <a href="http://www.yomiuri.co.jp/">Yomiuri Shimbun</a>.</p><pre>安倍首相は３０日、野党党首との党首討論で、トランプ米政権が検討している輸入車への高関税措置について、「同盟国の日本に高関税を課すのは極めて理解しがたく、受け入れることはできない」と述べ、反対する意向を明言した。</pre><h3><strong>Start from Translation</strong></h3><p>Since we don’t know what the text is saying, we might as well translate it first with the <a href="https://cloud.google.com/translate/">Translation API</a>. We start with what we know: English and our favorite programming language <a href="https://golang.org/">Go</a>.</p><p>The translation API is pleasantly easy to use.</p><pre>package main</pre><pre>import (<br>    &quot;context&quot;<br>    &quot;fmt&quot;<br>    &quot;log&quot;</pre><pre>    &quot;cloud.google.com/go/translate&quot;<br>    xlang &quot;golang.org/x/text/language&quot;<br>)</pre><pre>const text = &quot;安倍首相は３０日...&quot; // full text omitted.</pre><pre>func main() {<br>    ctx := context.Background()<br>    tc, err := translate.NewClient(ctx)<br>    if err != nil {<br>        log.Fatalf(&quot;failed to create translate client: %s&quot;, err)<br>    }<br>    ts, err := tc.Translate(ctx, []string{text}, xlang.English, nil)<br>    if err != nil {<br>        log.Fatalf(&quot;failed to translate text: %s&quot;, err)<br>    }<br>    if len(ts) != 1 {<br>        log.Fatalf(&quot;unexpected count. want 1, got %d&quot;, len(ts))<br>    }<br>    fmt.Printf(&quot;Translation: %s\n&quot;, ts[0].Text)<br>}</pre><p>After creating a translate client, we pass a slice of the strings we want to translate (which we’ve hard-coded) and the target language English. We add error checking to avoid any surprises and finally print out the Text property of the first Translation. This is likely the simplest use of the translate client. There are a number of additional features worth knowing about. See <a href="https://godoc.org/cloud.google.com/go/translate">the GoDoc</a> for more.</p><p>There are a number of ways to <a href="https://cloud.google.com/docs/authentication/production">authenticate against the API</a>. For the example here, I have created a private key associated with a <a href="https://cloud.google.com/iam/docs/creating-managing-service-account-keys">service account</a>, downloaded it into the same directory as the main.go file, and am invoking our Go program with an environment variable like so:</p><pre>$ GOOGLE_APPLICATION_CREDENTIALS=service-account.json go run main.go</pre><p>The translation API does a decent job, too, and provides this translation (which I have refrained from editing except for replacing the HTML character entity &amp;quot; with actual quotation marks):</p><pre>On the 30th, Prime Minister Shinzo Abe said in a party discussion with opposition party leader, “About high tariff measures on imported vehicles examined by the Trumpe administration,” It is extremely difficult to understand imposing high tariffs on Japan of allies, We can not accept it, “he declared the intention to object.</pre><p>The sentence describes Prime Minister Abe’s negative reaction to the Trump administration’s consideration of imposing high tariffs on imports. Anyone reading the news is probably aware of similar policy discussions already. So, we understand what the sentence says.</p><p>Developing an understanding of what a sentence means is only half the fun. Understanding <em>how</em> a sentence communicates its meaning is just as fascinating. So let’s use the Cloud Natural Language API to look at the how our sentence is constructed.</p><h3>A Quick Intro to Japanese Grammar</h3><p>Before we analyze syntax, let’s talk briefly about Japanese grammar.</p><p>Unlike English which uses the word order SVO, i.e., Subject-Verb-Object, Japanese uses SOV, or Subject-Object-Verb. In other words, the object comes before the verb. And yes, that means that sometimes you have to wait until the end of a sentence to know what action occurred for a given object!</p><p>Two other points are worth mentioning. First, adverbs precede verbs. Whereas English permits adverbs on either side of the verb, e.g., “they quickly ate” vs “they ate quickly,” Japanese grammar requires an adverb come before the verb. Second, any modification of a noun, e.g., “the red hat” or “the red hat I wore every day until I lost it,” comes before the noun. For example, to say “the red hat I wore every day until I lost it,” you might say this:</p><pre>naku shita made mainichi kabutteita akai bōshi</pre><pre>なくしたまで毎日かぶっていた赤い帽子</pre><p>If we ignore the details, the important thing to understand is that the word for “hat,” i.e., <em>bōshi</em> 帽子, comes at the tail end after the modifier (“that I wore every day until I lost it”).</p><p>If Japanese grammar seems endlessly fascinating (it is!), a great place to learn lots more is <a href="http://www.guidetojapanese.org/learn/grammar">Tae Kim’s Guide to Learning Japanese</a>.</p><h3>Analyzing the Syntax</h3><p>Now we are ready to write some code to analyze the syntax of our sentence.</p><pre>package main</pre><pre>import (<br>    &quot;context&quot;<br>    &quot;fmt&quot;<br>    &quot;log&quot;</pre><pre>    language &quot;cloud.google.com/<a href="https://goto.google.com/language">go/language/apiv1</a>&quot;<br>    langpb &quot;google.golang.org/genproto/googleapis/cloud/language/v1&quot;<br>)</pre><pre>const text = &quot;安倍首相は３０日...&quot; // full text omitted.</pre><pre>func main() {</pre><pre>    ctx := context.Background()</pre><pre>    lc, err := language.NewClient(ctx)</pre><pre>    if err != nil {</pre><pre>        log.Fatalf(&quot;failed to create language client: %s&quot;, err)</pre><pre>    }</pre><pre>    resp, err := lc.AnalyzeSyntax(ctx, buildSyntaxRequest(text))</pre><pre>    if err != nil {</pre><pre>        log.Fatalf(&quot;failed to analyze syntax: %s&quot;, err)</pre><pre>    }</pre><pre>    for _, t := range resp.Tokens {</pre><pre>        fmt.Printf(&quot;%s\t\t=&gt; %s\n&quot;, t.Text.Content, t.PartOfSpeech)</pre><pre>    }</pre><pre>}</pre><p>As with the translate client above, we create a context.Context and then create a client for the Cloud Natural Language API. Again, we will invoke this program with the GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to our service account private key for authentication. There are a number of interesting features in the language package. So definitely read through <a href="https://godoc.org/cloud.google.com/go/language/apiv1">the GoDoc</a>. To start, we will use only <a href="https://godoc.org/cloud.google.com/go/language/apiv1#Client.AnalyzeSyntax">AnalyzeSyntax</a>.</p><p>Because the request type is a little verbose, I have extracted its creation into a separate function called buildSyntaxRequest. That code looks like this:</p><pre>func buildSyntaxRequest(text string) *langpb.AnalyzeSyntaxRequest {</pre><pre>    return &amp;langpb.AnalyzeSyntaxRequest{</pre><pre>        Document: &amp;langpb.Document{</pre><pre>        Type: langpb.Document_PLAIN_TEXT,</pre><pre>            Source: &amp;langpb.Document_Content{</pre><pre>                Content: text,</pre><pre>            },</pre><pre>        },</pre><pre>        EncodingType: langpb.EncodingType_UTF8,</pre><pre>    }</pre><pre>}</pre><p>For our purposes, we care only about the text in the request. Nonetheless, there are a number of additional supported features such that it’s worth looking at <a href="https://godoc.org/google.golang.org/genproto/googleapis/cloud/language/v1#AnalyzeSyntaxRequest">the GoDoc</a> for details.</p><h3>First, find the subject of the sentence</h3><p>The response from AnalyzeSyntax has a number of <a href="https://godoc.org/google.golang.org/genproto/googleapis/cloud/language/v1#Token">tokens</a>, each of which includes a <a href="https://godoc.org/google.golang.org/genproto/googleapis/cloud/language/v1#PartOfSpeech">part of speech</a>. Looking at just the tail end of the printed response, we have:</p><pre>反対      =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>する      =&gt; tag:VERB form:ADNOMIAL proper:NOT_PROPER</pre><pre>意向      =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>を        =&gt; tag:PRT case:ACCUSATIVE proper:NOT_PROPER</pre><pre>明言      =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>し        =&gt; tag:VERB form:GERUND proper:NOT_PROPER</pre><pre>た        =&gt; tag:VERB form:FINAL_ENDING proper:NOT_PROPER tense:PAST</pre><pre>。        =&gt; tag:PUNCT proper:NOT_PROPER</pre><p>Even when we’re just printing the part of speech, we get lots of information here! In particular, we have tags for nouns, verbs, particles (i.e., PRT), and punctuation (i.e., PUNCT). The full list of tags is <a href="https://cloud.google.com/natural-language/docs/reference/rpc/google.cloud.language.v1beta2#google.cloud.language.v1beta2.PartOfSpeech.Tag">documented here</a>.</p><p>Let’s take another look at our sentence again.</p><pre>安倍首相は３０日、野党党首との党首討論で、トランプ米政権が検討している輸入車への高関税措置について、「同盟国の日本に高関税を課すのは極めて理解しがたく、受け入れることはできない」と述べ、反対する意向を明言した。</pre><p>Somewhere in there is a subject, an object, and a verb. Aside from telling us the parts of speech, the API has parsed word boundaries for us, itself a difficult task for a student of Japanese. So, if we look at the head of the response, we see a proper noun followed by a noun:</p><pre>安倍        =&gt; tag:NOUN proper:PROPER</pre><pre>首相        =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>は          =&gt; tag:PRT proper:NOT_PROPER</pre><pre>３０        =&gt; tag:NUM proper:NOT_PROPER</pre><pre>日          =&gt; tag:AFFIX proper:NOT_PROPER</pre><pre>、          =&gt; tag:PUNCT proper:NOT_PROPER</pre><p>Knowing that modifiers precede the nouns they modify, we might guess that the first two nouns are “Prime Minister Abe,” or following the words as they appear in the original, “Abe Prime Minister.” And we would be right! It doesn’t hurt to use <a href="https://translate.google.com/">Google Translate</a> to double check such things, too. We’ve found our subject!</p><h3>Now, let’s find the verb</h3><p>To make the task easier, let’s eliminate what we know cannot be the verb. We know adverbs come before verbs. Can we eliminate any adverbs or adverbial phrases? Yes, we can!</p><p>Looking at the API response, we see a couple of adverbial particles that precede a punctuation mark:</p><pre>野党        =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>党首        =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>と          =&gt; tag:PRT case:ADVERBIAL proper:NOT_PROPER</pre><pre>の          =&gt; tag:PRT case:GENITIVE proper:NOT_PROPER</pre><pre>党首        =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>討論        =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>で          =&gt; tag:PRT case:ADVERBIAL proper:NOT_PROPER // &lt;---</pre><pre>、          =&gt; tag:PUNCT proper:NOT_PROPER</pre><p>And:</p><pre>トランプ        =&gt; tag:NOUN proper:PROPER</pre><pre>米             =&gt; tag:NOUN proper:PROPER</pre><pre>政権           =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>が            =&gt; tag:PRT case:NOMINATIVE proper:NOT_PROPER</pre><pre>検討           =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>し             =&gt; tag:VERB form:GERUND proper:NOT_PROPER</pre><pre>て             =&gt; tag:PRT proper:NOT_PROPER</pre><pre>いる           =&gt; tag:VERB form:ADNOMIAL proper:NOT_PROPER</pre><pre>輸入           =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>車             =&gt; tag:AFFIX proper:NOT_PROPER</pre><pre>へ             =&gt; tag:PRT case:ADVERBIAL proper:NOT_PROPER</pre><pre>の             =&gt; tag:PRT case:GENITIVE proper:NOT_PROPER</pre><pre>高関税          =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>措置            =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>について         =&gt; tag:PRT case:ADVERBIAL proper:NOT_PROPER // &lt;---</pre><pre>、              =&gt; tag:PUNCT proper:NOT_PROPER</pre><p>Let’s remove these two phrases since they cannot be the verb we are looking for. If we know what Japanese quote marks look like, i.e., 「 and 」, we may ignore the quoted statement, as well.</p><pre>安倍首相は３０日、... と述べ、反対する意向を明言した。</pre><p>So what was once a long sentence is now reduced down to “Prime Minister Abe… something, something, something.”</p><p>We see that the character following “30” is an “affix,” which is a grammatical term for something that attaches to another word. Both a prefix and a suffix are types of affixes. Since we know this piece of news describes an event which occurred on the “30th,” we can probably ignore that part of the sentence. After all, it’s not the verb.</p><p>Since it does not come at the end of the sentence, we may also eliminate <a href="https://en.wikipedia.org/wiki/Quotative#Japanese">the word which precedes a comma</a> and seems to mark the end of the quoted text.</p><pre>と              =&gt; tag:PRT case:COMPLEMENTIVE proper:NOT_PROPER</pre><pre>述べ            =&gt; tag:VERB form:GERUND proper:NOT_PROPER</pre><p>That leaves us with:</p><pre>安倍首相は ... 反対する意向を明言した。</pre><p>Now, we’re getting closer to finding that verb. Let’s look at the very end of the API response:</p><pre>意向      =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>を        =&gt; tag:PRT case:ACCUSATIVE proper:NOT_PROPER</pre><pre>明言      =&gt; tag:NOUN proper:NOT_PROPER</pre><pre>し        =&gt; tag:VERB form:GERUND proper:NOT_PROPER</pre><pre>た        =&gt; tag:VERB form:FINAL_ENDING proper:NOT_PROPER tense:PAST</pre><p>Identifying the accusative particle <em>o</em> を, i.e., the particle which marks the direct object of the verb, is especially helpful. Before the particle comes the object, <em>ishi </em>意向, which <a href="https://translate.google.com/#auto/en/%E6%84%8F%E5%90%91">Google Translate</a> tells us means “intention.” And after it comes the verb <em>meigen shita </em>明言した, which means “made a statement.”</p><p>And now we have the subject, object, and verb, and have a basic understanding of how the meaning is assembled! “Prime Minister Abe made a statement of intention.”</p><p>That may seem like a lot of work for a trifling result. If it’s any consolation, know that Japanese is <a href="http://www.businessinsider.com/the-hardest-languages-to-learn-2014-5">one of the hardest languages</a> for English speakers to learn.</p><h3><strong>Wrapping Up</strong></h3><p>While it’s probably not the place to start for an early stage language learner, the Cloud Natural Language API provides some powerful tools for understanding Japanese, Chinese, and Korean to name just a few of <a href="https://cloud.google.com/natural-language/docs/languages">the supported languages</a>. Beyond just syntax, the API supports sentiment analysis (“what is the sentiment of the words?”), entity analysis (“what proper nouns are found?”), and even entity sentiment analysis (“what is the sentiment for each of the proper nouns?”). See <a href="https://cloud.google.com/natural-language/docs/how-to">here</a> for more details.</p><p>In the case of Japanese, parsing a sentence into words and its parts of speech can be tremendously difficult for a student. After all, unlike English, Japanese does not need spaces to indicate word boundaries. The API does the hard work of identifying word boundaries for us. Granted, for the sentence we analyzed, there is a lot more meaning and nuance that we skipped over. Nonetheless, with a little understanding of Japanese grammar and lots of help from the API, we managed to identify the sentence’s core grammatical structure, its meaning, and how it conveys that meaning. That’s pretty exciting!</p><p>Finally, the program we wrote in this post is more of a one-off invocation of the API to demonstrate how easy the API is to use and how useful it can be. I hope a reader will be inspired to build more sophisticated and involved applications, and have some fun while doing it!</p><h3>Further Reading</h3><ul><li><a href="https://github.com/GoogleCloudPlatform/golang-samples/tree/master/language">Golang Samples</a> for Cloud Natural Language API</li><li><a href="https://cloud.google.com/natural-language/docs/reference/libraries?authuser=1">Natural Language API Client Libraries</a></li><li><a href="https://cloud.google.com/natural-language/docs/quickstart-client-libraries#client-libraries-install-go">Quickstart: Using Client Libraries</a></li><li><a href="https://cloud.google.com/natural-language/docs/basics?authuser=1">Natural Language API Basics</a></li><li><a href="https://medium.com/google-cloud/transcribe-japanese-using-go-and-machine-learning-apis-3ccc74f6c800">Transcribe Japanese using Go and Machine Learning APIs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64b26cb2436" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What a Go developer needs to know about Google Cloud Platform]]></title>
            <link>https://medium.com/google-cloud/what-a-go-developer-needs-to-know-about-google-cloud-platform-e046c9e11abf?source=rss-ccacdc8049f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e046c9e11abf</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Eno Compton]]></dc:creator>
            <pubDate>Mon, 11 Jun 2018 16:42:16 GMT</pubDate>
            <atom:updated>2018-10-16T19:54:39.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*ljrmSJj5Ca2MJk-1l5Jz7A.jpeg" /></figure><p><strong>UPDATE (Oct. 16, 2018)</strong>: A lot has changed since I wrote this post. In addition to GCE and GKE (see below), App Engine has <a href="https://blog.golang.org/appengine-go111">improved significantly</a> and support for Go on Cloud Functions has been announced (private alpha at the time of writing).</p><p>For running Go code on <a href="https://cloud.google.com/">Google Cloud Platform</a> (GCP), there are two great choices for portable code: <a href="https://cloud.google.com/compute/">Google Compute Engine</a> (GCE), and <a href="https://cloud.google.com/kubernetes-engine/">Google Kubernetes Engine</a> (GKE). Let’s look at each in depth as well as a number of additional options for Go developers.</p><h3>Two Great Choices: GCE and GKE</h3><p>Billed as Google’s offering for “scalable, high-performance virtual machines,” GCE is a straightforward product with some niceties. See the <a href="https://cloud.google.com/go/docs/tutorials/bookshelf-on-compute-engine">quickstart here</a>. It comes with the usual costs and benefits. As a nice feature, GCE does <a href="https://cloud.google.com/compute/docs/instances/live-migration">live migrations</a>, which means Google performs security updates for you without any impact to a virtual machine’s (VM) workload. Needless to say, it is the user’s responsibility to create machines and networks in whatever configuration necessary. GCE comes with the nice feature of allowing users to <a href="https://www.youtube.com/watch?v=wKiW1nufh1k">create a VM with a container</a> in addition to offering a <a href="https://cloud.google.com/compute/docs/images">wide range of host OS’s</a>.</p><p>GKE is almost certainly the more exciting offering from a Go developer’s perspective. See the <a href="https://cloud.google.com/go/docs/tutorials/bookshelf-on-kubernetes-engine">quickstart here</a>. You get all the power of Kubernetes, without the <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way">difficulty of running it the hard way</a> on raw compute instances. For smaller systems, GKE might be overkill, but it certainly provides a great story for how you will scale your system as it grows.</p><p>Which of these two options you pick depends entirely on what your system looks like, what kind of requirements you have for uptime and scalability, and so on. One reason to use GCE is that it’s significantly cheaper for a small service, whereas a GKE cluster with a load balancer ingress can be much more pricey. For some, it might be best to build a Go binary and run it on GCE using simple tools like <a href="http://supervisord.org/">supervisord</a> and <a href="https://linux.die.net/man/1/scp">scp</a>. Alternatively, it’s fairly easy to create a Kubernetes cluster and move the deployment over to GKE. For others, starting with GKE might be the right choice.</p><h3>Thoughts on App Engine</h3><p>Aside from GCE and GKE, Google Cloud does offer a third choice to Go developers: <a href="https://cloud.google.com/appengine/">App Engine</a>. If you accept the definition that <a href="https://www.youtube.com/watch?v=tISy7EJQPzI&amp;t=8m17s">software engineering is programming integrated over time</a>, you will likely find it hard to see App Engine as a reasonable choice. It certainly has significant strengths, e.g., “scaling from zero to planet scale”, but it also suffers from some major weaknesses.</p><p>App Engine consists of <a href="https://cloud.google.com/appengine/docs/go/">two environments</a>: Standard and Flexible. The Standard environment breaks with the <a href="https://12factor.net/">Twelve Factor App</a> design principle of “maximum portability between execution environments” and makes requirements of <a href="https://github.com/GoogleCloudPlatform/golang-samples/blob/f08cfc98f4c8e537114c8b1d02d7c32b235701bd/appengine/helloworld/hello.go#L16">how you write your main function</a>. Granted, there are reasonable ways <a href="https://blog.golang.org/the-app-engine-sdk-and-workspaces-gopath">to deal with this</a>. The Standard environment also tends to run one minor version behind the newest Go release. For instance, Go 1.10 was released February 16, 2018. Meanwhile, at the time of writing, the newest version supported by App Engine is Go 1.9. Since <a href="https://blog.golang.org/go1.6">February 16, 2016</a>, Go has supported <a href="https://golang.org/cmd/go/#hdr-Vendor_Directories">vendoring one’s dependencies</a>. More than two years later, App Engine still does not support vendoring. One can at least use the old approach of checking-in an entire GOPATH per project, a tedious and cumbersome practice otherwise abandoned by the community given the support for vendoring.</p><p>While the Standard environment makes some onerous demands on a user’s code, the Flexible environment is closer to the Twelve Factor PaaS many people are used to. The Flexible environment also supports deploying a containizered app. The only problem is that deploys to the Flexible environment are <a href="https://stackoverflow.com/questions/37683120/gcloud-preview-app-deploy-process-takes-8-minutes-is-this-normal">painfully</a> <a href="https://groups.google.com/forum/#!topic/google-appengine/hZMEkmmObDU">slow</a>. For example, deploying the <a href="https://github.com/GoogleCloudPlatform/golang-samples/blob/master/appengine_flexible/helloworld/helloworld.go">Hello World sample</a> took 12 minutes on a fresh deploy and 11 minutes on a second deploy with no changes. For me, a slow deploy defeats the purpose of a PaaS.</p><p>If your use case <a href="https://open.nytimes.com/moving-the-new-york-times-games-platform-to-google-app-engine-e9337f2c9444">falls squarely within what makes App Engine powerful</a> or you’re looking to deploy something simple like a <a href="https://github.com/rsc/swtch/tree/master/app/rsc-io">GoDoc redirect</a> for <a href="https://github.com/googleCloudPlatform/govanityurls">a vanity import path</a>, it can be a great choice. Overall, though, App Engine requires you to write non-portable code or to suffer slow deploys. For some, these might be justifiable shortcomings. For many, they will likely be deal-breakers.</p><h3>Go support on Google Cloud Functions</h3><p>Go is currently not supported on <a href="https://cloud.google.com/functions/">Google Cloud Functions</a> (GCF). I am certain all Go developers hope this will change soon. Meanwhile, there is an <a href="https://github.com/GoogleCloudPlatform/cloud-functions-go">unofficial (and unsupported) native Go runtime</a> for people who might like to experiment. Alternatively, there are ways to run Go functions on top of Kubernetes. For example, see <a href="https://www.openfaas.com/">OpenFaaS</a> or <a href="https://github.com/projectriff/riff">riff</a>.</p><p>Once Go receives proper support on GCF, the entire story here will likely change. In fact, for the majority of request/response workloads, I imagine GCF will be the best place for developers to start deploying Go code.</p><h3>Some Helpful Tools Worth Knowing About</h3><p>Although not specific to Go per se, a developer will be happy to know about <a href="https://cloud.google.com/source-repositories/">Cloud Source Repositories</a>, <a href="https://cloud.google.com/container-registry/">Container Registry</a>, and <a href="https://cloud.google.com/container-builder/">Container Builder</a>. There are a number of <a href="https://cloud.google.com/products/tools/">other developer tools</a>, as well, but the three named here are especially useful. When deploying applications on GCP, it’s nice to consolidate source code, Docker images, and the steps to build, test, and deploy in the same place. Container Builder is especially nice given it’s support for <a href="https://cloud.google.com/container-builder/docs/configuring-builds/build-test-deploy-artifacts">building, testing, and deploying artifacts</a>.</p><p>Finally, there are countless useful APIs available with Go bindings thanks to the <a href="https://github.com/googlecloudplatform/google-cloud-go">Google Cloud Client Libraries for Go</a>. Supported APIs include things like:</p><ul><li><a href="https://cloud.google.com/pubsub/">Cloud Pub/Sub</a>,</li><li><a href="https://cloud.google.com/natural-language/">Natural Language Processing</a>,</li><li><a href="https://cloud.google.com/bigquery/">BigQuery</a>,</li><li><a href="https://cloud.google.com/spanner/">Cloud Spanner</a>,</li><li><a href="https://cloud.google.com/datastore/">Cloud Datastore</a>,</li><li>and so on.</li></ul><p>See the <a href="https://godoc.org/cloud.google.com/go">GoDoc for details</a>. And, it’s helpful to read <a href="https://medium.com/google-cloud/gcp-products-described-in-4-words-or-less-f3056550e595">GCP products described in 4 words or less</a>, simply because there are so many offerings. Provided one has <a href="https://cloud.google.com/docs/authentication/production">handled authentication</a>, there are no special steps necessary to call the various APIs from GCE. In the case of GKE, one may use GCP APIs through a <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/add-on/service-broker">service broker</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*eIMbmSVLP69ZJA4-GGD1MA.jpeg" /></figure><h3>Key Takeaways</h3><p>When deploying Go code on GCP, GKE is the exceptional option. For users who prefer working with VMs directly, GCE is a powerful and comparatively cheap option. While App Engine for Go offers a mix of strengths and weaknesses, most users probably won’t spend much time considering it and instead look at GKE given the justifiable excitement over Kubernetes. Finally, given GCP’s strong <a href="https://cloud.google.com/products/machine-learning/">machine learning APIs</a>, easily accessible through the Go client library, GCP is worth considering when evaluating IaaS options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e046c9e11abf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/what-a-go-developer-needs-to-know-about-google-cloud-platform-e046c9e11abf">What a Go developer needs to know about Google Cloud Platform</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transcribe Japanese using Go and Machine Learning APIs]]></title>
            <link>https://medium.com/google-cloud/transcribe-japanese-using-go-and-machine-learning-apis-3ccc74f6c800?source=rss-ccacdc8049f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ccc74f6c800</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[japanese]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Eno Compton]]></dc:creator>
            <pubDate>Mon, 14 May 2018 21:15:16 GMT</pubDate>
            <atom:updated>2018-05-15T20:30:14.013Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the hardest skills to develop when learning Japanese is solid listening comprehension. A great way to practice is to listen to the news in Japanese. For that, there’s nothing better than the NHK Radio News, or <a href="http://www.nhk.or.jp/radionews/"><em>rajio nyūsu</em> ラジオニュース</a>. The Japanese in this program adheres to the crystal clear standards of NHK and the site allows listeners to adjust the speed of the audio between regular, slow, and fast.</p><p>As much as adjusting the playback speed may help, a language learner is bound to encounter unfamiliar words. While it is an equally important skill to identify unknown words to lookup on one’s own, a transcription of the audio makes a big difference in the speed of learning. The only problem is that NHK does not provide transcriptions. So, let’s create them ourselves!</p><p>To do that, we’re going to use Google Cloud Platform’s <a href="https://cloud.google.com/speech-to-text/">Speech-to-Text API</a> and its <a href="https://github.com/googlecloudplatform/google-cloud-go">Go API client</a>. There are three steps.</p><h3>Download an audio sample</h3><p>The Speech-to-Text API makes a distinction between short and long audio files with a runtime below or above about one minute. If the audio file is longer than a minute, we need to use the asynchronous API for <a href="https://godoc.org/cloud.google.com/go/speech/apiv1#Client.LongRunningRecognize">long running recognition</a>. For this example, we are going to use the <a href="https://godoc.org/cloud.google.com/go/speech/apiv1#Client.Recognize">synchronous API</a>. The API client also <a href="https://godoc.org/google.golang.org/genproto/googleapis/cloud/speech/v1#RecognitionAudio_Uri">supports remote URIs</a>, but to keep things simple we will upload an audio sample ourselves.</p><p>The easiest way to get a copy of an audio file is to download it directly from the <a href="http://www.nhk.or.jp/radionews/">radio program’s homepage</a>. Note, a link to download the episode isn’t visible on the page. Instead, you will need to use your browser’s developer tools to inspect the audio player’s HTML after starting a particular episode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XD6afHPrhRmn2Me0hZxYBQ.png" /></figure><p>Then, find the corresponding audio element whose src attribute points to an MP3 file of the episode. Download that file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1fTx0KLUInxR-CF7x4CBMw.png" /></figure><h3>Process the sample for best results</h3><p>Now that we have a Japanese audio sample, we need to do some minor processing to ensure best results. As the <a href="https://cloud.google.com/speech-to-text/docs/best-practices">documentation on best practices</a> notes, for optimal results we need to use a FLAC encoding and a sampling rate of 16,000 Hz. In addition, I have found it helps to submit samples mixed to mono rather than to stereo. The <a href="https://www.ffmpeg.org/">ffmpeg</a> CLI is invaluable for this kind of work.</p><p>First, we can view the various bits of metadata about a file with the following command:</p><pre>ffprobe -v error -show_format -show_streams input.mp3</pre><p>Next, we need to convert from MP3 to FLAC:</p><pre>ffmpeg -i input.mp3 output.flac</pre><p>To keep our sample under a minute, we will trim the audio sample to a runtime of thirty seconds. For your particular clip, you will need to find a good start time and a good stop time. In the clip I am using, I want to start at 10 seconds and stop 30 seconds later:</p><pre>ffmpeg -ss 10 -t 30 input.flac output.flac</pre><p>The broadcast episodes are already mono, but in case you want to remix a stereo sample to mono, the command is also simple:</p><pre>ffmpeg -i input.flac -ac 1 output-mono.flac</pre><p>Now with the processing done, we are ready to write some code and submit the sample to the Speech-to-Text API.</p><h3>Send the sample to the Speech-to-Text API</h3><p>Let’s write some <a href="https://golang.org/">Go</a>.</p><p>First, we will download a copy of the client libraries for Go:</p><pre>go get -u cloud.google.com/go/...</pre><p>Then, in a directory within our GOPATH, we create a main.go with the following code. We first create a new speech client.</p><p>Note, in the code below, we make no explicit reference to API credentials. Instead, the client will read the GOOGLE_APPLICATION_CREDENTIALS variable from the environment to locate the service-account.json file which provides authentication information. For more details on the various ways to set up authentication, see the <a href="https://cloud.google.com/docs/authentication/production">documentation</a>. Also, there are a number of helpful examples in <a href="https://godoc.org/cloud.google.com/go#example-package--ApplicationDefaultCredentials">GoDoc</a>.</p><pre>// ~/go/src/github.com/gobuildit/gobuildit/transcribe/main.go</pre><pre>package main</pre><pre>import (</pre><pre>    &quot;fmt&quot;</pre><pre>    &quot;io/ioutil&quot;</pre><pre>    &quot;log&quot;</pre><pre>    &quot;golang.org/x/net/context&quot;</pre><pre>    speech &quot;cloud.google.com/go/speech/apiv1&quot;</pre><pre>    speechpb &quot;google.golang.org/genproto/googleapis/cloud/speech/v1&quot;</pre><pre>)</pre><pre>func main() {</pre><pre>    ctx := context.Background()</pre><pre>    client, err := speech.NewClient(ctx)</pre><pre>    if err != nil {</pre><pre>        log.Fatalf(&quot;failed to create client: %v&quot;, err)</pre><pre>    }</pre><pre>    // ...</pre><pre>}</pre><p>Next, we read the audio sample into memory:</p><pre>// ...</pre><pre>data, err := ioutil.ReadFile(&quot;nhk-radio-news.flac&quot;)</pre><pre>if err != nil {</pre><pre>    log.Fatalf(&quot;failed to read file: %v&quot;, err)</pre><pre>}</pre><pre>// ...</pre><p>And now, we are ready to create the API request and send it along:</p><pre>// ...</pre><pre>resp, err := client.Recognize(ctx, &amp;speechpb.RecognizeRequest{</pre><pre>    Config: &amp;speechpb.RecognitionConfig{</pre><pre>        Encoding:        speechpb.RecognitionConfig_FLAC,</pre><pre>        SampleRateHertz: int32(16000),</pre><pre>        LanguageCode:    &quot;ja-JP&quot;,</pre><pre>    }, </pre><pre>    Audio: &amp;speechpb.RecognitionAudio{</pre><pre>        AudioSource: &amp;speechpb.RecognitionAudio_Content{<br>            Content: data,<br>        },</pre><pre>    },</pre><pre>})</pre><pre>if err != nil {</pre><pre>    log.Fatalf(&quot;failed to recognize: %v&quot;, err)</pre><pre>}</pre><pre>// ...</pre><p>In the code above, we configure the RecognizeRequest with details about the audio sample. There are a <a href="https://godoc.org/google.golang.org/genproto/googleapis/cloud/speech/v1#RecognitionConfig">number of additional properties</a> available worth knowing about that we don’t use here.</p><p>Finally, provided our request succeeds, we print out the results:</p><pre>// ...</pre><pre>for _, result := range resp.Results {</pre><pre>    for _, alt := range result.Alternatives {</pre><pre>        fmt.Printf(&quot;\&quot;%v\&quot; (confidence=%3f)\n&quot;, alt.Transcript, alt.Confidence)</pre><pre>    }</pre><pre>}</pre><pre>// end of main</pre><p>It’s possible the results will include a number of Alternatives and so we will print them all as well as the Confidence value, which indicates the API’s estimate at how likely the transcript is correct. Note, the Alternatives are ordered by accuracy, with those of highest confidence coming first. See the <a href="https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize">docs here</a> for more.</p><p>Now, we’re ready to transcribe our audio sample. Note, the following command may take a moment to complete.</p><pre>$ GOOGLE_APPLICATION_CREDENTIALS=service-account.json go run main.go</pre><pre>ではニュースです # “And now for the news.” (full transcription result omitted)</pre><p>And look at that! We have a transcript of our audio sample!</p><h3>Possible Next Steps</h3><p>Given how easy it is to take audio and convert it into a transcript, one could easily imagine extending this code into a <a href="https://github.com/GoogleCloudPlatform/golang-samples/tree/master/speech/livecaption">realtime captioning service</a>. Given a steady input of audio, perhaps split into sub-minute spans, we could submit those samples to an automated processing step. From there, the processed audio could be sent to the speech-to-text API to produce captions.</p><p>Of course, it’s almost certainly not a match for already existing systems, but as machine learning continues to improves in accuracy and speed, it’s also not hard to see how systems like live captioning become that much easier to create. For now, though, we have a powerful tool to aid the language learning process.</p><h4>Further Reading</h4><ul><li><a href="https://cloud.google.com/speech-to-text/docs/">Cloud Speech-to-Text Documentation</a></li><li><a href="https://github.com/GoogleCloudPlatform/golang-samples/tree/master/speech">Sample applications in Go</a></li><li><a href="https://www.youtube.com/watch?v=gVz9jKE_9iU">Intro to machine learning on Google Cloud Platform</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ccc74f6c800" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/transcribe-japanese-using-go-and-machine-learning-apis-3ccc74f6c800">Transcribe Japanese using Go and Machine Learning APIs</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a Container on GCP the Easy Way]]></title>
            <link>https://medium.com/@enocom/deploy-a-container-on-gcp-the-easy-way-4e5fd64aca76?source=rss-ccacdc8049f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5fd64aca76</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Eno Compton]]></dc:creator>
            <pubDate>Wed, 25 Apr 2018 21:41:40 GMT</pubDate>
            <atom:updated>2018-04-25T21:56:03.916Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s deploy a container on <a href="https://cloud.google.com/">Google Cloud Platform</a>. We’ll do it in a way that requires no preexisting infrastructure (e.g., a Kubernetes cluster on GKE, a VM running Docker, etc.). All we will need is an existing account with an associated project as well as an <a href="https://docs.docker.com/install/">installation of Docker</a>.</p><p>Running a single container is a great use case for things like deploying an HTTP server or a Twitter bot, doing some video processing, or just trying out the platform without much overhead.</p><p>We are going to deploy a small HTTP server that responds to JSON requests with random <a href="https://go-proverbs.github.io/">Go proverbs</a>. All the code including the Dockerfile can be found <a href="https://github.com/gobuildit/gobuildit/tree/master/proverb">here</a>.</p><h3>Add Google Container Registry to Docker</h3><p>First, we will configure Docker to support pushing to the <a href="https://cloud.google.com/container-registry/">Google Container Registry</a>, otherwise known as GCR. If you don’t have gcloud installed, see <a href="https://cloud.google.com/sdk/">here</a>.</p><pre>gcloud auth configure-docker</pre><h3>Push the Image</h3><p>Now, assuming we have already built the container image (named gcr.io/enocom-dev/proverb), we need to push that image to GCR. For those following along on the command line, you will need to swap out enocom-dev with your own project ID.</p><pre>docker push gcr.io/enocom-dev/proverb:latest</pre><h3>Allow Ingress Traffic on Port 80</h3><p>Since we will be running an HTTP server within our container, we have one more thing to do before deploying. We need to configure a firewall rule to allow incoming HTTP traffic.</p><pre>gcloud compute firewall-rules create allow-http \<br>    -target-tags http-server \<br>    -allow tcp:80</pre><h3>Deploy the Container</h3><p>Now that we have our image stored in GCR and we have configured a firewall rule, we are ready to deploy the container. Again, note you will need to swap out the project ID identifying the container image.</p><pre>gcloud beta compute instances \<br>    create-with-container proverb-vm \<br>    -tags http-server \ <br>    -container-image gcr.io/enocom-dev/proverb:latest</pre><p>Users of Docker might noticed the absence of any port mappings in the deploy command. By default, the container is started using the host network. In the case here, that means port 80 in the container will map to port 80 on the host VM.</p><h3>Send a Request to the Deployed Container</h3><p>Now with the container deployed, we are ready to send a request to our HTTP server:</p><pre># Note: your IP address will be different<br>curl -i 35.184.67.112/proverbs/random</pre><p>Provided all goes well, we will get a response that looks something like:</p><pre>HTTP/1.1 200 OK<br>Content-Type: application/json; charset=utf-8<br>Date: Wed, 25 Apr 2018 21:25:18 GMT<br>Content-Length: 100</pre><pre>{&quot;link&quot;:&quot;https://github.com/golang/go/wiki/CodeReviewComments#dont-panic&quot;,&quot;content&quot;:&quot;Don&#39;t panic.&quot;}</pre><p>And with that we have a container running on Google Cloud Platform.</p><h3>Teardown</h3><p>Teardown is also easy. Here’s what you need to remove all created resources:</p><pre># Remove any references to gcr.io under the<br># credHelpers key in ~/.docker/config.json</pre><pre># Delete the image from GCR<br>gcloud -q container images delete gcr.io/PROJECT_ID/proverb:latest</pre><pre># Delete the created VM<br>gcloud -q compute instances delete proverb-vm</pre><pre># Delete the firewall rule<br>gcloud -q compute firewall-rules delete allow-http</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5fd64aca76" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>