├── .gitignore ├── README.adoc ├── data ├── text.txt ├── text2.txt └── text3.txt ├── rest_server_template.dockerfile └── training ├── models └── placeholder.txt ├── training_files └── placeholder.txt └── training_template.dockerfile /.gitignore: -------------------------------------------------------------------------------- 1 | training/models/*model 2 | training/models_* 3 | training/training_files/*conllu 4 | training/training_fi.dockerfile 5 | training/training_se.dockerfile 6 | rest_server_fi.dockerfile 7 | rest_server_se.dockerfile 8 | work/ 9 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = UDPipe REST server Docker 2 | 3 | Docker container for UDPipe (https://github.com/ufal/udpipe) REST server. 4 | 5 | UDPipe is trainable pipeline for tokenizing, tagging, lemmatizing and parsing Universal Treebanks and other CoNLL-U files. 6 | 7 | == Usage 8 | 9 | To use UDPipe REST server Docker image, you need to: 10 | 11 | * Find a language model. 12 | ** Train it or get if from somewhere. 13 | * To train a modeL: 14 | ** Get a training file. For example, from https://github.com/UniversalDependencies/[Universal Dependencies]. 15 | ** Train UDPipe for the language. 16 | * Build Docker image with the language model. 17 | * Run Docker image. 18 | * Use it. 19 | 20 | Example how to use is described below. It shows how to train UDPipe for Finnish and create UDPipe REST server Docker image for Finnish. 21 | 22 | == Training 23 | 24 | Training needs some manual steps. 25 | 26 | . Download or clone this repository to your computer. 27 | . Create directory _training_files_ under _training_-directory. 28 | . Download Finnish training file https://github.com/UniversalDependencies/UD_Finnish-TDT/blob/master/fi_tdt-ud-train.conllu[fi_tdt-ud-train.conllu] to _training_files_-directory. 29 | ** GitHub repo of the file is: https://github.com/UniversalDependencies/UD_Finnish-TDT[UD_Finnish-TDT] 30 | . Copy _training/training_template.dockerfile_ to _training/training_fi.dockerfile_. 31 | . Find ENV-entries in the _training_fi.dockerfile_: 32 | ** Set training file name in _training_files_-directory. 33 | *** Finnish training file: _fi_tdt-ud-train.conllu_. 34 | ** Set model name. For example: _fi_20180111.model_. 35 | . Start training by executing docker build: 36 | ** Change to _training_-directory. 37 | ** `docker build -t training_fi -f training_fi.dockerfile .` 38 | . Wait... wait... wait for it... 39 | . Eventually, start the Docker-container: 40 | ** `docker run -it --rm -p 8000:8000 training_fi` 41 | . Use browser and go to http://127.0.0.1:8000[http://127.0.0.1:8000]. 42 | ** Download model file to _training/models_-directory. 43 | 44 | The next step is to build REST-server Docker image using the model file you just downloaded. 45 | 46 | == REST server 47 | 48 | During training, we trained the model file to be used with UDPipe REST server. Follow the instructions to build the actual REST server image. 49 | 50 | . Copy _rest_server_template.dockerfile_ to _rest_server_fi.dockerfile_. 51 | . Open _rest_server_fi.dockerfile_ and find ENV-entries 52 | ** change _MODEL_FILE_NAME_ to the model name from previous section 53 | *** For example: _fi_ 54 | ** change _MODEL_NAME_ and _MODEL_DESC_ to some descriptive name. 55 | *** For example: _finnish_model_20180112_ 56 | . Build Docker image: 57 | ** `docker build -t udpipe-rest-server-fi -f rest_server_fi.dockerfile .` 58 | . Run Docker image: 59 | ** `docker run -it --rm -p 8080:8080 -t udpipe-rest-server-fi` 60 | . Access and test using browser: 61 | ** http://127.0.0.1:8080/process?data=Hei%20maailma!Mitä%20kuuluu?&tokenizer&tagger&parser[http://127.0.0.1:8080/process?data=Hei%20maailma!Mitä%20kuuluu?&tokenizer&tagger&parser] 62 | 63 | http://ufal.mff.cuni.cz/udpipe/users-manual#udpipe_server[See also documentation about the REST server]. 64 | 65 | You can use curl to test: 66 | 67 | * `curl -F data=@data/text.txt -F tokenizer= -F tagger= -F parser= http://127.0.0.1:8080/process` 68 | 69 | To get CoNLL-U back, use this: 70 | 71 | * `curl -F data=@data/text.txt -F tokenizer= -F tagger= -F parser= http://127.0.0.1:8080/process | PYTHONIOENCODING=utf-8 python -c "import sys,json; sys.stdout.write(json.load(sys.stdin)['result'])"`` 72 | 73 | == Misc notes 74 | 75 | https://github.com/UniversalDependencies/[Universal Dependencies] includes quite many languages and each of them have training files. All of them can be used to build model for the UDPipe REST server. 76 | 77 | Many models can be included in single REST server Docker image. See http://ufal.mff.cuni.cz/udpipe/users-manual#udpipe_server[UDPipe docs] how to start server with many models and change Docker file accordingly. 78 | 79 | Pre-existing models can be also used. You can find some models from http://ufal.mff.cuni.cz/udpipe[UDPipe web site] licensed under the http://creativecommons.org/licenses/by-nc-sa/4.0/[CC-BY-SA]. 80 | 81 | == Disclaimer 82 | 83 | Everything in this repo, including all code is "AS IS". No support, no warranty, no fitness for any purpose, nothing is expressed or implied, not by me (nor my employer). 84 | 85 | == License 86 | 87 | I am not sure what license to apply, so I don't claim any licensing. 88 | 89 | If you want to know more and be sure, please seek legal advice. 90 | -------------------------------------------------------------------------------- /data/text.txt: -------------------------------------------------------------------------------- 1 | Turun yliopisto on suomalainen yliopisto, joka on opiskelijamäärältään Suomen toiseksi suurin yliopisto Helsingin yliopiston jälkeen. Vuonna 2009 yliopistossa opiskeli yhteensä 18 577 opiskelijaa, joista 2 325 suoritti tieteellistä jatkotutkintoa. Ylempiä korkea­koulu­tutkintoja suoritettiin 1 899 ja tohtorintutkintoja 133 kappaletta. Yliopiston palveluksessa työskentelee noin 3 000 henkilöä. Elokuussa 2012 yliopiston rehtoriksi valittiin Kalervo Väänänen. Yliopiston viimeisenä kanslerina ennen instituution lakkauttamista toimi vuosina 2010–2013 Pekka Puska. Yliopiston Turun kampus sijaitsee kaupungin keskustan alueella Yliopistonmäen läheisyydessä. Yliopisto toimii Turun lisäksi Raumalla (lastentarha-, luokanopettaja- ja käsityöopettajakoulutus) ja Porissa (kauppakorkeakoulu, kulttuurituotanto ja maisemantutkimus). Turkuun perustettiin jo vuonna 1640 yliopisto, Turun Akatemia, joka on nykyisen Helsingin yliopiston edeltäjä. Se oli kolmas Ruotsin valtakuntaan perustettu yliopisto ja Suomen ainoa. Turun palon jälkeen vuonna 1827 Akatemia siirrettiin Helsinkiin. Akatemian siirtämisen jälkeen yliopistollinen opetus Turussa loppui vuoteen 1917 asti. Turun Akatemian ajoista Turun yliopistolla muistuttavat nykyisin muun muassa Akatemiatalo ja yliopiston päärakennuksen vierellä sijaitseva Kolme vekkulia -niminen monumentti, joka esittää vuonna 1822 Turun Akatemiassa opintonsa aloittaneita J. V. Snellmania, Elias Lönnrotia ja J. L. Runebergia. -------------------------------------------------------------------------------- /data/text2.txt: -------------------------------------------------------------------------------- 1 | Vierailin ystävän luona. -------------------------------------------------------------------------------- /data/text3.txt: -------------------------------------------------------------------------------- 1 | Valtioneuvostolla tarkoitetaan toisaalta pääministerin ja ministereiden muodostamaa yleistä hallintovaltaa käyttävää toimielintä, ja toisaalta valtioneuvoston yleisistunnon ja ministeriöiden muodostamaa hallitus- ja hallintoasioiden päätöksentekoelintä. 2 | 3 | Valtioneuvostossa on nykyisin 12 ministeriötä. Kukin ministeriö vastaa toimialallaan valtioneuvostolle kuuluvien asioiden valmistelusta ja hallinnon asianmukaisesta toiminnasta. 4 | 5 | Valtioneuvoston yleisistunnossa asioiden käsittelyä johtaa pääministeri. Pääministeri on myös lakisääteisten ministerivaliokuntien puheenjohtaja. 6 | Valtioneuvoston toiminta 7 | Valtioneuvoston ohjesääntö - Finlex 8 | Valtioneuvoston kanslia 9 | 10 | Valtioneuvoston kanslia on pääministerin johtama ministeriö, joka vastaa hallitusohjelman toimeenpanon valvonnasta ja avustaa pääministeriä valtioneuvoston johtamisessa. Kanslia turvaa pääministerin ja hallituksen toimintaedellytykset kaikissa olosuhteissa. 11 | 12 | Ministeriön tehtäviin kuuluvat Suomen EU-politiikan yhteensovittaminen sekä valtion omistajapolitiikka ja valtioneuvoston kanslian alaisten valtio-omisteisten yhtiöiden omistajaohjaus. Sille kuuluvat valtioneuvoston viestintä ja valtionhallinnon viestinnän yhteensovittaminen sekä valtioneuvoston yhteinen tilannekuva, varautuminen ja turvallisuus sekä häiriötilanteiden hallinnan yleinen yhteensovittaminen. Kanslian uusimpiin tehtäviin kuuluu valtion sektoritutkimuksen tavoitteiden yhteensovittaminen päätöksenteon tueksi. 13 | vnk.fi -------------------------------------------------------------------------------- /rest_server_template.dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN apt-get update 4 | RUN apt-get -y install gcc clang build-essential wget unzip 5 | 6 | #get udpipe code 7 | WORKDIR /udpipe 8 | #RUN git clone https://github.com/ufal/udpipe.git 9 | RUN wget -q https://github.com/ufal/udpipe/archive/master.zip 10 | RUN unzip -q master.zip 11 | WORKDIR /udpipe/udpipe-master/src 12 | 13 | #make udpipe server 14 | RUN make server 15 | 16 | #set your model file name is like: fi_20180811.model 17 | #this model have been trained and it is in training/models directory 18 | ENV MODEL_FILE_NAME 19 | #set model name. UDPipe REST server shows this name 20 | #for example: fi 21 | ENV MODEL_NAME 22 | #model description is something that REST servers shows 23 | ENV MODEL_DESC 24 | 25 | WORKDIR /udpipe/udpipe-master/src/rest_server 26 | 27 | #add the model 28 | ADD training/models/${MODEL_FILE_NAME} . 29 | 30 | EXPOSE 8080 31 | #start udpipe REST server 32 | #using custom model 33 | CMD ./udpipe_server 8080 ${MODEL_NAME} ${MODEL_NAME} ./${MODEL_FILE_NAME} "${MODEL_DESC}" 34 | 35 | #CMD ["/bin/bash"] 36 | 37 | -------------------------------------------------------------------------------- /training/models/placeholder.txt: -------------------------------------------------------------------------------- 1 | Language models here. 2 | -------------------------------------------------------------------------------- /training/training_files/placeholder.txt: -------------------------------------------------------------------------------- 1 | Copy CoNLL-U formatted training files here. 2 | 3 | Get training files from https://github.com/UniversalDependencies. 4 | -------------------------------------------------------------------------------- /training/training_template.dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN apt-get update 4 | RUN apt-get -y install gcc clang build-essential wget unzip python 5 | 6 | #get udpipe code 7 | WORKDIR /udpipe 8 | #RUN git clone https://github.com/ufal/udpipe.git 9 | RUN wget -q https://github.com/ufal/udpipe/archive/master.zip 10 | RUN unzip -q master.zip 11 | WORKDIR /udpipe/udpipe-master/src 12 | 13 | #make udpipe 14 | RUN make 15 | 16 | ENV TRAINING_MODEL_FILE_NAME 17 | #set your model name is like: fi_20180811.model 18 | ENV MODEL_FILE_NAME 19 | 20 | #add training model 21 | ADD training_files/${TRAINING_MODEL_FILE_NAME} . 22 | 23 | #train udpipe, this will take time 24 | RUN ./udpipe --train ${MODEL_FILE_NAME} ${TRAINING_MODEL_FILE_NAME} 25 | 26 | #web server to download model 27 | RUN mkdir models 28 | RUN cp ${MODEL_FILE_NAME} ./models 29 | WORKDIR /udpipe/udpipe-master/src/models 30 | EXPOSE 8000 31 | CMD python -m SimpleHTTPServer 32 | #CMD ["/bin/bash"] 33 | 34 | --------------------------------------------------------------------------------