github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/examples/inference/multi_language_inference/README.md (about) 1 <!-- 2 Licensed to the Apache Software Foundation (ASF) under one 3 or more contributor license agreements. See the NOTICE file 4 distributed with this work for additional information 5 regarding copyright ownership. The ASF licenses this file 6 to you under the Apache License, Version 2.0 (the 7 "License"); you may not use this file except in compliance 8 with the License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, 13 software distributed under the License is distributed on an 14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 KIND, either express or implied. See the License for the 16 specific language governing permissions and limitations 17 under the License. 18 --> 19 For a detailed explanation of this inference example, visit the [documentation](https://beam.apache.org/documentation/ml/multi-language-inference/). 20 ## Set up Python virtual environment 21 Make sure to set up a virtual environment for Python with all the required dependencies. 22 More details on how to do this can be found [here](https://beam.apache.org/get-started/quickstart-py/#set-up-your-environment). 23 ## Running the Java pipeline 24 Make sure you have Maven installed and added to PATH. Also make sure that JAVA_HOME 25 points to the correct Java version. 26 27 First we need to download the Maven archetype for Beam. Run the following command: 28 29 ```bash 30 export BEAM_VERSION=<Beam version> 31 32 mvn archetype:generate \ 33 -DarchetypeGroupId=org.apache.beam \ 34 -DarchetypeArtifactId=beam-sdks-java-maven-archetypes-examples \ 35 -DarchetypeVersion=$BEAM_VERSION \ 36 -DgroupId=org.example \ 37 -DartifactId=multi-language-beam \ 38 -Dversion="0.1" \ 39 -Dpackage=org.apache.beam.examples \ 40 -DinteractiveMode=false 41 ``` 42 This will set up all the required dependencies for the Java pipeline. Next the pipeline needs to be 43 implemented. The logic of this pipeline is written in the `MultiLangRunInference.java` file. After that, 44 run the following command to start the Java pipeline: 45 46 ```bash 47 export GCP_PROJECT=<your gcp project> 48 export GCP_BUCKET=<your gcp bucker> 49 export GCP_REGION=<region of bucket> 50 export MODEL_NAME=bert-base-uncased 51 export LOCAL_PACKAGE=<path to tarball> 52 53 cd last_word_prediction 54 mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.MultiLangRunInference \ 55 -Dexec.args="--runner=DataflowRunner \ 56 --project=$GCP_PROJECT\ 57 --region=$GCP_REGION \ 58 --gcpTempLocation=gs://$GCP_BUCKET/temp/ \ 59 --inputFile=gs://$GCP_BUCKET/input/imdb_reviews.csv \ 60 --outputFile=gs://$GCP_BUCKET/output/ouput.txt \ 61 --modelPath=gs://$GCP_BUCKET/input/bert-model/bert-base-uncased.pth \ 62 --modelName=$MODEL_NAME \ 63 --localPackage=$LOCAL_PACKAGE" \ 64 -Pdataflow-runner 65 ``` 66 67 The `localPackage` argument is the path to a locally available package compiled as a tarball. This package must be created by the user and contain the python transforms used in the pipeline. 68 Make sure to run this in the [`last_word_prediction`](https://github.com/apache/beam/tree/master/sdks/python/apache_beam/examples/inference/multi_language_inference/last_word_prediction) directory. This will start the Java pipeline. 69